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 "core/InspectorFrontend.h" 36 #include "core/inspector/InspectorBaseAgent.h" 37 #include "core/inspector/InspectorResourceContentLoader.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 LocalFrame; 48 class GraphicsContext; 49 class GraphicsLayer; 50 class InjectedScriptManager; 51 class InspectorClient; 52 class InspectorOverlay; 53 class InspectorResourceContentLoader; 54 class InstrumentingAgents; 55 class IntSize; 56 class KURL; 57 class LayoutRect; 58 class Page; 59 class RenderObject; 60 class SharedBuffer; 61 class StyleResolver; 62 63 typedef String ErrorString; 64 65 class InspectorPageAgent FINAL : public InspectorBaseAgent<InspectorPageAgent>, public InspectorBackendDispatcher::PageCommandHandler { 66 WTF_MAKE_NONCOPYABLE(InspectorPageAgent); 67 public: 68 enum ResourceType { 69 DocumentResource, 70 StylesheetResource, 71 ImageResource, 72 FontResource, 73 MediaResource, 74 ScriptResource, 75 TextTrackResource, 76 XHRResource, 77 WebSocketResource, 78 OtherResource 79 }; 80 81 static PassOwnPtr<InspectorPageAgent> create(Page*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 82 83 // Settings overrides. 84 void setTextAutosizingEnabled(bool); 85 void setDeviceScaleAdjustment(float); 86 87 static Vector<Document*> importsForFrame(LocalFrame*); 88 static bool cachedResourceContent(Resource*, String* result, bool* base64Encoded); 89 static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result); 90 91 static PassRefPtr<SharedBuffer> resourceData(LocalFrame*, const KURL&, String* textEncodingName); 92 static Resource* cachedResource(LocalFrame*, const KURL&); 93 static TypeBuilder::Page::ResourceType::Enum resourceTypeJson(ResourceType); 94 static ResourceType cachedResourceType(const Resource&); 95 static TypeBuilder::Page::ResourceType::Enum cachedResourceTypeJson(const Resource&); 96 97 // Page API for InspectorFrontend 98 virtual void enable(ErrorString*) OVERRIDE; 99 virtual void disable(ErrorString*) OVERRIDE; 100 virtual void addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* result) OVERRIDE; 101 virtual void removeScriptToEvaluateOnLoad(ErrorString*, const String& identifier) OVERRIDE; 102 virtual void reload(ErrorString*, const bool* optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad, const String* optionalScriptPreprocessor) OVERRIDE; 103 virtual void navigate(ErrorString*, const String& url) OVERRIDE; 104 virtual void getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies) OVERRIDE; 105 virtual void deleteCookie(ErrorString*, const String& cookieName, const String& url) OVERRIDE; 106 virtual void getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page::FrameResourceTree>&) OVERRIDE; 107 virtual void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded) OVERRIDE; 108 virtual void hasTouchInputs(ErrorString*, bool* result) OVERRIDE; 109 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> >&) OVERRIDE; 110 virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html) OVERRIDE; 111 virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, const bool* optionalTextAutosizing, const double* optionalFontScaleFactor) OVERRIDE; 112 virtual void clearDeviceMetricsOverride(ErrorString*) OVERRIDE; 113 virtual void setShowPaintRects(ErrorString*, bool show) OVERRIDE; 114 virtual void setShowDebugBorders(ErrorString*, bool show) OVERRIDE; 115 virtual void setShowFPSCounter(ErrorString*, bool show) OVERRIDE; 116 virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled) OVERRIDE; 117 virtual void setShowScrollBottleneckRects(ErrorString*, bool show) OVERRIDE; 118 virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*) OVERRIDE; 119 virtual void setScriptExecutionDisabled(ErrorString*, bool) OVERRIDE; 120 virtual void setTouchEmulationEnabled(ErrorString*, bool) OVERRIDE; 121 virtual void setEmulatedMedia(ErrorString*, const String&) OVERRIDE; 122 virtual void setShowViewportSizeOnResize(ErrorString*, bool show, const bool* showGrid) OVERRIDE; 123 124 // InspectorInstrumentation API 125 void didClearDocumentOfWindowObject(LocalFrame*); 126 void domContentLoadedEventFired(LocalFrame*); 127 void loadEventFired(LocalFrame*); 128 void didCommitLoad(LocalFrame*, DocumentLoader*); 129 void frameAttachedToParent(LocalFrame*); 130 void frameDetachedFromParent(LocalFrame*); 131 void loaderDetachedFromFrame(DocumentLoader*); 132 void frameStartedLoading(LocalFrame*); 133 void frameStoppedLoading(LocalFrame*); 134 void frameScheduledNavigation(LocalFrame*, double delay); 135 void frameClearedScheduledNavigation(LocalFrame*); 136 void willRunJavaScriptDialog(const String& message); 137 void didRunJavaScriptDialog(); 138 bool applyViewportStyleOverride(StyleResolver*); 139 void applyEmulatedMedia(String*); 140 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&); 141 void didLayout(RenderObject*); 142 void didScroll(); 143 void didResizeMainFrame(); 144 void didRecalculateStyle(int); 145 void scriptsEnabled(bool isEnabled); 146 147 // Inspector Controller API 148 virtual void setFrontend(InspectorFrontend*) OVERRIDE; 149 virtual void clearFrontend() OVERRIDE; 150 virtual void restore() OVERRIDE; 151 152 // Cross-agents API page()153 Page* page() { return m_page; } 154 LocalFrame* mainFrame(); 155 String createIdentifier(); 156 LocalFrame* frameForId(const String& frameId); 157 String frameId(LocalFrame*); 158 bool hasIdForFrame(LocalFrame*) const; 159 String loaderId(DocumentLoader*); 160 LocalFrame* findFrameWithSecurityOrigin(const String& originRawString); 161 LocalFrame* assertFrame(ErrorString*, const String& frameId); scriptPreprocessorSource()162 String scriptPreprocessorSource() { return m_scriptPreprocessorSource; } 163 const AtomicString& resourceSourceMapURL(const String& url); 164 bool deviceMetricsOverrideEnabled(); 165 static DocumentLoader* assertDocumentLoader(ErrorString*, LocalFrame*); resourceContentLoader()166 InspectorResourceContentLoader* resourceContentLoader() { return m_inspectorResourceContentLoader.get(); } 167 168 private: 169 static void resourceContent(ErrorString*, LocalFrame*, const KURL&, String* result, bool* base64Encoded); 170 171 InspectorPageAgent(Page*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*); 172 bool deviceMetricsChanged(bool enabled, int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, double fontScaleFactor, bool textAutosizing); 173 void updateViewMetricsFromState(); 174 void updateViewMetrics(bool enabled, int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, double fontScaleFactor, bool textAutosizingEnabled); 175 void updateTouchEventEmulationInPage(bool); 176 bool compositingEnabled(ErrorString*); 177 178 static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result); 179 180 PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(LocalFrame*); 181 PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(LocalFrame*); 182 Page* m_page; 183 InjectedScriptManager* m_injectedScriptManager; 184 InspectorClient* m_client; 185 InspectorFrontend::Page* m_frontend; 186 InspectorOverlay* m_overlay; 187 long m_lastScriptIdentifier; 188 String m_pendingScriptToEvaluateOnLoadOnce; 189 String m_scriptToEvaluateOnLoadOnce; 190 String m_pendingScriptPreprocessor; 191 String m_scriptPreprocessorSource; 192 HashMap<LocalFrame*, String> m_frameToIdentifier; 193 HashMap<String, LocalFrame*> m_identifierToFrame; 194 HashMap<DocumentLoader*, String> m_loaderToIdentifier; 195 bool m_enabled; 196 bool m_ignoreScriptsEnabledNotification; 197 bool m_deviceMetricsOverridden; 198 bool m_emulateViewportEnabled; 199 200 bool m_touchEmulationEnabled; 201 bool m_originalTouchEnabled; 202 bool m_originalDeviceSupportsMouse; 203 bool m_originalDeviceSupportsTouch; 204 205 bool m_embedderTextAutosizingEnabled; 206 double m_embedderFontScaleFactor; 207 208 OwnPtr<InspectorResourceContentLoader> m_inspectorResourceContentLoader; 209 }; 210 211 212 } // namespace WebCore 213 214 215 #endif // !defined(InspectorPagerAgent_h) 216