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

Unified Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 267393003: DevTools: Load document (html) content from disk cache in page agent enabling. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorPageAgent.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/Source/core/inspector/InspectorCSSAgent.cpp b/Source/core/inspector/InspectorCSSAgent.cpp
index 554696ef8e49339237bc6141c013128189211f4c..d05b28792ce20d0b164436d0a2c01979856ab28b 100644
--- a/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/Source/core/inspector/InspectorCSSAgent.cpp
@@ -26,7 +26,6 @@
#include "core/inspector/InspectorCSSAgent.h"
#include "CSSPropertyNames.h"
-#include "FetchInitiatorTypeNames.h"
#include "InspectorTypeBuilder.h"
#include "StylePropertyShorthand.h"
#include "bindings/v8/ExceptionState.h"
@@ -49,15 +48,13 @@
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/Node.h"
#include "core/dom/NodeList.h"
-#include "core/fetch/CSSStyleSheetResource.h"
-#include "core/fetch/ResourceClient.h"
-#include "core/fetch/ResourceFetcher.h"
-#include "core/fetch/StyleSheetResourceClient.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLHeadElement.h"
+#include "core/html/VoidCallback.h"
#include "core/inspector/InspectorHistory.h"
#include "core/inspector/InspectorPageAgent.h"
#include "core/inspector/InspectorResourceAgent.h"
+#include "core/inspector/InspectorResourceContentLoader.h"
#include "core/inspector/InspectorState.h"
#include "core/inspector/InstrumentingAgents.h"
#include "core/loader/DocumentLoader.h"
@@ -128,45 +125,30 @@ public:
}
};
-class InspectorCSSAgent::EnableResourceClient FINAL : public StyleSheetResourceClient {
+class InspectorCSSAgent::InspectorResourceContentLoaderCallback FINAL : public VoidCallback {
public:
- EnableResourceClient(InspectorCSSAgent*, const Vector<InspectorStyleSheet*>&, PassRefPtr<EnableCallback>);
-
- virtual void setCSSStyleSheet(const String&, const KURL&, const String&, const CSSStyleSheetResource*) OVERRIDE;
+ InspectorResourceContentLoaderCallback(InspectorCSSAgent*, PassRefPtr<EnableCallback>);
+ virtual void handleEvent() OVERRIDE;
private:
- RefPtr<EnableCallback> m_callback;
InspectorCSSAgent* m_cssAgent;
- int m_pendingResources;
- Vector<InspectorStyleSheet*> m_styleSheets;
+ RefPtr<EnableCallback> m_callback;
};
-InspectorCSSAgent::EnableResourceClient::EnableResourceClient(InspectorCSSAgent* cssAgent, const Vector<InspectorStyleSheet*>& styleSheets, PassRefPtr<EnableCallback> callback)
- : m_callback(callback)
- , m_cssAgent(cssAgent)
- , m_pendingResources(styleSheets.size())
- , m_styleSheets(styleSheets)
+InspectorCSSAgent::InspectorResourceContentLoaderCallback::InspectorResourceContentLoaderCallback(InspectorCSSAgent* cssAgent, PassRefPtr<EnableCallback> callback)
+ : m_cssAgent(cssAgent)
+ , m_callback(callback)
{
- for (size_t i = 0; i < styleSheets.size(); ++i) {
- InspectorStyleSheet* styleSheet = styleSheets.at(i);
- Document* document = styleSheet->ownerDocument();
- FetchRequest request(ResourceRequest(styleSheet->finalURL()), FetchInitiatorTypeNames::internal);
- ResourcePtr<Resource> resource = document->fetcher()->fetchCSSStyleSheet(request);
- resource->addClient(this);
- }
}
-void InspectorCSSAgent::EnableResourceClient::setCSSStyleSheet(const String&, const KURL& url, const String&, const CSSStyleSheetResource* resource)
+void InspectorCSSAgent::InspectorResourceContentLoaderCallback::handleEvent()
{
- const_cast<CSSStyleSheetResource*>(resource)->removeClient(this);
- --m_pendingResources;
- if (m_pendingResources)
+ // enable always succeeds.
+ if (!m_callback->isActive())
return;
- // enable always succeeds.
- if (m_callback->isActive())
- m_cssAgent->wasEnabled(m_callback.release());
- delete this;
+ m_cssAgent->wasEnabled();
+ m_callback->sendSuccess();
}
class InspectorCSSAgent::SetStyleSheetTextAction FINAL : public InspectorCSSAgent::StyleSheetAction {
@@ -401,7 +383,7 @@ void InspectorCSSAgent::discardAgent()
void InspectorCSSAgent::restore()
{
if (m_state->getBoolean(CSSAgentState::cssAgentEnabled))
- wasEnabled(nullptr);
+ wasEnabled();
}
void InspectorCSSAgent::flushPendingFrontendMessages()
@@ -434,39 +416,15 @@ void InspectorCSSAgent::resetNonPersistentData()
void InspectorCSSAgent::enable(ErrorString*, PassRefPtr<EnableCallback> prpCallback)
{
m_state->setBoolean(CSSAgentState::cssAgentEnabled, true);
-
- Vector<InspectorStyleSheet*> styleSheets;
- collectAllStyleSheets(styleSheets);
-
- // Re-issue stylesheet requets for resources that are no longer in memory cache.
- Vector<InspectorStyleSheet*> styleSheetsToFetch;
- HashSet<String> urlsToFetch;
- for (size_t i = 0; i < styleSheets.size(); ++i) {
- InspectorStyleSheet* styleSheet = styleSheets.at(i);
- String url = styleSheet->finalURL();
- if (urlsToFetch.contains(url))
- continue;
- CSSStyleSheet* pageStyleSheet = styleSheet->pageStyleSheet();
- if (pageStyleSheet->isInline() || !pageStyleSheet->contents()->loadCompleted())
- continue;
- Document* document = styleSheet->ownerDocument();
- if (!document)
- continue;
- Resource* cachedResource = document->fetcher()->cachedResource(document->completeURL(url));
- if (cachedResource)
- continue;
- urlsToFetch.add(styleSheet->finalURL());
- styleSheetsToFetch.append(styleSheet);
- }
-
- if (styleSheetsToFetch.isEmpty()) {
- wasEnabled(prpCallback);
+ if (!m_pageAgent->resourceContentLoader()) {
+ wasEnabled();
+ prpCallback->sendSuccess();
return;
}
- new EnableResourceClient(this, styleSheetsToFetch, prpCallback);
+ m_pageAgent->resourceContentLoader()->addListener(adoptPtr(new InspectorCSSAgent::InspectorResourceContentLoaderCallback(this, prpCallback)));
}
-void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
+void InspectorCSSAgent::wasEnabled()
{
if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) {
// We were disabled while fetching resources.
@@ -477,9 +435,6 @@ void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
Vector<Document*> documents = m_domAgent->documents();
for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it)
updateActiveStyleSheets(*it, InitialFrontendLoad);
-
- if (callback)
- callback->sendSuccess();
}
void InspectorCSSAgent::disable(ErrorString*)
@@ -546,7 +501,7 @@ void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsUpdateType styleSheetsUpdateType)
{
Vector<CSSStyleSheet*> newSheetsVector;
- collectAllDocumentStyleSheets(document, newSheetsVector);
+ InspectorCSSAgent::collectAllDocumentStyleSheets(document, newSheetsVector);
setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType);
}
@@ -1169,25 +1124,17 @@ Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId)
return toElement(node);
}
-void InspectorCSSAgent::collectAllStyleSheets(Vector<InspectorStyleSheet*>& result)
-{
- Vector<CSSStyleSheet*> cssStyleSheets;
- Vector<Document*> documents = m_domAgent->documents();
- for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it)
- collectAllDocumentStyleSheets(*it, cssStyleSheets);
- for (Vector<CSSStyleSheet*>::iterator it = cssStyleSheets.begin(); it != cssStyleSheets.end(); ++it)
- result.append(bindStyleSheet(*it));
-}
-
+// static
void InspectorCSSAgent::collectAllDocumentStyleSheets(Document* document, Vector<CSSStyleSheet*>& result)
{
const WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> > activeStyleSheets = document->styleEngine()->activeStyleSheetsForInspector();
for (WillBeHeapVector<RefPtrWillBeMember<CSSStyleSheet> >::const_iterator it = activeStyleSheets.begin(); it != activeStyleSheets.end(); ++it) {
CSSStyleSheet* styleSheet = it->get();
- collectStyleSheets(styleSheet, result);
+ InspectorCSSAgent::collectStyleSheets(styleSheet, result);
}
}
+// static
void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Vector<CSSStyleSheet*>& result)
{
result.append(styleSheet);
@@ -1196,7 +1143,7 @@ void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, Vector<CSS
if (rule->type() == CSSRule::IMPORT_RULE) {
CSSStyleSheet* importedStyleSheet = toCSSImportRule(rule)->styleSheet();
if (importedStyleSheet)
- collectStyleSheets(importedStyleSheet, result);
+ InspectorCSSAgent::collectStyleSheets(importedStyleSheet, result);
}
}
}
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorPageAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698