Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 "bindings/core/v8/ScriptString.h"
35 #include "core/InspectorFrontend.h"
36 #include "core/inspector/InspectorBaseAgent.h"
37 #include "platform/Timer.h"
38 #include "platform/heap/Handle.h"
39 #include "wtf/PassOwnPtr.h"
40 #include "wtf/text/WTFString.h"
41
42 namespace WTF {
43 class String;
44 }
45
46 namespace blink {
47
48 class Resource;
49 struct FetchInitiatorInfo;
50 class Document;
51 class DocumentLoader;
52 class FormData;
53 class LocalFrame;
54 class HTTPHeaderMap;
55 class InspectorFrontend;
56 class InspectorPageAgent;
57 class InstrumentingAgents;
58 class JSONObject;
59 class KURL;
60 class NetworkResourcesData;
61 class Page;
62 class ResourceError;
63 class ResourceLoader;
64 class ResourceRequest;
65 class ResourceResponse;
66 class ThreadableLoaderClient;
67 class XHRReplayData;
68 class XMLHttpRequest;
69
70 class WebSocketHandshakeRequest;
71 class WebSocketHandshakeResponse;
72
73 typedef String ErrorString;
74
75 class InspectorResourceAgent FINAL : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
76 public:
77     static PassOwnPtrWillBeRawPtr<InspectorResourceAgent> create(InspectorPageAgent* pageAgent)
78     {
79         return adoptPtrWillBeNoop(new InspectorResourceAgent(pageAgent));
80     }
81
82     virtual void setFrontend(InspectorFrontend*) OVERRIDE;
83     virtual void clearFrontend() OVERRIDE;
84     virtual void restore() OVERRIDE;
85
86     virtual ~InspectorResourceAgent();
87     virtual void trace(Visitor*) OVERRIDE;
88
89     // Called from instrumentation.
90     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
91     void markResourceAsCached(unsigned long identifier);
92     void didReceiveResourceResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
93     void didReceiveData(LocalFrame*, unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
94     void didFinishLoading(unsigned long identifier, DocumentLoader*, double monotonicFinishTime, int64_t encodedDataLength);
95     void didReceiveCORSRedirectResponse(LocalFrame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
96     void didFailLoading(unsigned long identifier, const ResourceError&);
97     void didCommitLoad(LocalFrame*, DocumentLoader*);
98     void scriptImported(unsigned long identifier, const String& sourceString);
99     void didReceiveScriptResponse(unsigned long identifier);
100
101     void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
102     void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, FormData* body, const HTTPHeaderMap& headers, bool includeCrendentials);
103     void didFailXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*);
104     void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const AtomicString&, const String&, const String&, unsigned);
105
106     void willDestroyResource(Resource*);
107
108     void applyUserAgentOverride(String* userAgent);
109
110     // FIXME: InspectorResourceAgent should not be aware of style recalculation.
111     void willRecalculateStyle(Document*);
112     void didRecalculateStyle(int);
113     void didScheduleStyleRecalculation(Document*);
114
115     void frameScheduledNavigation(LocalFrame*, double);
116     void frameClearedScheduledNavigation(LocalFrame*);
117
118     PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
119
120     void didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&);
121     void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest*);
122     void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const WebSocketHandshakeRequest*, const WebSocketHandshakeResponse*);
123     void didCloseWebSocket(Document*, unsigned long identifier);
124     void didReceiveWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
125     void didSendWebSocketFrame(unsigned long identifier, int opCode, bool masked, const char* payload, size_t payloadLength);
126     void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
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*) OVERRIDE;
133     virtual void disable(ErrorString*) OVERRIDE;
134     virtual void setUserAgentOverride(ErrorString*, const String& userAgent) OVERRIDE;
135     virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&) OVERRIDE;
136     virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded) OVERRIDE;
137
138     virtual void replayXHR(ErrorString*, const String& requestId) OVERRIDE;
139
140     virtual void canClearBrowserCache(ErrorString*, bool*) OVERRIDE;
141     virtual void canClearBrowserCookies(ErrorString*, bool*) OVERRIDE;
142     virtual void emulateNetworkConditions(ErrorString*, bool, double, double, double) OVERRIDE;
143     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled) OVERRIDE;
144
145     virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>) OVERRIDE;
146
147     // Called from other agents.
148     void setHostId(const String&);
149     bool fetchResourceContent(Document*, const KURL&, String* content, bool* base64Encoded);
150
151 private:
152     explicit InspectorResourceAgent(InspectorPageAgent*);
153
154     void enable();
155     void delayedRemoveReplayXHR(XMLHttpRequest*);
156     void removeFinishedReplayXHRFired(Timer<InspectorResourceAgent>*);
157
158     RawPtrWillBeMember<InspectorPageAgent> m_pageAgent;
159     InspectorFrontend::Network* m_frontend;
160     String m_userAgentOverride;
161     String m_hostId;
162     OwnPtr<NetworkResourcesData> m_resourcesData;
163
164     typedef WillBeHeapHashMap<ThreadableLoaderClient*, RefPtrWillBeMember<XHRReplayData> > PendingXHRReplayDataMap;
165     PendingXHRReplayDataMap m_pendingXHRReplayData;
166
167     typedef HashMap<String, RefPtr<TypeBuilder::Network::Initiator> > FrameNavigationInitiatorMap;
168     FrameNavigationInitiatorMap m_frameNavigationInitiatorMap;
169
170     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
171     RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
172     bool m_isRecalculatingStyle;
173
174     WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRs;
175     WillBeHeapHashSet<RefPtrWillBeMember<XMLHttpRequest> > m_replayXHRsToBeDeleted;
176     Timer<InspectorResourceAgent> m_removeFinishedReplayXHRTimer;
177 };
178
179 } // namespace blink
180
181
182 #endif // !defined(InspectorResourceAgent_h)