blob: 76f8358e42a6b140ebf3a291bdd78bd1855bc4c1 [file] [log] [blame]
loislo@chromium.org0857b042011-03-29 18:01:10 +00001/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
bburg@apple.com84eff9e2015-09-05 16:06:23 +00003 * Copyright (C) 2015 Apple Inc. All rights reserved.
loislo@chromium.org0857b042011-03-29 18:01:10 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef InspectorPageAgent_h
33#define InspectorPageAgent_h
34
joepeck@webkit.orga3198442013-12-11 22:40:23 +000035#include "InspectorWebAgentBase.h"
akling@apple.com4d3b9892013-09-06 22:08:14 +000036#include "IntSize.h"
37#include "LayoutRect.h"
joepeck@webkit.orgdd1777c2014-10-20 17:59:24 +000038#include <inspector/InspectorBackendDispatchers.h>
39#include <inspector/InspectorFrontendDispatchers.h>
caseq@chromium.orgafd52dc2011-06-15 15:44:00 +000040#include <wtf/HashMap.h>
weinig@apple.com3f5ab022012-09-06 17:36:48 +000041#include <wtf/text/WTFString.h>
loislo@chromium.org0857b042011-03-29 18:01:10 +000042
joepeck@webkit.orga3198442013-12-11 22:40:23 +000043namespace Inspector {
44class InspectorArray;
45class InspectorObject;
46}
47
loislo@chromium.org0857b042011-03-29 18:01:10 +000048namespace WebCore {
49
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000050class CachedResource;
loislo@chromium.org0857b042011-03-29 18:01:10 +000051class DOMWrapperWorld;
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000052class DocumentLoader;
loislo@chromium.org0857b042011-03-29 18:01:10 +000053class Frame;
54class Frontend;
pfeldman@chromium.org0dd290a2012-02-21 11:28:47 +000055class InspectorClient;
caseq@chromium.org2361a762012-07-18 14:04:58 +000056class InspectorOverlay;
bburg@apple.comd81c28d2015-09-05 18:52:16 +000057class MainFrame;
darin@apple.com5ffbb5c2013-09-27 16:39:41 +000058class URL;
loislo@chromium.org0857b042011-03-29 18:01:10 +000059class Page;
simon.fraser@apple.com159ad602014-08-22 19:07:17 +000060class RenderObject;
commit-queue@webkit.org8a96dd52011-06-17 20:00:33 +000061class SharedBuffer;
vsevik@chromium.org920c4052012-02-22 15:07:58 +000062class TextResourceDecoder;
loislo@chromium.org0857b042011-03-29 18:01:10 +000063
64typedef String ErrorString;
65
burg@cs.washington.edu91ba8732015-02-14 23:25:53 +000066class InspectorPageAgent final : public InspectorAgentBase, public Inspector::PageBackendDispatcherHandler {
loislo@chromium.org0857b042011-03-29 18:01:10 +000067 WTF_MAKE_NONCOPYABLE(InspectorPageAgent);
akling@apple.com36ae30d2014-04-25 18:15:48 +000068 WTF_MAKE_FAST_ALLOCATED;
loislo@chromium.org0857b042011-03-29 18:01:10 +000069public:
bburg@apple.comd81c28d2015-09-05 18:52:16 +000070 InspectorPageAgent(PageAgentContext&, InspectorClient*, InspectorOverlay*);
andersca@apple.com7313f582014-01-12 00:54:27 +000071
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000072 enum ResourceType {
73 DocumentResource,
74 StylesheetResource,
75 ImageResource,
76 FontResource,
77 ScriptResource,
78 XHRResource,
79 WebSocketResource,
80 OtherResource
81 };
82
commit-queue@webkit.org82c8f672011-06-22 17:51:59 +000083 static bool cachedResourceContent(CachedResource*, String* result, bool* base64Encoded);
gyuyoung.kim@webkit.org36a26f72015-09-17 05:40:02 +000084 static bool sharedBufferContent(RefPtr<SharedBuffer>&&, const String& textEncodingName, bool withBase64Encode, String* result);
burg@cs.washington.edu809db5f82014-10-01 04:34:19 +000085 static void resourceContent(ErrorString&, Frame*, const URL&, String* result, bool* base64Encoded);
joepeck@webkit.org1a56ea52013-04-19 21:06:03 +000086 static String sourceMapURLForResource(CachedResource*);
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000087
darin@apple.com5ffbb5c2013-09-27 16:39:41 +000088 static PassRefPtr<SharedBuffer> resourceData(Frame*, const URL&, String* textEncodingName);
89 static CachedResource* cachedResource(Frame*, const URL&);
burg@cs.washington.edu100f3c82014-08-25 18:39:25 +000090 static Inspector::Protocol::Page::ResourceType resourceTypeJson(ResourceType);
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000091 static ResourceType cachedResourceType(const CachedResource&);
burg@cs.washington.edu100f3c82014-08-25 18:39:25 +000092 static Inspector::Protocol::Page::ResourceType cachedResourceTypeJson(const CachedResource&);
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +000093
loislo@chromium.org0857b042011-03-29 18:01:10 +000094 // Page API for InspectorFrontend
darin@apple.com11ff47c2016-03-04 16:47:55 +000095 void enable(ErrorString&) override;
96 void disable(ErrorString&) override;
97 void addScriptToEvaluateOnLoad(ErrorString&, const String& source, String* result) override;
98 void removeScriptToEvaluateOnLoad(ErrorString&, const String& identifier) override;
99 void reload(ErrorString&, const bool* optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad) override;
100 void navigate(ErrorString&, const String& url) override;
101 void getCookies(ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Page::Cookie>>& cookies) override;
102 void deleteCookie(ErrorString&, const String& cookieName, const String& url) override;
103 void getResourceTree(ErrorString&, RefPtr<Inspector::Protocol::Page::FrameResourceTree>&) override;
104 void getResourceContent(ErrorString&, const String& frameId, const String& url, String* content, bool* base64Encoded) override;
105 void searchInResource(ErrorString&, const String& frameId, const String& url, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::GenericTypes::SearchMatch>>&) override;
106 void searchInResources(ErrorString&, const String&, const bool* caseSensitive, const bool* isRegex, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Page::SearchResult>>&) override;
107 void setDocumentContent(ErrorString&, const String& frameId, const String& html) override;
108 void setShowPaintRects(ErrorString&, bool show) override;
109 void getScriptExecutionStatus(ErrorString&, Inspector::PageBackendDispatcherHandler::Result*) override;
110 void setScriptExecutionDisabled(ErrorString&, bool) override;
111 void setTouchEmulationEnabled(ErrorString&, bool) override;
112 void setEmulatedMedia(ErrorString&, const String&) override;
113 void getCompositingBordersVisible(ErrorString&, bool* out_param) override;
114 void setCompositingBordersVisible(ErrorString&, bool) override;
115 void snapshotNode(ErrorString&, int nodeId, String* outDataURL) override;
116 void snapshotRect(ErrorString&, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL) override;
117 void handleJavaScriptDialog(ErrorString&, bool accept, const String* promptText) override;
118 void archive(ErrorString&, String* data) override;
kpiascik@rim.come716a492012-07-25 17:50:44 +0000119
burg@cs.washington.edub49c2972015-01-06 21:45:08 +0000120 // InspectorInstrumentation callbacks.
weinig@apple.com8f716032013-10-02 17:03:09 +0000121 void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld&);
loislo@chromium.org0857b042011-03-29 18:01:10 +0000122 void domContentEventFired();
123 void loadEventFired();
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +0000124 void frameNavigated(DocumentLoader*);
burg@cs.washington.edub49c2972015-01-06 21:45:08 +0000125 void frameDetached(Frame&);
126 void loaderDetachedFromFrame(DocumentLoader&);
andersca@apple.coma69100b2014-01-10 15:40:52 +0000127 void frameStartedLoading(Frame&);
128 void frameStoppedLoading(Frame&);
andersca@apple.com8a458862014-01-11 00:38:16 +0000129 void frameScheduledNavigation(Frame&, double delay);
130 void frameClearedScheduledNavigation(Frame&);
commit-queue@webkit.org417bc8f2013-02-01 08:50:19 +0000131 void willRunJavaScriptDialog(const String& message);
132 void didRunJavaScriptDialog();
burg@cs.washington.edub49c2972015-01-06 21:45:08 +0000133 void applyEmulatedMedia(String&);
simon.fraser@apple.com159ad602014-08-22 19:07:17 +0000134 void didPaint(RenderObject*, const LayoutRect&);
apavlov@chromium.org1c55c7c2012-04-02 12:20:44 +0000135 void didLayout();
pfeldman@chromium.orgb9ada392012-08-31 09:35:57 +0000136 void didScroll();
pfeldman@chromium.org6de498c2012-11-14 09:57:24 +0000137 void didRecalculateStyle();
vivek.vg@samsung.comcc349f12013-02-12 20:45:44 +0000138 void scriptsEnabled(bool isEnabled);
loislo@chromium.org0857b042011-03-29 18:01:10 +0000139
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +0000140 // Inspector Controller API
darin@apple.com11ff47c2016-03-04 16:47:55 +0000141 void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override;
142 void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override;
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +0000143
144 // Cross-agents API
bburg@apple.comd81c28d2015-09-05 18:52:16 +0000145 Page& page() { return m_page; }
146 MainFrame& mainFrame();
vsevik@chromium.org7eda8252011-07-19 16:38:33 +0000147 String createIdentifier();
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +0000148 Frame* frameForId(const String& frameId);
timothy@apple.com6e81b9e2014-09-24 19:58:08 +0000149 WEBCORE_EXPORT String frameId(Frame*);
aandrey@chromium.orgbe1c75e2013-01-31 12:45:12 +0000150 bool hasIdForFrame(Frame*) const;
pfeldman@chromium.orged8eab02011-04-25 14:12:28 +0000151 String loaderId(DocumentLoader*);
apavlov@chromium.org7c79f6f2013-02-21 14:08:29 +0000152 Frame* findFrameWithSecurityOrigin(const String& originRawString);
burg@cs.washington.edu809db5f82014-10-01 04:34:19 +0000153 Frame* assertFrame(ErrorString&, const String& frameId);
154 static DocumentLoader* assertDocumentLoader(ErrorString&, Frame*);
loislo@chromium.org0857b042011-03-29 18:01:10 +0000155
156private:
apavlov@chromium.org81b64ef2012-08-08 13:11:54 +0000157#if ENABLE(TOUCH_EVENTS)
158 void updateTouchEventEmulationInPage(bool);
159#endif
loislo@chromium.org0857b042011-03-29 18:01:10 +0000160
burg@cs.washington.eduad7d0832014-10-25 22:05:57 +0000161 double timestamp();
162
beidson@apple.com1b1b9402012-10-11 18:29:32 +0000163 static bool mainResourceContent(Frame*, bool withBase64Encode, String* result);
164 static bool dataContent(const char* data, unsigned size, const String& textEncodingName, bool withBase64Encode, String* result);
165
joepeck@webkit.org9f378ef2015-01-07 23:29:03 +0000166 Ref<Inspector::Protocol::Page::Frame> buildObjectForFrame(Frame*);
167 Ref<Inspector::Protocol::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
bburg@apple.com8c7a4542015-09-01 17:52:15 +0000168
burg@cs.washington.edu91ba8732015-02-14 23:25:53 +0000169 std::unique_ptr<Inspector::PageFrontendDispatcher> m_frontendDispatcher;
170 RefPtr<Inspector::PageBackendDispatcher> m_backendDispatcher;
bburg@apple.com8c7a4542015-09-01 17:52:15 +0000171
bburg@apple.comd81c28d2015-09-05 18:52:16 +0000172 Page& m_page;
bburg@apple.com8c7a4542015-09-01 17:52:15 +0000173 InspectorClient* m_client { nullptr };
174 InspectorOverlay* m_overlay { nullptr };
175
176 long m_lastScriptIdentifier { 0 };
caseq@chromium.orgeba6a872011-10-25 09:25:37 +0000177 String m_pendingScriptToEvaluateOnLoadOnce;
178 String m_scriptToEvaluateOnLoadOnce;
caseq@chromium.orgace96f32011-06-29 14:38:06 +0000179 HashMap<Frame*, String> m_frameToIdentifier;
180 HashMap<String, Frame*> m_identifierToFrame;
vsevik@chromium.orgb03da0a2011-07-18 14:04:28 +0000181 HashMap<DocumentLoader*, String> m_loaderToIdentifier;
bburg@apple.com8c7a4542015-09-01 17:52:15 +0000182 bool m_enabled { false };
183 bool m_isFirstLayoutAfterOnLoad { false };
184 bool m_originalScriptExecutionDisabled { false };
185 bool m_ignoreScriptsEnabledNotification { false };
186 bool m_showPaintRects { false };
commit-queue@webkit.orgd9bc7db2013-10-31 00:26:12 +0000187 String m_emulatedMedia;
joepeck@webkit.orga3198442013-12-11 22:40:23 +0000188 RefPtr<Inspector::InspectorObject> m_scriptsToEvaluateOnLoad;
loislo@chromium.org0857b042011-03-29 18:01:10 +0000189};
190
191
192} // namespace WebCore
193
loislo@chromium.org3639d622011-04-04 08:33:47 +0000194#endif // !defined(InspectorPagerAgent_h)