• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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
13  * distribution.
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.
17  *
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.
29  */
30 
31 #ifndef InspectorResourceAgent_h
32 #define InspectorResourceAgent_h
33 
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"
39 
40 
41 namespace WTF {
42 class String;
43 }
44 
45 namespace WebCore {
46 
47 class Resource;
48 struct FetchInitiatorInfo;
49 class Document;
50 class DocumentLoader;
51 class FormData;
52 class LocalFrame;
53 class HTTPHeaderMap;
54 class InspectorFrontend;
55 class InspectorPageAgent;
56 class InstrumentingAgents;
57 class JSONObject;
58 class KURL;
59 class NetworkResourcesData;
60 class Page;
61 class ResourceError;
62 class ResourceLoader;
63 class ResourceRequest;
64 class ResourceResponse;
65 class ThreadableLoaderClient;
66 class XHRReplayData;
67 class XMLHttpRequest;
68 
69 class WebSocketHandshakeRequest;
70 class WebSocketHandshakeResponse;
71 
72 typedef String ErrorString;
73 
74 class InspectorResourceAgent FINAL : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
75 public:
create(InspectorPageAgent * pageAgent)76     static PassOwnPtr<InspectorResourceAgent> create(InspectorPageAgent* pageAgent)
77     {
78         return adoptPtr(new InspectorResourceAgent(pageAgent));
79     }
80 
81     virtual void setFrontend(InspectorFrontend*) OVERRIDE;
82     virtual void clearFrontend() OVERRIDE;
83     virtual void restore() OVERRIDE;
84 
85     virtual ~InspectorResourceAgent();
86 
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);
98 
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);
103 
104     void willDestroyResource(Resource*);
105 
106     void applyUserAgentOverride(String* userAgent);
107 
108     // FIXME: InspectorResourceAgent should not be aware of style recalculation.
109     void willRecalculateStyle(Document*);
110     void didRecalculateStyle(int);
111     void didScheduleStyleRecalculation(Document*);
112 
113     void frameScheduledNavigation(LocalFrame*, double);
114     void frameClearedScheduledNavigation(LocalFrame*);
115 
116     PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
117 
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&);
125 
126     // called from Internals for layout test purposes.
127     void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
128 
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;
135 
136     virtual void replayXHR(ErrorString*, const String& requestId) OVERRIDE;
137 
138     virtual void canClearBrowserCache(ErrorString*, bool*) OVERRIDE;
139     virtual void canClearBrowserCookies(ErrorString*, bool*) OVERRIDE;
140     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled) OVERRIDE;
141 
142     virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>) OVERRIDE;
143 
144     // Called from other agents.
145     void setHostId(const String&);
146     bool fetchResourceContent(LocalFrame*, const KURL&, String* content, bool* base64Encoded);
147 
148 private:
149     InspectorResourceAgent(InspectorPageAgent*);
150 
151     void enable();
152 
153     InspectorPageAgent* m_pageAgent;
154     InspectorFrontend::Network* m_frontend;
155     String m_userAgentOverride;
156     String m_hostId;
157     OwnPtr<NetworkResourcesData> m_resourcesData;
158 
159     typedef HashMap<ThreadableLoaderClient*, RefPtr<XHRReplayData> > PendingXHRReplayDataMap;
160     PendingXHRReplayDataMap m_pendingXHRReplayData;
161 
162     typedef HashMap<String, RefPtr<TypeBuilder::Network::Initiator> > FrameNavigationInitiatorMap;
163     FrameNavigationInitiatorMap m_frameNavigationInitiatorMap;
164 
165     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
166     RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
167     bool m_isRecalculatingStyle;
168 };
169 
170 } // namespace WebCore
171 
172 
173 #endif // !defined(InspectorResourceAgent_h)
174