| 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 1f33abf225b3841ccb631a385d72ea304034e2a8..a75a86d42b59d4e6495fb93a686cc9bc1a6a438c 100644
|
| --- a/content/browser/devtools/protocol/network_handler.cc
|
| +++ b/content/browser/devtools/protocol/network_handler.cc
|
| @@ -25,15 +25,13 @@
|
| #include "net/url_request/url_request_context_getter.h"
|
|
|
| namespace content {
|
| -namespace devtools {
|
| -namespace network {
|
| -
|
| -using Response = DevToolsProtocolClient::Response;
|
| -using CookieListCallback = net::CookieStore::GetCookieListCallback;
|
| -using SetCookieCallback = net::CookieStore::SetCookiesCallback;
|
| -
|
| +namespace protocol {
|
| namespace {
|
|
|
| +using GetCookiesCallback = protocol::Network::Backend::GetCookiesCallback;
|
| +using SetCookieCallback = protocol::Network::Backend::SetCookieCallback;
|
| +using DeleteCookieCallback = protocol::Network::Backend::DeleteCookieCallback;
|
| +
|
| net::URLRequestContext* GetRequestContextOnIO(
|
| ResourceContext* resource_context,
|
| net::URLRequestContextGetter* context_getter,
|
| @@ -47,8 +45,8 @@ net::URLRequestContext* GetRequestContextOnIO(
|
| return context;
|
| }
|
|
|
| -void GotCookiesForURLOnIO(
|
| - const CookieListCallback& callback,
|
| +void GotCookiesOnIO(
|
| + const net::CookieStore::GetCookieListCallback& callback,
|
| const net::CookieList& cookie_list) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| BrowserThread::PostTask(
|
| @@ -61,56 +59,32 @@ void GetCookiesForURLOnIO(
|
| ResourceContext* resource_context,
|
| net::URLRequestContextGetter* context_getter,
|
| const GURL& url,
|
| - const CookieListCallback& callback) {
|
| + const net::CookieStore::GetCookieListCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| net::URLRequestContext* request_context =
|
| GetRequestContextOnIO(resource_context, context_getter, url);
|
| request_context->cookie_store()->GetAllCookiesForURLAsync(
|
| - url, base::Bind(&GotCookiesForURLOnIO, callback));
|
| + url, base::Bind(&GotCookiesOnIO, callback));
|
| }
|
|
|
| -void GetCookiesForURLOnUI(
|
| +void GetAllCookiesOnIO(
|
| ResourceContext* resource_context,
|
| net::URLRequestContextGetter* context_getter,
|
| - const GURL& url,
|
| - const CookieListCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO,
|
| - FROM_HERE,
|
| - base::Bind(&GetCookiesForURLOnIO,
|
| - base::Unretained(resource_context),
|
| - base::Unretained(context_getter),
|
| - url,
|
| - callback));
|
| -}
|
| -
|
| -void GetCookiesOnIO(ResourceContext* resource_context,
|
| - net::URLRequestContextGetter* context_getter,
|
| - const CookieListCallback& callback) {
|
| + const net::CookieStore::GetCookieListCallback& callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| net::URLRequestContext* request_context =
|
| context_getter->GetURLRequestContext();
|
| request_context->cookie_store()->GetAllCookiesAsync(
|
| - base::Bind(&GotCookiesForURLOnIO, callback));
|
| + base::Bind(&GotCookiesOnIO, callback));
|
| }
|
|
|
| -void GetCookiesOnUI(ResourceContext* resource_context,
|
| - net::URLRequestContextGetter* context_getter,
|
| - const CookieListCallback& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO, FROM_HERE,
|
| - base::Bind(&GetCookiesOnIO, base::Unretained(resource_context),
|
| - base::Unretained(context_getter), callback));
|
| -}
|
| -
|
| -void DeletedCookieOnIO(const base::Closure& callback) {
|
| +void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| BrowserThread::PostTask(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| - callback);
|
| + base::Bind(&DeleteCookieCallback::sendSuccess,
|
| + base::Passed(std::move(callback))));
|
| }
|
|
|
| void DeleteCookieOnIO(
|
| @@ -118,38 +92,23 @@ void DeleteCookieOnIO(
|
| net::URLRequestContextGetter* context_getter,
|
| const GURL& url,
|
| const std::string& cookie_name,
|
| - const base::Closure& callback) {
|
| + std::unique_ptr<DeleteCookieCallback> callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| net::URLRequestContext* request_context =
|
| GetRequestContextOnIO(resource_context, context_getter, url);
|
| request_context->cookie_store()->DeleteCookieAsync(
|
| - url, cookie_name, base::Bind(&DeletedCookieOnIO, callback));
|
| -}
|
| -
|
| -void DeleteCookieOnUI(
|
| - ResourceContext* resource_context,
|
| - net::URLRequestContextGetter* context_getter,
|
| - const GURL& url,
|
| - const std::string& cookie_name,
|
| - const base::Closure& callback) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - BrowserThread::PostTask(
|
| - BrowserThread::IO,
|
| - FROM_HERE,
|
| - base::Bind(&DeleteCookieOnIO,
|
| - base::Unretained(resource_context),
|
| - base::Unretained(context_getter),
|
| - url,
|
| - cookie_name,
|
| - callback));
|
| + url, cookie_name, base::Bind(&DeletedCookieOnIO,
|
| + base::Passed(std::move(callback))));
|
| }
|
|
|
| -void CookieSetOnIO(const SetCookieCallback& callback, bool success) {
|
| +void CookieSetOnIO(std::unique_ptr<SetCookieCallback> callback, bool success) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| BrowserThread::PostTask(
|
| BrowserThread::UI,
|
| FROM_HERE,
|
| - base::Bind(callback, success));
|
| + base::Bind(&SetCookieCallback::sendSuccess,
|
| + base::Passed(std::move(callback)),
|
| + success));
|
| }
|
|
|
| void SetCookieOnIO(
|
| @@ -164,7 +123,7 @@ void SetCookieOnIO(
|
| bool http_only,
|
| net::CookieSameSite same_site,
|
| base::Time expires,
|
| - const SetCookieCallback& callback) {
|
| + std::unique_ptr<SetCookieCallback> callback) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| net::URLRequestContext* request_context =
|
| GetRequestContextOnIO(resource_context, context_getter, url);
|
| @@ -183,51 +142,29 @@ void SetCookieOnIO(
|
| 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));
|
| + base::Bind(&CookieSetOnIO, base::Passed(std::move(callback))));
|
| }
|
|
|
| class GetCookiesCommand {
|
| public:
|
| - GetCookiesCommand(RenderFrameHostImpl* frame_host,
|
| - bool global,
|
| - const CookieListCallback& callback)
|
| - : callback_(callback), request_count_(0) {
|
| - CookieListCallback got_cookies_callback = base::Bind(
|
| + GetCookiesCommand(
|
| + RenderFrameHostImpl* frame_host,
|
| + bool global,
|
| + std::unique_ptr<GetCookiesCallback> callback)
|
| + : callback_(std::move(callback)),
|
| + request_count_(0) {
|
| + net::CookieStore::GetCookieListCallback got_cookies_callback = base::Bind(
|
| &GetCookiesCommand::GotCookiesForURL, base::Unretained(this));
|
|
|
| if (global) {
|
| request_count_ = 1;
|
| - GetCookiesOnUI(frame_host->GetSiteInstance()
|
| - ->GetBrowserContext()
|
| - ->GetResourceContext(),
|
| - frame_host->GetProcess()
|
| - ->GetStoragePartition()
|
| - ->GetURLRequestContext(),
|
| - got_cookies_callback);
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
|
| + &GetAllCookiesOnIO,
|
| + base::Unretained(frame_host->GetSiteInstance()->GetBrowserContext()->
|
| + GetResourceContext()),
|
| + base::Unretained(frame_host->GetProcess()->GetStoragePartition()->
|
| + GetURLRequestContext()),
|
| + got_cookies_callback));
|
| return;
|
| }
|
|
|
| @@ -241,13 +178,14 @@ class GetCookiesCommand {
|
| if (node->current_frame_host()->IsCrossProcessSubframe())
|
| continue;
|
| ++request_count_;
|
| - GetCookiesForURLOnUI(
|
| - frame_host->GetSiteInstance()->GetBrowserContext()->
|
| - GetResourceContext(),
|
| - frame_host->GetProcess()->GetStoragePartition()->
|
| - GetURLRequestContext(),
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
|
| + &GetCookiesForURLOnIO,
|
| + base::Unretained(frame_host->GetSiteInstance()->GetBrowserContext()->
|
| + GetResourceContext()),
|
| + base::Unretained(frame_host->GetProcess()->GetStoragePartition()->
|
| + GetURLRequestContext()),
|
| node->current_url(),
|
| - got_cookies_callback);
|
| + got_cookies_callback));
|
|
|
| for (size_t i = 0; i < node->child_count(); ++i)
|
| queue.push(node->child_at(i));
|
| @@ -268,41 +206,68 @@ class GetCookiesCommand {
|
| }
|
| --request_count_;
|
| if (!request_count_) {
|
| - net::CookieList list;
|
| - list.reserve(cookies_.size());
|
| - for (const auto& pair : cookies_)
|
| - list.push_back(pair.second);
|
| - callback_.Run(list);
|
| + SendResponse();
|
| delete this;
|
| }
|
| }
|
|
|
| - CookieListCallback callback_;
|
| + void SendResponse() {
|
| + std::unique_ptr<protocol::Array<Network::Cookie>> cookies =
|
| + protocol::Array<Network::Cookie>::create();
|
| + for (const auto& pair : cookies_) {
|
| + const net::CanonicalCookie& cookie = pair.second;
|
| + std::unique_ptr<Network::Cookie> devtools_cookie =
|
| + Network::Cookie::Create()
|
| + .SetName(cookie.Name())
|
| + .SetValue(cookie.Value())
|
| + .SetDomain(cookie.Domain())
|
| + .SetPath(cookie.Path())
|
| + .SetExpires(cookie.ExpiryDate().ToDoubleT() * 1000)
|
| + .SetSize(cookie.Name().length() + cookie.Value().length())
|
| + .SetHttpOnly(cookie.IsHttpOnly())
|
| + .SetSecure(cookie.IsSecure())
|
| + .SetSession(!cookie.IsPersistent())
|
| + .Build();
|
| +
|
| + switch (cookie.SameSite()) {
|
| + case net::CookieSameSite::STRICT_MODE:
|
| + devtools_cookie->SetSameSite(Network::CookieSameSiteEnum::Strict);
|
| + break;
|
| + case net::CookieSameSite::LAX_MODE:
|
| + devtools_cookie->SetSameSite(Network::CookieSameSiteEnum::Lax);
|
| + break;
|
| + case net::CookieSameSite::NO_RESTRICTION:
|
| + break;
|
| + }
|
| + cookies->addItem(std::move(devtools_cookie));
|
| + }
|
| + callback_->sendSuccess(std::move(cookies));
|
| + }
|
| +
|
| + std::unique_ptr<GetCookiesCallback> callback_;
|
| int request_count_;
|
| base::hash_map<std::string, net::CanonicalCookie> cookies_;
|
| };
|
|
|
| } // namespace
|
|
|
| -typedef DevToolsProtocolClient::Response Response;
|
| -
|
| NetworkHandler::NetworkHandler()
|
| - : host_(nullptr), enabled_(false), weak_factory_(this) {
|
| + : host_(nullptr), enabled_(false) {
|
| }
|
|
|
| NetworkHandler::~NetworkHandler() {
|
| }
|
|
|
| -void NetworkHandler::SetRenderFrameHost(RenderFrameHostImpl* host) {
|
| - host_ = host;
|
| +void NetworkHandler::Wire(UberDispatcher* dispatcher) {
|
| + Network::Dispatcher::wire(dispatcher, this);
|
| }
|
|
|
| -void NetworkHandler::SetClient(std::unique_ptr<Client> client) {
|
| - client_.swap(client);
|
| +void NetworkHandler::SetRenderFrameHost(RenderFrameHostImpl* host) {
|
| + host_ = host;
|
| }
|
|
|
| -Response NetworkHandler::Enable(const int* max_total_size,
|
| - const int* max_resource_size) {
|
| +Response NetworkHandler::Enable(Maybe<int> max_total_size,
|
| + Maybe<int> max_resource_size) {
|
| enabled_ = true;
|
| return Response::FallThrough();
|
| }
|
| @@ -324,130 +289,80 @@ Response NetworkHandler::ClearBrowserCookies() {
|
| return Response::OK();
|
| }
|
|
|
| -Response NetworkHandler::GetCookies(DevToolsCommandId command_id,
|
| - const bool* global) {
|
| +void NetworkHandler::GetCookies(
|
| + Maybe<bool> global,
|
| + std::unique_ptr<GetCookiesCallback> callback) {
|
| if (!host_)
|
| - return Response::InternalError("Could not connect to view");
|
| - new GetCookiesCommand(host_, global ? *global : false,
|
| - base::Bind(&NetworkHandler::SendGetCookiesResponse,
|
| - weak_factory_.GetWeakPtr(), command_id));
|
| - return Response::OK();
|
| + callback->sendFailure(Response::InternalError());
|
| + else
|
| + new GetCookiesCommand(host_, global.fromMaybe(false), std::move(callback));
|
| }
|
|
|
| -Response NetworkHandler::SetCookie(DevToolsCommandId command_id,
|
| +void NetworkHandler::SetCookie(
|
| 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");
|
| + Maybe<std::string> domain,
|
| + Maybe<std::string> path,
|
| + Maybe<bool> secure,
|
| + Maybe<bool> http_only,
|
| + Maybe<std::string> same_site,
|
| + Maybe<double> expires,
|
| + std::unique_ptr<SetCookieCallback> callback) {
|
| + if (!host_) {
|
| + callback->sendFailure(Response::InternalError());
|
| + return;
|
| + }
|
|
|
| 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;
|
| + if (same_site.isJust()) {
|
| + if (same_site.fromJust() == Network::CookieSameSiteEnum::Lax)
|
| + same_site_enum = net::CookieSameSite::LAX_MODE;
|
| + else if (same_site.fromJust() == Network::CookieSameSiteEnum::Strict)
|
| + same_site_enum = net::CookieSameSite::STRICT_MODE;
|
| + }
|
|
|
| base::Time expiration_date;
|
| - if (expires)
|
| - expiration_date = (*expires == 0)
|
| + if (expires.isJust()) {
|
| + expiration_date = expires.fromJust() == 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) {
|
| - std::vector<scoped_refptr<Cookie>> cookies;
|
| - for (size_t i = 0; i < cookie_list.size(); ++i) {
|
| - const net::CanonicalCookie& cookie = cookie_list[i];
|
| - scoped_refptr<Cookie> devtools_cookie = Cookie::Create()
|
| - ->set_name(cookie.Name())
|
| - ->set_value(cookie.Value())
|
| - ->set_domain(cookie.Domain())
|
| - ->set_path(cookie.Path())
|
| - ->set_expires(cookie.ExpiryDate().ToDoubleT() * 1000)
|
| - ->set_size(cookie.Name().length() + cookie.Value().length())
|
| - ->set_http_only(cookie.IsHttpOnly())
|
| - ->set_secure(cookie.IsSecure())
|
| - ->set_session(!cookie.IsPersistent());
|
| -
|
| - switch (cookie.SameSite()) {
|
| - case net::CookieSameSite::STRICT_MODE:
|
| - devtools_cookie->set_same_site(kCookieSameSiteStrict);
|
| - break;
|
| - case net::CookieSameSite::LAX_MODE:
|
| - devtools_cookie->set_same_site(kCookieSameSiteLax);
|
| - break;
|
| - case net::CookieSameSite::NO_RESTRICTION:
|
| - break;
|
| - }
|
| - cookies.push_back(devtools_cookie);
|
| + : base::Time::FromDoubleT(expires.fromJust());
|
| }
|
| - client_->SendGetCookiesResponse(command_id,
|
| - GetCookiesResponse::Create()->set_cookies(cookies));
|
| +
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
|
| + &SetCookieOnIO,
|
| + base::Unretained(host_->GetSiteInstance()->GetBrowserContext()->
|
| + GetResourceContext()),
|
| + base::Unretained(host_->GetProcess()->GetStoragePartition()->
|
| + GetURLRequestContext()),
|
| + GURL(url), name, value, domain.fromMaybe(""), path.fromMaybe(""),
|
| + secure.fromMaybe(false), http_only.fromMaybe(false), same_site_enum,
|
| + expiration_date, base::Passed(std::move(callback))));
|
| }
|
|
|
| -Response NetworkHandler::DeleteCookie(
|
| - DevToolsCommandId command_id,
|
| +void NetworkHandler::DeleteCookie(
|
| const std::string& cookie_name,
|
| - const std::string& url) {
|
| - if (!host_)
|
| - return Response::InternalError("Could not connect to view");
|
| - DeleteCookieOnUI(
|
| - host_->GetSiteInstance()->GetBrowserContext()->GetResourceContext(),
|
| - host_->GetProcess()->GetStoragePartition()->GetURLRequestContext(),
|
| + const std::string& url,
|
| + std::unique_ptr<DeleteCookieCallback> callback) {
|
| + if (!host_) {
|
| + callback->sendFailure(Response::InternalError());
|
| + return;
|
| + }
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(
|
| + &DeleteCookieOnIO,
|
| + base::Unretained(host_->GetSiteInstance()->GetBrowserContext()->
|
| + GetResourceContext()),
|
| + base::Unretained(host_->GetProcess()->GetStoragePartition()->
|
| + GetURLRequestContext()),
|
| GURL(url),
|
| cookie_name,
|
| - base::Bind(&NetworkHandler::SendDeleteCookieResponse,
|
| - weak_factory_.GetWeakPtr(),
|
| - command_id));
|
| - return Response::OK();
|
| -}
|
| -
|
| -void NetworkHandler::SendDeleteCookieResponse(DevToolsCommandId command_id) {
|
| - client_->SendDeleteCookieResponse(command_id,
|
| - DeleteCookieResponse::Create());
|
| + base::Passed(std::move(callback))));
|
| }
|
|
|
| -
|
| Response NetworkHandler::CanEmulateNetworkConditions(bool* result) {
|
| *result = false;
|
| return Response::OK();
|
| }
|
|
|
| -Response NetworkHandler::EmulateNetworkConditions(
|
| - bool offline,
|
| - double latency,
|
| - double download_throughput,
|
| - double upload_throughput,
|
| - const std::string* connection_type) {
|
| - return Response::FallThrough();
|
| -}
|
| -
|
| -} // namespace network
|
| -} // namespace devtools
|
| +} // namespace protocol
|
| } // namespace content
|
|
|