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

Commit

Permalink
Add chrome.cookies.{getAll, set, get} for Pinterest Save Button exten…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlawler committed Jun 8, 2017
1 parent e571682 commit 710685d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
10 changes: 9 additions & 1 deletion atom/browser/api/atom_api_cookies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ Cookies::Cookies(v8::Isolate* isolate,
Cookies::~Cookies() {
}

void Cookies::GetAll(const base::DictionaryValue& filter,
const GetCallback& callback) {
Cookies::Get(filter, callback);
}

void Cookies::Get(const base::DictionaryValue& filter,
const GetCallback& callback) {
std::unique_ptr<base::DictionaryValue> copied(filter.CreateDeepCopy());
Expand Down Expand Up @@ -255,9 +260,12 @@ void Cookies::BuildPrototype(v8::Isolate* isolate,
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("get", &Cookies::Get)
.SetMethod("remove", &Cookies::Remove)
.SetMethod("set", &Cookies::Set);
.SetMethod("set", &Cookies::Set)
.SetMethod("getAll", &Cookies::GetAll);
}

} // namespace api

} // namespace atom


1 change: 1 addition & 0 deletions atom/browser/api/atom_api_cookies.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Cookies : public mate::TrackableObject<Cookies> {
Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~Cookies() override;

void GetAll(const base::DictionaryValue& filter, const GetCallback& callback);
void Get(const base::DictionaryValue& filter, const GetCallback& callback);
void Remove(const GURL& url, const std::string& name,
const base::Closure& callback);
Expand Down
40 changes: 38 additions & 2 deletions atom/common/api/resources/cookies_bindings.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
var binding = require('binding').Binding.create('cookies')
var ipc = require('ipc_utils')
var lastError = require('lastError')

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

apiFunctions.setHandleRequest('getAll', function (details, cb) {
var nothing = []
cb(nothing)
var responseId = ipc.guid()
cb && ipc.once('chrome-cookies-getall-response-' + responseId, function (evt, error, cookielist) {
if (error) {
lastError.run('cookies.getall', error, '', () => { cb(null) })
} else {
cb(cookielist)
}
})

ipc.send('chrome-cookies-getall', responseId, details)
})

apiFunctions.setHandleRequest('get', function (details, cb) {
var responseId = ipc.guid()
cb && ipc.once('chrome-cookies-get-response-' + responseId, function (evt, error, cookie) {
if (error) {
lastError.run('cookies.get', error, '', () => { cb(null) })
} else {
cb(cookie)
}
})

ipc.send('chrome-cookies-get', responseId, details)
})

apiFunctions.setHandleRequest('set', function (details, cb) {
var responseId = ipc.guid()
cb && ipc.once('chrome-cookies-set-response-' + responseId, function (evt, error, cookie) {
if (error) {
lastError.run('cookies.set', error, '', () => { cb(null) })
} else {
cb(cookie)
}
})

ipc.send('chrome-cookies-set', responseId, details)
})
})

Expand Down
30 changes: 30 additions & 0 deletions lib/browser/api/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,36 @@ ipcMain.on('register-chrome-window-focus', function (evt, extensionId) {
addBackgroundPageEvent(extensionId, 'chrome-window-focus')
})

ipcMain.on('chrome-cookies-getall', function (evt, responseId, details) {
const cb = (error, cookielist) => {
if (!evt.sender.isDestroyed()) {
evt.sender.send('chrome-cookies-getall-response-' + responseId, error, cookielist)
}
}

evt.sender.session.cookies.getAll(details, cb)
})

ipcMain.on('chrome-cookies-get', function (evt, responseId, details) {
const cb = (error, cookie) => {
if (!evt.sender.isDestroyed()) {
evt.sender.send('chrome-cookies-get-response-' + responseId, error, cookie)
}
}

evt.sender.session.cookies.get(details, cb)
})

ipcMain.on('chrome-cookies-set', function (evt, responseId, details) {
const cb = (error, cookie) => {
if (!evt.sender.isDestroyed()) {
evt.sender.send('chrome-cookies-set-response-' + responseId, error, cookie)
}
}

evt.sender.session.cookies.set(details, cb)
})

app.on('browser-window-focus', function (event, browserWindow) {
var forthcomingWindow = browserWindow
var forthcomingId = (forthcomingWindow == null) ? -1 : forthcomingWindow.id
Expand Down

0 comments on commit 710685d

Please sign in to comment.