OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "web/InspectorFrontendClientImpl.h" | |
33 | |
34 #include "bindings/core/v8/V8InspectorFrontendHost.h" | |
35 #include "bindings/core/v8/ScriptController.h" | |
36 #include "core/frame/LocalFrame.h" | |
37 #include "core/inspector/InspectorFrontendHost.h" | |
38 #include "core/page/Page.h" | |
39 #include "public/platform/WebFloatPoint.h" | |
40 #include "public/platform/WebString.h" | |
41 #include "public/web/WebDevToolsFrontendClient.h" | |
42 #include "web/WebDevToolsFrontendImpl.h" | |
43 #include "wtf/text/WTFString.h" | |
44 | |
45 namespace blink { | |
46 | |
47 InspectorFrontendClientImpl::InspectorFrontendClientImpl(Page* frontendPage, Web
DevToolsFrontendClient* client, WebDevToolsFrontendImpl* frontend) | |
48 : m_frontendPage(frontendPage) | |
49 , m_client(client) | |
50 { | |
51 } | |
52 | |
53 InspectorFrontendClientImpl::~InspectorFrontendClientImpl() | |
54 { | |
55 ASSERT(!m_frontendHost); | |
56 } | |
57 | |
58 void InspectorFrontendClientImpl::trace(Visitor* visitor) | |
59 { | |
60 visitor->trace(m_frontendPage); | |
61 visitor->trace(m_frontendHost); | |
62 InspectorFrontendClient::trace(visitor); | |
63 } | |
64 | |
65 void InspectorFrontendClientImpl::dispose() | |
66 { | |
67 if (m_frontendHost) { | |
68 m_frontendHost->disconnectClient(); | |
69 m_frontendHost = nullptr; | |
70 } | |
71 m_client = 0; | |
72 } | |
73 | |
74 void InspectorFrontendClientImpl::windowObjectCleared() | |
75 { | |
76 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
77 ASSERT(m_frontendPage->mainFrame()); | |
78 ScriptState* scriptState = ScriptState::forMainWorld(m_frontendPage->depreca
tedLocalMainFrame()); | |
79 ScriptState::Scope scope(scriptState); | |
80 | |
81 if (m_frontendHost) | |
82 m_frontendHost->disconnectClient(); | |
83 m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage); | |
84 v8::Handle<v8::Object> global = scriptState->context()->Global(); | |
85 v8::Handle<v8::Value> frontendHostObj = toV8(m_frontendHost.get(), global, s
criptState->isolate()); | |
86 | |
87 global->Set(v8::String::NewFromUtf8(isolate, "InspectorFrontendHost"), front
endHostObj); | |
88 ScriptController* scriptController = m_frontendPage->mainFrame() ? &m_fronte
ndPage->deprecatedLocalMainFrame()->script() : 0; | |
89 if (scriptController) { | |
90 String installAdditionalAPI = | |
91 "" // Wrap messages that go to embedder. | |
92 "(function(host, methodEntries) {" | |
93 " host._lastCallId = 0;" | |
94 " host._callbacks = [];" | |
95 " host.embedderMessageAck = function(id, error)" | |
96 " {" | |
97 " var callback = host._callbacks[id];" | |
98 " delete host._callbacks[id];" | |
99 " if (callback)" | |
100 " callback(error);" | |
101 " };" | |
102 " function dispatch(methodName, argumentCount)" | |
103 " {" | |
104 " var callId = ++host._lastCallId;" | |
105 " var argsArray = Array.prototype.slice.call(arguments, 2);" | |
106 " var callback = argsArray[argsArray.length - 1];" | |
107 " if (typeof callback === \"function\") {" | |
108 " argsArray.pop();" | |
109 " host._callbacks[callId] = callback;" | |
110 " }" | |
111 " var message = { \"id\": callId, \"method\": methodName };" | |
112 " argsArray = argsArray.slice(0, argumentCount);" | |
113 " if (argsArray.length)" | |
114 " message.params = argsArray;" | |
115 " host.sendMessageToEmbedder(JSON.stringify(message));" | |
116 " };" | |
117 " methodEntries.forEach(function(methodEntry) { host[methodEntry[
0]] = dispatch.bind(null, methodEntry[0], methodEntry[1]); });" | |
118 "})(InspectorFrontendHost," | |
119 " [['addFileSystem', 0]," | |
120 " ['append', 2]," | |
121 " ['bringToFront', 0]," | |
122 " ['closeWindow', 0]," | |
123 " ['indexPath', 2]," | |
124 " ['inspectElementCompleted', 0]," | |
125 " ['inspectedURLChanged', 1]," | |
126 " ['moveWindowBy', 2]," | |
127 " ['openInNewTab', 1]," | |
128 " ['openUrlOnRemoteDeviceAndInspect', 2]," | |
129 " ['removeFileSystem', 1]," | |
130 " ['requestFileSystems', 0]," | |
131 " ['resetZoom', 0]," | |
132 " ['save', 3]," | |
133 " ['searchInPath', 3]," | |
134 " ['setDeviceCountUpdatesEnabled', 1]," | |
135 " ['setDevicesUpdatesEnabled', 1]," | |
136 " ['setWhitelistedShortcuts', 1]," | |
137 " ['setContentsResizingStrategy', 2]," | |
138 " ['setInspectedPageBounds', 1]," | |
139 " ['setIsDocked', 1]," | |
140 " ['stopIndexing', 1]," | |
141 " ['zoomIn', 0]," | |
142 " ['zoomOut', 0]]);" | |
143 "" | |
144 "" // Support for legacy front-ends (<M34). Do not add items here. | |
145 "InspectorFrontendHost.requestSetDockSide = function(dockSide)" | |
146 "{" | |
147 " InspectorFrontendHost.setIsDocked(dockSide !== \"undocked\");" | |
148 "};" | |
149 "InspectorFrontendHost.supportsFileSystems = function() { return tru
e; };" | |
150 "" | |
151 "" // Support for legacy front-ends (<M28). Do not add items here. | |
152 "InspectorFrontendHost.canInspectWorkers = function() { return true;
};" | |
153 "InspectorFrontendHost.canSaveAs = function() { return true; };" | |
154 "InspectorFrontendHost.canSave = function() { return true; };" | |
155 "InspectorFrontendHost.loaded = function() {};" | |
156 "InspectorFrontendHost.hiddenPanels = function() { return ""; };" | |
157 "InspectorFrontendHost.localizedStringsURL = function() { return "";
};" | |
158 "InspectorFrontendHost.close = function(url) { };"; | |
159 scriptController->executeScriptInMainWorld(installAdditionalAPI, ScriptC
ontroller::ExecuteScriptWhenScriptsDisabled); | |
160 } | |
161 } | |
162 | |
163 void InspectorFrontendClientImpl::sendMessageToBackend(const String& message) | |
164 { | |
165 m_client->sendMessageToBackend(message); | |
166 } | |
167 | |
168 void InspectorFrontendClientImpl::sendMessageToEmbedder(const String& message) | |
169 { | |
170 m_client->sendMessageToEmbedder(message); | |
171 } | |
172 | |
173 bool InspectorFrontendClientImpl::isUnderTest() | |
174 { | |
175 return m_client->isUnderTest(); | |
176 } | |
177 | |
178 } // namespace blink | |
OLD | NEW |