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 31 #ifndef InspectorPageAgent_h 32 #define InspectorPageAgent_h 33 34 35 #include "InspectorFrontend.h" 36 #include "core/inspector/InspectorBaseAgent.h" 37 #include "modules/device_orientation/DeviceOrientationData.h" 38 #include "modules/geolocation/GeolocationPosition.h" 39 #include "wtf/HashMap.h" 40 #include "wtf/text/WTFString.h" 41 42 namespace WebCore { 43 44 class Resource; 45 class DOMWrapperWorld; 46 class Document; 47 class DocumentLoader; 48 class Frame; 49 class GraphicsContext; 50 class InjectedScriptManager; 51 class InspectorClient; 52 class InspectorOverlay; 53 class InstrumentingAgents; 54 class IntSize; 55 class KURL; 56 class LayoutRect; 57 class Page; 58 class RenderObject; 59 class SharedBuffer; 60 61 typedef String ErrorString; 62 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 Font, 71 ScriptResource, 72 XHRResource, 73 WebSocketResource, 74 OtherResource 75 }; 76 77 static PassOwnPtr<InspectorPageAgent> create(InstrumentingAgents*, Page*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 78 79 static bool cachedResourceContent(Resource*, String* result, bool* base64Encoded); 80 static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result); 81 static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded); 82 83 static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName); 84 static Resource* cachedResource(Frame*, const KURL&); 85 static TypeBuilder::Page::ResourceType::Enum resourceTypeJson(ResourceType); 86 static ResourceType cachedResourceType(const Resource&); 87 static TypeBuilder::Page::ResourceType::Enum cachedResourceTypeJson(const Resource&); 88 89 // Page API for InspectorFrontend 90 virtual void enable(ErrorString*); 91 virtual void disable(ErrorString*); 92 virtual void addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* result); 93 virtual void removeScriptToEvaluateOnLoad(ErrorString*, const String& identifier); 94 virtual void reload(ErrorString*, const bool* optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad, const String* optionalScriptPreprocessor); 95 virtual void navigate(ErrorString*, const String& url); 96 virtual void getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies, WTF::String* cookiesString); 97 virtual void deleteCookie(ErrorString*, const String& cookieName, const String& url); 98 virtual void getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page::FrameResourceTree>&); 99 virtual void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded); 100 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> >&); 101 virtual void searchInResources(ErrorString*, const String&, const bool* caseSensitive, const bool* isRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchResult> >&); 102 virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html); 103 virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor, bool fitWindow); 104 virtual void setShowPaintRects(ErrorString*, bool show); 105 virtual void setShowDebugBorders(ErrorString*, bool show); 106 virtual void setShowFPSCounter(ErrorString*, bool show); 107 virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled); 108 virtual void setShowScrollBottleneckRects(ErrorString*, bool show); 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 setDeviceOrientationOverride(ErrorString*, double, double, double); 114 virtual void clearDeviceOrientationOverride(ErrorString*); 115 virtual void setTouchEmulationEnabled(ErrorString*, bool); 116 virtual void setEmulatedMedia(ErrorString*, const String&); 117 virtual void setForceCompositingMode(ErrorString*, bool force); 118 virtual void captureScreenshot(ErrorString*, String* data); 119 virtual void handleJavaScriptDialog(ErrorString*, bool accept, const String* promptText); 120 virtual void setShowViewportSizeOnResize(ErrorString*, bool show, const bool* showGrid); 121 122 // Geolocation override helpers. 123 GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*); 124 125 // DeviceOrientation helper 126 DeviceOrientationData* overrideDeviceOrientation(DeviceOrientationData*); 127 128 // InspectorInstrumentation API 129 void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*); 130 void domContentLoadedEventFired(Frame*); 131 void loadEventFired(Frame*); 132 void childDocumentOpened(Document*); 133 void didCommitLoad(Frame*, DocumentLoader*); 134 void frameDetachedFromParent(Frame*); 135 void loaderDetachedFromFrame(DocumentLoader*); 136 void frameStartedLoading(Frame*); 137 void frameStoppedLoading(Frame*); 138 void frameScheduledNavigation(Frame*, double delay); 139 void frameClearedScheduledNavigation(Frame*); 140 void willRunJavaScriptDialog(const String& message); 141 void didRunJavaScriptDialog(); 142 void applyScreenWidthOverride(long*); 143 bool shouldApplyScreenWidthOverride(); 144 void applyScreenHeightOverride(long*); 145 bool shouldApplyScreenHeightOverride(); 146 void applyEmulatedMedia(String*); 147 void didPaint(RenderObject*, GraphicsContext*, const LayoutRect&); 148 void didLayout(RenderObject*); 149 void didScroll(); 150 void didResizeMainFrame(); 151 void didRecalculateStyle(); 152 void scriptsEnabled(bool isEnabled); 153 154 // Inspector Controller API 155 virtual void setFrontend(InspectorFrontend*); 156 virtual void clearFrontend(); 157 virtual void restore(); 158 159 void webViewResized(const IntSize&); 160 161 // Cross-agents API 162 Page* page() { return m_page; } 163 Frame* mainFrame(); 164 String createIdentifier(); 165 Frame* frameForId(const String& frameId); 166 String frameId(Frame*); 167 bool hasIdForFrame(Frame*) const; 168 String loaderId(DocumentLoader*); 169 Frame* findFrameWithSecurityOrigin(const String& originRawString); 170 Frame* assertFrame(ErrorString*, const String& frameId); 171 String scriptPreprocessor() { return m_scriptPreprocessor; } 172 String resourceSourceMapURL(const String& url); 173 static DocumentLoader* assertDocumentLoader(ErrorString*, Frame*); 174 175 private: 176 InspectorPageAgent(InstrumentingAgents*, Page*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 177 bool deviceMetricsChanged(int width, int height, double fontScaleFactor, bool fitWindow); 178 void updateViewMetrics(int, int, double, bool); 179 void updateTouchEventEmulationInPage(bool); 180 void updateOverridesTopOffset(); 181 182 static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result); 183 184 PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*); 185 PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*); 186 Page* m_page; 187 InjectedScriptManager* m_injectedScriptManager; 188 InspectorClient* m_client; 189 InspectorFrontend::Page* m_frontend; 190 InspectorOverlay* m_overlay; 191 long m_lastScriptIdentifier; 192 String m_pendingScriptToEvaluateOnLoadOnce; 193 String m_scriptToEvaluateOnLoadOnce; 194 String m_pendingScriptPreprocessor; 195 String m_scriptPreprocessor; 196 HashMap<Frame*, String> m_frameToIdentifier; 197 HashMap<String, Frame*> m_identifierToFrame; 198 HashMap<DocumentLoader*, String> m_loaderToIdentifier; 199 bool m_enabled; 200 bool m_isFirstLayoutAfterOnLoad; 201 bool m_geolocationOverridden; 202 bool m_ignoreScriptsEnabledNotification; 203 bool m_didForceCompositingMode; 204 RefPtr<GeolocationPosition> m_geolocationPosition; 205 RefPtr<GeolocationPosition> m_platformGeolocationPosition; 206 RefPtr<DeviceOrientationData> m_deviceOrientation; 207 }; 208 209 210 } // namespace WebCore 211 212 213 #endif // !defined(InspectorPagerAgent_h) 214