2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef InspectorResourceAgent_h
32 #define InspectorResourceAgent_h
34 #include "bindings/core/v8/ScriptString.h"
35 #include "core/InspectorFrontend.h"
36 #include "core/inspector/InspectorBaseAgent.h"
37 #include "platform/Timer.h"
38 #include "platform/heap/Handle.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/text/WTFString.h"
49 struct FetchInitiatorInfo;
55 class InspectorFrontend;
56 class InspectorPageAgent;
57 class InstrumentingAgents;
60 class NetworkResourcesData;
64 class ResourceRequest;
65 class ResourceResponse;
66 class ThreadableLoaderClient;
70 class WebSocketHandshakeRequest;
71 class WebSocketHandshakeResponse;
73 typedef String ErrorString;
75 class InspectorResourceAgent FINAL : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
77 static PassOwnPtrWillBeRawPtr<InspectorResourceAgent> create(InspectorPageAgent* pageAgent)
79 return adoptPtrWillBeNoop(new InspectorResourceAgent(pageAgent));
82 virtual void setFrontend(InspectorFrontend*) OVERRIDE;
83 virtual void clearFrontend() OVERRIDE;
84 virtual void restore() OVERRIDE;
86 virtual ~InspectorResourceAgent();
87 virtual void trace(Visitor*) OVERRIDE;
89 // Called from instrumentation.
90 void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
91 void markResourceAsCached(unsigned long identifier);
92 void didReceiveResourceResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
93 void didReceiveData(LocalFrame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
94 void didFinishLoading(unsigned long identifier, DocumentLoader*, double monotonicFinishTime, int64_t encodedDataLength);
95 void didReceiveCORSRedirectResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
96 void didFailLoading(unsigned long identifier, const ResourceError&);
97 void didCommitLoad(LocalFrame*, DocumentLoader*);
98 void scriptImported(unsigned long identifier, const String& sourceString);
99 void didReceiveScriptResponse(unsigned long identifier);
100 bool shouldForceCORSPreflight();
102 void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
103 void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, PassRefPtr<FormData> body, const HTTPHeaderMap& headers, bool includeCrendentials);
104 void didFailXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*);
105 void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const AtomicString&, const String&, const String&, unsigned);
107 void willDestroyResource(Resource*);
109 void applyUserAgentOverride(String* userAgent);
111 // FIXME: InspectorResourceAgent should not be aware of style recalculation.
112 void willRecalculateStyle(Document*);
113 void didRecalculateStyle(int);
114 void didScheduleStyleRecalculation(Document*);
116 void frameScheduledNavigation(LocalFrame*, double);
117 void frameClearedScheduledNavigation(LocalFrame*);
119 PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
121 void didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&);
122 void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest*);
123 void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const WebSocketHandshakeRequest*, const WebSocketHandshakeResponse*);
124 void didCloseWebSocket(Document*, unsigned long identifier);
125 void didReceiveWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
126 void didSendWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
127 void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
129 // called from Internals for layout test purposes.
130 void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
132 // Called from frontend
133 virtual void enable(ErrorString*) OVERRIDE;
134 virtual void disable(ErrorString*) OVERRIDE;
135 virtual void setUserAgentOverride(ErrorString*, const String& userAgent) OVERRIDE;
136 virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&) OVERRIDE;
137 virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded) OVERRIDE;
139 virtual void replayXHR(ErrorString*, const String& requestId) OVERRIDE;
141 virtual void canClearBrowserCache(ErrorString*, bool*) OVERRIDE;
142 virtual void canClearBrowserCookies(ErrorString*, bool*) OVERRIDE;
143 virtual void emulateNetworkConditions(ErrorString*, bool, double, double, double) OVERRIDE;
144 virtual void setCacheDisabled(ErrorString*, bool cacheDisabled) OVERRIDE;
146 virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtrWillBeRawPtr<LoadResourceForFrontendCallback>) OVERRIDE;
148 // Called from other agents.
149 void setHostId(const String&);
150 bool fetchResourceContent(Document*, const KURL&, String* content, bool* base64Encoded);
153 explicit InspectorResourceAgent(InspectorPageAgent*);
156 void delayedRemoveReplayXHR(XMLHttpRequest*);
157 void removeFinishedReplayXHRFired(Timer<InspectorResourceAgent>*);
159 RawPtrWillBeMember<InspectorPageAgent> m_pageAgent;
160 InspectorFrontend::Network* m_frontend;
161 String m_userAgentOverride;
163 OwnPtr<NetworkResourcesData> m_resourcesData;
165 typedef WillBeHeapHashMap<ThreadableLoaderClient*, RefPtrWillBeMember<XHRReplayData> > PendingXHRReplayDataMap;
166 PendingXHRReplayDataMap m_pendingXHRReplayData;
168 typedef HashMap<String, RefPtr<TypeBuilder::Network::Initiator> > FrameNavigationInitiatorMap;
169 FrameNavigationInitiatorMap m_frameNavigationInitiatorMap;
171 // FIXME: InspectorResourceAgent should now be aware of style recalculation.
172 RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
173 bool m_isRecalculatingStyle;
175 WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRs;
176 WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRsToBeDeleted;
177 Timer<InspectorResourceAgent> m_removeFinishedReplayXHRTimer;
183 #endif // !defined(InspectorResourceAgent_h)