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..9ed9f88e1e5f599100cf4d78e2f47be54edecfff 100644 |
| --- a/content/browser/devtools/protocol/network_handler.cc |
| +++ b/content/browser/devtools/protocol/network_handler.cc |
| @@ -32,6 +32,7 @@ namespace content { |
| namespace devtools { |
| namespace network { |
| +using Response = DevToolsProtocolClient::Response; |
| using CookieListCallback = net::CookieStore::GetCookieListCallback; |
| namespace { |
| @@ -126,6 +127,60 @@ void DeleteCookieOnUI( |
| callback)); |
| } |
| +void CookieSetOnIO(const base::Closure& callback, bool success) { |
|
dgozman
2016/08/09 01:07:25
Let's send an error over protocol if !success.
allada
2016/08/10 02:46:54
Done.
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + callback); |
| +} |
| + |
| +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 base::Closure& 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 base::Closure& 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, httpOnly, |
| + sameSite, expires, callback)); |
| +} |
| + |
| class GetCookiesCommand { |
| public: |
| explicit GetCookiesCommand( |
| @@ -220,6 +275,7 @@ Response NetworkHandler::ClearBrowserCookies() { |
| Response NetworkHandler::GetCookies(DevToolsCommandId command_id) { |
| if (!host_) |
| return Response::InternalError("Could not connect to view"); |
| + |
| new GetCookiesCommand( |
| host_, |
| base::Bind(&NetworkHandler::SendGetCookiesResponse, |
| @@ -228,6 +284,44 @@ 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 == "lax") |
|
dgozman
2016/08/09 01:07:24
There are generated constants for all enums in pro
allada
2016/08/10 02:46:54
Done.
|
| + sameSiteEnum = net::CookieSameSite::LAX_MODE; |
| + else if (sameSite && *sameSite == "strict") |
| + 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) { |
| + client_->SendSetCookieResponse(command_id, |
| + SetCookieResponse::Create()); |
| +} |
| + |
| void NetworkHandler::SendGetCookiesResponse( |
| DevToolsCommandId command_id, |
| const net::CookieList& cookie_list) { |