OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 11 matching lines...) Expand all Loading... |
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "core/inspector/DevToolsHost.h" | 30 #include "core/inspector/DevToolsHost.h" |
31 | 31 |
| 32 #include "bindings/core/v8/ScriptFunctionCall.h" |
32 #include "bindings/core/v8/ScriptState.h" | 33 #include "bindings/core/v8/ScriptState.h" |
33 #include "bindings/core/v8/V8ScriptRunner.h" | |
34 #include "core/clipboard/Pasteboard.h" | 34 #include "core/clipboard/Pasteboard.h" |
35 #include "core/dom/ExecutionContext.h" | 35 #include "core/dom/ExecutionContext.h" |
36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
37 #include "core/events/EventTarget.h" | 37 #include "core/events/EventTarget.h" |
38 #include "core/fetch/ResourceFetcher.h" | 38 #include "core/fetch/ResourceFetcher.h" |
39 #include "core/frame/FrameView.h" | 39 #include "core/frame/FrameView.h" |
40 #include "core/frame/LocalDOMWindow.h" | 40 #include "core/frame/LocalDOMWindow.h" |
41 #include "core/frame/LocalFrame.h" | 41 #include "core/frame/LocalFrame.h" |
42 #include "core/html/parser/TextResourceDecoder.h" | 42 #include "core/html/parser/TextResourceDecoder.h" |
43 #include "core/inspector/InspectorFrontendClient.h" | 43 #include "core/inspector/InspectorFrontendClient.h" |
44 #include "core/layout/LayoutTheme.h" | 44 #include "core/layout/LayoutTheme.h" |
45 #include "core/loader/FrameLoader.h" | 45 #include "core/loader/FrameLoader.h" |
46 #include "core/page/ContextMenuController.h" | 46 #include "core/page/ContextMenuController.h" |
47 #include "core/page/ContextMenuProvider.h" | 47 #include "core/page/ContextMenuProvider.h" |
48 #include "core/page/Page.h" | 48 #include "core/page/Page.h" |
49 #include "platform/ContextMenu.h" | 49 #include "platform/ContextMenu.h" |
50 #include "platform/ContextMenuItem.h" | 50 #include "platform/ContextMenuItem.h" |
51 #include "platform/HostWindow.h" | 51 #include "platform/HostWindow.h" |
| 52 #include "platform/ScriptForbiddenScope.h" |
52 #include "platform/SharedBuffer.h" | 53 #include "platform/SharedBuffer.h" |
53 #include "platform/UserGestureIndicator.h" | 54 #include "platform/UserGestureIndicator.h" |
54 #include "platform/network/ResourceError.h" | 55 #include "platform/network/ResourceError.h" |
55 #include "platform/network/ResourceRequest.h" | 56 #include "platform/network/ResourceRequest.h" |
56 #include "platform/network/ResourceResponse.h" | 57 #include "platform/network/ResourceResponse.h" |
57 | 58 |
58 namespace blink { | 59 namespace blink { |
59 | 60 |
60 class FrontendMenuProvider final : public ContextMenuProvider { | 61 class FrontendMenuProvider final : public ContextMenuProvider { |
61 public: | 62 public: |
62 static PassRefPtrWillBeRawPtr<FrontendMenuProvider> create(DevToolsHost* dev
toolsHost, const Vector<ContextMenuItem>& items) | 63 static PassRefPtrWillBeRawPtr<FrontendMenuProvider> create(DevToolsHost* dev
toolsHost, ScriptValue devtoolsApiObject, const Vector<ContextMenuItem>& items) |
63 { | 64 { |
64 return adoptRefWillBeNoop(new FrontendMenuProvider(devtoolsHost, items))
; | 65 return adoptRefWillBeNoop(new FrontendMenuProvider(devtoolsHost, devtool
sApiObject, items)); |
65 } | 66 } |
66 | 67 |
67 ~FrontendMenuProvider() override | 68 ~FrontendMenuProvider() override |
68 { | 69 { |
69 // Verify that this menu provider has been detached. | 70 // Verify that this menu provider has been detached. |
70 ASSERT(!m_devtoolsHost); | 71 ASSERT(!m_devtoolsHost); |
71 } | 72 } |
72 | 73 |
73 DEFINE_INLINE_VIRTUAL_TRACE() | 74 DEFINE_INLINE_VIRTUAL_TRACE() |
74 { | 75 { |
75 visitor->trace(m_devtoolsHost); | 76 visitor->trace(m_devtoolsHost); |
76 ContextMenuProvider::trace(visitor); | 77 ContextMenuProvider::trace(visitor); |
77 } | 78 } |
78 | 79 |
79 void disconnect() | 80 void disconnect() |
80 { | 81 { |
| 82 m_devtoolsApiObject = ScriptValue(); |
81 m_devtoolsHost = nullptr; | 83 m_devtoolsHost = nullptr; |
82 } | 84 } |
83 | 85 |
84 void contextMenuCleared() override | 86 void contextMenuCleared() override |
85 { | 87 { |
86 if (m_devtoolsHost) { | 88 if (m_devtoolsHost) { |
87 m_devtoolsHost->evaluateScript("DevToolsAPI.contextMenuCleared()"); | 89 if (!ScriptForbiddenScope::isScriptForbidden()) { |
| 90 ScriptFunctionCall function(m_devtoolsApiObject, "contextMenuCle
ared"); |
| 91 function.call(); |
| 92 } |
88 m_devtoolsHost->clearMenuProvider(); | 93 m_devtoolsHost->clearMenuProvider(); |
89 m_devtoolsHost = nullptr; | 94 m_devtoolsHost = nullptr; |
90 } | 95 } |
91 m_items.clear(); | 96 m_items.clear(); |
92 } | 97 } |
93 | 98 |
94 void populateContextMenu(ContextMenu* menu) override | 99 void populateContextMenu(ContextMenu* menu) override |
95 { | 100 { |
96 for (size_t i = 0; i < m_items.size(); ++i) | 101 for (size_t i = 0; i < m_items.size(); ++i) |
97 menu->appendItem(m_items[i]); | 102 menu->appendItem(m_items[i]); |
98 } | 103 } |
99 | 104 |
100 void contextMenuItemSelected(const ContextMenuItem* item) override | 105 void contextMenuItemSelected(const ContextMenuItem* item) override |
101 { | 106 { |
102 if (!m_devtoolsHost) | 107 if (!m_devtoolsHost) |
103 return; | 108 return; |
| 109 |
| 110 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture
); |
104 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; | 111 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; |
105 m_devtoolsHost->evaluateScript("DevToolsAPI.contextMenuItemSelected(" +
String::number(itemNumber) + ")"); | 112 |
| 113 if (!ScriptForbiddenScope::isScriptForbidden()) { |
| 114 ScriptFunctionCall function(m_devtoolsApiObject, "contextMenuItemSel
ected"); |
| 115 function.appendArgument(itemNumber); |
| 116 function.call(); |
| 117 } |
106 } | 118 } |
107 | 119 |
108 private: | 120 private: |
109 FrontendMenuProvider(DevToolsHost* devtoolsHost, const Vector<ContextMenuIte
m>& items) | 121 FrontendMenuProvider(DevToolsHost* devtoolsHost, ScriptValue devtoolsApiObje
ct, const Vector<ContextMenuItem>& items) |
110 : m_devtoolsHost(devtoolsHost) | 122 : m_devtoolsHost(devtoolsHost) |
| 123 , m_devtoolsApiObject(devtoolsApiObject) |
111 , m_items(items) | 124 , m_items(items) |
112 { | 125 { |
113 } | 126 } |
114 | 127 |
115 RawPtrWillBeMember<DevToolsHost> m_devtoolsHost; | 128 RawPtrWillBeMember<DevToolsHost> m_devtoolsHost; |
| 129 ScriptValue m_devtoolsApiObject; |
| 130 |
116 Vector<ContextMenuItem> m_items; | 131 Vector<ContextMenuItem> m_items; |
117 }; | 132 }; |
118 | 133 |
119 DevToolsHost::DevToolsHost(InspectorFrontendClient* client, LocalFrame* frontend
Frame) | 134 DevToolsHost::DevToolsHost(InspectorFrontendClient* client, LocalFrame* frontend
Frame) |
120 : m_client(client) | 135 : m_client(client) |
121 , m_frontendFrame(frontendFrame) | 136 , m_frontendFrame(frontendFrame) |
122 , m_menuProvider(nullptr) | 137 , m_menuProvider(nullptr) |
123 { | 138 { |
124 } | 139 } |
125 | 140 |
126 DevToolsHost::~DevToolsHost() | 141 DevToolsHost::~DevToolsHost() |
127 { | 142 { |
128 ASSERT(!m_client); | 143 ASSERT(!m_client); |
129 } | 144 } |
130 | 145 |
131 DEFINE_TRACE(DevToolsHost) | 146 DEFINE_TRACE(DevToolsHost) |
132 { | 147 { |
133 visitor->trace(m_frontendFrame); | 148 visitor->trace(m_frontendFrame); |
134 visitor->trace(m_menuProvider); | 149 visitor->trace(m_menuProvider); |
135 } | 150 } |
136 | 151 |
137 void DevToolsHost::evaluateScript(const String& expression) | |
138 { | |
139 if (!m_frontendFrame) | |
140 return; | |
141 ScriptState* scriptState = ScriptState::forMainWorld(m_frontendFrame); | |
142 if (!scriptState) | |
143 return; | |
144 ScriptState::Scope scope(scriptState); | |
145 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | |
146 v8::Local<v8::String> source = v8AtomicString(scriptState->isolate(), expres
sion.utf8().data()); | |
147 V8ScriptRunner::compileAndRunInternalScript(source, scriptState->isolate(),
String(), TextPosition()); | |
148 } | |
149 | |
150 void DevToolsHost::disconnectClient() | 152 void DevToolsHost::disconnectClient() |
151 { | 153 { |
152 m_client = 0; | 154 m_client = 0; |
153 if (m_menuProvider) { | 155 if (m_menuProvider) { |
154 m_menuProvider->disconnect(); | 156 m_menuProvider->disconnect(); |
155 m_menuProvider = nullptr; | 157 m_menuProvider = nullptr; |
156 } | 158 } |
157 m_frontendFrame = nullptr; | 159 m_frontendFrame = nullptr; |
158 } | 160 } |
159 | 161 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 211 |
210 void DevToolsHost::sendMessageToEmbedder(const String& message) | 212 void DevToolsHost::sendMessageToEmbedder(const String& message) |
211 { | 213 { |
212 if (m_client) | 214 if (m_client) |
213 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); | 215 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); |
214 } | 216 } |
215 | 217 |
216 void DevToolsHost::showContextMenu(LocalFrame* targetFrame, float x, float y, co
nst Vector<ContextMenuItem>& items) | 218 void DevToolsHost::showContextMenu(LocalFrame* targetFrame, float x, float y, co
nst Vector<ContextMenuItem>& items) |
217 { | 219 { |
218 ASSERT(m_frontendFrame); | 220 ASSERT(m_frontendFrame); |
219 RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider
::create(this, items); | 221 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendFrame
); |
| 222 if (!frontendScriptState) |
| 223 return; |
| 224 ScriptValue devtoolsApiObject = frontendScriptState->getFromGlobalObject("De
vToolsAPI"); |
| 225 ASSERT(devtoolsApiObject.isObject()); |
| 226 |
| 227 RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider
::create(this, devtoolsApiObject, items); |
220 m_menuProvider = menuProvider.get(); | 228 m_menuProvider = menuProvider.get(); |
221 float zoom = targetFrame->pageZoomFactor(); | 229 float zoom = targetFrame->pageZoomFactor(); |
222 if (m_client) | 230 if (m_client) |
223 m_client->showContextMenu(targetFrame, x * zoom, y * zoom, menuProvider)
; | 231 m_client->showContextMenu(targetFrame, x * zoom, y * zoom, menuProvider)
; |
224 } | 232 } |
225 | 233 |
226 String DevToolsHost::getSelectionBackgroundColor() | 234 String DevToolsHost::getSelectionBackgroundColor() |
227 { | 235 { |
228 return LayoutTheme::theme().activeSelectionBackgroundColor().serialized(); | 236 return LayoutTheme::theme().activeSelectionBackgroundColor().serialized(); |
229 } | 237 } |
230 | 238 |
231 String DevToolsHost::getSelectionForegroundColor() | 239 String DevToolsHost::getSelectionForegroundColor() |
232 { | 240 { |
233 return LayoutTheme::theme().activeSelectionForegroundColor().serialized(); | 241 return LayoutTheme::theme().activeSelectionForegroundColor().serialized(); |
234 } | 242 } |
235 | 243 |
236 bool DevToolsHost::isUnderTest() | 244 bool DevToolsHost::isUnderTest() |
237 { | 245 { |
238 return m_client && m_client->isUnderTest(); | 246 return m_client && m_client->isUnderTest(); |
239 } | 247 } |
240 | 248 |
241 bool DevToolsHost::isHostedMode() | 249 bool DevToolsHost::isHostedMode() |
242 { | 250 { |
243 return false; | 251 return false; |
244 } | 252 } |
245 | 253 |
246 } // namespace blink | 254 } // namespace blink |
OLD | NEW |