Skip to content
This repository was archived by the owner on Jan 4, 2019. It is now read-only.

Commit 8d5a1de

Browse files
committed
Fix broken import cookies
fix brave/browser-laptop#8849 Auditors: @bridiver, @bbondy
1 parent 14d24b4 commit 8d5a1de

8 files changed

+81
-12
lines changed

atom/browser/api/atom_api_importer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "base/strings/utf_string_conversions.h"
1919
#include "base/threading/thread_task_runner_handle.h"
2020
#include "brave/browser/brave_content_browser_client.h"
21-
#include "chrome/browser/importer/external_process_importer_host.h"
21+
#include "brave/browser/importer/brave_external_process_importer_host.h"
2222
#include "chrome/browser/importer/importer_list.h"
2323
#include "content/public/browser/browser_thread.h"
2424
#include "native_mate/dictionary.h"
@@ -121,7 +121,7 @@ void Importer::StartImport(
121121

122122
import_did_succeed_ = false;
123123

124-
importer_host_ = new ExternalProcessImporterHost();
124+
importer_host_ = new BraveExternalProcessImporterHost();
125125
importer_host_->set_observer(this);
126126
importer_host_->StartImportSettings(source_profile, NULL,
127127
imported_items,

brave/browser/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ source_set("browser") {
3232
"brave_javascript_dialog_manager.cc",
3333
"brave_permission_manager.h",
3434
"brave_permission_manager.cc",
35+
"importer/brave_external_process_importer_host.cc",
36+
"importer/brave_external_process_importer_host.h",
3537
"password_manager/brave_credentials_filter.h",
3638
"password_manager/brave_credentials_filter.cc",
3739
"password_manager/brave_password_manager_client.h",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2017 The Brave Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "brave/browser/importer/brave_external_process_importer_host.h"
6+
7+
#include "atom/browser/importer/external_process_importer_client.h"
8+
#include "atom/browser/importer/in_process_importer_bridge.h"
9+
10+
BraveExternalProcessImporterHost::BraveExternalProcessImporterHost()
11+
: ExternalProcessImporterHost() {}
12+
13+
void BraveExternalProcessImporterHost::LaunchImportIfReady() {
14+
if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() ||
15+
!is_source_readable_ || cancelled_)
16+
return;
17+
18+
// This is the in-process half of the bridge, which catches data from the IPC
19+
// pipe and feeds it to the ProfileWriter. The external process half of the
20+
// bridge lives in the external process (see ProfileImportThread).
21+
// The ExternalProcessImporterClient created in the next line owns the bridge,
22+
// and will delete it.
23+
atom::InProcessImporterBridge* bridge =
24+
new atom::InProcessImporterBridge(writer_.get(),
25+
weak_ptr_factory_.GetWeakPtr());
26+
client_ = new atom::ExternalProcessImporterClient(
27+
weak_ptr_factory_.GetWeakPtr(), source_profile_, items_, bridge);
28+
client_->Start();
29+
}
30+
31+
BraveExternalProcessImporterHost::~BraveExternalProcessImporterHost() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2017 The Brave Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_
6+
#define BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_
7+
8+
#include "chrome/browser/importer/external_process_importer_host.h"
9+
10+
class BraveExternalProcessImporterHost : public ExternalProcessImporterHost {
11+
public:
12+
BraveExternalProcessImporterHost();
13+
14+
private:
15+
~BraveExternalProcessImporterHost() override;
16+
17+
// Launches the utility process that starts the import task, unless bookmark
18+
// or template model are not yet loaded. If load is not detected, this method
19+
// will be called when the loading observer sees that model loading is
20+
// complete.
21+
void LaunchImportIfReady() override;
22+
23+
DISALLOW_COPY_AND_ASSIGN(BraveExternalProcessImporterHost);
24+
};
25+
26+
#endif // BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_

brave/utility/importer/chrome_importer.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <memory>
88
#include <string>
99

10-
#include "atom/browser/importer/in_process_importer_bridge.h"
10+
#include "brave/utility/importer/brave_external_process_importer_bridge.h"
1111
#include "base/files/file_util.h"
1212
#include "base/json/json_reader.h"
1313
#include "base/macros.h"
@@ -246,7 +246,7 @@ void ChromeImporter::ImportCookies() {
246246
}
247247

248248
if (!cookies.empty() && !cancelled())
249-
static_cast<atom::InProcessImporterBridge*>(bridge_.get())->
249+
static_cast<BraveExternalProcessImporterBridge*>(bridge_.get())->
250250
SetCookies(cookies);
251251
}
252252

brave/utility/importer/firefox_importer.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <vector>
88

9-
#include "atom/browser/importer/in_process_importer_bridge.h"
9+
#include "brave/utility/importer/brave_external_process_importer_bridge.h"
1010
#include "base/files/file_enumerator.h"
1111
#include "base/files/file_util.h"
1212
#include "base/macros.h"
@@ -33,15 +33,12 @@ void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile,
3333

3434
bridge_ = bridge;
3535
source_path_ = source_profile.source_path;
36-
37-
bridge_->NotifyStarted();
3836
if ((items & importer::COOKIES) && !cancelled()) {
3937
bridge_->NotifyItemStarted(importer::COOKIES);
4038
ImportCookies();
4139
bridge_->NotifyItemEnded(importer::COOKIES);
4240
}
4341
bridge_->NotifyEnded();
44-
bridge_->NotifyEnded();
4542
}
4643

