• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/OwnPtr.h>
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/Vector.h>
40 
41 #if ENABLE(INSPECTOR)
42 
43 namespace WTF {
44 class String;
45 }
46 
47 namespace WebCore {
48 
49 class CachedResource;
50 class Document;
51 class DocumentLoader;
52 class Frame;
53 class InspectorArray;
54 class InspectorFrontend;
55 class InspectorFrontendProxy;
56 class InspectorObject;
57 class InspectorState;
58 class InstrumentingAgents;
59 class KURL;
60 class EventsCollector;
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:
create(InstrumentingAgents * instrumentingAgents,Page * page,InspectorState * state)76     static PassRefPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, Page* page, InspectorState* state)
77     {
78         return adoptRef(new InspectorResourceAgent(instrumentingAgents, page, state));
79     }
80 
81     void setFrontend(InspectorFrontend*);
82     void clearFrontend();
83     void restore();
84 
85     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorState*, InspectorFrontend*);
86 
87     static void resourceContent(ErrorString*, Frame*, const KURL&, String* result);
88     static void resourceContentBase64(ErrorString*, Frame*, const KURL&, String* result);
89     static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName);
90     static CachedResource* cachedResource(Frame*, const KURL&);
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&);
97     void didReceiveContentLength(unsigned long identifier, int dataLength, int encodedDataLength);
98     void didFinishLoading(unsigned long identifier, double finishTime);
99     void didFailLoading(unsigned long identifier, const ResourceError&);
100     void didLoadResourceFromMemoryCache(DocumentLoader*, const CachedResource*);
101     void setInitialScriptContent(unsigned long identifier, const String& sourceString);
102     void setInitialXHRContent(unsigned long identifier, const String& sourceString);
103     void domContentEventFired();
104     void loadEventFired();
105     void didCommitLoad(DocumentLoader*);
106     void frameDetachedFromParent(Frame*);
107 
108 #if ENABLE(WEB_SOCKETS)
109     void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
110     void willSendWebSocketHandshakeRequest(unsigned long identifier, const WebSocketHandshakeRequest&);
111     void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const WebSocketHandshakeResponse&);
112     void didCloseWebSocket(unsigned long identifier);
113 #endif
114 
115     Frame* frameForId(const String& frameId);
116     bool backgroundEventsCollectionEnabled();
117 
118     // Called from frontend
119     void enable(ErrorString*);
120     void disable(ErrorString*);
121     void getCachedResources(ErrorString*, RefPtr<InspectorObject>*);
122     void getResourceContent(ErrorString*, const String& frameId, const String& url, const bool* const base64Encode, String* content);
123     void setExtraHeaders(ErrorString*, PassRefPtr<InspectorObject>);
124 
125 private:
126     InspectorResourceAgent(InstrumentingAgents*, Page*, InspectorState*);
127 
128     void enable();
129 
130     InstrumentingAgents* m_instrumentingAgents;
131     Page* m_page;
132     InspectorState* m_state;
133     OwnPtr<EventsCollector> m_eventsCollector;
134     InspectorFrontend::Network* m_frontend;
135     OwnPtr<InspectorFrontend::Network> m_mockFrontend;
136     OwnPtr<InspectorFrontendProxy> m_inspectorFrontendProxy;
137 };
138 
139 } // namespace WebCore
140 
141 #endif // ENABLE(INSPECTOR)
142 
143 #endif // !defined(InspectorResourceAgent_h)
144