2015-06-14 08:19:53 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/api/atom_api_cookies.h"
|
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
2016-07-04 06:08:55 +00:00
|
|
|
#include "atom/browser/atom_browser_context.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "atom/browser/cookie_change_notifier.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2015-06-18 10:38:32 +00:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2015-06-14 08:19:53 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2015-06-15 13:18:40 +00:00
|
|
|
#include "base/time/time.h"
|
2015-08-10 07:02:16 +00:00
|
|
|
#include "base/values.h"
|
2015-06-18 10:38:32 +00:00
|
|
|
#include "content/public/browser/browser_context.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
#include "content/public/browser/browser_task_traits.h"
|
2015-06-14 08:19:53 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2019-04-24 19:49:30 +00:00
|
|
|
#include "content/public/browser/storage_partition.h"
|
2015-06-14 08:19:53 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
#include "native_mate/object_template_builder.h"
|
2018-04-11 09:25:51 +00:00
|
|
|
#include "net/cookies/canonical_cookie.h"
|
2015-06-14 08:19:53 +00:00
|
|
|
#include "net/cookies/cookie_store.h"
|
|
|
|
#include "net/cookies/cookie_util.h"
|
|
|
|
#include "net/url_request/url_request_context.h"
|
2015-06-18 10:38:32 +00:00
|
|
|
#include "net/url_request/url_request_context_getter.h"
|
2015-06-14 08:19:53 +00:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
namespace mate {
|
2015-06-14 08:19:53 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2015-12-12 07:33:51 +00:00
|
|
|
struct Converter<atom::api::Cookies::Error> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
atom::api::Cookies::Error val) {
|
|
|
|
if (val == atom::api::Cookies::SUCCESS)
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
2016-06-29 01:44:00 +00:00
|
|
|
return v8::Exception::Error(StringToV8(isolate, "Setting cookie failed"));
|
2015-06-14 08:19:53 +00:00
|
|
|
}
|
2015-12-12 07:33:51 +00:00
|
|
|
};
|
2015-06-15 07:33:09 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2015-12-12 07:33:51 +00:00
|
|
|
struct Converter<net::CanonicalCookie> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const net::CanonicalCookie& val) {
|
|
|
|
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
|
|
|
dict.Set("name", val.Name());
|
|
|
|
dict.Set("value", val.Value());
|
|
|
|
dict.Set("domain", val.Domain());
|
|
|
|
dict.Set("hostOnly", net::cookie_util::DomainIsHostOnly(val.Domain()));
|
|
|
|
dict.Set("path", val.Path());
|
|
|
|
dict.Set("secure", val.IsSecure());
|
|
|
|
dict.Set("httpOnly", val.IsHttpOnly());
|
|
|
|
dict.Set("session", !val.IsPersistent());
|
2016-05-08 05:38:07 +00:00
|
|
|
if (val.IsPersistent())
|
2015-12-12 07:33:51 +00:00
|
|
|
dict.Set("expirationDate", val.ExpiryDate().ToDoubleT());
|
|
|
|
return dict.GetHandle();
|
2015-06-15 07:33:09 +00:00
|
|
|
}
|
2015-12-12 07:33:51 +00:00
|
|
|
};
|
2015-06-15 07:33:09 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2018-10-04 18:08:56 +00:00
|
|
|
struct Converter<network::mojom::CookieChangeCause> {
|
|
|
|
static v8::Local<v8::Value> ToV8(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
const network::mojom::CookieChangeCause& val) {
|
2016-09-21 23:24:03 +00:00
|
|
|
switch (val) {
|
2018-10-04 18:08:56 +00:00
|
|
|
case network::mojom::CookieChangeCause::INSERTED:
|
|
|
|
case network::mojom::CookieChangeCause::EXPLICIT:
|
2016-09-21 23:24:03 +00:00
|
|
|
return mate::StringToV8(isolate, "explicit");
|
2018-10-04 18:08:56 +00:00
|
|
|
case network::mojom::CookieChangeCause::OVERWRITE:
|
2016-09-21 23:24:03 +00:00
|
|
|
return mate::StringToV8(isolate, "overwrite");
|
2018-10-04 18:08:56 +00:00
|
|
|
case network::mojom::CookieChangeCause::EXPIRED:
|
2016-09-21 23:24:03 +00:00
|
|
|
return mate::StringToV8(isolate, "expired");
|
2018-10-04 18:08:56 +00:00
|
|
|
case network::mojom::CookieChangeCause::EVICTED:
|
2016-09-21 23:24:03 +00:00
|
|
|
return mate::StringToV8(isolate, "evicted");
|
2018-10-04 18:08:56 +00:00
|
|
|
case network::mojom::CookieChangeCause::EXPIRED_OVERWRITE:
|
2016-09-21 23:24:03 +00:00
|
|
|
return mate::StringToV8(isolate, "expired-overwrite");
|
|
|
|
default:
|
|
|
|
return mate::StringToV8(isolate, "unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
} // namespace mate
|
2015-06-15 13:18:40 +00:00
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
namespace atom {
|
2015-06-15 13:18:40 +00:00
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
namespace api {
|
2015-06-15 13:18:40 +00:00
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
namespace {
|
2015-06-14 08:19:53 +00:00
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
// Returns whether |domain| matches |filter|.
|
|
|
|
bool MatchesDomain(std::string filter, const std::string& domain) {
|
2015-06-14 08:19:53 +00:00
|
|
|
// Add a leading '.' character to the filter domain if it doesn't exist.
|
2015-12-12 07:33:51 +00:00
|
|
|
if (net::cookie_util::DomainIsHostOnly(filter))
|
|
|
|
filter.insert(0, ".");
|
2015-06-14 08:19:53 +00:00
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
std::string sub_domain(domain);
|
2015-06-14 08:19:53 +00:00
|
|
|
// Strip any leading '.' character from the input cookie domain.
|
|
|
|
if (!net::cookie_util::DomainIsHostOnly(sub_domain))
|
|
|
|
sub_domain = sub_domain.substr(1);
|
|
|
|
|
|
|
|
// Now check whether the domain argument is a subdomain of the filter domain.
|
2015-12-12 07:33:51 +00:00
|
|
|
for (sub_domain.insert(0, "."); sub_domain.length() >= filter.length();) {
|
|
|
|
if (sub_domain == filter)
|
2015-06-14 08:19:53 +00:00
|
|
|
return true;
|
|
|
|
const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
|
|
|
|
sub_domain.erase(0, next_dot);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
// Returns whether |cookie| matches |filter|.
|
2019-04-24 19:49:30 +00:00
|
|
|
bool MatchesCookie(const base::Value& filter,
|
2015-06-20 02:41:40 +00:00
|
|
|
const net::CanonicalCookie& cookie) {
|
2019-04-24 19:49:30 +00:00
|
|
|
const std::string* str;
|
|
|
|
if ((str = filter.FindStringKey("name")) && *str != cookie.Name())
|
2015-06-14 08:19:53 +00:00
|
|
|
return false;
|
2019-04-24 19:49:30 +00:00
|
|
|
if ((str = filter.FindStringKey("path")) && *str != cookie.Path())
|
2015-06-14 08:19:53 +00:00
|
|
|
return false;
|
2019-04-24 19:49:30 +00:00
|
|
|
if ((str = filter.FindStringKey("domain")) &&
|
|
|
|
!MatchesDomain(*str, cookie.Domain()))
|
2015-06-14 08:19:53 +00:00
|
|
|
return false;
|
2019-04-24 19:49:30 +00:00
|
|
|
base::Optional<bool> secure_filter = filter.FindBoolKey("secure");
|
|
|
|
if (secure_filter && *secure_filter == cookie.IsSecure())
|
2015-06-14 08:19:53 +00:00
|
|
|
return false;
|
2019-04-24 19:49:30 +00:00
|
|
|
base::Optional<bool> session_filter = filter.FindBoolKey("session");
|
|
|
|
if (session_filter && *session_filter != !cookie.IsPersistent())
|
2015-06-14 08:19:53 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-12 07:33:51 +00:00
|
|
|
// Remove cookies from |list| not matching |filter|, and pass it to |callback|.
|
2019-04-24 19:49:30 +00:00
|
|
|
void FilterCookies(const base::Value& filter,
|
2019-02-21 12:32:44 +00:00
|
|
|
util::Promise promise,
|
2019-02-21 17:04:39 +00:00
|
|
|
const net::CookieList& list,
|
|
|
|
const net::CookieStatusList& excluded_list) {
|
2015-06-14 08:19:53 +00:00
|
|
|
net::CookieList result;
|
2015-12-12 07:33:51 +00:00
|
|
|
for (const auto& cookie : list) {
|
2019-04-24 19:49:30 +00:00
|
|
|
if (MatchesCookie(filter, cookie))
|
2015-06-14 08:19:53 +00:00
|
|
|
result.push_back(cookie);
|
|
|
|
}
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
promise.Resolve(result);
|
2015-06-15 07:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
std::string InclusionStatusToString(
|
|
|
|
net::CanonicalCookie::CookieInclusionStatus status) {
|
2019-02-27 10:35:52 +00:00
|
|
|
switch (status) {
|
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_HTTP_ONLY:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Failed to create httponly cookie";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_SECURE_ONLY:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Cannot create a secure cookie from an insecure URL";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Failed to parse cookie";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_DOMAIN:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Failed to get cookie domain";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_PREFIX:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Failed because the cookie violated prefix rules.";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::
|
|
|
|
EXCLUDE_NONCOOKIEABLE_SCHEME:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Cannot set cookie for current scheme";
|
2019-02-27 10:35:52 +00:00
|
|
|
case net::CanonicalCookie::CookieInclusionStatus::INCLUDE:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "";
|
2019-02-27 10:35:52 +00:00
|
|
|
default:
|
2019-04-24 19:49:30 +00:00
|
|
|
return "Setting cookie failed";
|
2019-03-22 03:21:36 +00:00
|
|
|
}
|
2015-12-12 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-11-27 03:27:14 +00:00
|
|
|
Cookies::Cookies(v8::Isolate* isolate, AtomBrowserContext* browser_context)
|
2018-03-30 13:24:55 +00:00
|
|
|
: browser_context_(browser_context) {
|
2016-04-25 01:17:54 +00:00
|
|
|
Init(isolate);
|
2018-08-14 21:07:53 +00:00
|
|
|
cookie_change_subscription_ =
|
2018-10-04 18:08:56 +00:00
|
|
|
browser_context_->cookie_change_notifier()->RegisterCookieChangeCallback(
|
|
|
|
base::Bind(&Cookies::OnCookieChanged, base::Unretained(this)));
|
2015-12-12 07:33:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 03:27:14 +00:00
|
|
|
Cookies::~Cookies() {}
|
2015-12-12 07:33:51 +00:00
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
v8::Local<v8::Promise> Cookies::Get(const base::DictionaryValue& filter) {
|
2019-02-21 12:32:44 +00:00
|
|
|
util::Promise promise(isolate());
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
std::string url_string;
|
|
|
|
filter.GetString("url", &url_string);
|
|
|
|
GURL url(url_string);
|
|
|
|
|
|
|
|
auto callback =
|
|
|
|
base::BindOnce(FilterCookies, filter.Clone(), std::move(promise));
|
|
|
|
|
|
|
|
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
|
|
|
browser_context_.get());
|
|
|
|
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
|
|
|
|
|
|
|
if (url.is_empty()) {
|
|
|
|
// GetAllCookies has a different callback signature than GetCookieList, but
|
|
|
|
// can be treated as the same, just returning no excluded cookies.
|
|
|
|
// |AddCookieStatusList| takes a |GetCookieListCallback| and returns a
|
|
|
|
// callback that calls the input callback with an empty excluded list.
|
|
|
|
manager->GetAllCookies(
|
|
|
|
net::cookie_util::AddCookieStatusList(std::move(callback)));
|
|
|
|
} else {
|
|
|
|
net::CookieOptions options;
|
|
|
|
options.set_include_httponly();
|
|
|
|
options.set_same_site_cookie_context(
|
|
|
|
net::CookieOptions::SameSiteCookieContext::SAME_SITE_STRICT);
|
|
|
|
options.set_do_not_update_access_time();
|
|
|
|
|
|
|
|
manager->GetCookieList(url, options, std::move(callback));
|
|
|
|
}
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2015-06-15 13:18:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
v8::Local<v8::Promise> Cookies::Remove(const GURL& url,
|
|
|
|
const std::string& name) {
|
2019-02-21 12:32:44 +00:00
|
|
|
util::Promise promise(isolate());
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
auto cookie_deletion_filter = network::mojom::CookieDeletionFilter::New();
|
|
|
|
cookie_deletion_filter->url = url;
|
|
|
|
cookie_deletion_filter->cookie_name = name;
|
|
|
|
|
|
|
|
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
|
|
|
browser_context_.get());
|
|
|
|
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
|
|
|
|
|
|
|
manager->DeleteCookies(
|
|
|
|
std::move(cookie_deletion_filter),
|
|
|
|
base::BindOnce(
|
|
|
|
[](util::Promise promise, uint32_t num_deleted) {
|
|
|
|
util::Promise::ResolveEmptyPromise(std::move(promise));
|
|
|
|
},
|
|
|
|
std::move(promise)));
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2015-06-15 13:18:40 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
v8::Local<v8::Promise> Cookies::Set(const base::DictionaryValue& details) {
|
2019-02-21 12:32:44 +00:00
|
|
|
util::Promise promise(isolate());
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
const std::string* url_string = details.FindStringKey("url");
|
|
|
|
const std::string* name = details.FindStringKey("name");
|
|
|
|
const std::string* value = details.FindStringKey("value");
|
|
|
|
const std::string* domain = details.FindStringKey("domain");
|
|
|
|
const std::string* path = details.FindStringKey("path");
|
|
|
|
bool secure = details.FindBoolKey("secure").value_or(false);
|
|
|
|
bool http_only = details.FindBoolKey("httpOnly").value_or(false);
|
|
|
|
base::Optional<double> creation_date = details.FindDoubleKey("creationDate");
|
|
|
|
base::Optional<double> expiration_date =
|
|
|
|
details.FindDoubleKey("expirationDate");
|
|
|
|
base::Optional<double> last_access_date =
|
|
|
|
details.FindDoubleKey("lastAccessDate");
|
|
|
|
|
|
|
|
base::Time creation_time = creation_date
|
|
|
|
? base::Time::FromDoubleT(*creation_date)
|
|
|
|
: base::Time::UnixEpoch();
|
|
|
|
base::Time expiration_time = expiration_date
|
|
|
|
? base::Time::FromDoubleT(*expiration_date)
|
|
|
|
: base::Time::UnixEpoch();
|
|
|
|
base::Time last_access_time = last_access_date
|
|
|
|
? base::Time::FromDoubleT(*last_access_date)
|
|
|
|
: base::Time::UnixEpoch();
|
|
|
|
|
|
|
|
GURL url(url_string ? *url_string : "");
|
|
|
|
if (url.is_empty()) {
|
|
|
|
promise.RejectWithErrorMessage(InclusionStatusToString(
|
|
|
|
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_INVALID_DOMAIN));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name || name->empty()) {
|
|
|
|
promise.RejectWithErrorMessage(InclusionStatusToString(
|
|
|
|
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto canonical_cookie = net::CanonicalCookie::CreateSanitizedCookie(
|
|
|
|
url, *name, value ? *value : "", domain ? *domain : "", path ? *path : "",
|
|
|
|
creation_time, expiration_time, last_access_time, secure, http_only,
|
|
|
|
net::CookieSameSite::NO_RESTRICTION, net::COOKIE_PRIORITY_DEFAULT);
|
|
|
|
if (!canonical_cookie || !canonical_cookie->IsCanonical()) {
|
|
|
|
promise.RejectWithErrorMessage(InclusionStatusToString(
|
|
|
|
net::CanonicalCookie::CookieInclusionStatus::EXCLUDE_FAILURE_TO_STORE));
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
net::CookieOptions options;
|
|
|
|
if (http_only) {
|
|
|
|
options.set_include_httponly();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
|
|
|
browser_context_.get());
|
|
|
|
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
|
|
|
manager->SetCanonicalCookie(
|
|
|
|
*canonical_cookie, url.scheme(), options,
|
|
|
|
base::BindOnce(
|
|
|
|
[](util::Promise promise,
|
|
|
|
net::CanonicalCookie::CookieInclusionStatus status) {
|
|
|
|
auto errmsg = InclusionStatusToString(status);
|
|
|
|
if (errmsg.empty()) {
|
|
|
|
promise.Resolve();
|
|
|
|
} else {
|
|
|
|
promise.RejectWithErrorMessage(errmsg);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
std::move(promise)));
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2015-08-10 07:02:16 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 18:11:35 +00:00
|
|
|
v8::Local<v8::Promise> Cookies::FlushStore() {
|
2019-02-21 12:32:44 +00:00
|
|
|
util::Promise promise(isolate());
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-04-24 19:49:30 +00:00
|
|
|
auto* storage_partition = content::BrowserContext::GetDefaultStoragePartition(
|
|
|
|
browser_context_.get());
|
|
|
|
auto* manager = storage_partition->GetCookieManagerForBrowserProcess();
|
|
|
|
|
|
|
|
manager->FlushCookieStore(
|
|
|
|
base::BindOnce(util::Promise::ResolveEmptyPromise, std::move(promise)));
|
2019-01-25 18:11:35 +00:00
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2017-04-14 13:12:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 07:23:42 +00:00
|
|
|
void Cookies::OnCookieChanged(const CookieDetails* details) {
|
2017-11-27 03:27:14 +00:00
|
|
|
Emit("changed", *(details->cookie), details->cause, details->removed);
|
2016-09-21 23:24:03 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 08:19:53 +00:00
|
|
|
// static
|
2018-04-18 01:55:30 +00:00
|
|
|
mate::Handle<Cookies> Cookies::Create(v8::Isolate* isolate,
|
|
|
|
AtomBrowserContext* browser_context) {
|
2016-04-25 01:17:54 +00:00
|
|
|
return mate::CreateHandle(isolate, new Cookies(isolate, browser_context));
|
2015-06-14 08:19:53 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 08:04:46 +00:00
|
|
|
// static
|
|
|
|
void Cookies::BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "Cookies"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2015-12-03 08:04:46 +00:00
|
|
|
.SetMethod("get", &Cookies::Get)
|
|
|
|
.SetMethod("remove", &Cookies::Remove)
|
2017-04-14 13:12:22 +00:00
|
|
|
.SetMethod("set", &Cookies::Set)
|
|
|
|
.SetMethod("flushStore", &Cookies::FlushStore);
|
2015-12-03 08:04:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-14 08:19:53 +00:00
|
|
|
} // namespace api
|
|
|
|
|
2015-08-10 07:36:47 +00:00
|
|
|
} // namespace atom
|