Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import history, bookmarks, cookies, and passwords from Brave #185

Merged
merged 9 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@

By installing this extension, you are agreeing to the Google Widevine Terms of Use. You agree that Brave is not responsible for any damages or losses in connection with your use of Google Widevine.
</message>
<!-- Brave Importer -->
<message name="IDS_IMPORT_FROM_BRAVE" desc="browser combo box: Brave">
Brave
</message>
<message name="IDS_BOOKMARK_GROUP_FROM_BRAVE" desc="The group name of bookmarks from Brave">
Imported From Brave
</message>
</messages>
<includes>
<include name="IDR_BRAVE_TAG_SERVICES_POLYFILL" file="resources/js/tag_services_polyfill.js" type="BINDATA" />
Expand Down
84 changes: 84 additions & 0 deletions chromium_src/chrome/browser/importer/importer_list.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "../../../../../chrome/browser/importer/importer_list.cc"

#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "brave/common/importer/brave_importer_utils.h"
#include "brave/common/importer/chrome_importer_utils.h"
#include "chrome/grit/generated_resources.h"

void AddChromeToProfiles(std::vector<importer::SourceProfile>* profiles,
base::ListValue* chrome_profiles,
base::FilePath& user_data_folder,
std::string& brand) {
for (const auto& value : *chrome_profiles) {
const base::DictionaryValue* dict;
if (!value.GetAsDictionary(&dict))
continue;
uint16_t items = importer::NONE;
std::string profile;
std::string name;
dict->GetString("id", &profile);
dict->GetString("name", &name);
if (!ChromeImporterCanImport(user_data_folder.Append(
base::FilePath::StringType(profile.begin(), profile.end())), &items))
continue;
importer::SourceProfile chrome;
std::string importer_name(brand);
importer_name.append(name);
chrome.importer_name = base::UTF8ToUTF16(importer_name);
chrome.importer_type = importer::TYPE_CHROME;
chrome.services_supported = items;
chrome.source_path =
user_data_folder.Append(
base::FilePath::StringType(profile.begin(), profile.end()));
profiles->push_back(chrome);
}
delete chrome_profiles;
}

void DetectChromeProfiles(std::vector<importer::SourceProfile>* profiles) {
base::AssertBlockingAllowed();

base::FilePath chrome_user_data_folder = GetChromeUserDataFolder();
base::ListValue* chrome_profiles = GetChromeSourceProfiles(chrome_user_data_folder);
std::string brand_chrome("Chrome ");
AddChromeToProfiles(profiles, chrome_profiles, chrome_user_data_folder, brand_chrome);

#if !defined(OS_LINUX)
base::FilePath canary_user_data_folder = GetCanaryUserDataFolder();
base::ListValue* canary_profiles =
GetChromeSourceProfiles(canary_user_data_folder);
std::string brandCanary("Chrome Canary ");
AddChromeToProfiles(profiles, canary_profiles, canary_user_data_folder,
brandCanary);
#endif

base::FilePath chromium_user_data_folder = GetChromiumUserDataFolder();
base::ListValue* chromium_profiles =
GetChromeSourceProfiles(chromium_user_data_folder);
std::string brandChromium("Chromium ");
AddChromeToProfiles(profiles, chromium_profiles, chromium_user_data_folder,
brandChromium);
}

