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

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

Issue 16199002: DevTools: Support asynchronous loading of resources without cross origin checks through backend for… (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ... Created 7 years, 7 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/InspectorResourceAgent.h ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/InspectorResourceAgent.cpp
diff --git a/Source/core/inspector/InspectorResourceAgent.cpp b/Source/core/inspector/InspectorResourceAgent.cpp
index d8a349596bc28bd47877e7811a0816220400f57f..24d4e816ca97786b356359d67e7259da36fd1f25 100644
--- a/Source/core/inspector/InspectorResourceAgent.cpp
+++ b/Source/core/inspector/InspectorResourceAgent.cpp
@@ -34,6 +34,10 @@
#include "InspectorFrontend.h"
#include "bindings/v8/ScriptCallStackFactory.h"
#include "core/dom/Document.h"
+#include "core/dom/Event.h"
+#include "core/dom/EventListener.h"
+#include "core/dom/EventTarget.h"
+#include "core/dom/ExceptionCode.h"
#include "core/dom/ExceptionCodePlaceholder.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/inspector/IdentifiersFactory.h"
@@ -70,6 +74,8 @@
#include <wtf/RefPtr.h>
#include <wtf/text/StringBuilder.h>
+typedef WebCore::InspectorBackendDispatcher::NetworkCommandHandler::LoadResourceForFrontendCallback LoadResourceForFrontendCallback;
+
namespace WebCore {
namespace ResourceAgentState {
@@ -79,6 +85,53 @@ static const char cacheDisabled[] = "cacheDisabled";
static const char userAgentOverride[] = "userAgentOverride";
}
+namespace {
+
+class SendXHRCallback : public EventListener {
+ WTF_MAKE_NONCOPYABLE(SendXHRCallback);
+public:
+ static PassRefPtr<SendXHRCallback> create(PassRefPtr<LoadResourceForFrontendCallback> callback)
+ {
+ return adoptRef(new SendXHRCallback(callback));
+ }
+
+ virtual ~SendXHRCallback() { }
+
+ virtual bool operator==(const EventListener& other) OVERRIDE
+ {
+ return this == &other;
+ }
+
+ virtual void handleEvent(ScriptExecutionContext*, Event* event) OVERRIDE
+ {
+ if (!m_callback->isActive())
+ return;
+ if (event->type() == eventNames().errorEvent) {
+ m_callback->sendFailure("Error loading resource.");
+ return;
+ }
+ if (event->type() != eventNames().readystatechangeEvent) {
+ m_callback->sendFailure("Unexpected event type.");
+ return;
+ }
+
+ XMLHttpRequest* xhr = static_cast<XMLHttpRequest*>(event->target());
+ if (xhr->readyState() != XMLHttpRequest::DONE)
+ return;
+
+ String responseText = xhr->responseText(IGNORE_EXCEPTION);
+ m_callback->sendSuccess(responseText);
+ }
+
+private:
+ SendXHRCallback(PassRefPtr<LoadResourceForFrontendCallback> callback)
+ : EventListener(EventListener::CPPEventListenerType)
+ , m_callback(callback) { }
+ RefPtr<LoadResourceForFrontendCallback> m_callback;
+};
+
+} // namespace
+
void InspectorResourceAgent::setFrontend(InspectorFrontend* frontend)
{
m_frontend = frontend->network();
@@ -613,7 +666,7 @@ void InspectorResourceAgent::replayXHR(ErrorString*, const String& requestId)
HTTPHeaderMap::const_iterator end = xhrReplayData->headers().end();
for (HTTPHeaderMap::const_iterator it = xhrReplayData->headers().begin(); it!= end; ++it)
xhr->setRequestHeader(it->key, it->value, IGNORE_EXCEPTION);
- xhr->sendFromInspector(xhrReplayData->formData(), IGNORE_EXCEPTION);
+ xhr->sendForInspectorXHRReplay(xhrReplayData->formData(), IGNORE_EXCEPTION);
}
void InspectorResourceAgent::canClearBrowserCache(ErrorString*, bool* result)
@@ -643,6 +696,44 @@ void InspectorResourceAgent::setCacheDisabled(ErrorString*, bool cacheDisabled)
memoryCache()->evictResources();
}
+void InspectorResourceAgent::loadResourceForFrontend(ErrorString* errorString, const String& frameId, const String& url, PassRefPtr<LoadResourceForFrontendCallback> callback)
+{
+ Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
+ if (!frame)
+ return;
+
+ Document* document = frame->document();
+ if (!document) {
+ *errorString = "No Document instance for the specified frame";
+ return;
+ }
+
+ RefPtr<XMLHttpRequest> xhr = XMLHttpRequest::create(document);
+
+ KURL kurl = KURL(ParsedURLString, url);
+ if (kurl.isLocalFile()) {
+ *errorString = "Can not load local file";
+ return;
+ }
+
+ ExceptionCode ec = 0;
+ xhr->open(ASCIILiteral("GET"), kurl, ec);
+ if (ec) {
+ *errorString = "Error opening an XMLHttpRequest";
+ return;
+ }
+
+ RefPtr<SendXHRCallback> sendXHRCallback = SendXHRCallback::create(callback);
+ xhr->addEventListener(eventNames().abortEvent, sendXHRCallback, false);
+ xhr->addEventListener(eventNames().errorEvent, sendXHRCallback, false);
+ xhr->addEventListener(eventNames().readystatechangeEvent, sendXHRCallback, false);
+ xhr->sendForInspector(ec);
+ if (ec) {
+ *errorString = "Error sending an XMLHttpRequest";
+ return;
+ }
+}
+
void InspectorResourceAgent::didCommitLoad(Frame* frame, DocumentLoader* loader)
{
if (loader->frame() != frame->page()->mainFrame())
« no previous file with comments | « Source/core/inspector/InspectorResourceAgent.h ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698