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/v8/ScriptString.h"
35 #include "core/InspectorFrontend.h"
36 #include "core/inspector/InspectorBaseAgent.h"
37 #include "wtf/PassOwnPtr.h"
38 #include "wtf/text/WTFString.h"
48 struct FetchInitiatorInfo;
54 class InspectorFrontend;
55 class InspectorPageAgent;
56 class InstrumentingAgents;
59 class NetworkResourcesData;
63 class ResourceRequest;
64 class ResourceResponse;
65 class ThreadableLoaderClient;
69 class WebSocketHandshakeRequest;
70 class WebSocketHandshakeResponse;
72 typedef String ErrorString;
74 class InspectorResourceAgent FINAL : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
76 static PassOwnPtr<InspectorResourceAgent> create(InspectorPageAgent* pageAgent)
78 return adoptPtr(new InspectorResourceAgent(pageAgent));
81 virtual void setFrontend(InspectorFrontend*) OVERRIDE;
82 virtual void clearFrontend() OVERRIDE;
83 virtual void restore() OVERRIDE;
85 virtual ~InspectorResourceAgent();
87 // Called from instrumentation.
88 void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
89 void markResourceAsCached(unsigned long identifier);
90 void didReceiveResourceResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
91 void didReceiveData(LocalFrame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
92 void didFinishLoading(unsigned long identifier, DocumentLoader*, double monotonicFinishTime, int64_t encodedDataLength);
93 void didReceiveCORSRedirectResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
94 void didFailLoading(unsigned long identifier, const ResourceError&);
95 void didCommitLoad(LocalFrame*, DocumentLoader*);
96 void scriptImported(unsigned long identifier, const String& sourceString);
97 void didReceiveScriptResponse(unsigned long identifier);
99 void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
100 void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, FormData* body, const HTTPHeaderMap& headers, bool includeCrendentials);
101 void didFailXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*);
102 void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const AtomicString&, const String&, const String&, unsigned);
104 void willDestroyResource(Resource*);
106 void applyUserAgentOverride(String* userAgent);
108 // FIXME: InspectorResourceAgent should not be aware of style recalculation.
109 void willRecalculateStyle(Document*);
110 void didRecalculateStyle(int);
111 void didScheduleStyleRecalculation(Document*);
113 void frameScheduledNavigation(LocalFrame*, double);
114 void frameClearedScheduledNavigation(LocalFrame*);
116 PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
118 void didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&);
119 void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest*);
120 void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const WebSocketHandshakeRequest*, const WebSocketHandshakeResponse*);
121 void didCloseWebSocket(Document*, unsigned long identifier);
122 void didReceiveWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
123 void didSendWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
124 void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
126 // called from Internals for layout test purposes.
127 void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
129 // Called from frontend
130 virtual void enable(ErrorString*) OVERRIDE;
131 virtual void disable(ErrorString*) OVERRIDE;
132 virtual void setUserAgentOverride(ErrorString*, const String& userAgent) OVERRIDE;
133 virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&) OVERRIDE;
134 virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded) OVERRIDE;
136 virtual void replayXHR(ErrorString*, const String& requestId) OVERRIDE;
138 virtual void canClearBrowserCache(ErrorString*, bool*) OVERRIDE;
139 virtual void canClearBrowserCookies(ErrorString*, bool*) OVERRIDE;
140 virtual void setCacheDisabled(ErrorString*, bool cacheDisabled) OVERRIDE;
142 virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>) OVERRIDE;
144 // Called from other agents.
145 void setHostId(const String&);
146 bool fetchResourceContent(LocalFrame*, const KURL&, String* content, bool* base64Encoded);
149 InspectorResourceAgent(InspectorPageAgent*);
153 InspectorPageAgent* m_pageAgent;
154 InspectorFrontend::Network* m_frontend;
155 String m_userAgentOverride;
157 OwnPtr<NetworkResourcesData> m_resourcesData;
159 typedef HashMap<ThreadableLoaderClient*, RefPtr<XHRReplayData> > PendingXHRReplayDataMap;
160 PendingXHRReplayDataMap m_pendingXHRReplayData;
162 typedef HashMap<String, RefPtr<TypeBuilder::Network::Initiator> > FrameNavigationInitiatorMap;
163 FrameNavigationInitiatorMap m_frameNavigationInitiatorMap;
165 // FIXME: InspectorResourceAgent should now be aware of style recalculation.
166 RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
167 bool m_isRecalculatingStyle;
170 } // namespace WebCore
173 #endif // !defined(InspectorResourceAgent_h)