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

Commit 2c4c390

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
1 parent 137f70b commit 2c4c390

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
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

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +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)
1033
})
1134

1235
apiFunctions.setHandleRequest('set', function (details, cb) {
13-
var noncookie = null
14-
cb(noncookie)
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)
1546
})
1647
})
1748

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)