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

Commit 9290284

Browse files
kevinlawlerhferreiro
authored andcommitted
Add chrome.cookies.{getAll, set, get} for Pinterest Save Button extension
(commit split from Pinterest key) brave/browser-laptop#6366 brave/browser-laptop#6262 brave/browser-laptop#8389
1 parent 8e3fdf6 commit 9290284

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-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

lib/browser/api/extensions.js

+30
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,36 @@ ipcMain.on('register-chrome-window-focus', function (evt, extensionId) {
494494
addBackgroundPageEvent(extensionId, 'chrome-window-focus')
495495
})
496496

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

0 commit comments

Comments
 (0)