Web Inspector: Remove InspectorState
[WebKit-https.git] / Source / WebCore / inspector / InspectorResourceAgent.h
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 "InspectorBaseAgent.h"
35 #include "InspectorFrontend.h"
36
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/RefCounted.h>
39 #include <wtf/Vector.h>
40 #include <wtf/text/WTFString.h>
41
42 #if ENABLE(INSPECTOR)
43
44 namespace WTF {
45 class String;
46 }
47
48 namespace WebCore {
49
50 class CachedResource;
51 class Document;
52 class DocumentLoader;
53 class FormData;
54 class Frame;
55 class HTTPHeaderMap;
56 class InspectorArray;
57 class InspectorClient;
58 class InspectorFrontend;
59 class InspectorObject;
60 class InspectorPageAgent;
61 class InstrumentingAgents;
62 class URL;
63 class NetworkResourcesData;
64 class Page;
65 class ResourceError;
66 class ResourceLoader;
67 class ResourceRequest;
68 class ResourceResponse;
69 class SharedBuffer;
70 class ThreadableLoaderClient;
71 class XHRReplayData;
72 class XMLHttpRequest;
73
74 #if ENABLE(WEB_SOCKETS)
75 struct WebSocketFrame;
76 #endif
77
78 typedef String ErrorString;
79
80 class InspectorResourceAgent : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
81 public:
82     static PassOwnPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client)
83     {
84         return adoptPtr(new InspectorResourceAgent(instrumentingAgents, pageAgent, client));
85     }
86
87     virtual void setFrontend(InspectorFrontend*);
88     virtual void clearFrontend();
89
90     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorFrontend*);
91
92     ~InspectorResourceAgent();
93
94     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
95     void markResourceAsCached(unsigned long identifier);
96     void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&, ResourceLoader*);
97     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
98     void didFinishLoading(unsigned long identifier, DocumentLoader*, double finishTime);
99     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
100     void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource*);
101     void mainFrameNavigated(DocumentLoader*);
102     void setInitialScriptContent(unsigned long identifier, const String& sourceString);
103     void didReceiveScriptResponse(unsigned long identifier);
104
105     void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
106     void willLoadXHR(ThreadableLoaderClient*, const String& method, const URL&, bool async, PassRefPtr<FormData> body, const HTTPHeaderMap& headers, bool includeCrendentials);
107     void didFailXHRLoading(ThreadableLoaderClient*);
108     void didFinishXHRLoading(ThreadableLoaderClient*, unsigned long identifier, const String& sourceString);
109     void didReceiveXHRResponse(unsigned long identifier);
110     void willLoadXHRSynchronously();
111     void didLoadXHRSynchronously();
112
113     void willDestroyCachedResource(CachedResource*);
114
115     void applyUserAgentOverride(String* userAgent);
116
117     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
118     void willRecalculateStyle();
119     void didRecalculateStyle();
120     void didScheduleStyleRecalculation(Document*);
121
122     PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*);
123
124 #if ENABLE(WEB_SOCKETS)
125     void didCreateWebSocket(unsigned long identifier, const URL& requestURL);
126     void willSendWebSocketHandshakeRequest(unsigned long identifier, const ResourceRequest&);
127     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const ResourceResponse&);
128     void didCloseWebSocket(unsigned long identifier);
129     void didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
130     void didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
131     void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
132 #endif
133
134     // called from Internals for layout test purposes.
135     void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
136
137     // Called from frontend
138     virtual void enable(ErrorString*);
139     virtual void disable(ErrorString*);
140     virtual void setUserAgentOverride(ErrorString*, const String& userAgent);
141     virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<InspectorObject>&);
142     virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
143
144     virtual void replayXHR(ErrorString*, const String& requestId);
145
146     virtual void canClearBrowserCache(ErrorString*, bool*);
147     virtual void clearBrowserCache(ErrorString*);
148     virtual void canClearBrowserCookies(ErrorString*, bool*);
149     virtual void clearBrowserCookies(ErrorString*);
150     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled);
151
152 private:
153     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*);
154
155     void enable();
156
157     InspectorPageAgent* m_pageAgent;
158     InspectorClient* m_client;
159     InspectorFrontend::Network* m_frontend;
160     String m_userAgentOverride;
161     OwnPtr<NetworkResourcesData> m_resourcesData;
162     bool m_enabled;
163     bool m_cacheDisabled;
164     bool m_loadingXHRSynchronously;
165     RefPtr<InspectorObject> m_extraRequestHeaders;
166
167     typedef HashMap<ThreadableLoaderClient*, RefPtr<XHRReplayData>> PendingXHRReplayDataMap;
168     PendingXHRReplayDataMap m_pendingXHRReplayData;
169     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
170     RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
171     bool m_isRecalculatingStyle;
172 };
173
174 } // namespace WebCore
175
176 #endif // ENABLE(INSPECTOR)
177
178 #endif // !defined(InspectorResourceAgent_h)