| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/devtools/protocol/network_handler.h" | 5 #include "content/browser/devtools/protocol/network_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace content { | 42 namespace content { |
| 43 namespace protocol { | 43 namespace protocol { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 using ProtocolCookieArray = Array<Network::Cookie>; | 46 using ProtocolCookieArray = Array<Network::Cookie>; |
| 47 using GetCookiesCallback = Network::Backend::GetCookiesCallback; | 47 using GetCookiesCallback = Network::Backend::GetCookiesCallback; |
| 48 using GetAllCookiesCallback = Network::Backend::GetAllCookiesCallback; | 48 using GetAllCookiesCallback = Network::Backend::GetAllCookiesCallback; |
| 49 using SetCookieCallback = Network::Backend::SetCookieCallback; | 49 using SetCookieCallback = Network::Backend::SetCookieCallback; |
| 50 using DeleteCookieCallback = Network::Backend::DeleteCookieCallback; | 50 using DeleteCookieCallback = Network::Backend::DeleteCookieCallback; |
| 51 using ClearBrowserCookiesCallback = |
| 52 Network::Backend::ClearBrowserCookiesCallback; |
| 51 | 53 |
| 52 net::URLRequestContext* GetRequestContextOnIO( | 54 net::URLRequestContext* GetRequestContextOnIO( |
| 53 ResourceContext* resource_context, | 55 ResourceContext* resource_context, |
| 54 net::URLRequestContextGetter* context_getter, | 56 net::URLRequestContextGetter* context_getter, |
| 55 const GURL& url) { | 57 const GURL& url) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 57 net::URLRequestContext* context = | 59 net::URLRequestContext* context = |
| 58 GetContentClient()->browser()->OverrideRequestContextForURL( | 60 GetContentClient()->browser()->OverrideRequestContextForURL( |
| 59 url, resource_context); | 61 url, resource_context); |
| 60 if (!context) | 62 if (!context) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 178 |
| 177 std::unique_ptr<GetCookiesCallback> callback_; | 179 std::unique_ptr<GetCookiesCallback> callback_; |
| 178 std::unique_ptr<GetAllCookiesCallback> all_callback_; | 180 std::unique_ptr<GetAllCookiesCallback> all_callback_; |
| 179 int callback_count_ = 0; | 181 int callback_count_ = 0; |
| 180 std::unordered_map<std::string, net::CanonicalCookie> cookies_; | 182 std::unordered_map<std::string, net::CanonicalCookie> cookies_; |
| 181 | 183 |
| 182 private: | 184 private: |
| 183 friend class base::RefCountedThreadSafe<CookieRetriever>; | 185 friend class base::RefCountedThreadSafe<CookieRetriever>; |
| 184 }; | 186 }; |
| 185 | 187 |
| 188 void ClearedCookiesOnIO(std::unique_ptr<ClearBrowserCookiesCallback> callback, |
| 189 int num_deleted) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 191 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 192 base::Bind(&ClearBrowserCookiesCallback::sendSuccess, |
| 193 base::Passed(std::move(callback)))); |
| 194 } |
| 195 |
| 196 void ClearCookiesOnIO(ResourceContext* resource_context, |
| 197 net::URLRequestContextGetter* context_getter, |
| 198 std::unique_ptr<ClearBrowserCookiesCallback> callback) { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 200 net::URLRequestContext* request_context = |
| 201 context_getter->GetURLRequestContext(); |
| 202 request_context->cookie_store()->DeleteAllAsync( |
| 203 base::Bind(&ClearedCookiesOnIO, base::Passed(std::move(callback)))); |
| 204 } |
| 205 |
| 186 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) { | 206 void DeletedCookieOnIO(std::unique_ptr<DeleteCookieCallback> callback) { |
| 187 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 188 BrowserThread::PostTask( | 208 BrowserThread::PostTask( |
| 189 BrowserThread::UI, | 209 BrowserThread::UI, |
| 190 FROM_HERE, | 210 FROM_HERE, |
| 191 base::Bind(&DeleteCookieCallback::sendSuccess, | 211 base::Bind(&DeleteCookieCallback::sendSuccess, |
| 192 base::Passed(std::move(callback)))); | 212 base::Passed(std::move(callback)))); |
| 193 } | 213 } |
| 194 | 214 |
| 195 void DeleteCookieOnIO( | 215 void DeleteCookieOnIO( |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 user_agent_ = std::string(); | 451 user_agent_ = std::string(); |
| 432 return Response::FallThrough(); | 452 return Response::FallThrough(); |
| 433 } | 453 } |
| 434 | 454 |
| 435 Response NetworkHandler::ClearBrowserCache() { | 455 Response NetworkHandler::ClearBrowserCache() { |
| 436 if (host_) | 456 if (host_) |
| 437 GetContentClient()->browser()->ClearCache(host_); | 457 GetContentClient()->browser()->ClearCache(host_); |
| 438 return Response::OK(); | 458 return Response::OK(); |
| 439 } | 459 } |
| 440 | 460 |
| 441 Response NetworkHandler::ClearBrowserCookies() { | 461 void NetworkHandler::ClearBrowserCookies( |
| 442 if (host_) | 462 std::unique_ptr<ClearBrowserCookiesCallback> callback) { |
| 443 GetContentClient()->browser()->ClearCookies(host_); | 463 if (!host_) { |
| 444 return Response::OK(); | 464 callback->sendFailure(Response::InternalError()); |
| 465 return; |
| 466 } |
| 467 |
| 468 BrowserThread::PostTask( |
| 469 BrowserThread::IO, FROM_HERE, |
| 470 base::Bind(&ClearCookiesOnIO, |
| 471 base::Unretained(host_->GetSiteInstance() |
| 472 ->GetBrowserContext() |
| 473 ->GetResourceContext()), |
| 474 base::Unretained(host_->GetProcess() |
| 475 ->GetStoragePartition() |
| 476 ->GetURLRequestContext()), |
| 477 base::Passed(std::move(callback)))); |
| 445 } | 478 } |
| 446 | 479 |
| 447 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls, | 480 void NetworkHandler::GetCookies(Maybe<Array<String>> protocol_urls, |
| 448 std::unique_ptr<GetCookiesCallback> callback) { | 481 std::unique_ptr<GetCookiesCallback> callback) { |
| 449 if (!host_) { | 482 if (!host_) { |
| 450 callback->sendFailure(Response::InternalError()); | 483 callback->sendFailure(Response::InternalError()); |
| 451 return; | 484 return; |
| 452 } | 485 } |
| 453 | 486 |
| 454 std::vector<GURL> urls = ComputeCookieURLs(host_, protocol_urls); | 487 std::vector<GURL> urls = ComputeCookieURLs(host_, protocol_urls); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 static_cast<double>(base::Time::kMicrosecondsPerSecond), | 753 static_cast<double>(base::Time::kMicrosecondsPerSecond), |
| 721 Page::ResourceTypeEnum::Document, error_string, cancelled); | 754 Page::ResourceTypeEnum::Document, error_string, cancelled); |
| 722 } | 755 } |
| 723 | 756 |
| 724 std::string NetworkHandler::UserAgentOverride() const { | 757 std::string NetworkHandler::UserAgentOverride() const { |
| 725 return enabled_ ? user_agent_ : std::string(); | 758 return enabled_ ? user_agent_ : std::string(); |
| 726 } | 759 } |
| 727 | 760 |
| 728 } // namespace protocol | 761 } // namespace protocol |
| 729 } // namespace content | 762 } // namespace content |
| OLD | NEW |