{"action":"created","comment":{"url":"https://api.github.com/repos/atom/electron/pulls/comments/32606824","id":32606824,"diff_hunk":"@@ -0,0 +1,355 @@\n+// Copyright (c) 2015 GitHub, Inc.\n+// Use of this source code is governed by the MIT license that can be\n+// found in the LICENSE file.\n+\n+#include \"atom/browser/api/atom_api_cookies.h\"\n+\n+#include \"atom/browser/atom_browser_context.h\"\n+#include \"atom/common/native_mate_converters/value_converter.h\"\n+#include \"base/bind.h\"\n+#include \"base/time/time.h\"\n+#include \"content/public/browser/browser_thread.h\"\n+#include \"native_mate/callback.h\"\n+#include \"native_mate/dictionary.h\"\n+#include \"native_mate/object_template_builder.h\"\n+#include \"net/cookies/cookie_monster.h\"\n+#include \"net/cookies/cookie_store.h\"\n+#include \"net/cookies/cookie_util.h\"\n+#include \"net/url_request/url_request_context.h\"\n+\n+#include \"atom/common/node_includes.h\"\n+\n+using content::BrowserThread;\n+\n+namespace {\n+\n+bool GetCookieListFromStore(net::CookieStore* cookie_store,\n+    const std::string& url,\n+    const net::CookieMonster::GetCookieListCallback& callback) {\n+  DCHECK(cookie_store);\n+  GURL gurl(url);\n+  net::CookieMonster* monster = cookie_store->GetCookieMonster();\n+  // Empty url will match all url cookies.\n+  if (url.empty()) {\n+    monster->GetAllCookiesAsync(callback);\n+    return true;\n+  }\n+\n+  if (!gurl.is_valid())\n+    return false;\n+\n+  monster->GetAllCookiesForURLAsync(gurl, callback);\n+  return true;\n+}\n+\n+void RunGetCookiesCallbackOnUIThread(const base::DictionaryValue* filter,\n+    const std::string& error_message, const net::CookieList& cookie_list,\n+    const atom::api::Cookies::CookiesCallback& callback) {\n+  DCHECK_CURRENTLY_ON(BrowserThread::UI);\n+\n+  // Should release filter here.\n+  delete filter;\n+\n+  v8::Isolate* isolate = v8::Isolate::GetCurrent();\n+  v8::Locker locker(isolate);\n+  v8::HandleScope handle_scope(isolate);\n+\n+  if (!error_message.empty()) {\n+    v8::Local<v8::String> error = v8::String::NewFromUtf8(isolate,\n+        error_message.c_str());\n+    callback.Run(error, v8::Null(isolate));\n+    return;\n+  }\n+  callback.Run(v8::Null(isolate),\n+      mate::Converter<net::CookieList>::ToV8(isolate, cookie_list));","path":"atom/browser/api/atom_api_cookies.cc","position":64,"original_position":64,"commit_id":"3334e52e935996aa1d2b3fa29ad7159241412155","original_commit_id":"3334e52e935996aa1d2b3fa29ad7159241412155","user":{"login":"zcbenz","id":639601,"avatar_url":"https://avatars.githubusercontent.com/u/639601?v=3","gravatar_id":"","url":"https://api.github.com/users/zcbenz","html_url":"https://github.com/zcbenz","followers_url":"https://api.github.com/users/zcbenz/followers","following_url":"https://api.github.com/users/zcbenz/following{/other_user}","gists_url":"https://api.github.com/users/zcbenz/gists{/gist_id}","starred_url":"https://api.github.com/users/zcbenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zcbenz/subscriptions","organizations_url":"https://api.github.com/users/zcbenz/orgs","repos_url":"https://api.github.com/users/zcbenz/repos","events_url":"https://api.github.com/users/zcbenz/events{/privacy}","received_events_url":"https://api.github.com/users/zcbenz/received_events","type":"User","site_admin":true},"body":"You can call `mate::ConvertToV8` without typing the class type.","created_at":"2015-06-17T09:01:18Z","updated_at":"2015-06-17T09:01:18Z","html_url":"https://github.com/atom/electron/pull/1981#discussion_r32606824","pull_request_url":"https://api.github.com/repos/atom/electron/pulls/1981","_links":{"self":{"href":"https://api.github.com/repos/atom/electron/pulls/comments/32606824"},"html":{"href":"https://github.com/atom/electron/pull/1981#discussion_r32606824"},"pull_request":{"href":"https://api.github.com/repos/atom/electron/pulls/1981"}}},"pull_request":{"url":"https://api.github.com/repos/atom/electron/pulls/1981","id":37694135,"html_url":"https://github.com/atom/electron/pull/1981","diff_url":"https://github.com/atom/electron/pull/1981.diff","patch_url":"https://github.com/atom/electron/pull/1981.patch","issue_url":"https://api.github.com/repos/atom/electron/issues/1981","number":1981,"state":"open","locked":false,"title":"Implement Cookies api","user":{"login":"hokein","id":2557445,"avatar_url":"https://avatars.githubusercontent.com/u/2557445?v=3","gravatar_id":"","url":"https://api.github.com/users/hokein","html_url":"https://github.com/hokein","followers_url":"https://api.github.com/users/hokein/followers","following_url":"https://api.github.com/users/hokein/following{/other_user}","gists_url":"https://api.github.com/users/hokein/gists{/gist_id}","starred_url":"https://api.github.com/users/hokein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hokein/subscriptions","organizations_url":"https://api.github.com/users/hokein/orgs","repos_url":"https://api.github.com/users/hokein/repos","events_url":"https://api.github.com/users/hokein/events{/privacy}","received_events_url":"https://api.github.com/users/hokein/received_events","type":"User","site_admin":false},"body":"Fixes #1606 . The cookies APIs are defined as followed:\r\n## Class: WebContents.session.cookies\r\n\r\nThe `cookies` gives you ability to query and modify cookies, an example is:\r\n\r\n```javascipt\r\nvar BrowserWindow = require('browser-window');\r\n\r\nvar win = new BrowserWindow({ width: 800, height: 600 });\r\n\r\nwin.loadUrl('https://github.com');\r\n\r\nwin.webContents.on('did-finish-load', function() {\r\n  // Query all cookies.\r\n  win.webContents.session.cookies.get({}, function(error, cookies) {\r\n    if (error) throw error;\r\n    console.log(cookies);\r\n  });\r\n\r\n  // Query all cookies that are associated with a specific url.\r\n  win.webContents.session.cookies.get({ url : \"http://www.github.com\" },\r\n      function(error, cookies) {\r\n        if (error) throw error;\r\n        console.log(cookies);\r\n  });\r\n\r\n  // Set a cookie with the given cookie data;\r\n  // may overwrite equivalent cookies if they exist.\r\n  win.webContents.session.cookies.set(\r\n    { url : \"http://www.github.com\", name : \"dummy_name\", value : \"dummy\"},\r\n    function(error, cookies) {\r\n        if (error) throw error;\r\n          console.log(cookies);\r\n});\r\n\r\n});\r\n```\r\n\r\n### WebContents.session.cookies.get(details, callback)\r\n\r\n* `details` Object\r\n  * `url` String - Retrieves cookies which are associated with `url`.\r\n    Empty imples retrieving cookies of all urls.\r\n  * `name` String - Filters cookies by name\r\n  * `domain` String - Retrieves cookies whose domains match or are subdomains of `domains`\r\n  * `path` String - Retrieves cookies whose path matches `path`\r\n  * `secure` Boolean - Filters cookies by their Secure property\r\n  * `session` Boolean - Filters out session or persistent cookies.\r\n* `callback` Function - function(error, cookies)\r\n  * `error` Error\r\n  * `cookies` Array - array of cookie objects.\r\n\r\n### WebContents.session.cookies.set(details, callback)\r\n\r\n* `details` Object\r\n  * `url` String - Retrieves cookies which are associated with `url`\r\n  * `name` String - The name of the cookie. Empty by default if omitted.\r\n  * `value` String - The value of the cookie. Empty by default if omitted.\r\n  * `domain` String - The domain of the cookie. Empty by default if omitted.\r\n  * `path` String - The path of the cookie. Empty by default if omitted.\r\n  * `secure` Boolean - Whether the cookie should be marked as Secure. Defaults to false.\r\n  * `session` Boolean - Whether the cookie should be marked as HttpOnly. Defaults to false.\r\n  * `expirationDate` Double -\tThe expiration date of the cookie as the number of\r\n    seconds since the UNIX epoch. If omitted, the cookie becomes a session cookie.\r\n\r\n* `callback` Function - function(error)\r\n  * `error` Error\r\n\r\n### WebContents.session.cookies.remove(details, callback)\r\n\r\n* `details` Object\r\n  * `url` String - The URL associated with the cookie\r\n  * `name` String - The name of cookie to remove\r\n* `callback` Function - function(error)\r\n  * `error` Error\r\n","created_at":"2015-06-15T14:01:04Z","updated_at":"2015-06-17T09:01:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8f0f065bb8d831f8bdcdbbce7ceaf641643c17a3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/atom/electron/pulls/1981/commits","review_comments_url":"https://api.github.com/repos/atom/electron/pulls/1981/comments","review_comment_url":"https://api.github.com/repos/atom/electron/pulls/comments{/number}","comments_url":"https://api.github.com/repos/atom/electron/issues/1981/comments","statuses_url":"https://api.github.com/repos/atom/electron/statuses/3334e52e935996aa1d2b3fa29ad7159241412155","head":{"label":"atom:cookies-api","ref":"cookies-api","sha":"3334e52e935996aa1d2b3fa29ad7159241412155","user":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"repo":{"id":9384267,"name":"electron","full_name":"atom/electron","owner":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/atom/electron","description":"Build cross platform desktop apps with web technologies","fork":false,"url":"https://api.github.com/repos/atom/electron","forks_url":"https://api.github.com/repos/atom/electron/forks","keys_url":"https://api.github.com/repos/atom/electron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atom/electron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atom/electron/teams","hooks_url":"https://api.github.com/repos/atom/electron/hooks","issue_events_url":"https://api.github.com/repos/atom/electron/issues/events{/number}","events_url":"https://api.github.com/repos/atom/electron/events","assignees_url":"https://api.github.com/repos/atom/electron/assignees{/user}","branches_url":"https://api.github.com/repos/atom/electron/branches{/branch}","tags_url":"https://api.github.com/repos/atom/electron/tags","blobs_url":"https://api.github.com/repos/atom/electron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atom/electron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atom/electron/git/refs{/sha}","trees_url":"https://api.github.com/repos/atom/electron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atom/electron/statuses/{sha}","languages_url":"https://api.github.com/repos/atom/electron/languages","stargazers_url":"https://api.github.com/repos/atom/electron/stargazers","contributors_url":"https://api.github.com/repos/atom/electron/contributors","subscribers_url":"https://api.github.com/repos/atom/electron/subscribers","subscription_url":"https://api.github.com/repos/atom/electron/subscription","commits_url":"https://api.github.com/repos/atom/electron/commits{/sha}","git_commits_url":"https://api.github.com/repos/atom/electron/git/commits{/sha}","comments_url":"https://api.github.com/repos/atom/electron/comments{/number}","issue_comment_url":"https://api.github.com/repos/atom/electron/issues/comments{/number}","contents_url":"https://api.github.com/repos/atom/electron/contents/{+path}","compare_url":"https://api.github.com/repos/atom/electron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atom/electron/merges","archive_url":"https://api.github.com/repos/atom/electron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atom/electron/downloads","issues_url":"https://api.github.com/repos/atom/electron/issues{/number}","pulls_url":"https://api.github.com/repos/atom/electron/pulls{/number}","milestones_url":"https://api.github.com/repos/atom/electron/milestones{/number}","notifications_url":"https://api.github.com/repos/atom/electron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atom/electron/labels{/name}","releases_url":"https://api.github.com/repos/atom/electron/releases{/id}","created_at":"2013-04-12T01:47:36Z","updated_at":"2015-06-17T08:38:01Z","pushed_at":"2015-06-17T07:53:15Z","git_url":"git://github.com/atom/electron.git","ssh_url":"git@github.com:atom/electron.git","clone_url":"https://github.com/atom/electron.git","svn_url":"https://github.com/atom/electron","homepage":"http://electron.atom.io","size":20428,"stargazers_count":12487,"watchers_count":12487,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":940,"mirror_url":null,"open_issues_count":194,"forks":940,"open_issues":194,"watchers":12487,"default_branch":"master"}},"base":{"label":"atom:master","ref":"master","sha":"bd704dd8aaa9a0f53897627838dfa5bffbaf0d78","user":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"repo":{"id":9384267,"name":"electron","full_name":"atom/electron","owner":{"login":"atom","id":1089146,"avatar_url":"https://avatars.githubusercontent.com/u/1089146?v=3","gravatar_id":"","url":"https://api.github.com/users/atom","html_url":"https://github.com/atom","followers_url":"https://api.github.com/users/atom/followers","following_url":"https://api.github.com/users/atom/following{/other_user}","gists_url":"https://api.github.com/users/atom/gists{/gist_id}","starred_url":"https://api.github.com/users/atom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atom/subscriptions","organizations_url":"https://api.github.com/users/atom/orgs","repos_url":"https://api.github.com/users/atom/repos","events_url":"https://api.github.com/users/atom/events{/privacy}","received_events_url":"https://api.github.com/users/atom/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/atom/electron","description":"Build cross platform desktop apps with web technologies","fork":false,"url":"https://api.github.com/repos/atom/electron","forks_url":"https://api.github.com/repos/atom/electron/forks","keys_url":"https://api.github.com/repos/atom/electron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atom/electron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atom/electron/teams","hooks_url":"https://api.github.com/repos/atom/electron/hooks","issue_events_url":"https://api.github.com/repos/atom/electron/issues/events{/number}","events_url":"https://api.github.com/repos/atom/electron/events","assignees_url":"https://api.github.com/repos/atom/electron/assignees{/user}","branches_url":"https://api.github.com/repos/atom/electron/branches{/branch}","tags_url":"https://api.github.com/repos/atom/electron/tags","blobs_url":"https://api.github.com/repos/atom/electron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atom/electron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atom/electron/git/refs{/sha}","trees_url":"https://api.github.com/repos/atom/electron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atom/electron/statuses/{sha}","languages_url":"https://api.github.com/repos/atom/electron/languages","stargazers_url":"https://api.github.com/repos/atom/electron/stargazers","contributors_url":"https://api.github.com/repos/atom/electron/contributors","subscribers_url":"https://api.github.com/repos/atom/electron/subscribers","subscription_url":"https://api.github.com/repos/atom/electron/subscription","commits_url":"https://api.github.com/repos/atom/electron/commits{/sha}","git_commits_url":"https://api.github.com/repos/atom/electron/git/commits{/sha}","comments_url":"https://api.github.com/repos/atom/electron/comments{/number}","issue_comment_url":"https://api.github.com/repos/atom/electron/issues/comments{/number}","contents_url":"https://api.github.com/repos/atom/electron/contents/{+path}","compare_url":"https://api.github.com/repos/atom/electron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atom/electron/merges","archive_url":"https://api.github.com/repos/atom/electron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atom/electron/downloads","issues_url":"https://api.github.com/repos/atom/electron/issues{/number}","pulls_url":"https://api.github.com/repos/atom/electron/pulls{/number}","milestones_url":"https://api.github.com/repos/atom/electron/milestones{/number}","notifications_url":"https://api.github.com/repos/atom/electron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atom/electron/labels{/name}","releases_url":"https://api.github.com/repos/atom/electron/releases{/id}","created_at":"2013-04-12T01:47:36Z","updated_at":"2015-06-17T08:38:01Z","pushed_at":"2015-06-17T07:53:15Z","git_url":"git://github.com/atom/electron.git","ssh_url":"git@github.com:atom/electron.git","clone_url":"https://github.com/atom/electron.git","svn_url":"https://github.com/atom/electron","homepage":"http://electron.atom.io","size":20428,"stargazers_count":12487,"watchers_count":12487,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":940,"mirror_url":null,"open_issues_count":194,"forks":940,"open_issues":194,"watchers":12487,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/atom/electron/pulls/1981"},"html":{"href":"https://github.com/atom/electron/pull/1981"},"issue":{"href":"https://api.github.com/repos/atom/electron/issues/1981"},"comments":{"href":"https://api.github.com/repos/atom/electron/issues/1981/comments"},"review_comments":{"href":"https://api.github.com/repos/atom/electron/pulls/1981/comments"},"review_comment":{"href":"https://api.github.com/repos/atom/electron/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/atom/electron/pulls/1981/commits"},"statuses":{"href":"https://api.github.com/repos/atom/electron/statuses/3334e52e935996aa1d2b3fa29ad7159241412155"}}}}