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