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 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 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)
     79     {
     80         return adoptPtr(new InspectorResourceAgent(instrumentingAgents, pageAgent, client, state));
     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     // Called from instrumentation.
     92     void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse, const FetchInitiatorInfo&);
     93     void markResourceAsCached(unsigned long identifier);
     94     void didReceiveResourceResponse(Frame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
     95     void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
     96     void didFinishLoading(unsigned long identifier, DocumentLoader*, double monotonicFinishTime);
     97     void didReceiveCORSRedirectResponse(Frame*, unsigned long identifier, DocumentLoader*, const ResourceResponse&, ResourceLoader*);
     98     void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
     99     void didCommitLoad(Frame*, DocumentLoader*);
    100     void scriptImported(unsigned long identifier, const String& sourceString);
    101     void didReceiveScriptResponse(unsigned long identifier);
    102 
    103     void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
    104     void willLoadXHR(XMLHttpRequest*, ThreadableLoaderClient*, const AtomicString& method, const KURL&, bool async, PassRefPtr<FormData> body, const HTTPHeaderMap& headers, bool includeCrendentials);
    105     void didFailXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*);
    106     void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long identifier, ScriptString sourceString, const String&, const String&, unsigned);
    107 
    108     void willDestroyResource(Resource*);
    109 
    110     void applyUserAgentOverride(String* userAgent);
    111 
    112     // FIXME: InspectorResourceAgent should not be aware of style recalculation.
    113     void willRecalculateStyle(Document*);
    114     void didRecalculateStyle();
    115     void didScheduleStyleRecalculation(Document*);
    116 
    117     void frameScheduledNavigation(Frame*, double);
    118     void frameClearedScheduledNavigation(Frame*);
    119 
    120     PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*, const FetchInitiatorInfo&);
    121 
    122     void didCreateWebSocket(Document*, unsigned long identifier, const KURL& requestURL, const String&);
    123     void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const WebSocketHandshakeRequest&);
    124     void didReceiveWebSocketHandshakeResponse(Document*, unsigned long identifier, const WebSocketHandshakeResponse&);
    125     void didCloseWebSocket(Document*, unsigned long identifier);
    126     void didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
    127     void didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
    128     void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
    129 
    130     // called from Internals for layout test purposes.
    131     void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
    132 
    133     // Called from frontend
    134     virtual void enable(ErrorString*);
    135     virtual void disable(ErrorString*);
    136     virtual void setUserAgentOverride(ErrorString*, const String& userAgent);
    137     virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<JSONObject>&);
    138     virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
    139 
    140     virtual void replayXHR(ErrorString*, const String& requestId);
    141 
    142     virtual void canClearBrowserCache(ErrorString*, bool*);
    143     virtual void clearBrowserCache(ErrorString*);
    144     virtual void canClearBrowserCookies(ErrorString*, bool*);
    145     virtual void clearBrowserCookies(ErrorString*);
    146     virtual void setCacheDisabled(ErrorString*, bool cacheDisabled);
    147 
    148     virtual void loadResourceForFrontend(ErrorString*, const String& frameId, const String& url, const RefPtr<JSONObject>* requestHeaders, PassRefPtr<LoadResourceForFrontendCallback>);
    149 
    150     // Called from other agents.
    151     bool fetchResourceContent(Frame*, const KURL&, String* content, bool* base64Encoded);
    152 
    153 private:
    154     InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*, InspectorCompositeState*);
    155 
    156     void enable();
    157 
    158     InspectorPageAgent* m_pageAgent;
    159     InspectorClient* m_client;
    160     InspectorFrontend::Network* m_frontend;
    161     String m_userAgentOverride;
    162     OwnPtr<NetworkResourcesData> m_resourcesData;
    163 
    164     typedef HashMap<ThreadableLoaderClient*, RefPtr<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 
    175 } // namespace WebCore
    176 
    177 
    178 #endif // !defined(InspectorResourceAgent_h)
    179