InspectorPageAgent.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (C) 2011 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 InspectorPageAgent_h
  31. #define InspectorPageAgent_h
  32. #if ENABLE(INSPECTOR)
  33. #include "DeviceOrientationData.h"
  34. #include "Frame.h"
  35. #include "GeolocationPosition.h"
  36. #include "InspectorBaseAgent.h"
  37. #include "InspectorFrontend.h"
  38. #include <wtf/HashMap.h>
  39. #include <wtf/RefCounted.h>
  40. #include <wtf/Vector.h>
  41. #include <wtf/text/WTFString.h>
  42. namespace WebCore {
  43. class CachedResource;
  44. class DOMWrapperWorld;
  45. class DocumentLoader;
  46. class Frame;
  47. class Frontend;
  48. class GraphicsContext;
  49. class InjectedScriptManager;
  50. class InspectorAgent;
  51. class InspectorArray;
  52. class InspectorClient;
  53. class InspectorObject;
  54. class InspectorOverlay;
  55. class InspectorState;
  56. class InstrumentingAgents;
  57. class KURL;
  58. class Page;
  59. class RegularExpression;
  60. class SharedBuffer;
  61. class TextResourceDecoder;
  62. typedef String ErrorString;
  63. class InspectorPageAgent : public InspectorBaseAgent<InspectorPageAgent>, public InspectorBackendDispatcher::PageCommandHandler {
  64. WTF_MAKE_NONCOPYABLE(InspectorPageAgent);
  65. public:
  66. enum ResourceType {
  67. DocumentResource,
  68. StylesheetResource,
  69. ImageResource,
  70. FontResource,
  71. ScriptResource,
  72. XHRResource,
  73. WebSocketResource,
  74. OtherResource
  75. };
  76. static PassOwnPtr<InspectorPageAgent> create(InstrumentingAgents*, Page*, InspectorAgent*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*);
  77. static bool cachedResourceContent(CachedResource*, String* result, bool* base64Encoded);
  78. static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result);
  79. static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded);
  80. static String sourceMapURLForResource(CachedResource*);
  81. static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName);
  82. static CachedResource* cachedResource(Frame*, const KURL&);
  83. static TypeBuilder::Page::ResourceType::Enum resourceTypeJson(ResourceType);
  84. static ResourceType cachedResourceType(const CachedResource&);
  85. static TypeBuilder::Page::ResourceType::Enum cachedResourceTypeJson(const CachedResource&);
  86. // Page API for InspectorFrontend
  87. virtual void enable(ErrorString*);
  88. virtual void disable(ErrorString*);
  89. virtual void addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* result);
  90. virtual void removeScriptToEvaluateOnLoad(ErrorString*, const String& identifier);
  91. virtual void reload(ErrorString*, const bool* optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad, const String* optionalScriptPreprocessor);
  92. virtual void navigate(ErrorString*, const String& url);
  93. virtual void getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies, WTF::String* cookiesString);
  94. virtual void deleteCookie(ErrorString*, const String& cookieName, const String& url);
  95. virtual void getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page::FrameResourceTree>&);
  96. virtual void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded);
  97. virtual void searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> >&);
  98. virtual void searchInResources(ErrorString*, const String&, const bool* caseSensitive, const bool* isRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchResult> >&);
  99. virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html);
  100. virtual void canOverrideDeviceMetrics(ErrorString*, bool*);
  101. virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor, bool fitWindow);
  102. virtual void setShowPaintRects(ErrorString*, bool show);
  103. virtual void canShowDebugBorders(ErrorString*, bool*);
  104. virtual void setShowDebugBorders(ErrorString*, bool show);
  105. virtual void canShowFPSCounter(ErrorString*, bool*);
  106. virtual void setShowFPSCounter(ErrorString*, bool show);
  107. virtual void canContinuouslyPaint(ErrorString*, bool*);
  108. virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled);
  109. virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*);
  110. virtual void setScriptExecutionDisabled(ErrorString*, bool);
  111. virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*);
  112. virtual void clearGeolocationOverride(ErrorString*);
  113. virtual void canOverrideGeolocation(ErrorString*, bool* out_param);
  114. virtual void setDeviceOrientationOverride(ErrorString*, double, double, double);
  115. virtual void clearDeviceOrientationOverride(ErrorString*);
  116. virtual void canOverrideDeviceOrientation(ErrorString*, bool*);
  117. virtual void setTouchEmulationEnabled(ErrorString*, bool);
  118. virtual void setEmulatedMedia(ErrorString*, const String&);
  119. virtual void getCompositingBordersVisible(ErrorString*, bool* out_param);
  120. virtual void setCompositingBordersVisible(ErrorString*, bool);
  121. virtual void captureScreenshot(ErrorString*, String* data);
  122. virtual void handleJavaScriptDialog(ErrorString*, bool accept, const String* promptText);
  123. // Geolocation override helpers.
  124. GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*);
  125. // DeviceOrientation helper
  126. DeviceOrientationData* overrideDeviceOrientation(DeviceOrientationData*);
  127. // InspectorInstrumentation API
  128. void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);
  129. void domContentEventFired();
  130. void loadEventFired();
  131. void frameNavigated(DocumentLoader*);
  132. void frameDetached(Frame*);
  133. void loaderDetachedFromFrame(DocumentLoader*);
  134. void frameStartedLoading(Frame*);
  135. void frameStoppedLoading(Frame*);
  136. void frameScheduledNavigation(Frame*, double delay);
  137. void frameClearedScheduledNavigation(Frame*);
  138. void willRunJavaScriptDialog(const String& message);
  139. void didRunJavaScriptDialog();
  140. void applyScreenWidthOverride(long*);
  141. void applyScreenHeightOverride(long*);
  142. void applyEmulatedMedia(String*);
  143. void didPaint(GraphicsContext*, const LayoutRect&);
  144. void didLayout();
  145. void didScroll();
  146. void didRecalculateStyle();
  147. void scriptsEnabled(bool isEnabled);
  148. // Inspector Controller API
  149. virtual void setFrontend(InspectorFrontend*);
  150. virtual void clearFrontend();
  151. virtual void restore();
  152. void webViewResized(const IntSize&);
  153. // Cross-agents API
  154. Page* page() { return m_page; }
  155. Frame* mainFrame();
  156. String createIdentifier();
  157. Frame* frameForId(const String& frameId);
  158. String frameId(Frame*);
  159. bool hasIdForFrame(Frame*) const;
  160. String loaderId(DocumentLoader*);
  161. Frame* findFrameWithSecurityOrigin(const String& originRawString);
  162. Frame* assertFrame(ErrorString*, const String& frameId);
  163. String scriptPreprocessor() { return m_scriptPreprocessor; }
  164. static DocumentLoader* assertDocumentLoader(ErrorString*, Frame*);
  165. private:
  166. InspectorPageAgent(InstrumentingAgents*, Page*, InspectorAgent*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*);
  167. bool deviceMetricsChanged(int width, int height, double fontScaleFactor, bool fitWindow);
  168. void updateViewMetrics(int, int, double, bool);
  169. #if ENABLE(TOUCH_EVENTS)
  170. void updateTouchEventEmulationInPage(bool);
  171. #endif
  172. static bool mainResourceContent(Frame*, bool withBase64Encode, String* result);
  173. static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result);
  174. PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*);
  175. PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
  176. Page* m_page;
  177. InspectorAgent* m_inspectorAgent;
  178. InjectedScriptManager* m_injectedScriptManager;
  179. InspectorClient* m_client;
  180. InspectorFrontend::Page* m_frontend;
  181. InspectorOverlay* m_overlay;
  182. long m_lastScriptIdentifier;
  183. String m_pendingScriptToEvaluateOnLoadOnce;
  184. String m_scriptToEvaluateOnLoadOnce;
  185. String m_pendingScriptPreprocessor;
  186. String m_scriptPreprocessor;
  187. HashMap<Frame*, String> m_frameToIdentifier;
  188. HashMap<String, Frame*> m_identifierToFrame;
  189. HashMap<DocumentLoader*, String> m_loaderToIdentifier;
  190. bool m_enabled;
  191. bool m_isFirstLayoutAfterOnLoad;
  192. bool m_originalScriptExecutionDisabled;
  193. bool m_geolocationOverridden;
  194. bool m_ignoreScriptsEnabledNotification;
  195. RefPtr<GeolocationPosition> m_geolocationPosition;
  196. RefPtr<GeolocationPosition> m_platformGeolocationPosition;
  197. RefPtr<DeviceOrientationData> m_deviceOrientation;
  198. };
  199. } // namespace WebCore
  200. #endif // ENABLE(INSPECTOR)
  201. #endif // !defined(InspectorPagerAgent_h)