Chromium Code Reviews| 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..670584d55215d612880d1ca53e79087ad088ea99 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 httpOnly, |
| + net::CookieSameSite sameSite, |
| + 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, |
| + httpOnly, |
| + sameSite, |
| + 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 httpOnly, |
| + net::CookieSameSite sameSite, |
| + base::Time expires, |
| + const SetCookieCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + BrowserThread::PostTask( |
|
dgozman
2016/08/12 05:22:46
Just inline this into SetCookie method.
allada
2016/08/16 01:10:39
I am following the pattern of DeleteCookieOnUI(),
dgozman
2016/08/16 18:56:59
I see, thanks.
|
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&SetCookieOnIO, |
| + base::Unretained(resource_context), |
| + base::Unretained(context_getter), |
| + url, name, value, domain, path, secure, httpOnly, |
| + sameSite, expires, callback)); |
| +} |
| + |
| class GetCookiesCommand { |
| public: |
| explicit GetCookiesCommand( |
| @@ -228,6 +296,51 @@ 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* httpOnly, |
| + const std::string* sameSite, |
| + double* expires) { |
| + if (!host_) |
| + return Response::InternalError("Could not connect to view"); |
| + |
| + net::CookieSameSite sameSiteEnum = net::CookieSameSite::DEFAULT_MODE; |
| + if (sameSite && *sameSite == kSameSiteLax) |
| + sameSiteEnum = net::CookieSameSite::LAX_MODE; |
| + else if (sameSite && *sameSite == kSameSiteStrict) |
| + sameSiteEnum = net::CookieSameSite::STRICT_MODE; |
| + |
| + base::Time expirationDate; |
| + if (expires) |
| + expirationDate = (*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, httpOnly ? *httpOnly : false, |
| + sameSiteEnum, expirationDate, |
| + 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)); |
|
dgozman
2016/08/12 05:22:46
nit: this fits previous line
allada
2016/08/16 01:10:39
Done.
|
| +} |
| + |
| void NetworkHandler::SendGetCookiesResponse( |
| DevToolsCommandId command_id, |
| const net::CookieList& cookie_list) { |
| @@ -247,10 +360,10 @@ void NetworkHandler::SendGetCookiesResponse( |
| switch (cookie.SameSite()) { |
| case net::CookieSameSite::STRICT_MODE: |
| - devtools_cookie->set_same_site(cookie::kSameSiteStrict); |
| + devtools_cookie->set_same_site(kSameSiteStrict); |
| break; |
| case net::CookieSameSite::LAX_MODE: |
| - devtools_cookie->set_same_site(cookie::kSameSiteLax); |
| + devtools_cookie->set_same_site(kSameSiteLax); |
| break; |
| case net::CookieSameSite::NO_RESTRICTION: |
| break; |