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

Side by Side Diff: Source/core/inspector/InspectorPageAgent.cpp

Issue 800113002: Use C++11 range-based for loop in Source/core/inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: REBASE AGAIN! Created 6 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 334 }
335 335
336 Resource* InspectorPageAgent::cachedResource(LocalFrame* frame, const KURL& url) 336 Resource* InspectorPageAgent::cachedResource(LocalFrame* frame, const KURL& url)
337 { 337 {
338 Document* document = frame->document(); 338 Document* document = frame->document();
339 if (!document) 339 if (!document)
340 return 0; 340 return 0;
341 Resource* cachedResource = document->fetcher()->cachedResource(url); 341 Resource* cachedResource = document->fetcher()->cachedResource(url);
342 if (!cachedResource) { 342 if (!cachedResource) {
343 Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame ); 343 Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame );
344 for (Vector<Document*>::const_iterator it = allImports.begin(); it != al lImports.end(); ++it) { 344 for (const auto& it : allImports) {
345 Document* import = *it; 345 Document* import = it;
346 cachedResource = import->fetcher()->cachedResource(url); 346 cachedResource = import->fetcher()->cachedResource(url);
347 if (cachedResource) 347 if (cachedResource)
348 break; 348 break;
349 } 349 }
350 } 350 }
351 if (!cachedResource) 351 if (!cachedResource)
352 cachedResource = memoryCache()->resourceForURL(url, document->fetcher()- >getCacheIdentifier()); 352 cachedResource = memoryCache()->resourceForURL(url, document->fetcher()- >getCacheIdentifier());
353 return cachedResource; 353 return cachedResource;
354 } 354 }
355 355
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 ListHashSet<Cookie>::iterator it = cookiesList.begin(); 621 ListHashSet<Cookie>::iterator it = cookiesList.begin();
622 for (int i = 0; it != end; ++it, i++) 622 for (int i = 0; it != end; ++it, i++)
623 cookies->addItem(buildObjectForCookie(*it)); 623 cookies->addItem(buildObjectForCookie(*it));
624 624
625 return cookies; 625 return cookies;
626 } 626 }
627 627
628 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs) 628 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs)
629 { 629 {
630 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources(); 630 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources();
631 ResourceFetcher::DocumentResourceMap::const_iterator end = allResources.end( ); 631 for (const auto& it : allResources) {
632 for (ResourceFetcher::DocumentResourceMap::const_iterator it = allResources. begin(); it != end; ++it) { 632 Resource* cachedResource = it.value.get();
633 Resource* cachedResource = it->value.get();
634 633
635 switch (cachedResource->type()) { 634 switch (cachedResource->type()) {
636 case Resource::Image: 635 case Resource::Image:
637 // Skip images that were not auto loaded (images disabled in the use r agent). 636 // Skip images that were not auto loaded (images disabled in the use r agent).
638 if (toImageResource(cachedResource)->stillNeedsLoad()) 637 if (toImageResource(cachedResource)->stillNeedsLoad())
639 continue; 638 continue;
640 break; 639 break;
641 case Resource::Font: 640 case Resource::Font:
642 // Skip fonts that were referenced in CSS but never used/downloaded. 641 // Skip fonts that were referenced in CSS but never used/downloaded.
643 if (toFontResource(cachedResource)->stillNeedsLoad()) 642 if (toFontResource(cachedResource)->stillNeedsLoad())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 return result; 684 return result;
686 } 685 }
687 686
688 static Vector<KURL> allResourcesURLsForFrame(LocalFrame* frame) 687 static Vector<KURL> allResourcesURLsForFrame(LocalFrame* frame)
689 { 688 {
690 Vector<KURL> result; 689 Vector<KURL> result;
691 690
692 result.append(urlWithoutFragment(frame->loader().documentLoader()->url())); 691 result.append(urlWithoutFragment(frame->loader().documentLoader()->url()));
693 692
694 Vector<Resource*> allResources = cachedResourcesForFrame(frame, false); 693 Vector<Resource*> allResources = cachedResourcesForFrame(frame, false);
695 for (Vector<Resource*>::const_iterator it = allResources.begin(); it != allR esources.end(); ++it) 694 for (const auto& it : allResources)
696 result.append(urlWithoutFragment((*it)->url())); 695 result.append(urlWithoutFragment(it->url()));
697 696
698 return result; 697 return result;
699 } 698 }
700 699
701 void InspectorPageAgent::getCookies(ErrorString*, RefPtr<TypeBuilder::Array<Type Builder::Page::Cookie> >& cookies) 700 void InspectorPageAgent::getCookies(ErrorString*, RefPtr<TypeBuilder::Array<Type Builder::Page::Cookie> >& cookies)
702 { 701 {
703 ListHashSet<Cookie> rawCookiesList; 702 ListHashSet<Cookie> rawCookiesList;
704 703
705 for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext(m ainFrame())) { 704 for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext(m ainFrame())) {
706 if (!frame->isLocalFrame()) 705 if (!frame->isLocalFrame())
707 continue; 706 continue;
708 Document* document = toLocalFrame(frame)->document(); 707 Document* document = toLocalFrame(frame)->document();
709 Vector<KURL> allURLs = allResourcesURLsForFrame(toLocalFrame(frame)); 708 Vector<KURL> allURLs = allResourcesURLsForFrame(toLocalFrame(frame));
710 for (Vector<KURL>::const_iterator it = allURLs.begin(); it != allURLs.en d(); ++it) { 709 for (const auto& it : allURLs) {
711 Vector<Cookie> docCookiesList; 710 Vector<Cookie> docCookiesList;
712 getRawCookies(document, *it, docCookiesList); 711 getRawCookies(document, it, docCookiesList);
713 int cookiesSize = docCookiesList.size(); 712 int cookiesSize = docCookiesList.size();
714 for (int i = 0; i < cookiesSize; i++) { 713 for (int i = 0; i < cookiesSize; i++) {
715 if (!rawCookiesList.contains(docCookiesList[i])) 714 if (!rawCookiesList.contains(docCookiesList[i]))
716 rawCookiesList.add(docCookiesList[i]); 715 rawCookiesList.add(docCookiesList[i]);
717 } 716 }
718 } 717 }
719 } 718 }
720 719
721 cookies = buildArrayForCookies(rawCookiesList); 720 cookies = buildArrayForCookies(rawCookiesList);
722 } 721 }
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 } 981 }
983 } 982 }
984 983
985 void InspectorPageAgent::didClearDocumentOfWindowObject(LocalFrame* frame) 984 void InspectorPageAgent::didClearDocumentOfWindowObject(LocalFrame* frame)
986 { 985 {
987 if (!m_frontend) 986 if (!m_frontend)
988 return; 987 return;
989 988
990 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad); 989 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad);
991 if (scripts) { 990 if (scripts) {
992 JSONObject::const_iterator end = scripts->end(); 991 for (const auto& it : *scripts) {
993 for (JSONObject::const_iterator it = scripts->begin(); it != end; ++it) {
994 String scriptText; 992 String scriptText;
995 if (it->value->asString(&scriptText)) 993 if (it.value->asString(&scriptText))
996 frame->script().executeScriptInMainWorld(scriptText); 994 frame->script().executeScriptInMainWorld(scriptText);
997 } 995 }
998 } 996 }
999 if (!m_scriptToEvaluateOnLoadOnce.isEmpty()) 997 if (!m_scriptToEvaluateOnLoadOnce.isEmpty())
1000 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce); 998 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce);
1001 } 999 }
1002 1000
1003 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame) 1001 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame)
1004 { 1002 {
1005 if (!frame->isMainFrame()) 1003 if (!frame->isMainFrame())
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 1288
1291 PassRefPtr<TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObject ForFrameTree(LocalFrame* frame) 1289 PassRefPtr<TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObject ForFrameTree(LocalFrame* frame)
1292 { 1290 {
1293 RefPtr<TypeBuilder::Page::Frame> frameObject = buildObjectForFrame(frame); 1291 RefPtr<TypeBuilder::Page::Frame> frameObject = buildObjectForFrame(frame);
1294 RefPtr<TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree::Resources> > subresources = TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree::Resourc es>::create(); 1292 RefPtr<TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree::Resources> > subresources = TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree::Resourc es>::create();
1295 RefPtr<TypeBuilder::Page::FrameResourceTree> result = TypeBuilder::Page::Fra meResourceTree::create() 1293 RefPtr<TypeBuilder::Page::FrameResourceTree> result = TypeBuilder::Page::Fra meResourceTree::create()
1296 .setFrame(frameObject) 1294 .setFrame(frameObject)
1297 .setResources(subresources); 1295 .setResources(subresources);
1298 1296
1299 Vector<Resource*> allResources = cachedResourcesForFrame(frame, true); 1297 Vector<Resource*> allResources = cachedResourcesForFrame(frame, true);
1300 for (Vector<Resource*>::const_iterator it = allResources.begin(); it != allR esources.end(); ++it) { 1298 for (const auto& it : allResources) {
1301 Resource* cachedResource = *it; 1299 Resource* cachedResource = it;
1302 1300
1303 RefPtr<TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = TypeBuilder::Page::FrameResourceTree::Resources::create() 1301 RefPtr<TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = TypeBuilder::Page::FrameResourceTree::Resources::create()
1304 .setUrl(urlWithoutFragment(cachedResource->url()).string()) 1302 .setUrl(urlWithoutFragment(cachedResource->url()).string())
1305 .setType(cachedResourceTypeJson(*cachedResource)) 1303 .setType(cachedResourceTypeJson(*cachedResource))
1306 .setMimeType(cachedResource->response().mimeType()); 1304 .setMimeType(cachedResource->response().mimeType());
1307 if (cachedResource->wasCanceled()) 1305 if (cachedResource->wasCanceled())
1308 resourceObject->setCanceled(true); 1306 resourceObject->setCanceled(true);
1309 else if (cachedResource->status() == Resource::LoadError) 1307 else if (cachedResource->status() == Resource::LoadError)
1310 resourceObject->setFailed(true); 1308 resourceObject->setFailed(true);
1311 subresources->addItem(resourceObject); 1309 subresources->addItem(resourceObject);
1312 } 1310 }
1313 1311
1314 Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame); 1312 Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame);
1315 for (Vector<Document*>::const_iterator it = allImports.begin(); it != allImp orts.end(); ++it) { 1313 for (const auto& it : allImports) {
1316 Document* import = *it; 1314 Document* import = it;
1317 RefPtr<TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = TypeBuilder::Page::FrameResourceTree::Resources::create() 1315 RefPtr<TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = TypeBuilder::Page::FrameResourceTree::Resources::create()
1318 .setUrl(urlWithoutFragment(import->url()).string()) 1316 .setUrl(urlWithoutFragment(import->url()).string())
1319 .setType(resourceTypeJson(InspectorPageAgent::DocumentResource)) 1317 .setType(resourceTypeJson(InspectorPageAgent::DocumentResource))
1320 .setMimeType(import->suggestedMIMEType()); 1318 .setMimeType(import->suggestedMIMEType());
1321 subresources->addItem(resourceObject); 1319 subresources->addItem(resourceObject);
1322 } 1320 }
1323 1321
1324 RefPtr<TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree> > childrenAr ray; 1322 RefPtr<TypeBuilder::Array<TypeBuilder::Page::FrameResourceTree> > childrenAr ray;
1325 for (Frame* child = frame->tree().firstChild(); child; child = child->tree() .nextSibling()) { 1323 for (Frame* child = frame->tree().firstChild(); child; child = child->tree() .nextSibling()) {
1326 if (!child->isLocalFrame()) 1324 if (!child->isLocalFrame())
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 void InspectorPageAgent::trace(Visitor* visitor) 1501 void InspectorPageAgent::trace(Visitor* visitor)
1504 { 1502 {
1505 visitor->trace(m_page); 1503 visitor->trace(m_page);
1506 visitor->trace(m_injectedScriptManager); 1504 visitor->trace(m_injectedScriptManager);
1507 visitor->trace(m_inspectorResourceContentLoader); 1505 visitor->trace(m_inspectorResourceContentLoader);
1508 InspectorBaseAgent::trace(visitor); 1506 InspectorBaseAgent::trace(visitor);
1509 } 1507 }
1510 1508
1511 } // namespace blink 1509 } // namespace blink
1512 1510
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698