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

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

Issue 2623063003: DevTools: Fix getCookies to report for all resources (Closed)
Patch Set: audit and line length fixes Created 3 years, 11 months 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 203 }
204 204
205 std::unique_ptr<Callback> callback_; 205 std::unique_ptr<Callback> callback_;
206 int request_count_; 206 int request_count_;
207 base::hash_map<std::string, net::CanonicalCookie> cookies_; 207 base::hash_map<std::string, net::CanonicalCookie> cookies_;
208 }; 208 };
209 209
210 class GetCookiesCommand : public GetCookiesCommandBase<GetCookiesCallback> { 210 class GetCookiesCommand : public GetCookiesCommandBase<GetCookiesCallback> {
211 public: 211 public:
212 GetCookiesCommand(RenderFrameHostImpl* frame_host, 212 GetCookiesCommand(RenderFrameHostImpl* frame_host,
213 std::unique_ptr<protocol::Array<std::string>> urls,
213 std::unique_ptr<GetCookiesCallback> callback) 214 std::unique_ptr<GetCookiesCallback> callback)
214 : GetCookiesCommandBase(std::move(callback)) { 215 : GetCookiesCommandBase(std::move(callback)) {
215 net::CookieStore::GetCookieListCallback got_cookies_callback = base::Bind( 216 net::CookieStore::GetCookieListCallback got_cookies_callback = base::Bind(
216 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this)); 217 &GetCookiesCommand::GotCookiesForURL, base::Unretained(this));
217 218
218 std::queue<FrameTreeNode*> queue; 219 for (size_t i = 0; i < urls->length(); i++) {
219 queue.push(frame_host->frame_tree_node());
220 while (!queue.empty()) {
221 FrameTreeNode* node = queue.front();
222 queue.pop();
223
224 // Only traverse nodes with the same local root.
225 if (node->current_frame_host()->IsCrossProcessSubframe())
226 continue;
227 ++request_count_; 220 ++request_count_;
228 BrowserThread::PostTask( 221 BrowserThread::PostTask(
pfeldman 2017/01/13 02:17:34 You should not post as many tasks as there are url
phulce 2017/01/18 00:52:34 Done.
229 BrowserThread::IO, FROM_HERE, 222 BrowserThread::IO, FROM_HERE,
230 base::Bind(&GetCookiesForURLOnIO, 223 base::Bind(&GetCookiesForURLOnIO,
231 base::Unretained(frame_host->GetSiteInstance() 224 base::Unretained(frame_host->GetSiteInstance()
232 ->GetBrowserContext() 225 ->GetBrowserContext()
233 ->GetResourceContext()), 226 ->GetResourceContext()),
234 base::Unretained(frame_host->GetProcess() 227 base::Unretained(frame_host->GetProcess()
235 ->GetStoragePartition() 228 ->GetStoragePartition()
236 ->GetURLRequestContext()), 229 ->GetURLRequestContext()),
237 node->current_url(), got_cookies_callback)); 230 GURL(urls->get(i)), got_cookies_callback));
238
239 for (size_t i = 0; i < node->child_count(); ++i)
240 queue.push(node->child_at(i));
241 } 231 }
242 } 232 }
243 }; 233 };
244 234
245 class GetAllCookiesCommand 235 class GetAllCookiesCommand
246 : public GetCookiesCommandBase<GetAllCookiesCallback> { 236 : public GetCookiesCommandBase<GetAllCookiesCallback> {
247 public: 237 public:
248 GetAllCookiesCommand(RenderFrameHostImpl* frame_host, 238 GetAllCookiesCommand(RenderFrameHostImpl* frame_host,
249 std::unique_ptr<GetAllCookiesCallback> callback) 239 std::unique_ptr<GetAllCookiesCallback> callback)
250 : GetCookiesCommandBase(std::move(callback)) { 240 : GetCookiesCommandBase(std::move(callback)) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return Response::OK(); 298 return Response::OK();
309 } 299 }
310 300
311 Response NetworkHandler::ClearBrowserCookies() { 301 Response NetworkHandler::ClearBrowserCookies() {
312 if (host_) 302 if (host_)
313 GetContentClient()->browser()->ClearCookies(host_); 303 GetContentClient()->browser()->ClearCookies(host_);
314 return Response::OK(); 304 return Response::OK();
315 } 305 }
316 306
317 void NetworkHandler::GetCookies( 307 void NetworkHandler::GetCookies(
308 std::unique_ptr<protocol::Array<std::string>> urls,
318 std::unique_ptr<GetCookiesCallback> callback) { 309 std::unique_ptr<GetCookiesCallback> callback) {
319 if (!host_) 310 if (!host_)
320 callback->sendFailure(Response::InternalError()); 311 callback->sendFailure(Response::InternalError());
321 else 312 else
322 new GetCookiesCommand(host_, std::move(callback)); 313 new GetCookiesCommand(host_, std::move(urls), std::move(callback));
323 } 314 }
324 315
325 void NetworkHandler::GetAllCookies( 316 void NetworkHandler::GetAllCookies(
326 std::unique_ptr<GetAllCookiesCallback> callback) { 317 std::unique_ptr<GetAllCookiesCallback> callback) {
327 if (!host_) 318 if (!host_)
328 callback->sendFailure(Response::InternalError()); 319 callback->sendFailure(Response::InternalError());
329 else 320 else
330 new GetAllCookiesCommand(host_, std::move(callback)); 321 new GetAllCookiesCommand(host_, std::move(callback));
331 } 322 }
332 323
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 *result = false; 396 *result = false;
406 return Response::OK(); 397 return Response::OK();
407 } 398 }
408 399
409 std::string NetworkHandler::UserAgentOverride() const { 400 std::string NetworkHandler::UserAgentOverride() const {
410 return enabled_ ? user_agent_ : std::string(); 401 return enabled_ ? user_agent_ : std::string();
411 } 402 }
412 403
413 } // namespace protocol 404 } // namespace protocol
414 } // namespace content 405 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698