Skip to content

Commit

Permalink
Fix cookies are not imported from Chrome
Browse files Browse the repository at this point in the history
Since the V11 cookies db schema, firstpartyonly column is renamed to samesite.
Also, BraveImporter and ChromeImporter should have different cookies query
string because muon uses old schema.
  • Loading branch information
simonhong committed Oct 29, 2019
1 parent 664709f commit bc513db
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
Binary file modified test/data/import/chrome/default/Cookies
Binary file not shown.
14 changes: 14 additions & 0 deletions utility/importer/brave_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

using base::Time;

namespace {
// This query is different from chrome's one.
// Chrome renamed firstpartyonly column to samesite since its V11 schema.
// But, muon still uses firstpartyonly.
const char kCookiesQueryString[] =
"SELECT creation_utc, host_key, name, value, encrypted_value, path, "
"expires_utc, is_secure, is_httponly, firstpartyonly, last_access_utc, "
"has_expires, is_persistent, priority FROM cookies";
} // namespace

BraveImporter::BraveImporter() {
}

Expand Down Expand Up @@ -166,6 +176,10 @@ void BraveImporter::ImportHistory() {
bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_BRAVE_IMPORTED);
}

const char* BraveImporter::GetCookiesQueryString() const {
return kCookiesQueryString;
}

void BraveImporter::ParseBookmarks(
std::vector<ImportedBookmarkEntry>* bookmarks) {
base::Optional<base::Value> session_store_json = ParseBraveStateFile(
Expand Down
1 change: 1 addition & 0 deletions utility/importer/brave_importer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class BraveImporter : public ChromeImporter {

void ImportBookmarks() override;
void ImportHistory() override;
const char* GetCookiesQueryString() const override;
void ImportStats();
bool ImportLedger();
void ImportWindows();
Expand Down
18 changes: 12 additions & 6 deletions utility/importer/chrome_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@

using base::Time;

namespace {
const char kCookiesQueryString[] =
"SELECT creation_utc, host_key, name, value, encrypted_value, path, "
"expires_utc, is_secure, is_httponly, samesite, last_access_utc, "
"has_expires, is_persistent, priority FROM cookies";
} // namespace

ChromeImporter::ChromeImporter() {
}

Expand Down Expand Up @@ -337,6 +344,10 @@ void ChromeImporter::ImportPasswords(const base::FilePath& prefs_filename) {
}
}

const char* ChromeImporter::GetCookiesQueryString() const {
return kCookiesQueryString;
}

void ChromeImporter::ImportCookies() {
base::FilePath cookies_path =
source_path_.Append(
Expand All @@ -348,12 +359,7 @@ void ChromeImporter::ImportCookies() {
if (!db.Open(cookies_path))
return;

const char query[] =
"SELECT creation_utc, host_key, name, value, encrypted_value, path, "
"expires_utc, is_secure, is_httponly, firstpartyonly, last_access_utc, "
"has_expires, is_persistent, priority FROM cookies";

sql::Statement s(db.GetUniqueStatement(query));
sql::Statement s(db.GetUniqueStatement(GetCookiesQueryString()));

net::CookieCryptoDelegate* delegate =
cookie_config::GetCookieCryptoDelegate();
Expand Down
4 changes: 3 additions & 1 deletion utility/importer/chrome_importer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright (c) 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/. */

Expand Down Expand Up @@ -47,6 +48,7 @@ class ChromeImporter : public Importer {
virtual void ImportHistory();
virtual void ImportPasswords(const base::FilePath& prefs_filename);
virtual void ImportCookies();
virtual const char* GetCookiesQueryString() const;

double chromeTimeToDouble(int64_t time);

Expand Down

0 comments on commit bc513db

Please sign in to comment.