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

Commit fdbb851

Browse files
committed
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 09aac19 commit fdbb851

File tree

6 files changed

+112
-3
lines changed

6 files changed

+112
-3
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/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/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_

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

0 commit comments

Comments
 (0)