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" | |
33 #include "bindings/core/v8/ScriptState.h" | 32 #include "bindings/core/v8/ScriptState.h" |
| 33 #include "bindings/core/v8/V8RecursionScope.h" |
| 34 #include "bindings/core/v8/V8ScriptRunner.h" |
34 #include "core/clipboard/Pasteboard.h" | 35 #include "core/clipboard/Pasteboard.h" |
35 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
36 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
37 #include "core/events/EventTarget.h" | 38 #include "core/events/EventTarget.h" |
38 #include "core/fetch/ResourceFetcher.h" | 39 #include "core/fetch/ResourceFetcher.h" |
39 #include "core/frame/FrameView.h" | 40 #include "core/frame/FrameView.h" |
40 #include "core/frame/LocalDOMWindow.h" | 41 #include "core/frame/LocalDOMWindow.h" |
41 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
42 #include "core/html/parser/TextResourceDecoder.h" | 43 #include "core/html/parser/TextResourceDecoder.h" |
43 #include "core/inspector/InspectorFrontendClient.h" | 44 #include "core/inspector/InspectorFrontendClient.h" |
44 #include "core/layout/LayoutTheme.h" | 45 #include "core/layout/LayoutTheme.h" |
45 #include "core/loader/FrameLoader.h" | 46 #include "core/loader/FrameLoader.h" |
46 #include "core/page/ContextMenuController.h" | 47 #include "core/page/ContextMenuController.h" |
47 #include "core/page/ContextMenuProvider.h" | 48 #include "core/page/ContextMenuProvider.h" |
48 #include "core/page/Page.h" | 49 #include "core/page/Page.h" |
49 #include "platform/ContextMenu.h" | 50 #include "platform/ContextMenu.h" |
50 #include "platform/ContextMenuItem.h" | 51 #include "platform/ContextMenuItem.h" |
51 #include "platform/HostWindow.h" | 52 #include "platform/HostWindow.h" |
52 #include "platform/ScriptForbiddenScope.h" | |
53 #include "platform/SharedBuffer.h" | 53 #include "platform/SharedBuffer.h" |
54 #include "platform/UserGestureIndicator.h" | 54 #include "platform/UserGestureIndicator.h" |
55 #include "platform/network/ResourceError.h" | 55 #include "platform/network/ResourceError.h" |
56 #include "platform/network/ResourceRequest.h" | 56 #include "platform/network/ResourceRequest.h" |
57 #include "platform/network/ResourceResponse.h" | 57 #include "platform/network/ResourceResponse.h" |
58 | 58 |
59 namespace blink { | 59 namespace blink { |
60 | 60 |
61 class FrontendMenuProvider final : public ContextMenuProvider { | 61 class FrontendMenuProvider final : public ContextMenuProvider { |
62 public: | 62 public: |
63 static PassRefPtrWillBeRawPtr<FrontendMenuProvider> create(DevToolsHost* dev
toolsHost, ScriptValue devtoolsApiObject, const Vector<ContextMenuItem>& items) | 63 static PassRefPtrWillBeRawPtr<FrontendMenuProvider> create(DevToolsHost* dev
toolsHost, const Vector<ContextMenuItem>& items) |
64 { | 64 { |
65 return adoptRefWillBeNoop(new FrontendMenuProvider(devtoolsHost, devtool
sApiObject, items)); | 65 return adoptRefWillBeNoop(new FrontendMenuProvider(devtoolsHost, items))
; |
66 } | 66 } |
67 | 67 |
68 ~FrontendMenuProvider() override | 68 ~FrontendMenuProvider() override |
69 { | 69 { |
70 // Verify that this menu provider has been detached. | 70 // Verify that this menu provider has been detached. |
71 ASSERT(!m_devtoolsHost); | 71 ASSERT(!m_devtoolsHost); |
72 } | 72 } |
73 | 73 |
74 DEFINE_INLINE_VIRTUAL_TRACE() | 74 DEFINE_INLINE_VIRTUAL_TRACE() |
75 { | 75 { |
76 visitor->trace(m_devtoolsHost); | 76 visitor->trace(m_devtoolsHost); |
77 ContextMenuProvider::trace(visitor); | 77 ContextMenuProvider::trace(visitor); |
78 } | 78 } |
79 | 79 |
80 void disconnect() | 80 void disconnect() |
81 { | 81 { |
82 m_devtoolsApiObject = ScriptValue(); | |
83 m_devtoolsHost = nullptr; | 82 m_devtoolsHost = nullptr; |
84 } | 83 } |
85 | 84 |
86 void contextMenuCleared() override | 85 void contextMenuCleared() override |
87 { | 86 { |
88 if (m_devtoolsHost) { | 87 if (m_devtoolsHost) { |
89 if (!ScriptForbiddenScope::isScriptForbidden()) { | 88 m_devtoolsHost->evaluateScript("DevToolsAPI.contextMenuCleared()"); |
90 ScriptFunctionCall function(m_devtoolsApiObject, "contextMenuCle
ared"); | |
91 function.call(); | |
92 } | |
93 m_devtoolsHost->clearMenuProvider(); | 89 m_devtoolsHost->clearMenuProvider(); |
94 m_devtoolsHost = nullptr; | 90 m_devtoolsHost = nullptr; |
95 } | 91 } |
96 m_items.clear(); | 92 m_items.clear(); |
97 } | 93 } |
98 | 94 |
99 void populateContextMenu(ContextMenu* menu) override | 95 void populateContextMenu(ContextMenu* menu) override |
100 { | 96 { |
101 for (size_t i = 0; i < m_items.size(); ++i) | 97 for (size_t i = 0; i < m_items.size(); ++i) |
102 menu->appendItem(m_items[i]); | 98 menu->appendItem(m_items[i]); |
103 } | 99 } |
104 | 100 |
105 void contextMenuItemSelected(const ContextMenuItem* item) override | 101 void contextMenuItemSelected(const ContextMenuItem* item) override |
106 { | 102 { |
107 if (!m_devtoolsHost) | 103 if (!m_devtoolsHost) |
108 return; | 104 return; |
109 | |
110 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture
); | |
111 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; | 105 int itemNumber = item->action() - ContextMenuItemBaseCustomTag; |
112 | 106 m_devtoolsHost->evaluateScript("DevToolsAPI.contextMenuItemSelected(" +
String::number(itemNumber) + ")"); |
113 if (!ScriptForbiddenScope::isScriptForbidden()) { | |
114 ScriptFunctionCall function(m_devtoolsApiObject, "contextMenuItemSel
ected"); | |
115 function.appendArgument(itemNumber); | |
116 function.call(); | |
117 } | |
118 } | 107 } |
119 | 108 |
120 private: | 109 private: |
121 FrontendMenuProvider(DevToolsHost* devtoolsHost, ScriptValue devtoolsApiObje
ct, const Vector<ContextMenuItem>& items) | 110 FrontendMenuProvider(DevToolsHost* devtoolsHost, const Vector<ContextMenuIte
m>& items) |
122 : m_devtoolsHost(devtoolsHost) | 111 : m_devtoolsHost(devtoolsHost) |
123 , m_devtoolsApiObject(devtoolsApiObject) | |
124 , m_items(items) | 112 , m_items(items) |
125 { | 113 { |
126 } | 114 } |
127 | 115 |
128 RawPtrWillBeMember<DevToolsHost> m_devtoolsHost; | 116 RawPtrWillBeMember<DevToolsHost> m_devtoolsHost; |
129 ScriptValue m_devtoolsApiObject; | |
130 | |
131 Vector<ContextMenuItem> m_items; | 117 Vector<ContextMenuItem> m_items; |
132 }; | 118 }; |
133 | 119 |
134 DevToolsHost::DevToolsHost(InspectorFrontendClient* client, LocalFrame* frontend
Frame) | 120 DevToolsHost::DevToolsHost(InspectorFrontendClient* client, LocalFrame* frontend
Frame) |
135 : m_client(client) | 121 : m_client(client) |
136 , m_frontendFrame(frontendFrame) | 122 , m_frontendFrame(frontendFrame) |
137 , m_menuProvider(nullptr) | 123 , m_menuProvider(nullptr) |
138 { | 124 { |
139 } | 125 } |
140 | 126 |
141 DevToolsHost::~DevToolsHost() | 127 DevToolsHost::~DevToolsHost() |
142 { | 128 { |
143 ASSERT(!m_client); | 129 ASSERT(!m_client); |
144 } | 130 } |
145 | 131 |
146 DEFINE_TRACE(DevToolsHost) | 132 DEFINE_TRACE(DevToolsHost) |
147 { | 133 { |
148 visitor->trace(m_frontendFrame); | 134 visitor->trace(m_frontendFrame); |
149 visitor->trace(m_menuProvider); | 135 visitor->trace(m_menuProvider); |
150 } | 136 } |
151 | 137 |
| 138 void DevToolsHost::evaluateScript(const String& expression) |
| 139 { |
| 140 if (!m_frontendFrame) |
| 141 return; |
| 142 ScriptState* scriptState = ScriptState::forMainWorld(m_frontendFrame); |
| 143 if (!scriptState) |
| 144 return; |
| 145 ScriptState::Scope scope(scriptState); |
| 146 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| 147 V8RecursionScope recursionScope(scriptState->isolate()); |
| 148 v8::Local<v8::String> source = v8AtomicString(scriptState->isolate(), expres
sion.utf8().data()); |
| 149 V8ScriptRunner::compileAndRunInternalScript(source, scriptState->isolate(),
String(), TextPosition()); |
| 150 } |
| 151 |
152 void DevToolsHost::disconnectClient() | 152 void DevToolsHost::disconnectClient() |
153 { | 153 { |
154 m_client = 0; | 154 m_client = 0; |
155 if (m_menuProvider) { | 155 if (m_menuProvider) { |
156 m_menuProvider->disconnect(); | 156 m_menuProvider->disconnect(); |
157 m_menuProvider = nullptr; | 157 m_menuProvider = nullptr; |
158 } | 158 } |
159 m_frontendFrame = nullptr; | 159 m_frontendFrame = nullptr; |
160 } | 160 } |
161 | 161 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 void DevToolsHost::sendMessageToEmbedder(const String& message) | 212 void DevToolsHost::sendMessageToEmbedder(const String& message) |
213 { | 213 { |
214 if (m_client) | 214 if (m_client) |
215 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); | 215 m_client->sendMessageToEmbedder(escapeUnicodeNonCharacters(message)); |
216 } | 216 } |
217 | 217 |
218 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) |
219 { | 219 { |
220 ASSERT(m_frontendFrame); | 220 ASSERT(m_frontendFrame); |
221 ScriptState* frontendScriptState = ScriptState::forMainWorld(m_frontendFrame
); | 221 RefPtrWillBeRawPtr<FrontendMenuProvider> menuProvider = FrontendMenuProvider
::create(this, items); |
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); | |
228 m_menuProvider = menuProvider.get(); | 222 m_menuProvider = menuProvider.get(); |
229 float zoom = targetFrame->pageZoomFactor(); | 223 float zoom = targetFrame->pageZoomFactor(); |
230 if (m_client) | 224 if (m_client) |
231 m_client->showContextMenu(targetFrame, x * zoom, y * zoom, menuProvider)
; | 225 m_client->showContextMenu(targetFrame, x * zoom, y * zoom, menuProvider)
; |
232 } | 226 } |
233 | 227 |
234 String DevToolsHost::getSelectionBackgroundColor() | 228 String DevToolsHost::getSelectionBackgroundColor() |
235 { | 229 { |
236 return LayoutTheme::theme().activeSelectionBackgroundColor().serialized(); | 230 return LayoutTheme::theme().activeSelectionBackgroundColor().serialized(); |
237 } | 231 } |
238 | 232 |
239 String DevToolsHost::getSelectionForegroundColor() | 233 String DevToolsHost::getSelectionForegroundColor() |
240 { | 234 { |
241 return LayoutTheme::theme().activeSelectionForegroundColor().serialized(); | 235 return LayoutTheme::theme().activeSelectionForegroundColor().serialized(); |
242 } | 236 } |
243 | 237 |
244 bool DevToolsHost::isUnderTest() | 238 bool DevToolsHost::isUnderTest() |
245 { | 239 { |
246 return m_client && m_client->isUnderTest(); | 240 return m_client && m_client->isUnderTest(); |
247 } | 241 } |
248 | 242 |
249 bool DevToolsHost::isHostedMode() | 243 bool DevToolsHost::isHostedMode() |
250 { | 244 { |
251 return false; | 245 return false; |
252 } | 246 } |
253 | 247 |
254 } // namespace blink | 248 } // namespace blink |
OLD | NEW |