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/geolocation/GeolocationPosition.h" 38 #include "wtf/HashMap.h" 39 #include "wtf/text/WTFString.h" 40 41 namespace WebCore { 42 43 class Resource; 44 class DOMWrapperWorld; 45 class Document; 46 class DocumentLoader; 47 class Frame; 48 class GraphicsContext; 49 class GraphicsLayer; 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 class StyleResolver; 61 62 typedef String ErrorString; 63 64 class InspectorPageAgent : public InspectorBaseAgent<InspectorPageAgent>, public InspectorBackendDispatcher::PageCommandHandler { 65 WTF_MAKE_NONCOPYABLE(InspectorPageAgent); 66 public: 67 enum ResourceType { 68 DocumentResource, 69 StylesheetResource, 70 ImageResource, 71 Font, 72 ScriptResource, 73 XHRResource, 74 WebSocketResource, 75 OtherResource 76 }; 77 78 static PassOwnPtr<InspectorPageAgent> create(InstrumentingAgents*, Page*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 79 80 static bool cachedResourceContent(Resource*, String* result, bool* base64Encoded); 81 static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result); 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 getNavigationHistory(ErrorString*, int*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::NavigationEntry> >&); 97 virtual void navigateToHistoryEntry(ErrorString*, int); 98 virtual void getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies); 99 virtual void deleteCookie(ErrorString*, const String& cookieName, const String& url); 100 virtual void getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page::FrameResourceTree>&); 101 virtual void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded); 102 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> >&); 103 virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html); 104 virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, const bool* optionalTextAutosizing, const double* optionalFontScaleFactor); 105 virtual void setShowPaintRects(ErrorString*, bool show); 106 virtual void setShowDebugBorders(ErrorString*, bool show); 107 virtual void setShowFPSCounter(ErrorString*, bool show); 108 virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled); 109 virtual void setShowScrollBottleneckRects(ErrorString*, bool show); 110 virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*); 111 virtual void setScriptExecutionDisabled(ErrorString*, bool); 112 virtual void setGeolocationOverride(ErrorString*, const double*, const double*, const double*); 113 virtual void clearGeolocationOverride(ErrorString*); 114 virtual void setDeviceOrientationOverride(ErrorString*, double, double, double); 115 virtual void clearDeviceOrientationOverride(ErrorString*); 116 virtual void setTouchEmulationEnabled(ErrorString*, bool); 117 virtual void setEmulatedMedia(ErrorString*, const String&); 118 virtual void captureScreenshot(ErrorString*, const String* format, const int* quality, const int* maxWidth, const int* maxHeight, String* data, RefPtr<TypeBuilder::Page::ScreencastFrameMetadata>& out_metadata); 119 virtual void canScreencast(ErrorString*, bool*); 120 virtual void startScreencast(ErrorString*, const String* format, const int* quality, const int* maxWidth, const int* maxHeight); 121 virtual void stopScreencast(ErrorString*); 122 virtual void handleJavaScriptDialog(ErrorString*, bool accept, const String* promptText); 123 virtual void queryUsageAndQuota(WebCore::ErrorString*, const WTF::String&, WTF::RefPtr<WebCore::TypeBuilder::Page::Quota>&, WTF::RefPtr<WebCore::TypeBuilder::Page::Usage>&); 124 virtual void setShowViewportSizeOnResize(ErrorString*, bool show, const bool* showGrid); 125 126 // Geolocation override helper. 127 GeolocationPosition* overrideGeolocationPosition(GeolocationPosition*); 128 129 // Text autosizing override helpers. 130 bool overrideTextAutosizing(bool); 131 // Note: This is used by Settings::deviceScaleAdjustment to calculate the overridden device scale adjustment. 132 float overrideFontScaleFactor(float); 133 134 // InspectorInstrumentation API 135 void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*); 136 void domContentLoadedEventFired(Frame*); 137 void loadEventFired(Frame*); 138 void didCommitLoad(Frame*, DocumentLoader*); 139 void frameAttachedToParent(Frame*); 140 void frameDetachedFromParent(Frame*); 141 void loaderDetachedFromFrame(DocumentLoader*); 142 void frameStartedLoading(Frame*); 143 void frameStoppedLoading(Frame*); 144 void frameScheduledNavigation(Frame*, double delay); 145 void frameClearedScheduledNavigation(Frame*); 146 void willRunJavaScriptDialog(const String& message); 147 void didRunJavaScriptDialog(); 148 bool applyViewportStyleOverride(StyleResolver*); 149 void applyEmulatedMedia(String*); 150 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&); 151 void didLayout(RenderObject*); 152 void didScroll(); 153 void didResizeMainFrame(); 154 void didRecalculateStyle(); 155 void scriptsEnabled(bool isEnabled); 156 157 // Inspector Controller API 158 virtual void setFrontend(InspectorFrontend*); 159 virtual void clearFrontend(); 160 virtual void restore(); 161 162 void webViewResized(const IntSize&); 163 164 // Cross-agents API 165 Page* page() { return m_page; } 166 Frame* mainFrame(); 167 String createIdentifier(); 168 Frame* frameForId(const String& frameId); 169 String frameId(Frame*); 170 bool hasIdForFrame(Frame*) const; 171 String loaderId(DocumentLoader*); 172 Frame* findFrameWithSecurityOrigin(const String& originRawString); 173 Frame* assertFrame(ErrorString*, const String& frameId); 174 String scriptPreprocessorSource() { return m_scriptPreprocessorSource; } 175 const AtomicString& resourceSourceMapURL(const String& url); 176 bool deviceMetricsOverrideEnabled(); 177 static DocumentLoader* assertDocumentLoader(ErrorString*, Frame*); 178 179 private: 180 static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded); 181 182 InspectorPageAgent(InstrumentingAgents*, Page*, InspectorCompositeState*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 183 bool deviceMetricsChanged(int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, double fontScaleFactor, bool textAutosizing); 184 void updateViewMetrics(int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow); 185 void updateTouchEventEmulationInPage(bool); 186 bool forceCompositingMode(ErrorString*); 187 188 static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result); 189 190 PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*); 191 PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*); 192 Page* m_page; 193 InjectedScriptManager* m_injectedScriptManager; 194 InspectorClient* m_client; 195 InspectorFrontend::Page* m_frontend; 196 InspectorOverlay* m_overlay; 197 long m_lastScriptIdentifier; 198 String m_pendingScriptToEvaluateOnLoadOnce; 199 String m_scriptToEvaluateOnLoadOnce; 200 String m_pendingScriptPreprocessor; 201 String m_scriptPreprocessorSource; 202 HashMap<Frame*, String> m_frameToIdentifier; 203 HashMap<String, Frame*> m_identifierToFrame; 204 HashMap<DocumentLoader*, String> m_loaderToIdentifier; 205 bool m_enabled; 206 bool m_geolocationOverridden; 207 bool m_ignoreScriptsEnabledNotification; 208 bool m_deviceMetricsOverridden; 209 bool m_emulateViewportEnabled; 210 RefPtr<GeolocationPosition> m_geolocationPosition; 211 RefPtr<GeolocationPosition> m_platformGeolocationPosition; 212 }; 213 214 215 } // namespace WebCore 216 217 218 #endif // !defined(InspectorPagerAgent_h) 219