| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/inspector/InspectorResourceContentLoader.h" | 6 #include "core/inspector/InspectorResourceContentLoader.h" |
| 7 | 7 |
| 8 #include "core/FetchInitiatorTypeNames.h" | 8 #include "core/FetchInitiatorTypeNames.h" |
| 9 #include "core/css/CSSStyleSheet.h" | 9 #include "core/css/CSSStyleSheet.h" |
| 10 #include "core/css/StyleSheetContents.h" | 10 #include "core/css/StyleSheetContents.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 { | 84 { |
| 85 m_started = true; | 85 m_started = true; |
| 86 Vector<Document*> documents; | 86 Vector<Document*> documents; |
| 87 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver
seNext()) { | 87 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver
seNext()) { |
| 88 if (!frame->isLocalFrame()) | 88 if (!frame->isLocalFrame()) |
| 89 continue; | 89 continue; |
| 90 LocalFrame* localFrame = toLocalFrame(frame); | 90 LocalFrame* localFrame = toLocalFrame(frame); |
| 91 documents.append(localFrame->document()); | 91 documents.append(localFrame->document()); |
| 92 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); | 92 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); |
| 93 } | 93 } |
| 94 for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum
entIt != documents.end(); ++documentIt) { | 94 for (Document* document : documents) { |
| 95 Document* document = *documentIt; | |
| 96 HashSet<String> urlsToFetch; | 95 HashSet<String> urlsToFetch; |
| 97 | 96 |
| 98 ResourceRequest resourceRequest; | 97 ResourceRequest resourceRequest; |
| 99 HistoryItem* item = document->frame() ? document->frame()->loader().curr
entItem() : 0; | 98 HistoryItem* item = document->frame() ? document->frame()->loader().curr
entItem() : 0; |
| 100 if (item) { | 99 if (item) { |
| 101 resourceRequest = FrameLoader::requestFromHistoryItem(item, ReturnCa
cheDataDontLoad); | 100 resourceRequest = FrameLoader::requestFromHistoryItem(item, ReturnCa
cheDataDontLoad); |
| 102 } else { | 101 } else { |
| 103 resourceRequest = document->url(); | 102 resourceRequest = document->url(); |
| 104 resourceRequest.setCachePolicy(ReturnCacheDataDontLoad); | 103 resourceRequest.setCachePolicy(ReturnCacheDataDontLoad); |
| 105 } | 104 } |
| 106 resourceRequest.setRequestContext(blink::WebURLRequest::RequestContextIn
ternal); | 105 resourceRequest.setRequestContext(blink::WebURLRequest::RequestContextIn
ternal); |
| 107 | 106 |
| 108 if (!resourceRequest.url().string().isEmpty()) { | 107 if (!resourceRequest.url().string().isEmpty()) { |
| 109 urlsToFetch.add(resourceRequest.url().string()); | 108 urlsToFetch.add(resourceRequest.url().string()); |
| 110 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter
nal); | 109 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter
nal); |
| 111 ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour
ce(request); | 110 ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour
ce(request); |
| 112 if (resource) { | 111 if (resource) { |
| 113 // Prevent garbage collection by holding a reference to this res
ource. | 112 // Prevent garbage collection by holding a reference to this res
ource. |
| 114 m_resources.append(resource.get()); | 113 m_resources.append(resource.get()); |
| 115 ResourceClient* resourceClient = new ResourceClient(this); | 114 ResourceClient* resourceClient = new ResourceClient(this); |
| 116 m_pendingResourceClients.add(resourceClient); | 115 m_pendingResourceClients.add(resourceClient); |
| 117 resourceClient->waitForResource(resource.get()); | 116 resourceClient->waitForResource(resource.get()); |
| 118 } | 117 } |
| 119 } | 118 } |
| 120 | 119 |
| 121 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > styleSheets; | 120 WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> > styleSheets; |
| 122 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); | 121 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); |
| 123 for (WillBeHeapVector<RawPtrWillBeMember<CSSStyleSheet> >::const_iterato
r stylesheetIt = styleSheets.begin(); stylesheetIt != styleSheets.end(); ++style
sheetIt) { | 122 for (CSSStyleSheet* styleSheet : styleSheets) { |
| 124 CSSStyleSheet* styleSheet = *stylesheetIt; | |
| 125 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
()) | 123 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
()) |
| 126 continue; | 124 continue; |
| 127 String url = styleSheet->baseURL().string(); | 125 String url = styleSheet->baseURL().string(); |
| 128 if (url.isEmpty() || urlsToFetch.contains(url)) | 126 if (url.isEmpty() || urlsToFetch.contains(url)) |
| 129 continue; | 127 continue; |
| 130 urlsToFetch.add(url); | 128 urlsToFetch.add(url); |
| 131 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::
internal); | 129 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::
internal); |
| 132 request.mutableResourceRequest().setRequestContext(blink::WebURLRequ
est::RequestContextInternal); | 130 request.mutableResourceRequest().setRequestContext(blink::WebURLRequ
est::RequestContextInternal); |
| 133 ResourcePtr<Resource> resource = document->fetcher()->fetchCSSStyleS
heet(request); | 131 ResourcePtr<Resource> resource = document->fetcher()->fetchCSSStyleS
heet(request); |
| 134 if (!resource) | 132 if (!resource) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 164 |
| 167 void InspectorResourceContentLoader::dispose() | 165 void InspectorResourceContentLoader::dispose() |
| 168 { | 166 { |
| 169 stop(); | 167 stop(); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void InspectorResourceContentLoader::stop() | 170 void InspectorResourceContentLoader::stop() |
| 173 { | 171 { |
| 174 HashSet<ResourceClient*> pendingResourceClients; | 172 HashSet<ResourceClient*> pendingResourceClients; |
| 175 m_pendingResourceClients.swap(pendingResourceClients); | 173 m_pendingResourceClients.swap(pendingResourceClients); |
| 176 for (HashSet<ResourceClient*>::const_iterator it = pendingResourceClients.be
gin(); it != pendingResourceClients.end(); ++it) | 174 for (const auto& client : pendingResourceClients) |
| 177 (*it)->m_loader = 0; | 175 client->m_loader = 0; |
| 178 m_resources.clear(); | 176 m_resources.clear(); |
| 179 // Make sure all callbacks are called to prevent infinite waiting time. | 177 // Make sure all callbacks are called to prevent infinite waiting time. |
| 180 checkDone(); | 178 checkDone(); |
| 181 } | 179 } |
| 182 | 180 |
| 183 bool InspectorResourceContentLoader::hasFinished() | 181 bool InspectorResourceContentLoader::hasFinished() |
| 184 { | 182 { |
| 185 return m_allRequestsStarted && m_pendingResourceClients.size() == 0; | 183 return m_allRequestsStarted && m_pendingResourceClients.size() == 0; |
| 186 } | 184 } |
| 187 | 185 |
| 188 void InspectorResourceContentLoader::checkDone() | 186 void InspectorResourceContentLoader::checkDone() |
| 189 { | 187 { |
| 190 if (!hasFinished()) | 188 if (!hasFinished()) |
| 191 return; | 189 return; |
| 192 PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> > callbacks; | 190 PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> > callbacks; |
| 193 callbacks.swap(m_callbacks); | 191 callbacks.swap(m_callbacks); |
| 194 for (PersistentHeapVectorWillBeHeapVector<Member<VoidCallback> >::const_iter
ator it = callbacks.begin(); it != callbacks.end(); ++it) | 192 for (const auto& callback : callbacks) |
| 195 (*it)->handleEvent(); | 193 callback->handleEvent(); |
| 196 } | 194 } |
| 197 | 195 |
| 198 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) | 196 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) |
| 199 { | 197 { |
| 200 m_pendingResourceClients.remove(client); | 198 m_pendingResourceClients.remove(client); |
| 201 checkDone(); | 199 checkDone(); |
| 202 } | 200 } |
| 203 | 201 |
| 204 } // namespace blink | 202 } // namespace blink |
| OLD | NEW |