InspectorResourceAgent.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef InspectorResourceAgent_h
  31. #define InspectorResourceAgent_h
  32. #include "InspectorBaseAgent.h"
  33. #include "InspectorFrontend.h"
  34. #include <wtf/PassOwnPtr.h>
  35. #include <wtf/RefCounted.h>
  36. #include <wtf/Vector.h>
  37. #include <wtf/text/WTFString.h>
  38. #if ENABLE(INSPECTOR)
  39. namespace WTF {
  40. class String;
  41. }
  42. namespace WebCore {
  43. class CachedResource;
  44. class Document;
  45. class DocumentLoader;
  46. class FormData;
  47. class Frame;
  48. class HTTPHeaderMap;
  49. class InspectorArray;
  50. class InspectorClient;
  51. class InspectorFrontend;
  52. class InspectorObject;
  53. class InspectorPageAgent;
  54. class InspectorState;
  55. class InstrumentingAgents;
  56. class KURL;
  57. class NetworkResourcesData;
  58. class Page;
  59. class ResourceError;
  60. class ResourceLoader;
  61. class ResourceRequest;
  62. class ResourceResponse;
  63. class SharedBuffer;
  64. class ThreadableLoaderClient;
  65. class XHRReplayData;
  66. class XMLHttpRequest;
  67. #if ENABLE(WEB_SOCKETS)
  68. struct WebSocketFrame;
  69. #endif
  70. typedef String ErrorString;
  71. class InspectorResourceAgent : public InspectorBaseAgent<InspectorResourceAgent>, public InspectorBackendDispatcher::NetworkCommandHandler {
  72. public:
  73. static PassOwnPtr<InspectorResourceAgent> create(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent, InspectorClient* client, InspectorCompositeState* state)
  74. {
  75. return adoptPtr(new InspectorResourceAgent(instrumentingAgents, pageAgent, client, state));
  76. }
  77. virtual void setFrontend(InspectorFrontend*);
  78. virtual void clearFrontend();
  79. virtual void restore();
  80. static PassRefPtr<InspectorResourceAgent> restore(Page*, InspectorCompositeState*, InspectorFrontend*);
  81. ~InspectorResourceAgent();
  82. void willSendRequest(unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
  83. void markResourceAsCached(unsigned long identifier);
  84. void didReceiveResponse(unsigned long identifier, DocumentLoader* laoder, const ResourceResponse&, ResourceLoader*);
  85. void didReceiveData(unsigned long identifier, const char* data, int dataLength, int encodedDataLength);
  86. void didFinishLoading(unsigned long identifier, DocumentLoader*, double finishTime);
  87. void didFailLoading(unsigned long identifier, DocumentLoader*, const ResourceError&);
  88. void didLoadResourceFromMemoryCache(DocumentLoader*, CachedResource*);
  89. void mainFrameNavigated(DocumentLoader*);
  90. void setInitialScriptContent(unsigned long identifier, const String& sourceString);
  91. void didReceiveScriptResponse(unsigned long identifier);
  92. void documentThreadableLoaderStartedLoadingForClient(unsigned long identifier, ThreadableLoaderClient*);
  93. void willLoadXHR(ThreadableLoaderClient*, const String& method, const KURL&, bool async, PassRefPtr<FormData> body, const HTTPHeaderMap& headers, bool includeCrendentials);
  94. void didFailXHRLoading(ThreadableLoaderClient*);
  95. void didFinishXHRLoading(ThreadableLoaderClient*, unsigned long identifier, const String& sourceString);
  96. void didReceiveXHRResponse(unsigned long identifier);
  97. void willLoadXHRSynchronously();
  98. void didLoadXHRSynchronously();
  99. void willDestroyCachedResource(CachedResource*);
  100. void applyUserAgentOverride(String* userAgent);
  101. // FIXME: InspectorResourceAgent should now be aware of style recalculation.
  102. void willRecalculateStyle();
  103. void didRecalculateStyle();
  104. void didScheduleStyleRecalculation(Document*);
  105. PassRefPtr<TypeBuilder::Network::Initiator> buildInitiatorObject(Document*);
  106. #if ENABLE(WEB_SOCKETS)
  107. void didCreateWebSocket(unsigned long identifier, const KURL& requestURL);
  108. void willSendWebSocketHandshakeRequest(unsigned long identifier, const ResourceRequest&);
  109. void didReceiveWebSocketHandshakeResponse(unsigned long identifier, const ResourceResponse&);
  110. void didCloseWebSocket(unsigned long identifier);
  111. void didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
  112. void didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame&);
  113. void didReceiveWebSocketFrameError(unsigned long identifier, const String&);
  114. #endif
  115. // called from Internals for layout test purposes.
  116. void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
  117. // Called from frontend
  118. virtual void enable(ErrorString*);
  119. virtual void disable(ErrorString*);
  120. virtual void setUserAgentOverride(ErrorString*, const String& userAgent);
  121. virtual void setExtraHTTPHeaders(ErrorString*, const RefPtr<InspectorObject>&);
  122. virtual void getResponseBody(ErrorString*, const String& requestId, String* content, bool* base64Encoded);
  123. virtual void replayXHR(ErrorString*, const String& requestId);
  124. virtual void canClearBrowserCache(ErrorString*, bool*);
  125. virtual void clearBrowserCache(ErrorString*);
  126. virtual void canClearBrowserCookies(ErrorString*, bool*);
  127. virtual void clearBrowserCookies(ErrorString*);
  128. virtual void setCacheDisabled(ErrorString*, bool cacheDisabled);
  129. private:
  130. InspectorResourceAgent(InstrumentingAgents*, InspectorPageAgent*, InspectorClient*, InspectorCompositeState*);
  131. void enable();
  132. InspectorPageAgent* m_pageAgent;
  133. InspectorClient* m_client;
  134. InspectorFrontend::Network* m_frontend;
  135. String m_userAgentOverride;
  136. OwnPtr<NetworkResourcesData> m_resourcesData;
  137. bool m_loadingXHRSynchronously;
  138. typedef HashMap<ThreadableLoaderClient*, RefPtr<XHRReplayData> > PendingXHRReplayDataMap;
  139. PendingXHRReplayDataMap m_pendingXHRReplayData;
  140. // FIXME: InspectorResourceAgent should now be aware of style recalculation.
  141. RefPtr<TypeBuilder::Network::Initiator> m_styleRecalculationInitiator;
  142. bool m_isRecalculatingStyle;
  143. };
  144. } // namespace WebCore
  145. #endif // ENABLE(INSPECTOR)
  146. #endif // !defined(InspectorResourceAgent_h)