| Index: content/browser/devtools/protocol/network_handler.cc
|
| diff --git a/content/browser/devtools/protocol/network_handler.cc b/content/browser/devtools/protocol/network_handler.cc
|
| index e41f27430ec0f90af4401c0ec96b2a562eea0b53..34f0552a5cbf1b289d4911902e901983f3ee13a7 100644
|
| --- a/content/browser/devtools/protocol/network_handler.cc
|
| +++ b/content/browser/devtools/protocol/network_handler.cc
|
| @@ -32,7 +32,9 @@ namespace content {
|
| namespace devtools {
|
| namespace network {
|
|
|
| +using Response = DevToolsProtocolClient::Response;
|
| using CookieListCallback = net::CookieStore::GetCookieListCallback;
|
| +using SetCookieCallback = net::CookieStore::SetCookiesCallback;
|
|
|
| namespace {
|
|
|
| @@ -126,6 +128,72 @@ void DeleteCookieOnUI(
|
| callback));
|
| }
|
|
|
| +void CookieSetOnIO(const SetCookieCallback& callback, bool success) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(callback, success));
|
| +}
|
| +
|
| +void SetCookieOnIO(
|
| + ResourceContext* resource_context,
|
| + net::URLRequestContextGetter* context_getter,
|
| + const GURL& url,
|
| + const std::string& name,
|
| + const std::string& value,
|
| + const std::string& domain,
|
| + const std::string& path,
|
| + bool secure,
|
| + bool http_only,
|
| + net::CookieSameSite same_site,
|
| + base::Time expires,
|
| + const SetCookieCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + net::URLRequestContext* request_context =
|
| + GetRequestContextOnIO(resource_context, context_getter, url);
|
| +
|
| + bool are_experimental_cookie_features_enabled =
|
| + request_context->network_delegate()
|
| + ->AreExperimentalCookieFeaturesEnabled();
|
| +
|
| + request_context->cookie_store()->SetCookieWithDetailsAsync(
|
| + url, name, value, domain, path,
|
| + base::Time(),
|
| + expires,
|
| + base::Time(),
|
| + secure,
|
| + http_only,
|
| + same_site,
|
| + are_experimental_cookie_features_enabled,
|
| + net::COOKIE_PRIORITY_DEFAULT,
|
| + base::Bind(&CookieSetOnIO, callback));
|
| +}
|
| +
|
| +void SetCookieOnUI(
|
| + ResourceContext* resource_context,
|
| + net::URLRequestContextGetter* context_getter,
|
| + const GURL& url,
|
| + const std::string& name,
|
| + const std::string& value,
|
| + const std::string& domain,
|
| + const std::string& path,
|
| + bool secure,
|
| + bool http_only,
|
| + net::CookieSameSite same_site,
|
| + base::Time expires,
|
| + const SetCookieCallback& callback) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&SetCookieOnIO,
|
| + base::Unretained(resource_context),
|
| + base::Unretained(context_getter),
|
| + url, name, value, domain, path, secure, http_only,
|
| + same_site, expires, callback));
|
| +}
|
| +
|
| class GetCookiesCommand {
|
| public:
|
| explicit GetCookiesCommand(
|
| @@ -228,6 +296,50 @@ Response NetworkHandler::GetCookies(DevToolsCommandId command_id) {
|
| return Response::OK();
|
| }
|
|
|
| +Response NetworkHandler::SetCookie(DevToolsCommandId command_id,
|
| + const std::string& url,
|
| + const std::string& name,
|
| + const std::string& value,
|
| + const std::string* domain,
|
| + const std::string* path,
|
| + bool* secure,
|
| + bool* http_only,
|
| + const std::string* same_site,
|
| + double* expires) {
|
| + if (!host_)
|
| + return Response::InternalError("Could not connect to view");
|
| +
|
| + net::CookieSameSite same_site_enum = net::CookieSameSite::DEFAULT_MODE;
|
| + if (same_site && *same_site == kCookieSameSiteLax)
|
| + same_site_enum = net::CookieSameSite::LAX_MODE;
|
| + else if (same_site && *same_site == kCookieSameSiteStrict)
|
| + same_site_enum = net::CookieSameSite::STRICT_MODE;
|
| +
|
| + base::Time expiration_date;
|
| + if (expires)
|
| + expiration_date = (*expires == 0)
|
| + ? base::Time::UnixEpoch()
|
| + : base::Time::FromDoubleT(*expires);
|
| +
|
| + SetCookieOnUI(
|
| + host_->GetSiteInstance()->GetBrowserContext()->GetResourceContext(),
|
| + host_->GetProcess()->GetStoragePartition()->GetURLRequestContext(),
|
| + GURL(url), name, value,
|
| + domain ? *domain : std::string(), path ? *path : std::string(),
|
| + secure ? *secure : false, http_only ? *http_only : false,
|
| + same_site_enum, expiration_date,
|
| + base::Bind(&NetworkHandler::SendSetCookieResponse,
|
| + weak_factory_.GetWeakPtr(),
|
| + command_id));
|
| + return Response::OK();
|
| +}
|
| +
|
| +void NetworkHandler::SendSetCookieResponse(DevToolsCommandId command_id,
|
| + bool success) {
|
| + client_->SendSetCookieResponse(command_id,
|
| + SetCookieResponse::Create()->set_success(success));
|
| +}
|
| +
|
| void NetworkHandler::SendGetCookiesResponse(
|
| DevToolsCommandId command_id,
|
| const net::CookieList& cookie_list) {
|
| @@ -247,10 +359,10 @@ void NetworkHandler::SendGetCookiesResponse(
|
|
|
| switch (cookie.SameSite()) {
|
| case net::CookieSameSite::STRICT_MODE:
|
| - devtools_cookie->set_same_site(cookie::kSameSiteStrict);
|
| + devtools_cookie->set_same_site(kCookieSameSiteStrict);
|
| break;
|
| case net::CookieSameSite::LAX_MODE:
|
| - devtools_cookie->set_same_site(cookie::kSameSiteLax);
|
| + devtools_cookie->set_same_site(kCookieSameSiteLax);
|
| break;
|
| case net::CookieSameSite::NO_RESTRICTION:
|
| break;
|
|
|