initial import
[vuplus_webkit] / 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 "InspectorFrontend.h"
35 #include "PlatformString.h"
36
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/Vector.h>
39
40 #if ENABLE(INSPECTOR)
41
42 namespace WTF {
43 class String;
44 }
45
46 namespace WebCore {
47
48 class CachedResource;
49 class Document;
50 class DocumentLoader;
51 class Frame;
52 class InspectorArray;
53 class InspectorClient;
54 class InspectorFrontend;
55 class InspectorObject;
56 class InspectorPageAgent;
57 class InspectorState;
58 class InstrumentingAgents;
59 class KURL;
60 class NetworkResourcesData;
61 class Page;
62 class ResourceError;
63 class ResourceRequest;
64 class ResourceResponse;
65 class SharedBuffer;
66
67 #if ENABLE(WEB_SOCKETS)
68 class WebSocketHandshakeRequest;
69 class WebSocketHandshakeResponse;
70 #endif
71
72 typedef String ErrorString;
73
74 class InspectorResourceAgent : public RefCounted<InspectorResourceAgent> {
75 public:
76     static PassRefPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorState* state)
77     {
78         return adoptRef(new InspectorResourceAgent(instrumentingAgents, pageAgent, client, state));
79     }
80
81     void setFrontend(InspectorFrontend*);
82     void clearFrontend();
83     void restore();
84
85     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorState*, InspectorFrontend*);
86
87     ~InspectorResourceAgent();
88
89     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
90     void markResourceAsCached(unsigned long identifier);
91     void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&);
92     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
93     void didFinishLoading(unsigned long identifier, DocumentLoader*, double finishTime);
94     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
95     void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource*);
96     void mainFrameNavigated(DocumentLoader*);
97     void setInitialScriptContent(unsigned long identifier, const String& sourceString);
98     void didReceiveScriptResponse(unsigned long identifier);
99     void setInitialXHRContent(unsigned long identifier, const String& sourceString);
100     void didReceiveXHRResponse(unsigned long identifier);
101     void willLoadXHRSynchronously();
102     void didLoadXHRSynchronously();
103
104     void applyUserAgentOverride(String* userAgent);
105
106     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
107     void willRecalculateStyle();
108     void didRecalculateStyle();
109     void didScheduleStyleRecalculation(Document*);
110
111     PassRefPtr<InspectorObject> buildInitiatorObject(Document*);
112
113 #if ENABLE(WEB_SOCKETS)
114     void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
115     void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
116     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse&);
117     void didCloseWebSocket(unsigned long identifier);
118 #endif
119
120     // called from Internals for layout test purposes.
121     void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
122
123     // Called from frontend
124     void enable(ErrorString*);
125     void disable(ErrorString*);
126     void setUserAgentOverride(ErrorString*, const String& userAgent);
127     void setExtraHeaders(ErrorString*, PassRefPtr<InspectorObject>);
128     void getResourceContent(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
129     void clearCache(ErrorString*, const String* const optionalPreservedLoaderId);
130
131     void clearBrowserCache(ErrorString*);
132     void clearBrowserCookies(ErrorString*);
133     void setCacheDisabled(ErrorString*, bool cacheDisabled);
134
135 private:
136     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*, InspectorState*);
137
138     void enable();
139
140     InstrumentingAgents* m_instrumentingAgents;
141     InspectorPageAgent* m_pageAgent;
142     InspectorClient* m_client;
143     InspectorState* m_state;
144     InspectorFrontend::Network* m_frontend;
145     String m_userAgentOverride;
146     OwnPtr<NetworkResourcesData> m_resourcesData;
147     bool m_loadingXHRSynchronously;
148
149     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
150     RefPtr<InspectorObject> m_styleRecalculationInitiator;
151     bool m_isRecalculatingStyle;
152 };
153
154 } // namespace WebCore
155
156 #endif // ENABLE(INSPECTOR)
157
158 #endif // !defined(InspectorResourceAgent_h)