OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @constructor | |
33 * @implements {InspectorFrontendHostAPI} | 31 * @implements {InspectorFrontendHostAPI} |
34 * @suppressGlobalPropertiesCheck | 32 * @unrestricted |
35 */ | 33 */ |
36 WebInspector.InspectorFrontendHostStub = function() | 34 WebInspector.InspectorFrontendHostStub = class { |
37 { | 35 /** |
| 36 * @suppressGlobalPropertiesCheck |
| 37 */ |
| 38 constructor() { |
38 /** | 39 /** |
39 * @param {!Event} event | 40 * @param {!Event} event |
40 */ | 41 */ |
41 function stopEventPropagation(event) | 42 function stopEventPropagation(event) { |
42 { | 43 // Let browser handle Ctrl+/Ctrl- shortcuts in hosted mode. |
43 // Let browser handle Ctrl+/Ctrl- shortcuts in hosted mode. | 44 var zoomModifier = WebInspector.isMac() ? event.metaKey : event.ctrlKey; |
44 var zoomModifier = WebInspector.isMac() ? event.metaKey : event.ctrlKey; | 45 if (zoomModifier && (event.keyCode === 187 || event.keyCode === 189)) |
45 if (zoomModifier && (event.keyCode === 187 || event.keyCode === 189)) | 46 event.stopPropagation(); |
46 event.stopPropagation(); | |
47 } | 47 } |
48 document.addEventListener("keydown", stopEventPropagation, true); | 48 document.addEventListener('keydown', stopEventPropagation, true); |
| 49 } |
| 50 |
| 51 /** |
| 52 * @override |
| 53 * @return {string} |
| 54 */ |
| 55 getSelectionBackgroundColor() { |
| 56 return '#6e86ff'; |
| 57 } |
| 58 |
| 59 /** |
| 60 * @override |
| 61 * @return {string} |
| 62 */ |
| 63 getSelectionForegroundColor() { |
| 64 return '#ffffff'; |
| 65 } |
| 66 |
| 67 /** |
| 68 * @override |
| 69 * @return {string} |
| 70 */ |
| 71 platform() { |
| 72 var match = navigator.userAgent.match(/Windows NT/); |
| 73 if (match) |
| 74 return 'windows'; |
| 75 match = navigator.userAgent.match(/Mac OS X/); |
| 76 if (match) |
| 77 return 'mac'; |
| 78 return 'linux'; |
| 79 } |
| 80 |
| 81 /** |
| 82 * @override |
| 83 */ |
| 84 loadCompleted() { |
| 85 } |
| 86 |
| 87 /** |
| 88 * @override |
| 89 */ |
| 90 bringToFront() { |
| 91 this._windowVisible = true; |
| 92 } |
| 93 |
| 94 /** |
| 95 * @override |
| 96 */ |
| 97 closeWindow() { |
| 98 this._windowVisible = false; |
| 99 } |
| 100 |
| 101 /** |
| 102 * @override |
| 103 * @param {boolean} isDocked |
| 104 * @param {function()} callback |
| 105 */ |
| 106 setIsDocked(isDocked, callback) { |
| 107 setTimeout(callback, 0); |
| 108 } |
| 109 |
| 110 /** |
| 111 * Requests inspected page to be placed atop of the inspector frontend with sp
ecified bounds. |
| 112 * @override |
| 113 * @param {{x: number, y: number, width: number, height: number}} bounds |
| 114 */ |
| 115 setInspectedPageBounds(bounds) { |
| 116 } |
| 117 |
| 118 /** |
| 119 * @override |
| 120 */ |
| 121 inspectElementCompleted() { |
| 122 } |
| 123 |
| 124 /** |
| 125 * @override |
| 126 * @param {string} origin |
| 127 * @param {string} script |
| 128 */ |
| 129 setInjectedScriptForOrigin(origin, script) { |
| 130 } |
| 131 |
| 132 /** |
| 133 * @override |
| 134 * @param {string} url |
| 135 * @suppressGlobalPropertiesCheck |
| 136 */ |
| 137 inspectedURLChanged(url) { |
| 138 document.title = WebInspector.UIString('Developer Tools - %s', url); |
| 139 } |
| 140 |
| 141 /** |
| 142 * @override |
| 143 * @param {string} text |
| 144 */ |
| 145 copyText(text) { |
| 146 WebInspector.console.error('Clipboard is not enabled in hosted mode. Please
inspect using chrome://inspect'); |
| 147 } |
| 148 |
| 149 /** |
| 150 * @override |
| 151 * @param {string} url |
| 152 */ |
| 153 openInNewTab(url) { |
| 154 window.open(url, '_blank'); |
| 155 } |
| 156 |
| 157 /** |
| 158 * @override |
| 159 * @param {string} url |
| 160 * @param {string} content |
| 161 * @param {boolean} forceSaveAs |
| 162 */ |
| 163 save(url, content, forceSaveAs) { |
| 164 WebInspector.console.error('Saving files is not enabled in hosted mode. Plea
se inspect using chrome://inspect'); |
| 165 this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.Cancele
dSaveURL, url); |
| 166 } |
| 167 |
| 168 /** |
| 169 * @override |
| 170 * @param {string} url |
| 171 * @param {string} content |
| 172 */ |
| 173 append(url, content) { |
| 174 WebInspector.console.error('Saving files is not enabled in hosted mode. Plea
se inspect using chrome://inspect'); |
| 175 } |
| 176 |
| 177 /** |
| 178 * @override |
| 179 * @param {string} message |
| 180 */ |
| 181 sendMessageToBackend(message) { |
| 182 } |
| 183 |
| 184 /** |
| 185 * @override |
| 186 * @param {string} actionName |
| 187 * @param {number} actionCode |
| 188 * @param {number} bucketSize |
| 189 */ |
| 190 recordEnumeratedHistogram(actionName, actionCode, bucketSize) { |
| 191 } |
| 192 |
| 193 /** |
| 194 * @override |
| 195 */ |
| 196 requestFileSystems() { |
| 197 this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.FileSys
temsLoaded, []); |
| 198 } |
| 199 |
| 200 /** |
| 201 * @override |
| 202 * @param {string=} fileSystemPath |
| 203 */ |
| 204 addFileSystem(fileSystemPath) { |
| 205 } |
| 206 |
| 207 /** |
| 208 * @override |
| 209 * @param {string} fileSystemPath |
| 210 */ |
| 211 removeFileSystem(fileSystemPath) { |
| 212 } |
| 213 |
| 214 /** |
| 215 * @override |
| 216 * @param {string} fileSystemId |
| 217 * @param {string} registeredName |
| 218 * @return {?DOMFileSystem} |
| 219 */ |
| 220 isolatedFileSystem(fileSystemId, registeredName) { |
| 221 return null; |
| 222 } |
| 223 |
| 224 /** |
| 225 * @override |
| 226 * @param {string} url |
| 227 * @param {string} headers |
| 228 * @param {number} streamId |
| 229 * @param {function(!InspectorFrontendHostAPI.LoadNetworkResourceResult)} call
back |
| 230 */ |
| 231 loadNetworkResource(url, headers, streamId, callback) { |
| 232 Runtime.loadResourcePromise(url) |
| 233 .then(function(text) { |
| 234 WebInspector.ResourceLoader.streamWrite(streamId, text); |
| 235 callback({statusCode: 200}); |
| 236 }) |
| 237 .catch(function() { |
| 238 callback({statusCode: 404}); |
| 239 }); |
| 240 } |
| 241 |
| 242 /** |
| 243 * @override |
| 244 * @param {function(!Object<string, string>)} callback |
| 245 */ |
| 246 getPreferences(callback) { |
| 247 var prefs = {}; |
| 248 for (var name in window.localStorage) |
| 249 prefs[name] = window.localStorage[name]; |
| 250 callback(prefs); |
| 251 } |
| 252 |
| 253 /** |
| 254 * @override |
| 255 * @param {string} name |
| 256 * @param {string} value |
| 257 */ |
| 258 setPreference(name, value) { |
| 259 window.localStorage[name] = value; |
| 260 } |
| 261 |
| 262 /** |
| 263 * @override |
| 264 * @param {string} name |
| 265 */ |
| 266 removePreference(name) { |
| 267 delete window.localStorage[name]; |
| 268 } |
| 269 |
| 270 /** |
| 271 * @override |
| 272 */ |
| 273 clearPreferences() { |
| 274 window.localStorage.clear(); |
| 275 } |
| 276 |
| 277 /** |
| 278 * @override |
| 279 * @param {!FileSystem} fileSystem |
| 280 */ |
| 281 upgradeDraggedFileSystemPermissions(fileSystem) { |
| 282 } |
| 283 |
| 284 /** |
| 285 * @override |
| 286 * @param {number} requestId |
| 287 * @param {string} fileSystemPath |
| 288 */ |
| 289 indexPath(requestId, fileSystemPath) { |
| 290 } |
| 291 |
| 292 /** |
| 293 * @override |
| 294 * @param {number} requestId |
| 295 */ |
| 296 stopIndexing(requestId) { |
| 297 } |
| 298 |
| 299 /** |
| 300 * @override |
| 301 * @param {number} requestId |
| 302 * @param {string} fileSystemPath |
| 303 * @param {string} query |
| 304 */ |
| 305 searchInPath(requestId, fileSystemPath, query) { |
| 306 } |
| 307 |
| 308 /** |
| 309 * @override |
| 310 * @return {number} |
| 311 */ |
| 312 zoomFactor() { |
| 313 return 1; |
| 314 } |
| 315 |
| 316 /** |
| 317 * @override |
| 318 */ |
| 319 zoomIn() { |
| 320 } |
| 321 |
| 322 /** |
| 323 * @override |
| 324 */ |
| 325 zoomOut() { |
| 326 } |
| 327 |
| 328 /** |
| 329 * @override |
| 330 */ |
| 331 resetZoom() { |
| 332 } |
| 333 |
| 334 /** |
| 335 * @override |
| 336 * @param {string} shortcuts |
| 337 */ |
| 338 setWhitelistedShortcuts(shortcuts) { |
| 339 } |
| 340 |
| 341 /** |
| 342 * @param {!Array<string>} certChain |
| 343 * @override |
| 344 */ |
| 345 showCertificateViewer(certChain) { |
| 346 } |
| 347 |
| 348 /** |
| 349 * @override |
| 350 * @return {boolean} |
| 351 */ |
| 352 isUnderTest() { |
| 353 return false; |
| 354 } |
| 355 |
| 356 /** |
| 357 * @override |
| 358 * @param {function()} callback |
| 359 */ |
| 360 reattach(callback) { |
| 361 } |
| 362 |
| 363 /** |
| 364 * @override |
| 365 */ |
| 366 readyForTest() { |
| 367 } |
| 368 |
| 369 /** |
| 370 * @override |
| 371 * @param {boolean} discoverUsbDevices |
| 372 * @param {boolean} portForwardingEnabled |
| 373 * @param {!Adb.PortForwardingConfig} portForwardingConfig |
| 374 */ |
| 375 setDevicesDiscoveryConfig(discoverUsbDevices, portForwardingEnabled, portForwa
rdingConfig) { |
| 376 } |
| 377 |
| 378 /** |
| 379 * @override |
| 380 * @param {boolean} enabled |
| 381 */ |
| 382 setDevicesUpdatesEnabled(enabled) { |
| 383 } |
| 384 |
| 385 /** |
| 386 * @override |
| 387 * @param {string} pageId |
| 388 * @param {string} action |
| 389 */ |
| 390 performActionOnRemotePage(pageId, action) { |
| 391 } |
| 392 |
| 393 /** |
| 394 * @override |
| 395 * @param {string} browserId |
| 396 * @param {string} url |
| 397 */ |
| 398 openRemotePage(browserId, url) { |
| 399 } |
| 400 |
| 401 /** |
| 402 * @override |
| 403 * @param {number} x |
| 404 * @param {number} y |
| 405 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items |
| 406 * @param {!Document} document |
| 407 */ |
| 408 showContextMenuAtPoint(x, y, items, document) { |
| 409 throw 'Soft context menu should be used'; |
| 410 } |
| 411 |
| 412 /** |
| 413 * @override |
| 414 * @return {boolean} |
| 415 */ |
| 416 isHostedMode() { |
| 417 return true; |
| 418 } |
49 }; | 419 }; |
50 | 420 |
51 WebInspector.InspectorFrontendHostStub.prototype = { | 421 /** |
52 /** | 422 * @unrestricted |
53 * @override | 423 */ |
54 * @return {string} | 424 var InspectorFrontendAPIImpl = class { |
55 */ | 425 constructor() { |
56 getSelectionBackgroundColor: function() | 426 this._debugFrontend = |
57 { | 427 !!Runtime.queryParam('debugFrontend') || (window['InspectorTest'] && win
dow['InspectorTest']['debugTest']); |
58 return "#6e86ff"; | 428 |
59 }, | 429 var descriptors = InspectorFrontendHostAPI.EventDescriptors; |
60 | 430 for (var i = 0; i < descriptors.length; ++i) |
61 /** | 431 this[descriptors[i][1]] = this._dispatch.bind(this, descriptors[i][0], des
criptors[i][2], descriptors[i][3]); |
62 * @override | 432 } |
63 * @return {string} | 433 |
64 */ | 434 /** |
65 getSelectionForegroundColor: function() | 435 * @param {symbol} name |
66 { | 436 * @param {!Array.<string>} signature |
67 return "#ffffff"; | 437 * @param {boolean} runOnceLoaded |
68 }, | 438 */ |
69 | 439 _dispatch(name, signature, runOnceLoaded) { |
70 /** | 440 var params = Array.prototype.slice.call(arguments, 3); |
71 * @override | 441 |
72 * @return {string} | 442 if (this._debugFrontend) |
73 */ | 443 setImmediate(innerDispatch); |
74 platform: function() | 444 else |
75 { | 445 innerDispatch(); |
76 var match = navigator.userAgent.match(/Windows NT/); | 446 |
77 if (match) | 447 function innerDispatch() { |
78 return "windows"; | 448 // Single argument methods get dispatched with the param. |
79 match = navigator.userAgent.match(/Mac OS X/); | 449 if (signature.length < 2) { |
80 if (match) | 450 try { |
81 return "mac"; | 451 InspectorFrontendHost.events.dispatchEventToListeners(name, params[0])
; |
82 return "linux"; | 452 } catch (e) { |
83 }, | 453 console.error(e + ' ' + e.stack); |
84 | 454 } |
85 /** | 455 return; |
86 * @override | 456 } |
87 */ | 457 var data = {}; |
88 loadCompleted: function() | 458 for (var i = 0; i < signature.length; ++i) |
89 { | 459 data[signature[i]] = params[i]; |
90 }, | 460 try { |
91 | 461 InspectorFrontendHost.events.dispatchEventToListeners(name, data); |
92 /** | 462 } catch (e) { |
93 * @override | 463 console.error(e + ' ' + e.stack); |
94 */ | 464 } |
95 bringToFront: function() | |
96 { | |
97 this._windowVisible = true; | |
98 }, | |
99 | |
100 /** | |
101 * @override | |
102 */ | |
103 closeWindow: function() | |
104 { | |
105 this._windowVisible = false; | |
106 }, | |
107 | |
108 /** | |
109 * @override | |
110 * @param {boolean} isDocked | |
111 * @param {function()} callback | |
112 */ | |
113 setIsDocked: function(isDocked, callback) | |
114 { | |
115 setTimeout(callback, 0); | |
116 }, | |
117 | |
118 /** | |
119 * Requests inspected page to be placed atop of the inspector frontend with
specified bounds. | |
120 * @override | |
121 * @param {{x: number, y: number, width: number, height: number}} bounds | |
122 */ | |
123 setInspectedPageBounds: function(bounds) | |
124 { | |
125 }, | |
126 | |
127 /** | |
128 * @override | |
129 */ | |
130 inspectElementCompleted: function() | |
131 { | |
132 }, | |
133 | |
134 /** | |
135 * @override | |
136 * @param {string} origin | |
137 * @param {string} script | |
138 */ | |
139 setInjectedScriptForOrigin: function(origin, script) | |
140 { | |
141 }, | |
142 | |
143 /** | |
144 * @override | |
145 * @param {string} url | |
146 * @suppressGlobalPropertiesCheck | |
147 */ | |
148 inspectedURLChanged: function(url) | |
149 { | |
150 document.title = WebInspector.UIString("Developer Tools - %s", url); | |
151 }, | |
152 | |
153 /** | |
154 * @override | |
155 * @param {string} text | |
156 */ | |
157 copyText: function(text) | |
158 { | |
159 WebInspector.console.error("Clipboard is not enabled in hosted mode. Ple
ase inspect using chrome://inspect"); | |
160 }, | |
161 | |
162 /** | |
163 * @override | |
164 * @param {string} url | |
165 */ | |
166 openInNewTab: function(url) | |
167 { | |
168 window.open(url, "_blank"); | |
169 }, | |
170 | |
171 /** | |
172 * @override | |
173 * @param {string} url | |
174 * @param {string} content | |
175 * @param {boolean} forceSaveAs | |
176 */ | |
177 save: function(url, content, forceSaveAs) | |
178 { | |
179 WebInspector.console.error("Saving files is not enabled in hosted mode.
Please inspect using chrome://inspect"); | |
180 this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.Can
celedSaveURL, url); | |
181 }, | |
182 | |
183 /** | |
184 * @override | |
185 * @param {string} url | |
186 * @param {string} content | |
187 */ | |
188 append: function(url, content) | |
189 { | |
190 WebInspector.console.error("Saving files is not enabled in hosted mode.
Please inspect using chrome://inspect"); | |
191 }, | |
192 | |
193 /** | |
194 * @override | |
195 * @param {string} message | |
196 */ | |
197 sendMessageToBackend: function(message) | |
198 { | |
199 }, | |
200 | |
201 /** | |
202 * @override | |
203 * @param {string} actionName | |
204 * @param {number} actionCode | |
205 * @param {number} bucketSize | |
206 */ | |
207 recordEnumeratedHistogram: function(actionName, actionCode, bucketSize) | |
208 { | |
209 }, | |
210 | |
211 /** | |
212 * @override | |
213 */ | |
214 requestFileSystems: function() | |
215 { | |
216 this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.Fil
eSystemsLoaded, []); | |
217 }, | |
218 | |
219 /** | |
220 * @override | |
221 * @param {string=} fileSystemPath | |
222 */ | |
223 addFileSystem: function(fileSystemPath) | |
224 { | |
225 }, | |
226 | |
227 /** | |
228 * @override | |
229 * @param {string} fileSystemPath | |
230 */ | |
231 removeFileSystem: function(fileSystemPath) | |
232 { | |
233 }, | |
234 | |
235 /** | |
236 * @override | |
237 * @param {string} fileSystemId | |
238 * @param {string} registeredName | |
239 * @return {?DOMFileSystem} | |
240 */ | |
241 isolatedFileSystem: function(fileSystemId, registeredName) | |
242 { | |
243 return null; | |
244 }, | |
245 | |
246 /** | |
247 * @override | |
248 * @param {string} url | |
249 * @param {string} headers | |
250 * @param {number} streamId | |
251 * @param {function(!InspectorFrontendHostAPI.LoadNetworkResourceResult)} ca
llback | |
252 */ | |
253 loadNetworkResource: function(url, headers, streamId, callback) | |
254 { | |
255 Runtime.loadResourcePromise(url).then(function(text) { | |
256 WebInspector.ResourceLoader.streamWrite(streamId, text); | |
257 callback({statusCode : 200}); | |
258 }).catch(function() { | |
259 callback({statusCode : 404}); | |
260 }); | |
261 }, | |
262 | |
263 /** | |
264 * @override | |
265 * @param {function(!Object<string, string>)} callback | |
266 */ | |
267 getPreferences: function(callback) | |
268 { | |
269 var prefs = {}; | |
270 for (var name in window.localStorage) | |
271 prefs[name] = window.localStorage[name]; | |
272 callback(prefs); | |
273 }, | |
274 | |
275 /** | |
276 * @override | |
277 * @param {string} name | |
278 * @param {string} value | |
279 */ | |
280 setPreference: function(name, value) | |
281 { | |
282 window.localStorage[name] = value; | |
283 }, | |
284 | |
285 /** | |
286 * @override | |
287 * @param {string} name | |
288 */ | |
289 removePreference: function(name) | |
290 { | |
291 delete window.localStorage[name]; | |
292 }, | |
293 | |
294 /** | |
295 * @override | |
296 */ | |
297 clearPreferences: function() | |
298 { | |
299 window.localStorage.clear(); | |
300 }, | |
301 | |
302 /** | |
303 * @override | |
304 * @param {!FileSystem} fileSystem | |
305 */ | |
306 upgradeDraggedFileSystemPermissions: function(fileSystem) | |
307 { | |
308 }, | |
309 | |
310 /** | |
311 * @override | |
312 * @param {number} requestId | |
313 * @param {string} fileSystemPath | |
314 */ | |
315 indexPath: function(requestId, fileSystemPath) | |
316 { | |
317 }, | |
318 | |
319 /** | |
320 * @override | |
321 * @param {number} requestId | |
322 */ | |
323 stopIndexing: function(requestId) | |
324 { | |
325 }, | |
326 | |
327 /** | |
328 * @override | |
329 * @param {number} requestId | |
330 * @param {string} fileSystemPath | |
331 * @param {string} query | |
332 */ | |
333 searchInPath: function(requestId, fileSystemPath, query) | |
334 { | |
335 }, | |
336 | |
337 /** | |
338 * @override | |
339 * @return {number} | |
340 */ | |
341 zoomFactor: function() | |
342 { | |
343 return 1; | |
344 }, | |
345 | |
346 /** | |
347 * @override | |
348 */ | |
349 zoomIn: function() | |
350 { | |
351 }, | |
352 | |
353 /** | |
354 * @override | |
355 */ | |
356 zoomOut: function() | |
357 { | |
358 }, | |
359 | |
360 /** | |
361 * @override | |
362 */ | |
363 resetZoom: function() | |
364 { | |
365 }, | |
366 | |
367 /** | |
368 * @override | |
369 * @param {string} shortcuts | |
370 */ | |
371 setWhitelistedShortcuts: function(shortcuts) | |
372 { | |
373 }, | |
374 | |
375 /** | |
376 * @param {!Array<string>} certChain | |
377 * @override | |
378 */ | |
379 showCertificateViewer: function(certChain) | |
380 { | |
381 }, | |
382 | |
383 /** | |
384 * @override | |
385 * @return {boolean} | |
386 */ | |
387 isUnderTest: function() | |
388 { | |
389 return false; | |
390 }, | |
391 | |
392 /** | |
393 * @override | |
394 * @param {function()} callback | |
395 */ | |
396 reattach: function(callback) | |
397 { | |
398 }, | |
399 | |
400 /** | |
401 * @override | |
402 */ | |
403 readyForTest: function() | |
404 { | |
405 }, | |
406 | |
407 /** | |
408 * @override | |
409 * @param {boolean} discoverUsbDevices | |
410 * @param {boolean} portForwardingEnabled | |
411 * @param {!Adb.PortForwardingConfig} portForwardingConfig | |
412 */ | |
413 setDevicesDiscoveryConfig: function(discoverUsbDevices, portForwardingEnable
d, portForwardingConfig) | |
414 { | |
415 }, | |
416 | |
417 /** | |
418 * @override | |
419 * @param {boolean} enabled | |
420 */ | |
421 setDevicesUpdatesEnabled: function(enabled) | |
422 { | |
423 }, | |
424 | |
425 /** | |
426 * @override | |
427 * @param {string} pageId | |
428 * @param {string} action | |
429 */ | |
430 performActionOnRemotePage: function(pageId, action) | |
431 { | |
432 }, | |
433 | |
434 /** | |
435 * @override | |
436 * @param {string} browserId | |
437 * @param {string} url | |
438 */ | |
439 openRemotePage: function(browserId, url) | |
440 { | |
441 }, | |
442 | |
443 /** | |
444 * @override | |
445 * @param {number} x | |
446 * @param {number} y | |
447 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items | |
448 * @param {!Document} document | |
449 */ | |
450 showContextMenuAtPoint: function(x, y, items, document) | |
451 { | |
452 throw "Soft context menu should be used"; | |
453 }, | |
454 | |
455 /** | |
456 * @override | |
457 * @return {boolean} | |
458 */ | |
459 isHostedMode: function() | |
460 { | |
461 return true; | |
462 } | 465 } |
| 466 } |
| 467 |
| 468 /** |
| 469 * @param {number} id |
| 470 * @param {string} chunk |
| 471 */ |
| 472 streamWrite(id, chunk) { |
| 473 WebInspector.ResourceLoader.streamWrite(id, chunk); |
| 474 } |
463 }; | 475 }; |
464 | 476 |
465 /** | 477 /** |
466 * @type {!InspectorFrontendHostAPI} | 478 * @type {!InspectorFrontendHostAPI} |
467 */ | 479 */ |
468 var InspectorFrontendHost = window.InspectorFrontendHost || null; | 480 var InspectorFrontendHost = window.InspectorFrontendHost || null; |
469 window.InspectorFrontendHost = InspectorFrontendHost; | 481 window.InspectorFrontendHost = InspectorFrontendHost; |
470 (function(){ | 482 (function() { |
471 | 483 |
472 function initializeInspectorFrontendHost() | 484 function initializeInspectorFrontendHost() { |
473 { | 485 if (!InspectorFrontendHost) { |
474 if (!InspectorFrontendHost) { | 486 // Instantiate stub for web-hosted mode if necessary. |
475 // Instantiate stub for web-hosted mode if necessary. | 487 window.InspectorFrontendHost = InspectorFrontendHost = new WebInspector.In
spectorFrontendHostStub(); |
476 window.InspectorFrontendHost = InspectorFrontendHost = new WebInspec
tor.InspectorFrontendHostStub(); | 488 } else { |
477 } else { | 489 // Otherwise add stubs for missing methods that are declared in the interf
ace. |
478 // Otherwise add stubs for missing methods that are declared in the
interface. | 490 var proto = WebInspector.InspectorFrontendHostStub.prototype; |
479 var proto = WebInspector.InspectorFrontendHostStub.prototype; | 491 for (var name in proto) { |
480 for (var name in proto) { | 492 var value = proto[name]; |
481 var value = proto[name]; | 493 if (typeof value !== 'function' || InspectorFrontendHost[name]) |
482 if (typeof value !== "function" || InspectorFrontendHost[name]) | 494 continue; |
483 continue; | |
484 | 495 |
485 InspectorFrontendHost[name] = stub.bind(null, name); | 496 InspectorFrontendHost[name] = stub.bind(null, name); |
486 } | 497 } |
487 } | |
488 | |
489 /** | |
490 * @param {string} name | |
491 * @return {?} | |
492 */ | |
493 function stub(name) | |
494 { | |
495 console.error("Incompatible embedder: method InspectorFrontendHost."
+ name + " is missing. Using stub instead."); | |
496 var args = Array.prototype.slice.call(arguments, 1); | |
497 return proto[name].apply(InspectorFrontendHost, args); | |
498 } | |
499 | |
500 // Attach the events object. | |
501 InspectorFrontendHost.events = new WebInspector.Object(); | |
502 } | 498 } |
503 | 499 |
504 /** | 500 /** |
505 * @constructor | 501 * @param {string} name |
| 502 * @return {?} |
506 */ | 503 */ |
507 function InspectorFrontendAPIImpl() | 504 function stub(name) { |
508 { | 505 console.error('Incompatible embedder: method InspectorFrontendHost.' + nam
e + ' is missing. Using stub instead.'); |
509 this._debugFrontend = !!Runtime.queryParam("debugFrontend") || (window["
InspectorTest"] && window["InspectorTest"]["debugTest"]); | 506 var args = Array.prototype.slice.call(arguments, 1); |
510 | 507 return proto[name].apply(InspectorFrontendHost, args); |
511 var descriptors = InspectorFrontendHostAPI.EventDescriptors; | |
512 for (var i = 0; i < descriptors.length; ++i) | |
513 this[descriptors[i][1]] = this._dispatch.bind(this, descriptors[i][0
], descriptors[i][2], descriptors[i][3]); | |
514 } | 508 } |
515 | 509 |
516 InspectorFrontendAPIImpl.prototype = { | 510 // Attach the events object. |
517 /** | 511 InspectorFrontendHost.events = new WebInspector.Object(); |
518 * @param {symbol} name | 512 } |
519 * @param {!Array.<string>} signature | |
520 * @param {boolean} runOnceLoaded | |
521 */ | |
522 _dispatch: function(name, signature, runOnceLoaded) | |
523 { | |
524 var params = Array.prototype.slice.call(arguments, 3); | |
525 | 513 |
526 if (this._debugFrontend) | 514 // FIXME: This file is included into both apps, since the devtools_app needs t
he InspectorFrontendHostAPI only, |
527 setImmediate(innerDispatch); | 515 // so the host instance should not initialized there. |
528 else | 516 initializeInspectorFrontendHost(); |
529 innerDispatch(); | 517 window.InspectorFrontendAPI = new InspectorFrontendAPIImpl(); |
530 | 518 WebInspector.setLocalizationPlatform(InspectorFrontendHost.platform()); |
531 function innerDispatch() | |
532 { | |
533 // Single argument methods get dispatched with the param. | |
534 if (signature.length < 2) { | |
535 try { | |
536 InspectorFrontendHost.events.dispatchEventToListeners(na
me, params[0]); | |
537 } catch (e) { | |
538 console.error(e + " " + e.stack); | |
539 } | |
540 return; | |
541 } | |
542 var data = {}; | |
543 for (var i = 0; i < signature.length; ++i) | |
544 data[signature[i]] = params[i]; | |
545 try { | |
546 InspectorFrontendHost.events.dispatchEventToListeners(name,
data); | |
547 } catch (e) { | |
548 console.error(e + " " + e.stack); | |
549 } | |
550 } | |
551 }, | |
552 | |
553 /** | |
554 * @param {number} id | |
555 * @param {string} chunk | |
556 */ | |
557 streamWrite: function(id, chunk) | |
558 { | |
559 WebInspector.ResourceLoader.streamWrite(id, chunk); | |
560 } | |
561 }; | |
562 | |
563 // FIXME: This file is included into both apps, since the devtools_app needs
the InspectorFrontendHostAPI only, | |
564 // so the host instance should not initialized there. | |
565 initializeInspectorFrontendHost(); | |
566 window.InspectorFrontendAPI = new InspectorFrontendAPIImpl(); | |
567 WebInspector.setLocalizationPlatform(InspectorFrontendHost.platform()); | |
568 })(); | 519 })(); |
569 | 520 |
570 /** | 521 /** |
571 * @type {!WebInspector.EventTarget} | 522 * @type {!WebInspector.EventTarget} |
572 */ | 523 */ |
573 InspectorFrontendHost.events; | 524 InspectorFrontendHost.events; |
OLD | NEW |