Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / inspector / InspectorPageAgent.h
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 "wtf/HashMap.h"
38 #include "wtf/text/WTFString.h"
39
40 namespace WebCore {
41
42 class Resource;
43 class DOMWrapperWorld;
44 class Document;
45 class DocumentLoader;
46 class Frame;
47 class GraphicsContext;
48 class GraphicsLayer;
49 class InjectedScriptManager;
50 class InspectorClient;
51 class InspectorOverlay;
52 class InstrumentingAgents;
53 class IntSize;
54 class KURL;
55 class LayoutRect;
56 class Page;
57 class RenderObject;
58 class SharedBuffer;
59 class StyleResolver;
60
61 typedef String ErrorString;
62
63 class InspectorPageAgent FINAL : 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(Page*, InjectedScriptManager*, InspectorClient*, InspectorOverlay*);
78
79     // Settings overrides.
80     void setTextAutosizingEnabled(bool);
81     void setDeviceScaleAdjustment(float);
82
83     static bool cachedResourceContent(Resource*, String* result, bool* base64Encoded);
84     static bool sharedBufferContent(PassRefPtr<SharedBuffer>, const String& textEncodingName, bool withBase64Encode, String* result);
85
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&);
91
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;
124
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*);
143     void didScroll();
144     void didResizeMainFrame();
145     void didRecalculateStyle();
146     void scriptsEnabled(bool isEnabled);
147
148     // Inspector Controller API
149     virtual void setFrontend(InspectorFrontend*) OVERRIDE;
150     virtual void clearFrontend() OVERRIDE;
151     virtual void restore() OVERRIDE;
152
153     void webViewResized(const IntSize&);
154
155     // Cross-agents API
156     Page* page() { return m_page; }
157     Frame* mainFrame();
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*);
169
170 private:
171     static void resourceContent(ErrorString*, Frame*, const KURL&, String* result, bool* base64Encoded);
172
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*);
178
179     static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result);
180
181     PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*);
182     PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
183     Page* m_page;
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;
196     bool m_enabled;
197     bool m_ignoreScriptsEnabledNotification;
198     bool m_deviceMetricsOverridden;
199     bool m_emulateViewportEnabled;
200     bool m_embedderTextAutosizingEnabled;
201     double m_embedderFontScaleFactor;
202 };
203
204
205 } // namespace WebCore
206
207
208 #endif // !defined(InspectorPagerAgent_h)