| 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" |
| 11 #include "core/fetch/CSSStyleSheetResource.h" | 11 #include "core/fetch/CSSStyleSheetResource.h" |
| 12 #include "core/fetch/RawResource.h" |
| 12 #include "core/fetch/Resource.h" | 13 #include "core/fetch/Resource.h" |
| 13 #include "core/fetch/ResourceFetcher.h" | 14 #include "core/fetch/ResourceFetcher.h" |
| 14 #include "core/fetch/ResourcePtr.h" | 15 #include "core/fetch/ResourcePtr.h" |
| 15 #include "core/fetch/StyleSheetResourceClient.h" | 16 #include "core/fetch/StyleSheetResourceClient.h" |
| 16 #include "core/frame/LocalFrame.h" | 17 #include "core/frame/LocalFrame.h" |
| 17 #include "core/html/VoidCallback.h" | 18 #include "core/html/VoidCallback.h" |
| 18 #include "core/inspector/InspectorCSSAgent.h" | 19 #include "core/inspector/InspectorCSSAgent.h" |
| 19 #include "core/inspector/InspectorPageAgent.h" | 20 #include "core/inspector/InspectorPageAgent.h" |
| 20 #include "core/page/Page.h" | 21 #include "core/page/Page.h" |
| 21 | 22 |
| 22 namespace WebCore { | 23 namespace WebCore { |
| 23 | 24 |
| 24 class InspectorResourceContentLoader::ResourceClient FINAL : private StyleSheetR
esourceClient { | 25 class InspectorResourceContentLoader::ResourceClient FINAL : private RawResource
Client, private StyleSheetResourceClient { |
| 25 public: | 26 public: |
| 26 ResourceClient(InspectorResourceContentLoader* loader) | 27 ResourceClient(InspectorResourceContentLoader* loader) |
| 27 : m_loader(loader) | 28 : m_loader(loader) |
| 28 { | 29 { |
| 29 } | 30 } |
| 30 | 31 |
| 31 void waitForResource(Resource* resource) | 32 void waitForResource(Resource* resource) |
| 32 { | 33 { |
| 33 resource->addClient(this); | 34 if (resource->type() == Resource::Raw) |
| 35 resource->addClient(static_cast<RawResourceClient*>(this)); |
| 36 else |
| 37 resource->addClient(static_cast<StyleSheetResourceClient*>(this)); |
| 34 } | 38 } |
| 35 | 39 |
| 36 private: | 40 private: |
| 37 InspectorResourceContentLoader* m_loader; | 41 InspectorResourceContentLoader* m_loader; |
| 38 | 42 |
| 39 virtual void setCSSStyleSheet(const String&, const KURL&, const String&, con
st CSSStyleSheetResource*) OVERRIDE; | 43 virtual void setCSSStyleSheet(const String&, const KURL&, const String&, con
st CSSStyleSheetResource*) OVERRIDE; |
| 44 virtual void notifyFinished(Resource*) OVERRIDE; |
| 45 void resourceFinished(Resource*); |
| 40 | 46 |
| 41 friend class InspectorResourceContentLoader; | 47 friend class InspectorResourceContentLoader; |
| 42 }; | 48 }; |
| 43 | 49 |
| 44 void InspectorResourceContentLoader::ResourceClient::setCSSStyleSheet(const Stri
ng&, const KURL& url, const String&, const CSSStyleSheetResource* resource) | 50 void InspectorResourceContentLoader::ResourceClient::resourceFinished(Resource*
resource) |
| 45 { | 51 { |
| 46 if (m_loader) | 52 if (m_loader) |
| 47 m_loader->resourceFinished(this); | 53 m_loader->resourceFinished(this); |
| 48 const_cast<CSSStyleSheetResource*>(resource)->removeClient(this); | 54 |
| 55 if (resource->type() == Resource::Raw) |
| 56 resource->removeClient(static_cast<RawResourceClient*>(this)); |
| 57 else |
| 58 resource->removeClient(static_cast<StyleSheetResourceClient*>(this)); |
| 59 |
| 49 delete this; | 60 delete this; |
| 50 } | 61 } |
| 51 | 62 |
| 63 void InspectorResourceContentLoader::ResourceClient::setCSSStyleSheet(const Stri
ng&, const KURL& url, const String&, const CSSStyleSheetResource* resource) |
| 64 { |
| 65 resourceFinished(const_cast<CSSStyleSheetResource*>(resource)); |
| 66 } |
| 67 |
| 68 void InspectorResourceContentLoader::ResourceClient::notifyFinished(Resource* re
source) |
| 69 { |
| 70 if (resource->type() == Resource::CSSStyleSheet) |
| 71 return; |
| 72 resourceFinished(resource); |
| 73 } |
| 74 |
| 52 InspectorResourceContentLoader::InspectorResourceContentLoader(Page* page) | 75 InspectorResourceContentLoader::InspectorResourceContentLoader(Page* page) |
| 53 : m_allRequestsStarted(false) | 76 : m_allRequestsStarted(false) |
| 54 { | 77 { |
| 55 Vector<Document*> documents; | 78 Vector<Document*> documents; |
| 56 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse
Next()) { | 79 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverse
Next()) { |
| 57 if (!frame->isLocalFrame()) | 80 if (!frame->isLocalFrame()) |
| 58 continue; | 81 continue; |
| 59 LocalFrame* localFrame = toLocalFrame(frame); | 82 LocalFrame* localFrame = toLocalFrame(frame); |
| 60 documents.append(localFrame->document()); | 83 documents.append(localFrame->document()); |
| 61 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); | 84 documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); |
| 62 } | 85 } |
| 63 for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum
entIt != documents.end(); ++documentIt) { | 86 for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum
entIt != documents.end(); ++documentIt) { |
| 64 Document* document = *documentIt; | 87 Document* document = *documentIt; |
| 88 HashSet<String> urlsToFetch; |
| 65 | 89 |
| 66 HashSet<String> urlsToFetch; | 90 ResourceRequest resourceRequest; |
| 91 |
| 92 if (!document->frame() || !document->frame()->loader().requestFromHistor
yForInspector(ReturnCacheDataDontLoad, &resourceRequest)) { |
| 93 resourceRequest = document->url(); |
| 94 resourceRequest.setCachePolicy(ReturnCacheDataDontLoad); |
| 95 } |
| 96 |
| 97 if (!resourceRequest.url().string().isEmpty()) { |
| 98 urlsToFetch.add(resourceRequest.url().string()); |
| 99 FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter
nal); |
| 100 ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour
ce(request); |
| 101 // Prevent garbage collection by holding a reference to this resourc
e. |
| 102 m_resources.append(resource.get()); |
| 103 ResourceClient* resourceClient = new ResourceClient(this); |
| 104 m_pendingResourceClients.add(resourceClient); |
| 105 resourceClient->waitForResource(resource.get()); |
| 106 } |
| 107 |
| 67 Vector<CSSStyleSheet*> styleSheets; | 108 Vector<CSSStyleSheet*> styleSheets; |
| 68 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); | 109 InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); |
| 69 for (Vector<CSSStyleSheet*>::const_iterator stylesheetIt = styleSheets.b
egin(); stylesheetIt != styleSheets.end(); ++stylesheetIt) { | 110 for (Vector<CSSStyleSheet*>::const_iterator stylesheetIt = styleSheets.b
egin(); stylesheetIt != styleSheets.end(); ++stylesheetIt) { |
| 70 CSSStyleSheet* styleSheet = *stylesheetIt; | 111 CSSStyleSheet* styleSheet = *stylesheetIt; |
| 71 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
()) | 112 if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
()) |
| 72 continue; | 113 continue; |
| 73 String url = styleSheet->baseURL().string(); | 114 String url = styleSheet->baseURL().string(); |
| 74 if (url.isEmpty() || urlsToFetch.contains(url)) | 115 if (url.isEmpty() || urlsToFetch.contains(url)) |
| 75 continue; | 116 continue; |
| 76 urlsToFetch.add(url); | 117 urlsToFetch.add(url); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 (*it)->handleEvent(); | 166 (*it)->handleEvent(); |
| 126 } | 167 } |
| 127 | 168 |
| 128 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) | 169 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) |
| 129 { | 170 { |
| 130 m_pendingResourceClients.remove(client); | 171 m_pendingResourceClients.remove(client); |
| 131 checkDone(); | 172 checkDone(); |
| 132 } | 173 } |
| 133 | 174 |
| 134 } // namespace WebCore | 175 } // namespace WebCore |
| OLD | NEW |