loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
bburg@apple.com | 84eff9e | 2015-09-05 16:06:23 +0000 | [diff] [blame] | 3 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 4 | * |
| 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.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 35 | #include "InspectorWebAgentBase.h" |
akling@apple.com | 4d3b989 | 2013-09-06 22:08:14 +0000 | [diff] [blame] | 36 | #include "IntSize.h" |
| 37 | #include "LayoutRect.h" |
joepeck@webkit.org | dd1777c | 2014-10-20 17:59:24 +0000 | [diff] [blame] | 38 | #include <inspector/InspectorBackendDispatchers.h> |
| 39 | #include <inspector/InspectorFrontendDispatchers.h> |
caseq@chromium.org | afd52dc | 2011-06-15 15:44:00 +0000 | [diff] [blame] | 40 | #include <wtf/HashMap.h> |
weinig@apple.com | 3f5ab02 | 2012-09-06 17:36:48 +0000 | [diff] [blame] | 41 | #include <wtf/text/WTFString.h> |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 42 | |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 43 | namespace Inspector { |
| 44 | class InspectorArray; |
| 45 | class InspectorObject; |
| 46 | } |
| 47 | |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 48 | namespace WebCore { |
| 49 | |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 50 | class CachedResource; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 51 | class DOMWrapperWorld; |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 52 | class DocumentLoader; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 53 | class Frame; |
| 54 | class Frontend; |
pfeldman@chromium.org | 0dd290a | 2012-02-21 11:28:47 +0000 | [diff] [blame] | 55 | class InspectorClient; |
caseq@chromium.org | 2361a76 | 2012-07-18 14:04:58 +0000 | [diff] [blame] | 56 | class InspectorOverlay; |
bburg@apple.com | d81c28d | 2015-09-05 18:52:16 +0000 | [diff] [blame] | 57 | class MainFrame; |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 58 | class URL; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 59 | class Page; |
simon.fraser@apple.com | 159ad60 | 2014-08-22 19:07:17 +0000 | [diff] [blame] | 60 | class RenderObject; |
commit-queue@webkit.org | 8a96dd5 | 2011-06-17 20:00:33 +0000 | [diff] [blame] | 61 | class SharedBuffer; |
vsevik@chromium.org | 920c405 | 2012-02-22 15:07:58 +0000 | [diff] [blame] | 62 | class TextResourceDecoder; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 63 | |
| 64 | typedef String ErrorString; |
| 65 | |
burg@cs.washington.edu | 91ba873 | 2015-02-14 23:25:53 +0000 | [diff] [blame] | 66 | class InspectorPageAgent final : public InspectorAgentBase, public Inspector::PageBackendDispatcherHandler { |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 67 | WTF_MAKE_NONCOPYABLE(InspectorPageAgent); |
akling@apple.com | 36ae30d | 2014-04-25 18:15:48 +0000 | [diff] [blame] | 68 | WTF_MAKE_FAST_ALLOCATED; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 69 | public: |
bburg@apple.com | d81c28d | 2015-09-05 18:52:16 +0000 | [diff] [blame] | 70 | InspectorPageAgent(PageAgentContext&, InspectorClient*, InspectorOverlay*); |
andersca@apple.com | 7313f58 | 2014-01-12 00:54:27 +0000 | [diff] [blame] | 71 | |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 72 | enum ResourceType { |
| 73 | DocumentResource, |
| 74 | StylesheetResource, |
| 75 | ImageResource, |
| 76 | FontResource, |
| 77 | ScriptResource, |
| 78 | XHRResource, |
| 79 | WebSocketResource, |
| 80 | OtherResource |
| 81 | }; |
| 82 | |
commit-queue@webkit.org | 82c8f67 | 2011-06-22 17:51:59 +0000 | [diff] [blame] | 83 | static bool cachedResourceContent(CachedResource*, String* result, bool* base64Encoded); |
gyuyoung.kim@webkit.org | 36a26f7 | 2015-09-17 05:40:02 +0000 | [diff] [blame] | 84 | static bool sharedBufferContent(RefPtr<SharedBuffer>&&, const String& textEncodingName, bool withBase64Encode, String* result); |
burg@cs.washington.edu | 809db5f8 | 2014-10-01 04:34:19 +0000 | [diff] [blame] | 85 | static void resourceContent(ErrorString&, Frame*, const URL&, String* result, bool* base64Encoded); |
joepeck@webkit.org | 1a56ea5 | 2013-04-19 21:06:03 +0000 | [diff] [blame] | 86 | static String sourceMapURLForResource(CachedResource*); |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 87 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 88 | static PassRefPtr<SharedBuffer> resourceData(Frame*, const URL&, String* textEncodingName); |
| 89 | static CachedResource* cachedResource(Frame*, const URL&); |
burg@cs.washington.edu | 100f3c8 | 2014-08-25 18:39:25 +0000 | [diff] [blame] | 90 | static Inspector::Protocol::Page::ResourceType resourceTypeJson(ResourceType); |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 91 | static ResourceType cachedResourceType(const CachedResource&); |
burg@cs.washington.edu | 100f3c8 | 2014-08-25 18:39:25 +0000 | [diff] [blame] | 92 | static Inspector::Protocol::Page::ResourceType cachedResourceTypeJson(const CachedResource&); |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 93 | |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 94 | // Page API for InspectorFrontend |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame^] | 95 | 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.com | e716a49 | 2012-07-25 17:50:44 +0000 | [diff] [blame] | 119 | |
burg@cs.washington.edu | b49c297 | 2015-01-06 21:45:08 +0000 | [diff] [blame] | 120 | // InspectorInstrumentation callbacks. |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 121 | void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld&); |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 122 | void domContentEventFired(); |
| 123 | void loadEventFired(); |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 124 | void frameNavigated(DocumentLoader*); |
burg@cs.washington.edu | b49c297 | 2015-01-06 21:45:08 +0000 | [diff] [blame] | 125 | void frameDetached(Frame&); |
| 126 | void loaderDetachedFromFrame(DocumentLoader&); |
andersca@apple.com | a69100b | 2014-01-10 15:40:52 +0000 | [diff] [blame] | 127 | void frameStartedLoading(Frame&); |
| 128 | void frameStoppedLoading(Frame&); |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 129 | void frameScheduledNavigation(Frame&, double delay); |
| 130 | void frameClearedScheduledNavigation(Frame&); |
commit-queue@webkit.org | 417bc8f | 2013-02-01 08:50:19 +0000 | [diff] [blame] | 131 | void willRunJavaScriptDialog(const String& message); |
| 132 | void didRunJavaScriptDialog(); |
burg@cs.washington.edu | b49c297 | 2015-01-06 21:45:08 +0000 | [diff] [blame] | 133 | void applyEmulatedMedia(String&); |
simon.fraser@apple.com | 159ad60 | 2014-08-22 19:07:17 +0000 | [diff] [blame] | 134 | void didPaint(RenderObject*, const LayoutRect&); |
apavlov@chromium.org | 1c55c7c | 2012-04-02 12:20:44 +0000 | [diff] [blame] | 135 | void didLayout(); |
pfeldman@chromium.org | b9ada39 | 2012-08-31 09:35:57 +0000 | [diff] [blame] | 136 | void didScroll(); |
pfeldman@chromium.org | 6de498c | 2012-11-14 09:57:24 +0000 | [diff] [blame] | 137 | void didRecalculateStyle(); |
vivek.vg@samsung.com | cc349f1 | 2013-02-12 20:45:44 +0000 | [diff] [blame] | 138 | void scriptsEnabled(bool isEnabled); |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 139 | |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 140 | // Inspector Controller API |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame^] | 141 | void didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) override; |
| 142 | void willDestroyFrontendAndBackend(Inspector::DisconnectReason) override; |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 143 | |
| 144 | // Cross-agents API |
bburg@apple.com | d81c28d | 2015-09-05 18:52:16 +0000 | [diff] [blame] | 145 | Page& page() { return m_page; } |
| 146 | MainFrame& mainFrame(); |
vsevik@chromium.org | 7eda825 | 2011-07-19 16:38:33 +0000 | [diff] [blame] | 147 | String createIdentifier(); |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 148 | Frame* frameForId(const String& frameId); |
timothy@apple.com | 6e81b9e | 2014-09-24 19:58:08 +0000 | [diff] [blame] | 149 | WEBCORE_EXPORT String frameId(Frame*); |
aandrey@chromium.org | be1c75e | 2013-01-31 12:45:12 +0000 | [diff] [blame] | 150 | bool hasIdForFrame(Frame*) const; |
pfeldman@chromium.org | ed8eab0 | 2011-04-25 14:12:28 +0000 | [diff] [blame] | 151 | String loaderId(DocumentLoader*); |
apavlov@chromium.org | 7c79f6f | 2013-02-21 14:08:29 +0000 | [diff] [blame] | 152 | Frame* findFrameWithSecurityOrigin(const String& originRawString); |
burg@cs.washington.edu | 809db5f8 | 2014-10-01 04:34:19 +0000 | [diff] [blame] | 153 | Frame* assertFrame(ErrorString&, const String& frameId); |
| 154 | static DocumentLoader* assertDocumentLoader(ErrorString&, Frame*); |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 155 | |
| 156 | private: |
apavlov@chromium.org | 81b64ef | 2012-08-08 13:11:54 +0000 | [diff] [blame] | 157 | #if ENABLE(TOUCH_EVENTS) |
| 158 | void updateTouchEventEmulationInPage(bool); |
| 159 | #endif |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 160 | |
burg@cs.washington.edu | ad7d083 | 2014-10-25 22:05:57 +0000 | [diff] [blame] | 161 | double timestamp(); |
| 162 | |
beidson@apple.com | 1b1b940 | 2012-10-11 18:29:32 +0000 | [diff] [blame] | 163 | 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.org | 9f378ef | 2015-01-07 23:29:03 +0000 | [diff] [blame] | 166 | Ref<Inspector::Protocol::Page::Frame> buildObjectForFrame(Frame*); |
| 167 | Ref<Inspector::Protocol::Page::FrameResourceTree> buildObjectForFrameTree(Frame*); |
bburg@apple.com | 8c7a454 | 2015-09-01 17:52:15 +0000 | [diff] [blame] | 168 | |
burg@cs.washington.edu | 91ba873 | 2015-02-14 23:25:53 +0000 | [diff] [blame] | 169 | std::unique_ptr<Inspector::PageFrontendDispatcher> m_frontendDispatcher; |
| 170 | RefPtr<Inspector::PageBackendDispatcher> m_backendDispatcher; |
bburg@apple.com | 8c7a454 | 2015-09-01 17:52:15 +0000 | [diff] [blame] | 171 | |
bburg@apple.com | d81c28d | 2015-09-05 18:52:16 +0000 | [diff] [blame] | 172 | Page& m_page; |
bburg@apple.com | 8c7a454 | 2015-09-01 17:52:15 +0000 | [diff] [blame] | 173 | InspectorClient* m_client { nullptr }; |
| 174 | InspectorOverlay* m_overlay { nullptr }; |
| 175 | |
| 176 | long m_lastScriptIdentifier { 0 }; |
caseq@chromium.org | eba6a87 | 2011-10-25 09:25:37 +0000 | [diff] [blame] | 177 | String m_pendingScriptToEvaluateOnLoadOnce; |
| 178 | String m_scriptToEvaluateOnLoadOnce; |
caseq@chromium.org | ace96f3 | 2011-06-29 14:38:06 +0000 | [diff] [blame] | 179 | HashMap<Frame*, String> m_frameToIdentifier; |
| 180 | HashMap<String, Frame*> m_identifierToFrame; |
vsevik@chromium.org | b03da0a | 2011-07-18 14:04:28 +0000 | [diff] [blame] | 181 | HashMap<DocumentLoader*, String> m_loaderToIdentifier; |
bburg@apple.com | 8c7a454 | 2015-09-01 17:52:15 +0000 | [diff] [blame] | 182 | 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.org | d9bc7db | 2013-10-31 00:26:12 +0000 | [diff] [blame] | 187 | String m_emulatedMedia; |
joepeck@webkit.org | a319844 | 2013-12-11 22:40:23 +0000 | [diff] [blame] | 188 | RefPtr<Inspector::InspectorObject> m_scriptsToEvaluateOnLoad; |
loislo@chromium.org | 0857b04 | 2011-03-29 18:01:10 +0000 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | |
| 192 | } // namespace WebCore |
| 193 | |
loislo@chromium.org | 3639d62 | 2011-04-04 08:33:47 +0000 | [diff] [blame] | 194 | #endif // !defined(InspectorPagerAgent_h) |