Skip to content

Commit

Permalink
Fix safari history import
Browse files Browse the repository at this point in the history
Makes all supported import service available always.
  • Loading branch information
simonhong committed Oct 12, 2020
1 parent 0281499 commit f42f9b0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
13 changes: 10 additions & 3 deletions chromium_src/chrome/common/importer/safari_importer_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
* 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/. */

#define SafariImporterCanImport SafariImporterCanImport_ChromiumImpl
#define SafariImporterCanImport SafariImporterCanImport_Chromium_Unused

#include "../../../../../chrome/common/importer/safari_importer_utils.mm"

#undef SafariImporterCanImport

// Upstream only shows supported list when browser can access to bookmarks.
// But, we let users know about disk access permission is needed when user
// select any services and we don't have proper access permission about it.
// So, we displays all supported services always.
bool SafariImporterCanImport(const base::FilePath& library_dir,
uint16_t* services_supported) {
SafariImporterCanImport_ChromiumImpl(library_dir, services_supported);
base::FilePath safari_dir = library_dir.Append("Safari");

if (base::PathExists(library_dir.Append("Safari").Append("History.db")))
if (base::PathExists(safari_dir.Append("Bookmarks.plist")))
*services_supported |= importer::FAVORITES;

if (base::PathExists(safari_dir.Append("History.db")))
*services_supported |= importer::HISTORY;

return *services_supported != importer::NONE;
Expand Down
5 changes: 2 additions & 3 deletions chromium_src/chrome/utility/importer/safari_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#define BRAVE_CHROMIUM_SRC_CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_

#define BRAVE_SAFARI_IMPORTER_H \
friend class BraveSafariImporter;

#define ImportHistory virtual ImportHistory
friend class BraveSafariImporter; \
virtual void ImportHistory() {}

#include "../../../../../chrome/utility/importer/safari_importer.h"

Expand Down
18 changes: 18 additions & 0 deletions chromium_src/chrome/utility/importer/safari_importer.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright 2020 The Brave Authors. All rights reserved.
* 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/. */

// Can't avoid this injection because this code should be surrounded by
// ImporterBridge::NotifyStarted() and NotifyEnded() with other import logic.
#define BRAVE_START_IMPORT \
if ((items & importer::HISTORY) && !cancelled()) { \
bridge_->NotifyItemStarted(importer::HISTORY); \
ImportHistory(); \
bridge_->NotifyItemEnded(importer::HISTORY); \
}

#include "../../../../../chrome/utility/importer/safari_importer.mm"

#undef BRAVE_START_IMPORT

12 changes: 12 additions & 0 deletions patches/chrome-utility-importer-safari_importer.mm.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/utility/importer/safari_importer.mm b/chrome/utility/importer/safari_importer.mm
index a83d19200f9b73f3adb22db0005891ab80d3dc80..7943f958997afe14390df7ceb77e95ade3385b5d 100644
--- a/chrome/utility/importer/safari_importer.mm
+++ b/chrome/utility/importer/safari_importer.mm
@@ -47,6 +47,7 @@ void SafariImporter::StartImport(const importer::SourceProfile& source_profile,
ImportBookmarks();
bridge_->NotifyItemEnded(importer::FAVORITES);
}
+ BRAVE_START_IMPORT

bridge_->NotifyEnded();
}
1 change: 0 additions & 1 deletion utility/importer/brave_safari_importer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
NSString* history_db = [safari_dir
stringByAppendingPathComponent:@"History.db"];

// Import favicons.
sql::Database db;
const char* db_path = [history_db fileSystemRepresentation];
if (!db.Open(base::FilePath(db_path)))
Expand Down

0 comments on commit f42f9b0

Please sign in to comment.