Part 2 of removing PlatformString.h, remove PlatformString.h
[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 Frame;
54 class InspectorArray;
55 class InspectorClient;
56 class InspectorFrontend;
57 class InspectorObject;
58 class InspectorPageAgent;
59 class InspectorState;
60 class InstrumentingAgents;
61 class KURL;
62 class NetworkResourcesData;
63 class Page;
64 class ResourceError;
65 class ResourceLoader;
66 class ResourceRequest;
67 class ResourceResponse;
68 class SharedBuffer;
69
70 #if ENABLE(WEB_SOCKETS)
71 struct WebSocketFrame;
72 class WebSocketHandshakeRequest;
73 class WebSocketHandshakeResponse;
74 #endif
75
76 typedef String ErrorString;
77
78 class InspectorResourceAgent : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
79 public:
80     static PassOwnPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorState* state)
81     {
82         return adoptPtr(new InspectorResourceAgent(instrumentingAgents, pageAgent, client, state));
83     }
84
85     virtual void setFrontend(InspectorFrontend*);
86     virtual void clearFrontend();
87     virtual void restore();
88
89     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorState*, InspectorFrontend*);
90
91     ~InspectorResourceAgent();
92
93     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
94     void markResourceAsCached(unsigned long identifier);
95     void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&, ResourceLoader*);
96     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
97     void didFinishLoading(unsigned long identifier, DocumentLoader*, double finishTime);
98     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
99     void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource*);
100     void mainFrameNavigated(DocumentLoader*);
101     void setInitialScriptContent(unsigned long identifier, const String& sourceString);
102     void didReceiveScriptResponse(unsigned long identifier);
103     void setInitialXHRContent(unsigned long identifier, const String& sourceString);
104     void didReceiveXHRResponse(unsigned long identifier);
105     void willLoadXHRSynchronously();
106     void didLoadXHRSynchronously();
107     void willDestroyCachedResource(CachedResource*);
108
109     void applyUserAgentOverride(String* userAgent);
110
111     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
112     void willRecalculateStyle();
113     void didRecalculateStyle();
114     void didScheduleStyleRecalculation(Document*);
115
116     PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*);
117
118 #if ENABLE(WEB_SOCKETS)
119     void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
120     void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
121     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse&);
122     void didCloseWebSocket(unsigned long identifier);
123     void didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
124     void didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
125     void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
126 #endif
127
128     // called from Internals for layout test purposes.
129     void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
130
131     // Called from frontend
132     virtual void enable(ErrorString*);
133     virtual void disable(ErrorString*);
134     virtual void setUserAgentOverride(ErrorString*, const String& userAgent);
135     virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<InspectorObject>&);
136     virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
137
138     virtual void canClearBrowserCache(ErrorString*, bool*);
139     virtual void clearBrowserCache(ErrorString*);
140     virtual void canClearBrowserCookies(ErrorString*, bool*);
141     virtual void clearBrowserCookies(ErrorString*);
142     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled);
143
144 private:
145     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*, InspectorState*);
146
147     void enable();
148
149     InspectorPageAgent* m_pageAgent;
150     InspectorClient* m_client;
151     InspectorFrontend::Network* m_frontend;
152     String m_userAgentOverride;
153     OwnPtr<NetworkResourcesData> m_resourcesData;
154     bool m_loadingXHRSynchronously;
155
156     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
157     RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
158     bool m_isRecalculatingStyle;
159 };
160
161 } // namespace WebCore
162
163 #endif // ENABLE(INSPECTOR)
164
165 #endif // !defined(InspectorResourceAgent_h)