2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef InspectorPageAgent_h
32 #define InspectorPageAgent_h
35 #include "InspectorFrontend.h"
36 #include "core/inspector/InspectorBaseAgent.h"
37 #include "wtf/HashMap.h"
38 #include "wtf/text/WTFString.h"
43 class DOMWrapperWorld;
47 class GraphicsContext;
49 class InjectedScriptManager;
50 class InspectorClient;
51 class InspectorOverlay;
52 class InstrumentingAgents;
61 typedef String ErrorString;
63 class InspectorPageAgent FINAL : public InspectorBaseAgent<InspectorPageAgent>, public InspectorBackendDispatcher::PageCommandHandler {
64 WTF_MAKE_NONCOPYABLE(InspectorPageAgent);
77 static PassOwnPtr<InspectorPageAgent> create(Page*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*);
79 // Settings overrides.
80 void setTextAutosizingEnabled(bool);
81 void setDeviceScaleAdjustment(float);
83 static bool cachedResourceContent(Resource*, String* result, bool* base64Encoded);
84 static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result);
86 static PassRefPtr<SharedBuffer> resourceData(Frame*, const KURL&, String* textEncodingName);
87 static Resource* cachedResource(Frame*, const KURL&);
88 static TypeBuilder::Page::ResourceType::Enum resourceTypeJson(ResourceType);
89 static ResourceType cachedResourceType(const Resource&);
90 static TypeBuilder::Page::ResourceType::Enum cachedResourceTypeJson(const Resource&);
92 // Page API for InspectorFrontend
93 virtual void enable(ErrorString*) OVERRIDE;
94 virtual void disable(ErrorString*) OVERRIDE;
95 virtual void addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* result) OVERRIDE;
96 virtual void removeScriptToEvaluateOnLoad(ErrorString*, const String& identifier) OVERRIDE;
97 virtual void reload(ErrorString*, const bool* optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad, const String* optionalScriptPreprocessor) OVERRIDE;
98 virtual void navigate(ErrorString*, const String& url) OVERRIDE;
99 virtual void getNavigationHistory(ErrorString*, int*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::NavigationEntry> >&) OVERRIDE;
100 virtual void navigateToHistoryEntry(ErrorString*, int) OVERRIDE;
101 virtual void getCookies(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::Page::Cookie> >& cookies) OVERRIDE;
102 virtual void deleteCookie(ErrorString*, const String& cookieName, const String& url) OVERRIDE;
103 virtual void getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page::FrameResourceTree>&) OVERRIDE;
104 virtual void getResourceContent(ErrorString*, const String& frameId, const String& url, String* content, bool* base64Encoded) OVERRIDE;
105 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;
106 virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html) OVERRIDE;
107 virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, const bool* optionalTextAutosizing, const double* optionalFontScaleFactor) OVERRIDE;
108 virtual void setShowPaintRects(ErrorString*, bool show) OVERRIDE;
109 virtual void setShowDebugBorders(ErrorString*, bool show) OVERRIDE;
110 virtual void setShowFPSCounter(ErrorString*, bool show) OVERRIDE;
111 virtual void setContinuousPaintingEnabled(ErrorString*, bool enabled) OVERRIDE;
112 virtual void setShowScrollBottleneckRects(ErrorString*, bool show) OVERRIDE;
113 virtual void getScriptExecutionStatus(ErrorString*, PageCommandHandler::Result::Enum*) OVERRIDE;
114 virtual void setScriptExecutionDisabled(ErrorString*, bool) OVERRIDE;
115 virtual void setTouchEmulationEnabled(ErrorString*, bool) OVERRIDE;
116 virtual void setEmulatedMedia(ErrorString*, const String&) OVERRIDE;
117 virtual void captureScreenshot(ErrorString*, const String* format, const int* quality, const int* maxWidth, const int* maxHeight, String* data, RefPtr<TypeBuilder::Page::ScreencastFrameMetadata>& out_metadata) OVERRIDE;
118 virtual void canScreencast(ErrorString*, bool*) OVERRIDE;
119 virtual void startScreencast(ErrorString*, const String* format, const int* quality, const int* maxWidth, const int* maxHeight) OVERRIDE;
120 virtual void stopScreencast(ErrorString*) OVERRIDE;
121 virtual void handleJavaScriptDialog(ErrorString*, bool accept, const String* promptText) OVERRIDE;
122 virtual void queryUsageAndQuota(WebCore::ErrorString*, const WTF::String&, WTF::RefPtr<WebCore::TypeBuilder::Page::Quota>&, WTF::RefPtr<WebCore::TypeBuilder::Page::Usage>&) OVERRIDE;
123 virtual void setShowViewportSizeOnResize(ErrorString*, bool show, const bool* showGrid) OVERRIDE;
125 // InspectorInstrumentation API
126 void didClearWindowObjectInMainWorld(Frame*);
127 void domContentLoadedEventFired(Frame*);
128 void loadEventFired(Frame*);
129 void didCommitLoad(Frame*, DocumentLoader*);
130 void frameAttachedToParent(Frame*);
131 void frameDetachedFromParent(Frame*);
132 void loaderDetachedFromFrame(DocumentLoader*);
133 void frameStartedLoading(Frame*);
134 void frameStoppedLoading(Frame*);
135 void frameScheduledNavigation(Frame*, double delay);
136 void frameClearedScheduledNavigation(Frame*);
137 void willRunJavaScriptDialog(const String& message);
138 void didRunJavaScriptDialog();
139 bool applyViewportStyleOverride(StyleResolver*);
140 void applyEmulatedMedia(String*);
141 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&);
142 void didLayout(RenderObject*);
144 void didResizeMainFrame();
145 void didRecalculateStyle();
146 void scriptsEnabled(bool isEnabled);
148 // Inspector Controller API
149 virtual void setFrontend(InspectorFrontend*) OVERRIDE;
150 virtual void clearFrontend() OVERRIDE;
151 virtual void restore() OVERRIDE;
153 void webViewResized(const IntSize&);
156 Page* page() { return m_page; }
158 String createIdentifier();
159 Frame* frameForId(const String& frameId);
160 String frameId(Frame*);
161 bool hasIdForFrame(Frame*) const;
162 String loaderId(DocumentLoader*);
163 Frame* findFrameWithSecurityOrigin(const String& originRawString);
164 Frame* assertFrame(ErrorString*, const String& frameId);
165 String scriptPreprocessorSource() { return m_scriptPreprocessorSource; }
166 const AtomicString& resourceSourceMapURL(const String& url);
167 bool deviceMetricsOverrideEnabled();
168 static DocumentLoader* assertDocumentLoader(ErrorString*, Frame*);
171 static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded);
173 InspectorPageAgent(Page*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*);
174 bool deviceMetricsChanged(int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, double fontScaleFactor, bool textAutosizing);
175 void updateViewMetrics(int width, int height, double deviceScaleFactor, bool emulateViewport, bool fitWindow, double fontScaleFactor, bool textAutosizingEnabled);
176 void updateTouchEventEmulationInPage(bool);
177 bool forceCompositingMode(ErrorString*);
179 static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result);
181 PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*);
182 PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
184 InjectedScriptManager* m_injectedScriptManager;
185 InspectorClient* m_client;
186 InspectorFrontend::Page* m_frontend;
187 InspectorOverlay* m_overlay;
188 long m_lastScriptIdentifier;
189 String m_pendingScriptToEvaluateOnLoadOnce;
190 String m_scriptToEvaluateOnLoadOnce;
191 String m_pendingScriptPreprocessor;
192 String m_scriptPreprocessorSource;
193 HashMap<Frame*, String> m_frameToIdentifier;
194 HashMap<String, Frame*> m_identifierToFrame;
195 HashMap<DocumentLoader*, String> m_loaderToIdentifier;
197 bool m_ignoreScriptsEnabledNotification;
198 bool m_deviceMetricsOverridden;
199 bool m_emulateViewportEnabled;
200 bool m_embedderTextAutosizingEnabled;
201 double m_embedderFontScaleFactor;
205 } // namespace WebCore
208 #endif // !defined(InspectorPagerAgent_h)