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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/InspectorResourceAgent.h ('k') | Source/core/xml/XMLHttpRequest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/inspector/InspectorResourceAgent.h" 32 #include "core/inspector/InspectorResourceAgent.h"
33 33
34 #include "InspectorFrontend.h" 34 #include "InspectorFrontend.h"
35 #include "bindings/v8/ScriptCallStackFactory.h" 35 #include "bindings/v8/ScriptCallStackFactory.h"
36 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
37 #include "core/dom/Event.h"
38 #include "core/dom/EventListener.h"
39 #include "core/dom/EventTarget.h"
40 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/ExceptionCodePlaceholder.h" 41 #include "core/dom/ExceptionCodePlaceholder.h"
38 #include "core/dom/ScriptableDocumentParser.h" 42 #include "core/dom/ScriptableDocumentParser.h"
39 #include "core/inspector/IdentifiersFactory.h" 43 #include "core/inspector/IdentifiersFactory.h"
40 #include "core/inspector/InspectorClient.h" 44 #include "core/inspector/InspectorClient.h"
41 #include "core/inspector/InspectorPageAgent.h" 45 #include "core/inspector/InspectorPageAgent.h"
42 #include "core/inspector/InspectorState.h" 46 #include "core/inspector/InspectorState.h"
43 #include "core/inspector/InspectorValues.h" 47 #include "core/inspector/InspectorValues.h"
44 #include "core/inspector/InstrumentingAgents.h" 48 #include "core/inspector/InstrumentingAgents.h"
45 #include "core/inspector/NetworkResourcesData.h" 49 #include "core/inspector/NetworkResourcesData.h"
46 #include "core/inspector/ScriptCallStack.h" 50 #include "core/inspector/ScriptCallStack.h"
(...skipping 16 matching lines...) Expand all
63 #include "modules/websockets/WebSocketFrame.h" 67 #include "modules/websockets/WebSocketFrame.h"
64 #include "modules/websockets/WebSocketHandshakeRequest.h" 68 #include "modules/websockets/WebSocketHandshakeRequest.h"
65 #include "modules/websockets/WebSocketHandshakeResponse.h" 69 #include "modules/websockets/WebSocketHandshakeResponse.h"
66 #include <wtf/CurrentTime.h> 70 #include <wtf/CurrentTime.h>
67 #include <wtf/HexNumber.h> 71 #include <wtf/HexNumber.h>
68 #include <wtf/ListHashSet.h> 72 #include <wtf/ListHashSet.h>
69 #include <wtf/MemoryInstrumentationHashMap.h> 73 #include <wtf/MemoryInstrumentationHashMap.h>
70 #include <wtf/RefPtr.h> 74 #include <wtf/RefPtr.h>
71 #include <wtf/text/StringBuilder.h> 75 #include <wtf/text/StringBuilder.h>
72 76
77 typedef WebCore::InspectorBackendDispatcher::NetworkCommandHandler::LoadResource ForFrontendCallback LoadResourceForFrontendCallback;
78
73 namespace WebCore { 79 namespace WebCore {
74 80
75 namespace ResourceAgentState { 81 namespace ResourceAgentState {
76 static const char resourceAgentEnabled[] = "resourceAgentEnabled"; 82 static const char resourceAgentEnabled[] = "resourceAgentEnabled";
77 static const char extraRequestHeaders[] = "extraRequestHeaders"; 83 static const char extraRequestHeaders[] = "extraRequestHeaders";
78 static const char cacheDisabled[] = "cacheDisabled"; 84 static const char cacheDisabled[] = "cacheDisabled";
79 static const char userAgentOverride[] = "userAgentOverride"; 85 static const char userAgentOverride[] = "userAgentOverride";
80 } 86 }
81 87
88 namespace {
89
90 class SendXHRCallback : public EventListener {
91 WTF_MAKE_NONCOPYABLE(SendXHRCallback);
92 public:
93 static PassRefPtr<SendXHRCallback> create(PassRefPtr<LoadResourceForFrontend Callback> callback)
94 {
95 return adoptRef(new SendXHRCallback(callback));
96 }
97
98 virtual ~SendXHRCallback() { }
99
100 virtual bool operator==(const EventListener& other) OVERRIDE
101 {
102 return this == &other;
103 }
104
105 virtual void handleEvent(ScriptExecutionContext*, Event* event) OVERRIDE
106 {
107 if (!m_callback->isActive())
108 return;
109 if (event->type() == eventNames().errorEvent) {
110 m_callback->sendFailure("Error loading resource.");
111 return;
112 }
113 if (event->type() != eventNames().readystatechangeEvent) {
114 m_callback->sendFailure("Unexpected event type.");
115 return;
116 }
117
118 XMLHttpRequest* xhr = static_cast<XMLHttpRequest*>(event->target());
119 if (xhr->readyState() != XMLHttpRequest::DONE)
120 return;
121
122 String responseText = xhr->responseText(IGNORE_EXCEPTION);
123 m_callback->sendSuccess(responseText);
124 }
125
126 private:
127 SendXHRCallback(PassRefPtr<LoadResourceForFrontendCallback> callback)
128 : EventListener(EventListener::CPPEventListenerType)
129 , m_callback(callback) { }
130 RefPtr<LoadResourceForFrontendCallback> m_callback;
131 };
132
133 } // namespace
134
82 void InspectorResourceAgent::setFrontend(InspectorFrontend* frontend) 135 void InspectorResourceAgent::setFrontend(InspectorFrontend* frontend)
83 { 136 {
84 m_frontend = frontend->network(); 137 m_frontend = frontend->network();
85 } 138 }
86 139
87 void InspectorResourceAgent::clearFrontend() 140 void InspectorResourceAgent::clearFrontend()
88 { 141 {
89 m_frontend = 0; 142 m_frontend = 0;
90 ErrorString error; 143 ErrorString error;
91 disable(&error); 144 disable(&error);
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 return; 659 return;
607 660
608 CachedResource* cachedResource = memoryCache()->resourceForURL(xhrReplayData ->url()); 661 CachedResource* cachedResource = memoryCache()->resourceForURL(xhrReplayData ->url());
609 if (cachedResource) 662 if (cachedResource)
610 memoryCache()->remove(cachedResource); 663 memoryCache()->remove(cachedResource);
611 664
612 xhr->open(xhrReplayData->method(), xhrReplayData->url(), xhrReplayData->asyn c(), IGNORE_EXCEPTION); 665 xhr->open(xhrReplayData->method(), xhrReplayData->url(), xhrReplayData->asyn c(), IGNORE_EXCEPTION);
613 HTTPHeaderMap::const_iterator end = xhrReplayData->headers().end(); 666 HTTPHeaderMap::const_iterator end = xhrReplayData->headers().end();
614 for (HTTPHeaderMap::const_iterator it = xhrReplayData->headers().begin(); it != end; ++it) 667 for (HTTPHeaderMap::const_iterator it = xhrReplayData->headers().begin(); it != end; ++it)
615 xhr->setRequestHeader(it->key, it->value, IGNORE_EXCEPTION); 668 xhr->setRequestHeader(it->key, it->value, IGNORE_EXCEPTION);
616 xhr->sendFromInspector(xhrReplayData->formData(), IGNORE_EXCEPTION); 669 xhr->sendForInspectorXHRReplay(xhrReplayData->formData(), IGNORE_EXCEPTION);
617 } 670 }
618 671
619 void InspectorResourceAgent::canClearBrowserCache(ErrorString*, bool* result) 672 void InspectorResourceAgent::canClearBrowserCache(ErrorString*, bool* result)
620 { 673 {
621 *result = true; 674 *result = true;
622 } 675 }
623 676
624 void InspectorResourceAgent::clearBrowserCache(ErrorString*) 677 void InspectorResourceAgent::clearBrowserCache(ErrorString*)
625 { 678 {
626 m_client->clearBrowserCache(); 679 m_client->clearBrowserCache();
627 } 680 }
628 681
629 void InspectorResourceAgent::canClearBrowserCookies(ErrorString*, bool* result) 682 void InspectorResourceAgent::canClearBrowserCookies(ErrorString*, bool* result)
630 { 683 {
631 *result = true; 684 *result = true;
632 } 685 }
633 686
634 void InspectorResourceAgent::clearBrowserCookies(ErrorString*) 687 void InspectorResourceAgent::clearBrowserCookies(ErrorString*)
635 { 688 {
636 m_client->clearBrowserCookies(); 689 m_client->clearBrowserCookies();
637 } 690 }
638 691
639 void InspectorResourceAgent::setCacheDisabled(ErrorString*, bool cacheDisabled) 692 void InspectorResourceAgent::setCacheDisabled(ErrorString*, bool cacheDisabled)
640 { 693 {
641 m_state->setBoolean(ResourceAgentState::cacheDisabled, cacheDisabled); 694 m_state->setBoolean(ResourceAgentState::cacheDisabled, cacheDisabled);
642 if (cacheDisabled) 695 if (cacheDisabled)
643 memoryCache()->evictResources(); 696 memoryCache()->evictResources();
644 } 697 }
645 698
699 void InspectorResourceAgent::loadResourceForFrontend(ErrorString* errorString, c onst String& frameId, const String& url, PassRefPtr<LoadResourceForFrontendCallb ack> callback)
700 {
701 Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
702 if (!frame)
703 return;
704
705 Document* document = frame->document();
706 if (!document) {
707 *errorString = "No Document instance for the specified frame";
708 return;
709 }
710
711 RefPtr<XMLHttpRequest> xhr = XMLHttpRequest::create(document);
712
713 KURL kurl = KURL(ParsedURLString, url);
714 if (kurl.isLocalFile()) {
715 *errorString = "Can not load local file";
716 return;
717 }
718
719 ExceptionCode ec = 0;
720 xhr->open(ASCIILiteral("GET"), kurl, ec);
721 if (ec) {
722 *errorString = "Error opening an XMLHttpRequest";
723 return;
724 }
725
726 RefPtr<SendXHRCallback> sendXHRCallback = SendXHRCallback::create(callback);
727 xhr->addEventListener(eventNames().abortEvent, sendXHRCallback, false);
728 xhr->addEventListener(eventNames().errorEvent, sendXHRCallback, false);
729 xhr->addEventListener(eventNames().readystatechangeEvent, sendXHRCallback, f alse);
730 xhr->sendForInspector(ec);
731 if (ec) {
732 *errorString = "Error sending an XMLHttpRequest";
733 return;
734 }
735 }
736
646 void InspectorResourceAgent::didCommitLoad(Frame* frame, DocumentLoader* loader) 737 void InspectorResourceAgent::didCommitLoad(Frame* frame, DocumentLoader* loader)
647 { 738 {
648 if (loader->frame() != frame->page()->mainFrame()) 739 if (loader->frame() != frame->page()->mainFrame())
649 return; 740 return;
650 741
651 if (m_state->getBoolean(ResourceAgentState::cacheDisabled)) 742 if (m_state->getBoolean(ResourceAgentState::cacheDisabled))
652 memoryCache()->evictResources(); 743 memoryCache()->evictResources();
653 744
654 m_resourcesData->clear(m_pageAgent->loaderId(loader)); 745 m_resourcesData->clear(m_pageAgent->loaderId(loader));
655 } 746 }
(...skipping 17 matching lines...) Expand all
673 , m_client(client) 764 , m_client(client)
674 , m_frontend(0) 765 , m_frontend(0)
675 , m_resourcesData(adoptPtr(new NetworkResourcesData())) 766 , m_resourcesData(adoptPtr(new NetworkResourcesData()))
676 , m_loadingXHRSynchronously(false) 767 , m_loadingXHRSynchronously(false)
677 , m_isRecalculatingStyle(false) 768 , m_isRecalculatingStyle(false)
678 { 769 {
679 } 770 }
680 771
681 } // namespace WebCore 772 } // namespace WebCore
682 773
OLDNEW
« 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