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

Unified Diff: Source/core/inspector/InspectorPageAgent.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/InspectorPageAgent.h ('k') | Source/core/inspector/InspectorResourceContentLoader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorPageAgent.cpp
diff --git a/Source/core/inspector/InspectorPageAgent.cpp b/Source/core/inspector/InspectorPageAgent.cpp
index 3572507ada281c891f7fe37ee183e419d91500fd..4e85861640d23eeb25ebdc709156c0bb057ba174 100644
--- a/Source/core/inspector/InspectorPageAgent.cpp
+++ b/Source/core/inspector/InspectorPageAgent.cpp
@@ -51,6 +51,7 @@
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLFrameOwnerElement.h"
+#include "core/html/VoidCallback.h"
#include "core/html/imports/HTMLImport.h"
#include "core/html/imports/HTMLImportLoader.h"
#include "core/html/imports/HTMLImportsController.h"
@@ -62,6 +63,7 @@
#include "core/inspector/InspectorClient.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/InspectorOverlay.h"
+#include "core/inspector/InspectorResourceContentLoader.h"
#include "core/inspector/InspectorState.h"
#include "core/inspector/InstrumentingAgents.h"
#include "core/loader/CookieJar.h"
@@ -115,6 +117,32 @@ KURL urlWithoutFragment(const KURL& url)
}
+class InspectorPageAgent::GetResourceContentLoadListener FINAL : public VoidCallback {
+public:
+ GetResourceContentLoadListener(InspectorPageAgent*, const String& frameId, const String& url, PassRefPtr<GetResourceContentCallback>);
+ virtual void handleEvent() OVERRIDE;
+private:
+ InspectorPageAgent* m_pageAgent;
+ String m_frameId;
+ String m_url;
+ RefPtr<GetResourceContentCallback> m_callback;
+};
+
+InspectorPageAgent::GetResourceContentLoadListener::GetResourceContentLoadListener(InspectorPageAgent* pageAgent, const String& frameId, const String& url, PassRefPtr<GetResourceContentCallback> callback)
+ : m_pageAgent(pageAgent)
+ , m_frameId(frameId)
+ , m_url(url)
+ , m_callback(callback)
+{
+}
+
+void InspectorPageAgent::GetResourceContentLoadListener::handleEvent()
+{
+ if (!m_callback->isActive())
+ return;
+ m_pageAgent->getResourceContentAfterResourcesContentLoaded(m_frameId, m_url, m_callback);
+}
+
static bool decodeBuffer(const char* buffer, unsigned size, const String& textEncodingName, String* result)
{
if (buffer) {
@@ -253,13 +281,26 @@ void InspectorPageAgent::resourceContent(ErrorString* errorString, LocalFrame* f
DocumentLoader* loader = assertDocumentLoader(errorString, frame);
if (!loader)
return;
+
if (!cachedResourceContent(cachedResource(frame, url), result, base64Encoded))
*errorString = "No resource with given URL found";
}
Resource* InspectorPageAgent::cachedResource(LocalFrame* frame, const KURL& url)
{
- Resource* cachedResource = frame->document()->fetcher()->cachedResource(url);
+ Document* document = frame->document();
+ if (!document)
+ return 0;
+ Resource* cachedResource = document->fetcher()->cachedResource(url);
+ if (!cachedResource) {
+ Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame);
+ for (Vector<Document*>::const_iterator it = allImports.begin(); it != allImports.end(); ++it) {
+ Document* import = *it;
+ cachedResource = import->fetcher()->cachedResource(url);
+ if (cachedResource)
+ break;
+ }
+ }
if (!cachedResource)
cachedResource = memoryCache()->resourceForURL(url);
return cachedResource;
@@ -403,6 +444,7 @@ void InspectorPageAgent::enable(ErrorString*)
m_enabled = true;
m_state->setBoolean(PageAgentState::pageAgentEnabled, true);
m_instrumentingAgents->setInspectorPageAgent(this);
+ m_inspectorResourceContentLoader = adoptPtr(new InspectorResourceContentLoader(m_page));
}
void InspectorPageAgent::disable(ErrorString*)
@@ -412,6 +454,7 @@ void InspectorPageAgent::disable(ErrorString*)
m_state->remove(PageAgentState::pageAgentScriptsToEvaluateOnLoad);
m_overlay->hide();
m_instrumentingAgents->setInspectorPageAgent(0);
+ m_inspectorResourceContentLoader.clear();
m_deviceMetricsOverridden = false;
setShowPaintRects(0, false);
@@ -511,7 +554,7 @@ static PassRefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> > buildArrayForC
return cookies;
}
-static void cachedResourcesForDocument(Document* document, Vector<Resource*>& result)
+static void cachedResourcesForDocument(Document* document, Vector<Resource*>& result, bool skipXHRs)
{
const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher()->allResources();
ResourceFetcher::DocumentResourceMap::const_iterator end = allResources.end();
@@ -529,6 +572,10 @@ static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re
if (toFontResource(cachedResource)->stillNeedsLoad())
continue;
break;
+ case Resource::Raw:
+ if (skipXHRs)
+ continue;
+ break;
default:
// All other Resource types download immediately.
break;
@@ -538,7 +585,8 @@ static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re
}
}
-static Vector<Document*> importsForFrame(LocalFrame* frame)
+// static
+Vector<Document*> InspectorPageAgent::importsForFrame(LocalFrame* frame)
{
Vector<Document*> result;
Document* rootDocument = frame->document();
@@ -553,15 +601,15 @@ static Vector<Document*> importsForFrame(LocalFrame* frame)
return result;
}
-static Vector<Resource*> cachedResourcesForFrame(LocalFrame* frame)
+static Vector<Resource*> cachedResourcesForFrame(LocalFrame* frame, bool skipXHRs)
{
Vector<Resource*> result;
Document* rootDocument = frame->document();
- Vector<Document*> loaders = importsForFrame(frame);
+ Vector<Document*> loaders = InspectorPageAgent::importsForFrame(frame);
- cachedResourcesForDocument(rootDocument, result);
+ cachedResourcesForDocument(rootDocument, result, skipXHRs);
for (size_t i = 0; i < loaders.size(); ++i)
- cachedResourcesForDocument(loaders[i], result);
+ cachedResourcesForDocument(loaders[i], result, skipXHRs);
return result;
}
@@ -572,7 +620,7 @@ static Vector<KURL> allResourcesURLsForFrame(LocalFrame* frame)
result.append(urlWithoutFragment(frame->loader().documentLoader()->url()));
- Vector<Resource*> allResources = cachedResourcesForFrame(frame);
+ Vector<Resource*> allResources = cachedResourcesForFrame(frame, false);
for (Vector<Resource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it)
result.append(urlWithoutFragment((*it)->url()));
@@ -616,12 +664,31 @@ void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page:
object = buildObjectForFrameTree(m_page->deprecatedLocalMainFrame());
}
-void InspectorPageAgent::getResourceContent(ErrorString* errorString, const String& frameId, const String& url, String* content, bool* base64Encoded)
+void InspectorPageAgent::getResourceContentAfterResourcesContentLoaded(const String& frameId, const String& url, PassRefPtr<GetResourceContentCallback> callback)
{
- LocalFrame* frame = assertFrame(errorString, frameId);
- if (!frame)
+ ErrorString errorString;
+ LocalFrame* frame = assertFrame(&errorString, frameId);
+ if (!frame) {
+ callback->sendFailure(errorString);
+ return;
+ }
+ String content;
+ bool base64Encoded;
+ resourceContent(&errorString, frame, KURL(ParsedURLString, url), &content, &base64Encoded);
+ if (!errorString.isEmpty()) {
+ callback->sendFailure(errorString);
return;
- resourceContent(errorString, frame, KURL(ParsedURLString, url), content, base64Encoded);
+ }
+ callback->sendSuccess(content, base64Encoded);
+}
+
+void InspectorPageAgent::getResourceContent(ErrorString* errorString, const String& frameId, const String& url, PassRefPtr<GetResourceContentCallback> callback)
+{
+ if (!m_inspectorResourceContentLoader) {
+ callback->sendFailure("Agent was not enabled before sending content requests.");
+ return;
+ }
+ m_inspectorResourceContentLoader->addListener(adoptPtr(new GetResourceContentLoadListener(this, frameId, url, callback)));
}
static bool textContentForResource(Resource* cachedResource, String* result)
@@ -857,7 +924,7 @@ void InspectorPageAgent::loadEventFired(LocalFrame* frame)
void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
{
- // FIXME: If "frame" is always guarenteed to be in the same Page as loader->frame()
+ // FIXME: If "frame" is always guaranteed to be in the same Page as loader->frame()
// then all we need to check here is loader->frame()->isMainFrame()
// and we don't need "frame" at all.
if (loader->frame() == m_page->mainFrame()) {
@@ -865,6 +932,8 @@ void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
m_scriptPreprocessorSource = m_pendingScriptPreprocessor;
m_pendingScriptToEvaluateOnLoadOnce = String();
m_pendingScriptPreprocessor = String();
+ if (m_inspectorResourceContentLoader)
+ m_inspectorResourceContentLoader->stop();
}
m_frontend->frameNavigated(buildObjectForFrame(loader->frame()));
}
@@ -1102,7 +1171,7 @@ PassRefPtr<TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObject
.setFrame(frameObject)
.setResources(subresources);
- Vector<Resource*> allResources = cachedResourcesForFrame(frame);
+ Vector<Resource*> allResources = cachedResourcesForFrame(frame, true);
for (Vector<Resource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) {
Resource* cachedResource = *it;
@@ -1117,7 +1186,7 @@ PassRefPtr<TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObject
subresources->addItem(resourceObject);
}
- Vector<Document*> allImports = importsForFrame(frame);
+ Vector<Document*> allImports = InspectorPageAgent::importsForFrame(frame);
for (Vector<Document*>::const_iterator it = allImports.begin(); it != allImports.end(); ++it) {
Document* import = *it;
RefPtr<TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = TypeBuilder::Page::FrameResourceTree::Resources::create()
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/core/inspector/InspectorResourceContentLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698