Home | History | Annotate | Download | only in inspector
      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 "bindings/v8/ScriptString.h"
     36 #include "core/inspector/InspectorBaseAgent.h"
     37 #include "wtf/PassOwnPtr.h"
     38 #include "wtf/text/WTFString.h"
     39 
     40 
     41 namespace WTF {
     42 class String;
     43 }
     44 
     45 namespace WebCore {
     46 
     47 class Resource;
     48 struct FetchInitiatorInfo;
     49 class Document;
     50 class DocumentLoader;
     51 class FormData;
     52 class Frame;
     53 class HTTPHeaderMap;
     54 class InspectorClient;
     55 class InspectorFrontend;
     56 class InspectorOverlay;
     57 class InspectorPageAgent;
     58 class InstrumentingAgents;
     59 class JSONObject;
     60 class KURL;
     61 class NetworkResourcesData;
     62 class Page;
     63 class ResourceError;
     64 class ResourceLoader;
     65 class ResourceRequest;
     66 class ResourceResponse;
     67 class ThreadableLoaderClient;
     68 class XHRReplayData;
     69 
     70 struct WebSocketFrame;
     71 class WebSocketHandshakeRequest;
     72 class WebSocketHandshakeResponse;
     73 
     74 typedef String ErrorString;
     75 
     76 class InspectorResourceAgent : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
     77 public:
     78     static PassOwnPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorCompositeState* state, InspectorOverlay* overlay)
     79     {
     80         return adoptPtr(new InspectorResourceAgent(instrumentingAgents, pageAgent, client, state, overlay));
     81     }
     82 
     83     virtual void setFrontend(InspectorFrontend*);
     84     virtual void clearFrontend();
     85     virtual void restore();
     86 
     87     static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorCompositeState*, InspectorFrontend*);
     88 
     89     ~InspectorResourceAgent();
     90 
     91     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
     92     void markResourceAsCached(unsigned long identifier);
     93     void didReceiveResourceResponse(unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
     94     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     95     void didFinishLoading(unsigned long identifier, DocumentLoader*, double monotonicFinishTime);
     96     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
     97     void didCommitLoad(Frame*, 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(ThreadableLoaderClient*, const String& method, const KURL&, bool async, PassRefPtr<FormData> body, const HTTPHeaderMap& headers, bool includeCrendentials);
    103     void didFailXHRLoading(ThreadableLoaderClient*);
    104     void didFinishXHRLoading(ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const String&, const String&, unsigned);
    105     void didReceiveXHRResponse(unsigned long identifier);
    106     void willLoadXHRSynchronously();
    107     void didLoadXHRSynchronously();
    108 
    109     void willDestroyResource(Resource*);
    110 
    111     void applyUserAgentOverride(String* userAgent);
    112 
    113     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
    114     void willRecalculateStyle(Document*);
    115     void didRecalculateStyle();
    116     void didScheduleStyleRecalculation(Document*);
    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 WebSocketHandshakeResponse&);
    123     void didCloseWebSocket(Document*, unsigned long identifier);
    124     void didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
    125     void didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
    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*);
    133     virtual void disable(ErrorString*);
    134     virtual void setUserAgentOverride(ErrorString*, const String& userAgent);
    135     virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&);
    136     virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
    137 
    138     virtual void replayXHR(ErrorString*, const String& requestId);
    139 
    140     virtual void canClearBrowserCache(ErrorString*, bool*);
    141     virtual void clearBrowserCache(ErrorString*);
    142     virtual void canClearBrowserCookies(ErrorString*, bool*);
    143     virtual void clearBrowserCookies(ErrorString*);
    144     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled);
    145 
    146     virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>);
    147 
    148 private:
    149     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*, InspectorCompositeState*, InspectorOverlay*);
    150 
    151     void enable();
    152 
    153     InspectorPageAgent* m_pageAgent;
    154     InspectorClient* m_client;
    155     InspectorOverlay* m_overlay;
    156     InspectorFrontend::Network* m_frontend;
    157     String m_userAgentOverride;
    158     OwnPtr<NetworkResourcesData> m_resourcesData;
    159     bool m_loadingXHRSynchronously;
    160 
    161     typedef HashMap<ThreadableLoaderClient*, RefPtr<XHRReplayData> > PendingXHRReplayDataMap;
    162     PendingXHRReplayDataMap m_pendingXHRReplayData;
    163     // FIXME: InspectorResourceAgent should now be aware of style recalculation.
    164     RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
    165     bool m_isRecalculatingStyle;
    166 };
    167 
    168 } // namespace WebCore
    169 
    170 
    171 #endif // !defined(InspectorResourceAgent_h)
    172