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);
101 void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
102 void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, FormData* body, const HTTPHeaderMap& headers, bool includeCrendentials);
103 void didFailXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*);
104 void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const AtomicString&, const String&, const String&, unsigned);
106 void willDestroyResource(Resource*);
108 void applyUserAgentOverride(String* userAgent);
110 // FIXME: InspectorResourceAgent should not be aware of style recalculation.
111 void willRecalculateStyle(Document*);
112 void didRecalculateStyle(int);
113 void didScheduleStyleRecalculation(Document*);
115 void frameScheduledNavigation(LocalFrame*, double);
116 void frameClearedScheduledNavigation(LocalFrame*);
118 PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
120 void didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&);
121 void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest*);
122 void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const WebSocketHandshakeRequest*, const WebSocketHandshakeResponse*);
123 void didCloseWebSocket(Document*, unsigned long identifier);
124 void didReceiveWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
125 void didSendWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
126 void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
128 // called from Internals for layout test purposes.
129 void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
131 // Called from frontend
132 virtual void enable(ErrorString*) OVERRIDE;
133 virtual void disable(ErrorString*) OVERRIDE;
134 virtual void setUserAgentOverride(ErrorString*, const String& userAgent) OVERRIDE;
135 virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&) OVERRIDE;
136 virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded) OVERRIDE;
138 virtual void replayXHR(ErrorString*, const String& requestId) OVERRIDE;
140 virtual void canClearBrowserCache(ErrorString*, bool*) OVERRIDE;
141 virtual void canClearBrowserCookies(ErrorString*, bool*) OVERRIDE;
142 virtual void emulateNetworkConditions(ErrorString*, bool, double, double, double) OVERRIDE;
143 virtual void setCacheDisabled(ErrorString*, bool cacheDisabled) OVERRIDE;
145 virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>) OVERRIDE;
147 // Called from other agents.
148 void setHostId(const String&);
149 bool fetchResourceContent(Document*, const KURL&, String* content, bool* base64Encoded);
152 explicit InspectorResourceAgent(InspectorPageAgent*);
155 void delayedRemoveReplayXHR(XMLHttpRequest*);
156 void removeFinishedReplayXHRFired(Timer<InspectorResourceAgent>*);
158 RawPtrWillBeMember<InspectorPageAgent> m_pageAgent;
159 InspectorFrontend::Network* m_frontend;
160 String m_userAgentOverride;
162 OwnPtr<NetworkResourcesData> m_resourcesData;
164 typedef WillBeHeapHashMap<ThreadableLoaderClient*, RefPtrWillBeMember<XHRReplayData> > PendingXHRReplayDataMap;
165 PendingXHRReplayDataMap m_pendingXHRReplayData;
167 typedef HashMap<String, RefPtr<TypeBuilder::Network::Initiator> > FrameNavigationInitiatorMap;
168 FrameNavigationInitiatorMap m_frameNavigationInitiatorMap;
170 // FIXME: InspectorResourceAgent should now be aware of style recalculation.
171 RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
172 bool m_isRecalculatingStyle;
174 WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRs;
175 WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRsToBeDeleted;
176 Timer<InspectorResourceAgent> m_removeFinishedReplayXHRTimer;
182 #endif // !defined(InspectorResourceAgent_h)