Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/browser/devtools/protocol/network_handler.cc

Issue 2554293002: devtools: Make it possible to retrieve all cookies (Closed)
Patch Set: Update front-end Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 BrowserThread::PostTask( 78 BrowserThread::PostTask(
79 BrowserThread::IO, 79 BrowserThread::IO,
80 FROM_HERE, 80 FROM_HERE,
81 base::Bind(&GetCookiesForURLOnIO, 81 base::Bind(&GetCookiesForURLOnIO,
82 base::Unretained(resource_context), 82 base::Unretained(resource_context),
83 base::Unretained(context_getter), 83 base::Unretained(context_getter),
84 url, 84 url,
85 callback)); 85 callback));
86 } 86 }
87 87
88 void GetCookiesOnIO(ResourceContext* resource_context,
89 net::URLRequestContextGetter* context_getter,
90 const CookieListCallback& callback) {
91 DCHECK_CURRENTLY_ON(BrowserThread::IO);
92 net::URLRequestContext* request_context =
93 context_getter->GetURLRequestContext();
94 request_context->cookie_store()->GetAllCookiesAsync(
95 base::Bind(&GotCookiesForURLOnIO, callback));
96 }
97
98 void GetCookiesOnUI(ResourceContext* resource_context,
99 net::URLRequestContextGetter* context_getter,
100 const CookieListCallback& callback) {
101 DCHECK_CURRENTLY_ON(BrowserThread::UI);
102 BrowserThread::PostTask(
103 BrowserThread::IO, FROM_HERE,
104 base::Bind(&GetCookiesOnIO, base::Unretained(resource_context),
105 base::Unretained(context_getter), callback));
106 }
107
88 void DeletedCookieOnIO(const base::Closure& callback) { 108 void DeletedCookieOnIO(const base::Closure& callback) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO); 109 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 BrowserThread::PostTask( 110 BrowserThread::PostTask(
91 BrowserThread::UI, 111 BrowserThread::UI,
92 FROM_HERE, 112 FROM_HERE,
93 callback); 113 callback);
94 } 114 }
95 115
96 void DeleteCookieOnIO( 116 void DeleteCookieOnIO(
97 ResourceContext* resource_context, 117 ResourceContext* resource_context,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 FROM_HERE, 205 FROM_HERE,
186 base::Bind(&SetCookieOnIO, 206 base::Bind(&SetCookieOnIO,
187 base::Unretained(resource_context), 207 base::Unretained(resource_context),
188 base::Unretained(context_getter), 208 base::Unretained(context_getter),
189 url, name, value, domain, path, secure, http_only, 209 url, name, value, domain, path, secure, http_only,
190 same_site, expires, callback)); 210 same_site, expires, callback));
191 } 211 }
192 212
193 class GetCookiesCommand { 213 class GetCookiesCommand {
194 public: 214 public:
195 explicit GetCookiesCommand( 215 GetCookiesCommand(RenderFrameHostImpl* frame_host,
196 RenderFrameHostImpl* frame_host, 216 bool global,
197 const CookieListCallback& callback) 217 const CookieListCallback& callback)
198 : callback_(callback), 218 : callback_(callback), request_count_(0) {
199 request_count_(0) {
200 CookieListCallback got_cookies_callback = base::Bind( 219 CookieListCallback got_cookies_callback = base::Bind(
201 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this)); 220 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this));
202 221
222 if (global) {
223 request_count_ = 1;
224 GetCookiesOnUI(frame_host->GetSiteInstance()
225 ->GetBrowserContext()
226 ->GetResourceContext(),
227 frame_host->GetProcess()
228 ->GetStoragePartition()
229 ->GetURLRequestContext(),
230 got_cookies_callback);
231 return;
232 }
233
203 std::queue<FrameTreeNode*> queue; 234 std::queue<FrameTreeNode*> queue;
204 queue.push(frame_host->frame_tree_node()); 235 queue.push(frame_host->frame_tree_node());
205 while (!queue.empty()) { 236 while (!queue.empty()) {
206 FrameTreeNode* node = queue.front(); 237 FrameTreeNode* node = queue.front();
207 queue.pop(); 238 queue.pop();
208 239
209 // Only traverse nodes with the same local root. 240 // Only traverse nodes with the same local root.
210 if (node->current_frame_host()->IsCrossProcessSubframe()) 241 if (node->current_frame_host()->IsCrossProcessSubframe())
211 continue; 242 continue;
212 ++request_count_; 243 ++request_count_;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 GetContentClient()->browser()->ClearCache(host_); 317 GetContentClient()->browser()->ClearCache(host_);
287 return Response::OK(); 318 return Response::OK();
288 } 319 }
289 320
290 Response NetworkHandler::ClearBrowserCookies() { 321 Response NetworkHandler::ClearBrowserCookies() {
291 if (host_) 322 if (host_)
292 GetContentClient()->browser()->ClearCookies(host_); 323 GetContentClient()->browser()->ClearCookies(host_);
293 return Response::OK(); 324 return Response::OK();
294 } 325 }
295 326
296 Response NetworkHandler::GetCookies(DevToolsCommandId command_id) { 327 Response NetworkHandler::GetCookies(DevToolsCommandId command_id,
328 const bool* global) {
297 if (!host_) 329 if (!host_)
298 return Response::InternalError("Could not connect to view"); 330 return Response::InternalError("Could not connect to view");
299 new GetCookiesCommand( 331 new GetCookiesCommand(host_, global ? *global : false,
300 host_, 332 base::Bind(&NetworkHandler::SendGetCookiesResponse,
301 base::Bind(&NetworkHandler::SendGetCookiesResponse, 333 weak_factory_.GetWeakPtr(), command_id));
302 weak_factory_.GetWeakPtr(),
303 command_id));
304 return Response::OK(); 334 return Response::OK();
305 } 335 }
306 336
307 Response NetworkHandler::SetCookie(DevToolsCommandId command_id, 337 Response NetworkHandler::SetCookie(DevToolsCommandId command_id,
308 const std::string& url, 338 const std::string& url,
309 const std::string& name, 339 const std::string& name,
310 const std::string& value, 340 const std::string& value,
311 const std::string* domain, 341 const std::string* domain,
312 const std::string* path, 342 const std::string* path,
313 bool* secure, 343 bool* secure,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 double latency, 444 double latency,
415 double download_throughput, 445 double download_throughput,
416 double upload_throughput, 446 double upload_throughput,
417 const std::string* connection_type) { 447 const std::string* connection_type) {
418 return Response::FallThrough(); 448 return Response::FallThrough();
419 } 449 }
420 450
421 } // namespace network 451 } // namespace network
422 } // namespace devtools 452 } // namespace devtools
423 } // namespace content 453 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698