4744

@@ -86,7 +83,7 @@ void FirefoxImporter::ImportCookies() {
8683
}
8784

8885
if (!cookies.empty() && !cancelled())
89-
static_cast<atom::InProcessImporterBridge*>(bridge_.get())->
86+
static_cast<BraveExternalProcessImporterBridge*>(bridge_.get())->
9087
SetCookies(cookies);
9188
}
9289

brave/utility/importer/importer_creator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ scoped_refptr<Importer> CreateImporterByType(importer::ImporterType type) {
3939
case importer::TYPE_BOOKMARKS_FILE:
4040
return new BookmarksFileImporter();
4141
case importer::TYPE_FIREFOX:
42-
return new FirefoxImporter();
42+
return new brave::FirefoxImporter();
4343
#if defined(OS_MACOSX)
4444
case importer::TYPE_SAFARI:
4545
return new SafariImporter(base::mac::GetUserLibraryPath());

patches/master_patch.patch

+15-2
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,17 @@ index edf5cc054ac3c703cc049509aed223313a875001..6c5f76eb7f8082afa02f6d0721efa3dc
121121
const importer::ImporterIE7PasswordInfo& importer_password_info) override;
122122

123123
diff --git a/chrome/browser/importer/external_process_importer_host.h b/chrome/browser/importer/external_process_importer_host.h
124-
index 08c6f28746cc5f345114a942834db18f5c7a1d41..45b3b8072cc352d3fc2824489b2b59a2cee38ec3 100644
124+
index 08c6f28746cc5f345114a942834db18f5c7a1d41..3a43ae76f054ba449e3b892ea752c62fdad2e5a3 100644
125125
--- a/chrome/browser/importer/external_process_importer_host.h
126126
+++ b/chrome/browser/importer/external_process_importer_host.h
127-
@@ -74,7 +74,9 @@ class ExternalProcessImporterHost
127+
@@ -74,7 +74,10 @@ class ExternalProcessImporterHost
128128

129129
private:
130130
// ExternalProcessImporterHost deletes itself in OnImportEnded().
131131
+ protected:
132132
~ExternalProcessImporterHost() override;
133133
+ private:
134+
+ friend class BraveExternalProcessImporterHost;
134135

135136
// Launches the utility process that starts the import task, unless bookmark
136137
// or template model are not yet loaded. If load is not detected, this method
@@ -831,6 +832,18 @@ index 7e05c4e04f8e61b418d373a73bd8901347df4c76..e7e6d9fa5e0d54c7755fe3a38eca6f70
831832

832833
// Holds strings needed by the external importer because the resource
833834
// bundle isn't available to the external process.
835+
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc
836+
index 7f8d598bca0243e62f11d5d2ce50d8c25ba88764..d198d90e8872eb1d7a371aeaca6119c73a6cda1c 100644
837+
--- a/chrome/utility/importer/firefox_importer.cc
838+
+++ b/chrome/utility/importer/firefox_importer.cc
839+
@@ -147,7 +147,6 @@ void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile,
840+
ImportAutofillFormData();
841+
bridge_->NotifyItemEnded(importer::AUTOFILL_FORM_DATA);
842+
}
843+
- bridge_->NotifyEnded();
844+
}
845+
846+
void FirefoxImporter::ImportHistory() {
834847
diff --git a/chrome/utility/importer/firefox_importer.h b/chrome/utility/importer/firefox_importer.h
835848
index c3f648f165483a2d618438c1a4ef1b35ad6fb10c..3c95e1256465b7b6a009d3bf7619c8f48e2d3d94 100644
836849
--- a/chrome/utility/importer/firefox_importer.h

0 commit comments

Comments
 (0)