| 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     , m_started(false) | 77     , m_started(false) | 
| 55     , m_page(page) | 78     , m_page(page) | 
| 56 { | 79 { | 
| 57 } | 80 } | 
| 58 | 81 | 
| 59 void InspectorResourceContentLoader::start() | 82 void InspectorResourceContentLoader::start() | 
| 60 { | 83 { | 
| 61     m_started = true; | 84     m_started = true; | 
| 62     Vector<Document*> documents; | 85     Vector<Document*> documents; | 
| 63     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver
     seNext()) { | 86     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traver
     seNext()) { | 
| 64         if (!frame->isLocalFrame()) | 87         if (!frame->isLocalFrame()) | 
| 65             continue; | 88             continue; | 
| 66         LocalFrame* localFrame = toLocalFrame(frame); | 89         LocalFrame* localFrame = toLocalFrame(frame); | 
| 67         documents.append(localFrame->document()); | 90         documents.append(localFrame->document()); | 
| 68         documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); | 91         documents.appendVector(InspectorPageAgent::importsForFrame(localFrame)); | 
| 69     } | 92     } | 
| 70     for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum
     entIt != documents.end(); ++documentIt) { | 93     for (Vector<Document*>::const_iterator documentIt = documents.begin(); docum
     entIt != documents.end(); ++documentIt) { | 
| 71         Document* document = *documentIt; | 94         Document* document = *documentIt; | 
|  | 95         HashSet<String> urlsToFetch; | 
| 72 | 96 | 
| 73         HashSet<String> urlsToFetch; | 97         ResourceRequest resourceRequest; | 
|  | 98         HistoryItem* item = document->frame() ? document->frame()->loader().curr
     entItem() : 0; | 
|  | 99         if (item) { | 
|  | 100             resourceRequest = FrameLoader::requestFromHistoryItem(item, ReturnCa
     cheDataDontLoad); | 
|  | 101         } else { | 
|  | 102             resourceRequest = document->url(); | 
|  | 103             resourceRequest.setCachePolicy(ReturnCacheDataDontLoad); | 
|  | 104         } | 
|  | 105 | 
|  | 106         if (!resourceRequest.url().string().isEmpty()) { | 
|  | 107             urlsToFetch.add(resourceRequest.url().string()); | 
|  | 108             FetchRequest request(resourceRequest, FetchInitiatorTypeNames::inter
     nal); | 
|  | 109             ResourcePtr<Resource> resource = document->fetcher()->fetchRawResour
     ce(request); | 
|  | 110             // Prevent garbage collection by holding a reference to this resourc
     e. | 
|  | 111             m_resources.append(resource.get()); | 
|  | 112             ResourceClient* resourceClient = new ResourceClient(this); | 
|  | 113             m_pendingResourceClients.add(resourceClient); | 
|  | 114             resourceClient->waitForResource(resource.get()); | 
|  | 115         } | 
|  | 116 | 
| 74         Vector<CSSStyleSheet*> styleSheets; | 117         Vector<CSSStyleSheet*> styleSheets; | 
| 75         InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); | 118         InspectorCSSAgent::collectAllDocumentStyleSheets(document, styleSheets); | 
| 76         for (Vector<CSSStyleSheet*>::const_iterator stylesheetIt = styleSheets.b
     egin(); stylesheetIt != styleSheets.end(); ++stylesheetIt) { | 119         for (Vector<CSSStyleSheet*>::const_iterator stylesheetIt = styleSheets.b
     egin(); stylesheetIt != styleSheets.end(); ++stylesheetIt) { | 
| 77             CSSStyleSheet* styleSheet = *stylesheetIt; | 120             CSSStyleSheet* styleSheet = *stylesheetIt; | 
| 78             if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
     ()) | 121             if (styleSheet->isInline() || !styleSheet->contents()->loadCompleted
     ()) | 
| 79                 continue; | 122                 continue; | 
| 80             String url = styleSheet->baseURL().string(); | 123             String url = styleSheet->baseURL().string(); | 
| 81             if (url.isEmpty() || urlsToFetch.contains(url)) | 124             if (url.isEmpty() || urlsToFetch.contains(url)) | 
| 82                 continue; | 125                 continue; | 
| 83             urlsToFetch.add(url); | 126             urlsToFetch.add(url); | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 134         (*it)->handleEvent(); | 177         (*it)->handleEvent(); | 
| 135 } | 178 } | 
| 136 | 179 | 
| 137 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) | 180 void InspectorResourceContentLoader::resourceFinished(ResourceClient* client) | 
| 138 { | 181 { | 
| 139     m_pendingResourceClients.remove(client); | 182     m_pendingResourceClients.remove(client); | 
| 140     checkDone(); | 183     checkDone(); | 
| 141 } | 184 } | 
| 142 | 185 | 
| 143 } // namespace WebCore | 186 } // namespace WebCore | 
| OLD | NEW | 
|---|