-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Import History from Safari""
This reverts commit c65b0fd.
- Loading branch information
Showing
9 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
chromium_src/chrome/common/importer/safari_importer_utils.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 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/. */ | ||
|
||
#define SafariImporterCanImport SafariImporterCanImport_ChromiumImpl | ||
|
||
#include "../../../../../chrome/common/importer/safari_importer_utils.mm" | ||
|
||
#undef SafariImporterCanImport | ||
|
||
bool SafariImporterCanImport(const base::FilePath& library_dir, | ||
uint16_t* services_supported) { | ||
SafariImporterCanImport_ChromiumImpl(library_dir, services_supported); | ||
|
||
if (base::PathExists(library_dir.Append("Safari").Append("History.db"))) | ||
*services_supported |= importer::HISTORY; | ||
|
||
return *services_supported != importer::NONE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Copyright 2019 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/. */ | ||
|
||
#include "brave/utility/importer/brave_safari_importer.h" | ||
|
||
#define SafariImporter BraveSafariImporter | ||
#include "../../../../../chrome/utility/importer/importer_creator.cc" | ||
#undef SafariImporter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* 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/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_ | ||
#define BRAVE_CHROMIUM_SRC_CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_ | ||
|
||
#define BRAVE_SAFARI_IMPORTER_H \ | ||
friend class BraveSafariImporter; | ||
|
||
#define ImportHistory virtual ImportHistory | ||
|
||
#include "../../../../../chrome/utility/importer/safari_importer.h" | ||
|
||
#undef BRAVE_SAFARI_IMPORTER_H | ||
#undef ImportHistory | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_CHROME_UTILITY_IMPORTER_SAFARI_IMPORTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/chrome/utility/importer/safari_importer.h b/chrome/utility/importer/safari_importer.h | ||
index 1891fa3eff16f4e7b8f0821bc9f793c5e00514f7..89bce81bbc3d2f682adb3aacd888ac29f6d06e74 100644 | ||
--- a/chrome/utility/importer/safari_importer.h | ||
+++ b/chrome/utility/importer/safari_importer.h | ||
@@ -46,6 +46,7 @@ class SafariImporter : public Importer { | ||
uint16_t items, | ||
ImporterBridge* bridge) override; | ||
|
||
+ BRAVE_SAFARI_IMPORTER_H | ||
private: | ||
FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, BookmarkImport); | ||
FRIEND_TEST_ALL_PREFIXES(SafariImporterTest, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* 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/. */ | ||
|
||
#ifndef BRAVE_UTILITY_IMPORTER_BRAVE_SAFARI_IMPORTER_H_ | ||
#define BRAVE_UTILITY_IMPORTER_BRAVE_SAFARI_IMPORTER_H_ | ||
|
||
#include "chrome/utility/importer/safari_importer.h" | ||
|
||
class BraveSafariImporter : public SafariImporter { | ||
public: | ||
using SafariImporter::SafariImporter; | ||
|
||
BraveSafariImporter(const BraveSafariImporter&) = delete; | ||
BraveSafariImporter& operator=(const BraveSafariImporter&) = delete; | ||
|
||
private: | ||
// SafariImporter overrides: | ||
void ImportHistory() override; | ||
|
||
~BraveSafariImporter() override; | ||
}; | ||
|
||
#endif // BRAVE_UTILITY_IMPORTER_BRAVE_SAFARI_IMPORTER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* 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/. */ | ||
|
||
#include <Cocoa/Cocoa.h> | ||
|
||
#include "brave/utility/importer/brave_safari_importer.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/files/file_path.h" | ||
#include "base/files/file_util.h" | ||
#include "base/strings/utf_string_conversions.h" | ||
#include "base/time/time.h" | ||
#include "chrome/common/importer/importer_bridge.h" | ||
#include "chrome/common/importer/importer_url_row.h" | ||
#include "sql/statement.h" | ||
#include "url/gurl.h" | ||
|
||
BraveSafariImporter::~BraveSafariImporter() = default; | ||
|
||
void BraveSafariImporter::ImportHistory() { | ||
// For importing history from History.plist. | ||
SafariImporter::ImportHistory(); | ||
|
||
// From now, try to import history from History.db. | ||
NSString* library_dir = [NSString | ||
stringWithUTF8String:library_dir_.value().c_str()]; | ||
NSString* safari_dir = [library_dir | ||
stringByAppendingPathComponent:@"Safari"]; | ||
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))) | ||
return; | ||
|
||
std::vector<ImporterURLRow> rows; | ||
const char query[] = "SELECT hi.url, hi.visit_count, hv.visit_time, hv.title " | ||
"FROM history_items as hi " | ||
"JOIN history_visits as hv ON hi.id == hv.history_item"; | ||
sql::Statement s(db.GetUniqueStatement(query)); | ||
while (s.Step() && !cancelled()) { | ||
const GURL url = GURL(s.ColumnString(0)); | ||
if (!url.is_valid()) | ||
continue; | ||
|
||
ImporterURLRow row(url); | ||
row.visit_count = s.ColumnInt(1); | ||
double visit_time = s.ColumnDouble(2); | ||
if (!visit_time) | ||
continue; | ||
row.last_visit = | ||
base::Time::FromDoubleT(visit_time + kCFAbsoluteTimeIntervalSince1970); | ||
std::string title = s.ColumnString(3); | ||
if (title.empty()) | ||
title = url.spec(); | ||
row.title = base::UTF8ToUTF16(title); | ||
row.hidden = 0; | ||
row.typed_count = 0; | ||
rows.push_back(row); | ||
} | ||
|
||
if (!rows.empty() && !cancelled()) { | ||
bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_SAFARI_IMPORTED); | ||
} | ||
} |