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

Side by Side Diff: Source/core/inspector/InspectorResourceAgent.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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 namespace { 88 namespace {
89 89
90 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc 90 // Keep in sync with kDevToolsRequestInitiator defined in devtools_network_contr oller.cc
91 const char kDevToolsRequestInitiator[] = "X-DevTools-Request-Initiator"; 91 const char kDevToolsRequestInitiator[] = "X-DevTools-Request-Initiator";
92 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id"; 92 const char kDevToolsEmulateNetworkConditionsClientId[] = "X-DevTools-Emulate-Net work-Conditions-Client-Id";
93 93
94 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers ) 94 static PassRefPtr<JSONObject> buildObjectForHeaders(const HTTPHeaderMap& headers )
95 { 95 {
96 RefPtr<JSONObject> headersObject = JSONObject::create(); 96 RefPtr<JSONObject> headersObject = JSONObject::create();
97 HTTPHeaderMap::const_iterator end = headers.end(); 97 for (const auto& it : headers)
98 for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) 98 headersObject->setString(it.key.string(), it.value);
99 headersObject->setString(it->key.string(), it->value);
100 return headersObject; 99 return headersObject;
101 } 100 }
102 101
103 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient { 102 class InspectorFileReaderLoaderClient final : public FileReaderLoaderClient {
104 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient); 103 WTF_MAKE_NONCOPYABLE(InspectorFileReaderLoaderClient);
105 public: 104 public:
106 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, PassOwnPtr< TextResourceDecoder> decoder, PassRefPtrWillBeRawPtr<GetResponseBodyCallback> ca llback) 105 InspectorFileReaderLoaderClient(PassRefPtr<BlobDataHandle> blob, PassOwnPtr< TextResourceDecoder> decoder, PassRefPtrWillBeRawPtr<GetResponseBodyCallback> ca llback)
107 : m_blob(blob) 106 : m_blob(blob)
108 , m_decoder(decoder) 107 , m_decoder(decoder)
109 , m_callback(callback) 108 , m_callback(callback)
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 type = InspectorPageAgent::XHRResource; 401 type = InspectorPageAgent::XHRResource;
403 m_resourcesData->setResourceType(requestId, type); 402 m_resourcesData->setResourceType(requestId, type);
404 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) { 403 } else if (initiatorInfo.name == FetchInitiatorTypeNames::document) {
405 type = InspectorPageAgent::DocumentResource; 404 type = InspectorPageAgent::DocumentResource;
406 m_resourcesData->setResourceType(requestId, type); 405 m_resourcesData->setResourceType(requestId, type);
407 } 406 }
408 407
409 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders); 408 RefPtr<JSONObject> headers = m_state->getObject(ResourceAgentState::extraReq uestHeaders);
410 409
411 if (headers) { 410 if (headers) {
412 JSONObject::const_iterator end = headers->end(); 411 for (const auto& it : *headers) {
413 for (JSONObject::const_iterator it = headers->begin(); it != end; ++it) {
414 String value; 412 String value;
415 if (it->value->asString(&value)) 413 if (it.value->asString(&value))
416 request.setHTTPHeaderField(AtomicString(it->key), AtomicString(v alue)); 414 request.setHTTPHeaderField(AtomicString(it.key), AtomicString(va lue));
417 } 415 }
418 } 416 }
419 417
420 request.setReportRawHeaders(true); 418 request.setReportRawHeaders(true);
421 419
422 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) { 420 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) {
423 request.setCachePolicy(ReloadBypassingCache); 421 request.setCachePolicy(ReloadBypassingCache);
424 request.setShouldResetAppCache(true); 422 request.setShouldResetAppCache(true);
425 } 423 }
426 424
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource); 565 m_resourcesData->setResourceType(IdentifiersFactory::requestId(identifier), InspectorPageAgent::XHRResource);
568 XHRReplayData* xhrReplayData = it->value.get(); 566 XHRReplayData* xhrReplayData = it->value.get();
569 String requestId = IdentifiersFactory::requestId(identifier); 567 String requestId = IdentifiersFactory::requestId(identifier);
570 m_resourcesData->setXHRReplayData(requestId, xhrReplayData); 568 m_resourcesData->setXHRReplayData(requestId, xhrReplayData);
571 } 569 }
572 570
573 void InspectorResourceAgent::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderCl ient* client, const AtomicString& method, const KURL& url, bool async, PassRefPt r<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials) 571 void InspectorResourceAgent::willLoadXHR(XMLHttpRequest* xhr, ThreadableLoaderCl ient* client, const AtomicString& method, const KURL& url, bool async, PassRefPt r<FormData> formData, const HTTPHeaderMap& headers, bool includeCredentials)
574 { 572 {
575 ASSERT(xhr); 573 ASSERT(xhr);
576 RefPtrWillBeRawPtr<XHRReplayData> xhrReplayData = XHRReplayData::create(xhr- >executionContext(), method, urlWithoutFragment(url), async, formData.get(), inc ludeCredentials); 574 RefPtrWillBeRawPtr<XHRReplayData> xhrReplayData = XHRReplayData::create(xhr- >executionContext(), method, urlWithoutFragment(url), async, formData.get(), inc ludeCredentials);
577 HTTPHeaderMap::const_iterator end = headers.end(); 575 for (const auto& it : headers)
578 for (HTTPHeaderMap::const_iterator it = headers.begin(); it!= end; ++it) 576 xhrReplayData->addHeader(it.key, it.value);
579 xhrReplayData->addHeader(it->key, it->value);
580 m_pendingXHRReplayData.set(client, xhrReplayData); 577 m_pendingXHRReplayData.set(client, xhrReplayData);
581 } 578 }
582 579
583 void InspectorResourceAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr) 580 void InspectorResourceAgent::delayedRemoveReplayXHR(XMLHttpRequest* xhr)
584 { 581 {
585 if (!m_replayXHRs.contains(xhr)) 582 if (!m_replayXHRs.contains(xhr))
586 return; 583 return;
587 584
588 m_replayXHRsToBeDeleted.add(xhr); 585 m_replayXHRsToBeDeleted.add(xhr);
589 m_replayXHRs.remove(xhr); 586 m_replayXHRs.remove(xhr);
(...skipping 20 matching lines...) Expand all
610 void InspectorResourceAgent::willDestroyResource(Resource* cachedResource) 607 void InspectorResourceAgent::willDestroyResource(Resource* cachedResource)
611 { 608 {
612 Vector<String> requestIds = m_resourcesData->removeResource(cachedResource); 609 Vector<String> requestIds = m_resourcesData->removeResource(cachedResource);
613 if (!requestIds.size()) 610 if (!requestIds.size())
614 return; 611 return;
615 612
616 String content; 613 String content;
617 bool base64Encoded; 614 bool base64Encoded;
618 if (!InspectorPageAgent::cachedResourceContent(cachedResource, &content, &ba se64Encoded)) 615 if (!InspectorPageAgent::cachedResourceContent(cachedResource, &content, &ba se64Encoded))
619 return; 616 return;
620 Vector<String>::iterator end = requestIds.end(); 617 for (auto it : requestIds)
621 for (Vector<String>::iterator it = requestIds.begin(); it != end; ++it) 618 m_resourcesData->setResourceContent(it, content, base64Encoded);
622 m_resourcesData->setResourceContent(*it, content, base64Encoded);
623 } 619 }
624 620
625 void InspectorResourceAgent::applyUserAgentOverride(String* userAgent) 621 void InspectorResourceAgent::applyUserAgentOverride(String* userAgent)
626 { 622 {
627 String userAgentOverride = m_state->getString(ResourceAgentState::userAgentO verride); 623 String userAgentOverride = m_state->getString(ResourceAgentState::userAgentO verride);
628 if (!userAgentOverride.isEmpty()) 624 if (!userAgentOverride.isEmpty())
629 *userAgent = userAgentOverride; 625 *userAgent = userAgentOverride;
630 } 626 }
631 627
632 void InspectorResourceAgent::willRecalculateStyle(Document*) 628 void InspectorResourceAgent::willRecalculateStyle(Document*)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 if (!executionContext) { 830 if (!executionContext) {
835 m_resourcesData->setXHRReplayData(requestId, 0); 831 m_resourcesData->setXHRReplayData(requestId, 0);
836 return; 832 return;
837 } 833 }
838 834
839 RefPtrWillBeRawPtr<XMLHttpRequest> xhr = XMLHttpRequest::create(executionCon text); 835 RefPtrWillBeRawPtr<XMLHttpRequest> xhr = XMLHttpRequest::create(executionCon text);
840 836
841 memoryCache()->removeURLFromCache(executionContext, xhrReplayData->url()); 837 memoryCache()->removeURLFromCache(executionContext, xhrReplayData->url());
842 838
843 xhr->open(xhrReplayData->method(), xhrReplayData->url(), xhrReplayData->asyn c(), IGNORE_EXCEPTION); 839 xhr->open(xhrReplayData->method(), xhrReplayData->url(), xhrReplayData->asyn c(), IGNORE_EXCEPTION);
844 HTTPHeaderMap::const_iterator end = xhrReplayData->headers().end(); 840 for (const auto& it : xhrReplayData->headers())
845 for (HTTPHeaderMap::const_iterator it = xhrReplayData->headers().begin(); it != end; ++it) 841 xhr->setRequestHeader(it.key, it.value, IGNORE_EXCEPTION);
846 xhr->setRequestHeader(it->key, it->value, IGNORE_EXCEPTION);
847 xhr->sendForInspectorXHRReplay(xhrReplayData->formData(), IGNORE_EXCEPTION); 842 xhr->sendForInspectorXHRReplay(xhrReplayData->formData(), IGNORE_EXCEPTION);
848 843
849 m_replayXHRs.add(xhr); 844 m_replayXHRs.add(xhr);
850 } 845 }
851 846
852 void InspectorResourceAgent::canClearBrowserCache(ErrorString*, bool* result) 847 void InspectorResourceAgent::canClearBrowserCache(ErrorString*, bool* result)
853 { 848 {
854 *result = true; 849 *result = true;
855 } 850 }
856 851
(...skipping 28 matching lines...) Expand all
885 if (!document) { 880 if (!document) {
886 *errorString = "No Document instance for the specified frame"; 881 *errorString = "No Document instance for the specified frame";
887 return; 882 return;
888 } 883 }
889 884
890 ResourceRequest request(url); 885 ResourceRequest request(url);
891 request.setHTTPMethod("GET"); 886 request.setHTTPMethod("GET");
892 request.setRequestContext(blink::WebURLRequest::RequestContextInternal); 887 request.setRequestContext(blink::WebURLRequest::RequestContextInternal);
893 request.setCachePolicy(ReloadIgnoringCacheData); 888 request.setCachePolicy(ReloadIgnoringCacheData);
894 if (requestHeaders) { 889 if (requestHeaders) {
895 for (JSONObject::iterator it = (*requestHeaders)->begin(); it != (*reque stHeaders)->end(); ++it) { 890 for (auto it : *(*requestHeaders)) {
896 String value; 891 String value;
897 bool success = it->value->asString(&value); 892 bool success = it.value->asString(&value);
898 if (!success) { 893 if (!success) {
899 *errorString = "Request header \"" + it->key + "\" value is not a string"; 894 *errorString = "Request header \"" + it.key + "\" value is not a string";
900 return; 895 return;
901 } 896 }
902 request.addHTTPHeaderField(AtomicString(it->key), AtomicString(value )); 897 request.addHTTPHeaderField(AtomicString(it.key), AtomicString(value) );
903 } 898 }
904 } 899 }
905 request.addHTTPHeaderField(kDevToolsRequestInitiator, "frontend"); 900 request.addHTTPHeaderField(kDevToolsRequestInitiator, "frontend");
906 901
907 ThreadableLoaderOptions options; 902 ThreadableLoaderOptions options;
908 options.crossOriginRequestPolicy = AllowCrossOriginRequests; 903 options.crossOriginRequestPolicy = AllowCrossOriginRequests;
909 904
910 ResourceLoaderOptions resourceLoaderOptions; 905 ResourceLoaderOptions resourceLoaderOptions;
911 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; 906 resourceLoaderOptions.allowCredentials = AllowStoredCredentials;
912 907
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 { 948 {
954 // First try to fetch content from the cached resource. 949 // First try to fetch content from the cached resource.
955 Resource* cachedResource = document->fetcher()->cachedResource(url); 950 Resource* cachedResource = document->fetcher()->cachedResource(url);
956 if (!cachedResource) 951 if (!cachedResource)
957 cachedResource = memoryCache()->resourceForURL(url, document->fetcher()- >getCacheIdentifier()); 952 cachedResource = memoryCache()->resourceForURL(url, document->fetcher()- >getCacheIdentifier());
958 if (cachedResource && InspectorPageAgent::cachedResourceContent(cachedResour ce, content, base64Encoded)) 953 if (cachedResource && InspectorPageAgent::cachedResourceContent(cachedResour ce, content, base64Encoded))
959 return true; 954 return true;
960 955
961 // Then fall back to resource data. 956 // Then fall back to resource data.
962 Vector<NetworkResourcesData::ResourceData*> resources = m_resourcesData->res ources(); 957 Vector<NetworkResourcesData::ResourceData*> resources = m_resourcesData->res ources();
963 for (Vector<NetworkResourcesData::ResourceData*>::iterator it = resources.be gin(); it != resources.end(); ++it) { 958 for (auto it : resources) {
pfeldman 2014/12/16 16:52:10 while you are here, auto it : m_resourcesData->res
zhaoze.zhou 2014/12/16 18:56:40 Done.
964 if ((*it)->url() == url) { 959 if (it->url() == url) {
965 *content = (*it)->content(); 960 *content = it->content();
966 *base64Encoded = (*it)->base64Encoded(); 961 *base64Encoded = it->base64Encoded();
967 return true; 962 return true;
968 } 963 }
969 } 964 }
970 return false; 965 return false;
971 } 966 }
972 967
973 void InspectorResourceAgent::removeFinishedReplayXHRFired(Timer<InspectorResourc eAgent>*) 968 void InspectorResourceAgent::removeFinishedReplayXHRFired(Timer<InspectorResourc eAgent>*)
974 { 969 {
975 m_replayXHRsToBeDeleted.clear(); 970 m_replayXHRsToBeDeleted.clear();
976 } 971 }
977 972
978 InspectorResourceAgent::InspectorResourceAgent(InspectorPageAgent* pageAgent) 973 InspectorResourceAgent::InspectorResourceAgent(InspectorPageAgent* pageAgent)
979 : InspectorBaseAgent<InspectorResourceAgent>("Network") 974 : InspectorBaseAgent<InspectorResourceAgent>("Network")
980 , m_pageAgent(pageAgent) 975 , m_pageAgent(pageAgent)
981 , m_frontend(0) 976 , m_frontend(0)
982 , m_resourcesData(adoptPtr(new NetworkResourcesData())) 977 , m_resourcesData(adoptPtr(new NetworkResourcesData()))
983 , m_isRecalculatingStyle(false) 978 , m_isRecalculatingStyle(false)
984 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired) 979 , m_removeFinishedReplayXHRTimer(this, &InspectorResourceAgent::removeFinish edReplayXHRFired)
985 { 980 {
986 } 981 }
987 982
988 bool InspectorResourceAgent::shouldForceCORSPreflight() 983 bool InspectorResourceAgent::shouldForceCORSPreflight()
989 { 984 {
990 return m_state->getBoolean(ResourceAgentState::cacheDisabled); 985 return m_state->getBoolean(ResourceAgentState::cacheDisabled);
991 } 986 }
992 987
993 } // namespace blink 988 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698