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

Commit b34d1c3

Browse files
darkdhkevinlawler
authored andcommitted
Add chrome.cookies.{getAll, set, get} for Pinterest Save Button extension
brave/browser-laptop#6366 brave/browser-laptop#6262 brave/browser-laptop#8389 Pinterest extension public key and string Fix broken import cookies fix brave/browser-laptop#8849 Auditors: @bridiver, @bbondy
1 parent 1b4abcb commit b34d1c3

14 files changed

+193
-15
lines changed

atom/browser/api/atom_api_cookies.cc

+9-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ Cookies::Cookies(v8::Isolate* isolate,
215215
Cookies::~Cookies() {
216216
}
217217

218+
void Cookies::GetAll(const base::DictionaryValue& filter,
219+
const GetCallback& callback) {
220+
Cookies::Get(filter, callback);
221+
}
222+
218223
void Cookies::Get(const base::DictionaryValue& filter,
219224
const GetCallback& callback) {
220225
std::unique_ptr<base::DictionaryValue> copied(filter.CreateDeepCopy());
@@ -255,9 +260,12 @@ void Cookies::BuildPrototype(v8::Isolate* isolate,
255260
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
256261
.SetMethod("get", &Cookies::Get)
257262
.SetMethod("remove", &Cookies::Remove)
258-
.SetMethod("set", &Cookies::Set);
263+
.SetMethod("set", &Cookies::Set)
264+
.SetMethod("getAll", &Cookies::GetAll);
259265
}
260266

261267
} // namespace api
262268

263269
} // namespace atom
270+
271+

atom/browser/api/atom_api_cookies.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
4747
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
4848
~Cookies() override;
4949

50+
void GetAll(const base::DictionaryValue& filter, const GetCallback& callback);
5051
void Get(const base::DictionaryValue& filter, const GetCallback& callback);
5152
void Remove(const GURL& url, const std::string& name,
5253
const base::Closure& callback);

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,

atom/common/api/resources/cookies_bindings.js

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
var binding = require('binding').Binding.create('cookies')
2+
var ipc = require('ipc_utils')
3+
var lastError = require('lastError')
24

35
binding.registerCustomHook(function (bindingsAPI, extensionId) {
46
var apiFunctions = bindingsAPI.apiFunctions
57
// var cookies = bindingsAPI.compiledApi
68

79
apiFunctions.setHandleRequest('getAll', function (details, cb) {
8-
var nothing = []
9-
cb(nothing)
10+
var responseId = ipc.guid()
11+
cb && ipc.once('chrome-cookies-getall-response-' + responseId, function (evt, error, cookielist) {
12+
if (error) {
13+
lastError.run('cookies.getall', error, '', () => { cb(null) })
14+
} else {
15+
cb(cookielist)
16+
}
17+
})
18+
19+
ipc.send('chrome-cookies-getall', responseId, details)
20+
})
21+
22+
apiFunctions.setHandleRequest('get', function (details, cb) {
23+
var responseId = ipc.guid()
24+
cb && ipc.once('chrome-cookies-get-response-' + responseId, function (evt, error, cookie) {
25+
if (error) {
26+
lastError.run('cookies.get', error, '', () => { cb(null) })
27+
} else {
28+
cb(cookie)
29+
}
30+
})
31+
32+
ipc.send('chrome-cookies-get', responseId, details)
33+
})
34+
35+
apiFunctions.setHandleRequest('set', function (details, cb) {
36+
var responseId = ipc.guid()
37+
cb && ipc.once('chrome-cookies-set-response-' + responseId, function (evt, error, cookie) {
38+
if (error) {
39+
lastError.run('cookies.set', error, '', () => { cb(null) })
40+
} else {
41+
cb(cookie)
42+
}
43+
})
44+
45+
ipc.send('chrome-cookies-set', responseId, details)
1046
})
1147
})
1248

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",