void DetectBraveProfiles(std::vector<importer::SourceProfile>* profiles) {
base::AssertBlockingAllowed();

base::FilePath brave_user_data_folder = GetBraveUserDataFolder();

uint16_t items = importer::NONE;
if (!BraveImporterCanImport(brave_user_data_folder, &items))
return;

importer::SourceProfile brave;
brave.importer_name =
l10n_util::GetStringUTF16(IDS_IMPORT_FROM_BRAVE);
brave.importer_type = importer::TYPE_BRAVE;
brave.services_supported = items;
brave.source_path = brave_user_data_folder;
profiles->push_back(brave);
}
5 changes: 5 additions & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ source_set("common") {
"extensions/extension_constants.h",
"extensions/manifest_handlers/pdfjs_manifest_override.cc",
"extensions/manifest_handlers/pdfjs_manifest_override.h",
"importer/brave_importer_utils.cc",
"importer/brave_importer_utils.h",
"importer/chrome_importer_utils.cc",
"importer/chrome_importer_utils.h",
"network_constants.cc",
Expand All @@ -33,6 +35,7 @@ source_set("common") {

if (is_mac) {
sources += [
"importer/brave_importer_utils_mac.mm",
"importer/chrome_importer_utils_mac.mm",
]
}
Expand All @@ -41,6 +44,7 @@ source_set("common") {
sources += [
"brave_channel_info_posix.cc",
"brave_channel_info_posix.h",
"importer/brave_importer_utils_linux.cc",
"importer/chrome_importer_utils_linux.cc",
]

Expand All @@ -51,6 +55,7 @@ source_set("common") {

if (is_win) {
sources += [
"importer/brave_importer_utils_win.cc",
"importer/chrome_importer_utils_win.cc",
]
}
Expand Down
39 changes: 39 additions & 0 deletions common/importer/brave_importer_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/common/importer/brave_importer_utils.h"

#include <memory>
#include <string>

#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/values.h"
#include "chrome/common/importer/importer_data_types.h"

bool BraveImporterCanImport(const base::FilePath& profile,
uint16_t* services_supported) {
DCHECK(services_supported);
*services_supported = importer::NONE;

base::FilePath history =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("History")));
base::FilePath session_store =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("session-store-1")));
base::FilePath passwords =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Login Data")));
base::FilePath cookies =
profile.Append(base::FilePath::StringType(FILE_PATH_LITERAL("Cookies")));

if (base::PathExists(history))
*services_supported |= importer::HISTORY;
if (base::PathExists(session_store))
*services_supported |= importer::FAVORITES;
if (base::PathExists(passwords))
*services_supported |= importer::PASSWORDS;
if (base::PathExists(cookies))
*services_supported |= importer::COOKIES;

return *services_supported != importer::NONE;
}
26 changes: 26 additions & 0 deletions common/importer/brave_importer_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMMON_IMPORTER_BRAVE_IMPORTER_UTILS_H_
#define BRAVE_COMMON_IMPORTER_BRAVE_IMPORTER_UTILS_H_

#include <stdint.h>

#include <vector>

namespace base {
class DictionaryValue;
class FilePath;
class ListValue;
}

base::FilePath GetBraveUserDataFolder();

base::ListValue* GetBraveSourceProfiles(
const base::FilePath& user_data_folder);

bool BraveImporterCanImport(const base::FilePath& profile,
uint16_t* services_supported);

#endif // BRAVE_COMMON_IMPORTER_BRAVE_IMPORTER_UTILS_H_
25 changes: 25 additions & 0 deletions common/importer/brave_importer_utils_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/common/importer/brave_importer_utils.h"

#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"

base::FilePath GetBraveUserDataFolder() {
base::FilePath home;
if (!PathService::Get(base::DIR_HOME, &home))
return base::FilePath();

base::FilePath result = home;

// If Brave is installed via Snap, use the sandboxed home directory.
if (base::PathExists(base::FilePath("/snap/bin/brave"))) {
result = result.Append("snap").Append("brave").Append("current");
}

return result.Append(".config").Append("brave");
}
16 changes: 16 additions & 0 deletions common/importer/brave_importer_utils_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <Cocoa/Cocoa.h>
#include <sys/param.h>

#include "brave/common/importer/brave_importer_utils.h"

#include "base/files/file_util.h"
#include "base/mac/foundation_util.h"

base::FilePath GetBraveUserDataFolder() {
base::FilePath result = base::mac::GetUserLibraryPath();
return result.Append("Application Support").Append("brave");
}
19 changes: 19 additions & 0 deletions common/importer/brave_importer_utils_win.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/common/importer/brave_importer_utils.h"

#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/strings/string16.h"

base::FilePath GetBraveUserDataFolder() {
base::FilePath result;
if (!PathService::Get(base::DIR_APP_DATA, &result))
return base::FilePath();

result = result.AppendASCII("brave");

return result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc
index 429c16dc6a56fcd0ea1d674508c1927a387e1905..433083d6802bea4213343a9315a496d9f5cb78e5 100644
--- a/chrome/browser/importer/external_process_importer_client.cc
+++ b/chrome/browser/importer/external_process_importer_client.cc
@@ -71,6 +71,12 @@ void ExternalProcessImporterClient::Start() {
localized_strings.SetKey(
base::IntToString(IDS_BOOKMARK_BAR_FOLDER_NAME),
base::Value(l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_FOLDER_NAME)));
+ localized_strings.SetKey(
+ base::IntToString(IDS_IMPORT_FROM_BRAVE),
+ base::Value(l10n_util::GetStringUTF8(IDS_IMPORT_FROM_BRAVE)));
+ localized_strings.SetKey(
+ base::IntToString(IDS_BOOKMARK_GROUP_FROM_BRAVE),
+ base::Value(l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_BRAVE)));

// If the utility process hasn't started yet the message will queue until it
// does.
Loading