b4410b375caf1d2e6fa62efe994caebb9ce19116
[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 "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 EventsCollector;
52 class Frame;
53 class InspectorArray;
54 class InspectorFrontend;
55 class InspectorFrontendProxy;
56 class InspectorObject;
57 class InspectorPageAgent;
58 class InspectorState;
59 class InstrumentingAgents;
60 class KURL;
61 class NetworkResourcesData;
62 class Page;
63 class ResourceError;
64 class ResourceRequest;
65 class ResourceResponse;
66 class SharedBuffer;
67
68 #if ENABLE(WEB_SOCKETS)
69 class WebSocketHandshakeRequest;
70 class WebSocketHandshakeResponse;
71 #endif
72
73 typedef String ErrorString;
74
75 class InspectorResourceAgent : public RefCounted<InspectorResourceAgent> {
76 public:
77     static PassRefPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorState* state)
78     {
79         return adoptRef(new InspectorResourceAgent(instrumentingAgents, pageAgent, state));
80     }
81
82     void setFrontend(InspectorFrontend*);
83     void clearFrontend();
84     void restore();
85
86     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorState*, InspectorFrontend*);
87
88     ~InspectorResourceAgent();
89
90     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
91     void markResourceAsCached(unsigned long identifier);
92     void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&);
93     void didReceiveContentLength(unsigned long identifier, int dataLength, int encodedDataLength);
94     void didFinishLoading(unsigned long identifier, DocumentLoader*, double finishTime);
95     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
96     void didLoadResourceFromMemoryCache(DocumentLoader*, const CachedResource*);
97     void mainFrameNavigated(DocumentLoader*);
98     void setInitialScriptContent(unsigned long identifier, const String& sourceString);
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 #if ENABLE(WEB_SOCKETS)
107     void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
108     void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
109     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse&);
110     void didCloseWebSocket(unsigned long identifier);
111 #endif
112
113     void isBackgroundEventsCollectionEnabled(ErrorString*, bool* enabled);
114     void setBackgroundEventsCollectionEnabled(ErrorString*, bool enabled);
115
116     // Called from frontend
117     void enable(ErrorString*);
118     void disable(ErrorString*);
119     void setUserAgentOverride(ErrorString*, const String& userAgent);
120     void setExtraHeaders(ErrorString*, PassRefPtr<InspectorObject>);
121     void getResourceContent(ErrorString*, unsigned long identifier, String* content, bool* base64Encoded);
122     void clearCache(ErrorString*, const String* const optionalPreservedLoaderId);
123
124 private:
125     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorState*);
126
127     bool isBackgroundEventsCollectionEnabled();
128     void enable();
129     void initializeBackgroundCollection();
130
131     InstrumentingAgents* m_instrumentingAgents;
132     InspectorPageAgent* m_pageAgent;
133     InspectorState* m_state;
134     InspectorFrontend::Network* m_frontend;
135     OwnPtr<EventsCollector> m_eventsCollector;
136     OwnPtr<InspectorFrontendProxy> m_inspectorFrontendProxy;
137     OwnPtr<InspectorFrontend::Network> m_mockFrontend;
138     String m_userAgentOverride;
139     OwnPtr<NetworkResourcesData> m_resourcesData;
140     bool m_loadingXHRSynchronously;
141 };
142
143 } // namespace WebCore
144
145 #endif // ENABLE(INSPECTOR)
146
147 #endif // !defined(InspectorResourceAgent_h)