brave/browser/api/brave_api_component_updater.cc

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ void ComponentUpdater::RegisterComponent(const std::string& component_id) {
142142
} else if (component_id == kHoneyId) {
143143
RegisterComponentForUpdate(
144144
kHoneyPublicKeyStr, registered_callback, ready_callback);
145+
} else if (component_id == kPinterestId) {
146+
RegisterComponentForUpdate(
147+
kPinterestPublicKeyStr, registered_callback, ready_callback);
145148
} else if (component_id == kWidevineId) {
146149
brave::RegisterWidevineCdmComponent(
147150
g_browser_process->component_updater(),

brave/browser/component_updater/default_extensions.h

+31
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,39 @@ const uint8_t kHoneyPublicKey[162] = {
372372
0x54, 0xf7, 0xd1, 0x76, 0xf5, 0x02, 0x03, 0x01,
373373
0x00, 0x01
374374
};
375+
375376
const std::string kHoneyPublicKeyStr( // NOLINT
376377
(const char *)kHoneyPublicKey, sizeof(kHoneyPublicKey));
377378
const std::string kHoneyId("bmnlcjabgnpnenekpadlanbbkooimhnj"); // NOLINT
378379

380+
// Pinterest
381+
// Download: https://clients2.google.com/service/update2/crx?response=redirect&prodversion=52.0.2743.116&x=id%3Dgpdjojdkbbmdfjfahjcgigfpmkopogic%26uc // NOLINT
382+
const uint8_t kPinterestPublicKey[162] = {
383+
0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
384+
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
385+
0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
386+
0x89, 0x02, 0x81, 0x81, 0x00, 0xc1, 0xf7, 0x9a,
387+
0xb6, 0x87, 0x2b, 0x78, 0xf5, 0x90, 0xee, 0x56,
388+
0x76, 0x08, 0xf7, 0x55, 0xda, 0x66, 0x1a, 0x90,
389+
0x91, 0xb5, 0xee, 0xd1, 0x7d, 0xdf, 0xce, 0x83,
390+
0x71, 0x3f, 0x18, 0x45, 0x6d, 0xfa, 0x86, 0x2b,
391+
0x0b, 0x6d, 0xb3, 0xdd, 0x0b, 0x27, 0xb9, 0x43,
392+
0xe4, 0x30, 0x88, 0x7e, 0x70, 0x60, 0xf1, 0x61,
393+
0x85, 0x86, 0x9d, 0xde, 0x5b, 0x81, 0xb1, 0x3a,
394+
0x09, 0x40, 0x2a, 0xb9, 0xe4, 0xb2, 0x62, 0x68,
395+
0xc8, 0x00, 0xf9, 0x3e, 0x74, 0x80, 0xb9, 0xfc,
396+
0x7c, 0x7c, 0x3d, 0xed, 0xad, 0x9b, 0xe8, 0xfd,
397+
0x90, 0x2a, 0x17, 0x1d, 0x71, 0xe5, 0x79, 0xb7,
398+
0x46, 0x6d, 0xf8, 0x12, 0x0b, 0xd5, 0x5d, 0xda,
399+
0xda, 0x96, 0x01, 0xd2, 0x62, 0x2a, 0x9c, 0x11,
400+
0x4f, 0xc5, 0x5f, 0x79, 0x18, 0x9c, 0xb2, 0xe1,
401+
0xaf, 0x64, 0xd2, 0xe2, 0x57, 0x2b, 0xb2, 0x7d,
402+
0x4a, 0x65, 0xdf, 0xe5, 0x71, 0x02, 0x03, 0x01,
403+
0x00, 0x01
404+
};
405+
406+
const std::string kPinterestPublicKeyStr( // NOLINT
407+
(const char *)kPinterestPublicKey, sizeof(kPinterestPublicKey));
408+
const std::string kPinterestId("gpdjojdkbbmdfjfahjcgigfpmkopogic"); // NOLINT
409+
379410
#endif // BRAVE_BROWSER_COMPONENT_UPDATER_DEFAULT_EXTENSIONS_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());

lib/browser/api/extensions.js

+30
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,36 @@ ipcMain.on('register-chrome-window-focus', function (evt, extensionId) {
488488
addBackgroundPageEvent(extensionId, 'chrome-window-focus')
489489
})
490490

491+
ipcMain.on('chrome-cookies-getall', function (evt, responseId, details) {
492+
const cb = (error, cookielist) => {
493+
if (!evt.sender.isDestroyed()) {
494+
evt.sender.send('chrome-cookies-getall-response-' + responseId, error, cookielist)
495+
}
496+
}
497+
498+
evt.sender.session.cookies.getAll(details, cb)
499+
})
500+
501+
ipcMain.on('chrome-cookies-get', function (evt, responseId, details) {
502+
const cb = (error, cookie) => {
503+
if (!evt.sender.isDestroyed()) {
504+
evt.sender.send('chrome-cookies-get-response-' + responseId, error, cookie)
505+
}
506+
}
507+
508+
evt.sender.session.cookies.get(details, cb)
509+
})
510+
511+
ipcMain.on('chrome-cookies-set', function (evt, responseId, details) {
512+
const cb = (error, cookie) => {
513+
if (!evt.sender.isDestroyed()) {
514+
evt.sender.send('chrome-cookies-set-response-' + responseId, error, cookie)
515+
}
516+
}
517+
518+
evt.sender.session.cookies.set(details, cb)
519+
})
520+
491521
app.on('browser-window-focus', function (event, browserWindow) {
492522
var forthcomingWindow = browserWindow
493523
var forthcomingId = (forthcomingWindow == null) ? -1 : forthcomingWindow.id

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)