2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 function InspectorFrontendHostAPI()
35 * @type {!WebInspector.EventTarget}
40 /** @typedef {{type:string, id:(number|undefined),
41 label:(string|undefined), enabled:(boolean|undefined), checked:(boolean|undefined),
42 subItems:(!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>|undefined)}} */
43 InspectorFrontendHostAPI.ContextMenuDescriptor;
45 InspectorFrontendHostAPI.Events = {
46 AppendedToURL: "appendedToURL",
47 CanceledSaveURL: "canceledSaveURL",
48 ContextMenuCleared: "contextMenuCleared",
49 ContextMenuItemSelected: "contextMenuItemSelected",
50 DeviceCountUpdated: "deviceCountUpdated",
51 DevicesUpdated: "devicesUpdated",
52 DispatchMessage: "dispatchMessage",
53 DispatchMessageChunk: "dispatchMessageChunk",
54 EnterInspectElementMode: "enterInspectElementMode",
55 FileSystemsLoaded: "fileSystemsLoaded",
56 FileSystemRemoved: "fileSystemRemoved",
57 FileSystemAdded: "fileSystemAdded",
58 IndexingTotalWorkCalculated: "indexingTotalWorkCalculated",
59 IndexingWorked: "indexingWorked",
60 IndexingDone: "indexingDone",
61 KeyEventUnhandled: "keyEventUnhandled",
62 RevealSourceLine: "revealSourceLine",
64 SearchCompleted: "searchCompleted",
65 SetToolbarColors: "setToolbarColors",
66 SetUseSoftMenu: "setUseSoftMenu",
67 ShowConsole: "showConsole"
70 InspectorFrontendHostAPI.EventDescriptors = [
71 [InspectorFrontendHostAPI.Events.AppendedToURL, ["url"]],
72 [InspectorFrontendHostAPI.Events.CanceledSaveURL, ["url"]],
73 [InspectorFrontendHostAPI.Events.ContextMenuCleared, []],
74 [InspectorFrontendHostAPI.Events.ContextMenuItemSelected, ["id"]],
75 [InspectorFrontendHostAPI.Events.DeviceCountUpdated, ["count"]],
76 [InspectorFrontendHostAPI.Events.DevicesUpdated, ["devices"]],
77 [InspectorFrontendHostAPI.Events.DispatchMessage, ["messageObject"]],
78 [InspectorFrontendHostAPI.Events.DispatchMessageChunk, ["messageChunk", "messageSize"]],
79 [InspectorFrontendHostAPI.Events.EnterInspectElementMode, []],
80 [InspectorFrontendHostAPI.Events.FileSystemsLoaded, ["fileSystems"]],
81 [InspectorFrontendHostAPI.Events.FileSystemRemoved, ["fileSystemPath"]],
82 [InspectorFrontendHostAPI.Events.FileSystemAdded, ["errorMessage", "fileSystem"]],
83 [InspectorFrontendHostAPI.Events.IndexingTotalWorkCalculated, ["requestId", "fileSystemPath", "totalWork"]],
84 [InspectorFrontendHostAPI.Events.IndexingWorked, ["requestId", "fileSystemPath", "worked"]],
85 [InspectorFrontendHostAPI.Events.IndexingDone, ["requestId", "fileSystemPath"]],
86 [InspectorFrontendHostAPI.Events.KeyEventUnhandled, ["event"]],
87 [InspectorFrontendHostAPI.Events.RevealSourceLine, ["url", "lineNumber", "columnNumber"]],
88 [InspectorFrontendHostAPI.Events.SavedURL, ["url"]],
89 [InspectorFrontendHostAPI.Events.SearchCompleted, ["requestId", "fileSystemPath", "files"]],
90 [InspectorFrontendHostAPI.Events.SetToolbarColors, ["backgroundColor", "color"]],
91 [InspectorFrontendHostAPI.Events.SetUseSoftMenu, ["useSoftMenu"]],
92 [InspectorFrontendHostAPI.Events.ShowConsole, []]
95 InspectorFrontendHostAPI.prototype = {
96 addFileSystem: function() { },
100 * @param {string} content
102 append: function(url, content) { },
104 loadCompleted: function() { },
107 * @param {number} requestId
108 * @param {string} fileSystemPath
110 indexPath: function(requestId, fileSystemPath) { },
115 getSelectionBackgroundColor: function() { },
120 getSelectionForegroundColor: function() { },
123 * Requests inspected page to be placed atop of the inspector frontend with specified bounds.
124 * @param {{x: number, y: number, width: number, height: number}} bounds
126 setInspectedPageBounds: function(bounds) { },
129 * Requests inspected page to be placed atop of the inspector frontend
130 * with passed insets from the frontend sides, respecting minimum size passed.
131 * @param {{top: number, left: number, right: number, bottom: number}} insets
132 * @param {{width: number, height: number}} minSize
134 setContentsResizingStrategy: function(insets, minSize) { },
137 * @param {string} shortcuts
139 setWhitelistedShortcuts: function(shortcuts) { },
141 inspectElementCompleted: function() { },
147 moveWindowBy: function(x, y) { },
150 * @param {string} url
152 openInNewTab: function(url) { },
155 * @param {string} fileSystemPath
157 removeFileSystem: function(fileSystemPath) { },
159 requestFileSystems: function() { },
162 * @param {string} url
163 * @param {string} content
164 * @param {boolean} forceSaveAs
166 save: function(url, content, forceSaveAs) { },
169 * @param {number} requestId
170 * @param {string} fileSystemPath
171 * @param {string} query
173 searchInPath: function(requestId, fileSystemPath, query) { },
176 * @param {number} requestId
178 stopIndexing: function(requestId) { },
180 bringToFront: function() { },
183 * @param {string} browserId
184 * @param {string} url
186 openUrlOnRemoteDeviceAndInspect: function(browserId, url) { },
188 closeWindow: function() { },
190 copyText: function(text) { },
193 * @param {string} url
195 inspectedURLChanged: function(url) { },
198 * @param {string} fileSystemId
199 * @param {string} registeredName
200 * @return {?DOMFileSystem}
202 isolatedFileSystem: function(fileSystemId, registeredName) { },
205 * @param {!FileSystem} fileSystem
207 upgradeDraggedFileSystemPermissions: function(fileSystem) { },
212 platform: function() { },
217 port: function() { },
220 * @param {number} actionCode
222 recordActionTaken: function(actionCode) { },
225 * @param {number} panelCode
227 recordPanelShown: function(panelCode) { },
230 * @param {string} message
232 sendMessageToBackend: function(message) { },
235 * @param {string} message
237 sendMessageToEmbedder: function(message) { },
240 * @param {boolean} enabled
242 setDeviceCountUpdatesEnabled: function(enabled) { },
245 * @param {boolean} enabled
247 setDevicesUpdatesEnabled: function(enabled) { },
250 * @param {string} origin
251 * @param {string} script
253 setInjectedScriptForOrigin: function(origin, script) { },
256 * @param {boolean} isDocked
257 * @param {function()} callback
259 setIsDocked: function(isDocked, callback) { },
262 * @param {number} zoom
264 setZoomFactor: function(zoom) { },
269 zoomFactor: function() { },
271 zoomIn: function() { },
273 zoomOut: function() { },
275 resetZoom: function() { },
280 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items
281 * @param {!Document} document
283 showContextMenuAtPoint: function(x, y, items, document) { },
288 isUnderTest: function() { },
293 isHostedMode: function() { }
298 * @implements {InspectorFrontendHostAPI}
299 * @suppressGlobalPropertiesCheck
301 WebInspector.InspectorFrontendHostStub = function()
304 * @param {!Event} event
306 function stopEventPropagation(event)
308 // Let browser handle Ctrl+/Ctrl- shortcuts in hosted mode.
309 var zoomModifier = WebInspector.isMac() ? event.metaKey : event.ctrlKey;
310 if (zoomModifier && (event.keyCode === 187 || event.keyCode === 189))
311 event.stopPropagation();
313 document.addEventListener("keydown", stopEventPropagation, true);
316 WebInspector.InspectorFrontendHostStub.prototype = {
320 getSelectionBackgroundColor: function()
328 getSelectionForegroundColor: function()
338 var match = navigator.userAgent.match(/Windows NT/);
341 match = navigator.userAgent.match(/Mac OS X/);
355 loadCompleted: function()
359 bringToFront: function()
361 this._windowVisible = true;
364 closeWindow: function()
366 this._windowVisible = false;
370 * @param {boolean} isDocked
371 * @param {function()} callback
373 setIsDocked: function(isDocked, callback)
378 * Requests inspected page to be placed atop of the inspector frontend with specified bounds.
379 * @param {{x: number, y: number, width: number, height: number}} bounds
381 setInspectedPageBounds: function(bounds)
386 * Requests inspected page to be placed atop of the inspector frontend
387 * with passed insets from the frontend sides, respecting minimum size passed.
388 * @param {{top: number, left: number, right: number, bottom: number}} insets
389 * @param {{width: number, height: number}} minSize
391 setContentsResizingStrategy: function(insets, minSize)
395 inspectElementCompleted: function()
403 moveWindowBy: function(x, y)
408 * @param {string} origin
409 * @param {string} script
411 setInjectedScriptForOrigin: function(origin, script)
416 * @param {string} url
417 * @suppressGlobalPropertiesCheck
419 inspectedURLChanged: function(url)
421 document.title = WebInspector.UIString("Developer Tools - %s", url);
425 * @param {string} text
427 copyText: function(text)
429 WebInspector.console.error("Clipboard is not enabled in hosted mode. Please inspect using chrome://inspect");
433 * @param {string} url
435 openInNewTab: function(url)
437 window.open(url, "_blank");
441 * @param {string} url
442 * @param {string} content
443 * @param {boolean} forceSaveAs
445 save: function(url, content, forceSaveAs)
447 WebInspector.console.error("Saving files is not enabled in hosted mode. Please inspect using chrome://inspect");
448 this.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.CanceledSaveURL, url);
452 * @param {string} url
453 * @param {string} content
455 append: function(url, content)
457 WebInspector.console.error("Saving files is not enabled in hosted mode. Please inspect using chrome://inspect");
461 * @param {string} message
463 sendMessageToBackend: function(message)
468 * @param {string} message
470 sendMessageToEmbedder: function(message)
475 * @param {number} actionCode
477 recordActionTaken: function(actionCode)
482 * @param {number} panelCode
484 recordPanelShown: function(panelCode)
488 requestFileSystems: function()
492 addFileSystem: function()
497 * @param {string} fileSystemPath
499 removeFileSystem: function(fileSystemPath)
504 * @param {string} fileSystemId
505 * @param {string} registeredName
506 * @return {?DOMFileSystem}
508 isolatedFileSystem: function(fileSystemId, registeredName)
514 * @param {!FileSystem} fileSystem
516 upgradeDraggedFileSystemPermissions: function(fileSystem)
521 * @param {number} requestId
522 * @param {string} fileSystemPath
524 indexPath: function(requestId, fileSystemPath)
529 * @param {number} requestId
531 stopIndexing: function(requestId)
536 * @param {number} requestId
537 * @param {string} fileSystemPath
538 * @param {string} query
540 searchInPath: function(requestId, fileSystemPath, query)
545 * @param {number} zoom
547 setZoomFactor: function(zoom)
554 zoomFactor: function()
567 resetZoom: function()
571 setWhitelistedShortcuts: function(shortcuts)
578 isUnderTest: function()
584 * @param {string} browserId
585 * @param {string} url
587 openUrlOnRemoteDeviceAndInspect: function(browserId, url)
592 * @param {boolean} enabled
594 setDeviceCountUpdatesEnabled: function(enabled)
599 * @param {boolean} enabled
601 setDevicesUpdatesEnabled: function(enabled)
608 * @param {!Array.<!InspectorFrontendHostAPI.ContextMenuDescriptor>} items
609 * @param {!Document} document
611 showContextMenuAtPoint: function(x, y, items, document)
613 throw "Soft context menu should be used";
619 isHostedMode: function()
626 * @type {!InspectorFrontendHostAPI}
628 var InspectorFrontendHost = window.InspectorFrontendHost || null;
631 if (!InspectorFrontendHost) {
632 // Instantiate stub for web-hosted mode if necessary.
633 InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub();
635 // Otherwise add stubs for missing methods that are declared in the interface.
636 var proto = WebInspector.InspectorFrontendHostStub.prototype;
637 for (var name in proto) {
638 var value = proto[name];
639 if (typeof value !== "function" || InspectorFrontendHost[name])
642 InspectorFrontendHost[name] = stub.bind(null, name);
647 * @param {string} name
651 console.error("Incompatible embedder: method InspectorFrontendHost." + name + " is missing. Using stub instead.");
652 var args = Array.prototype.slice.call(arguments, 1);
653 return proto[name].apply(InspectorFrontendHost, args);
656 // Attach the events object.
657 InspectorFrontendHost.events = new WebInspector.Object();
663 function InspectorFrontendAPIImpl()
665 this._debugFrontend = !!Runtime.queryParam("debugFrontend");
667 var descriptors = InspectorFrontendHostAPI.EventDescriptors;
668 for (var i = 0; i < descriptors.length; ++i)
669 this[descriptors[i][0]] = this._dispatch.bind(this, descriptors[i][0], descriptors[i][1], descriptors[i][2]);
672 InspectorFrontendAPIImpl.prototype = {
674 * @param {string} name
675 * @param {!Array.<string>} signature
676 * @param {boolean} runOnceLoaded
678 _dispatch: function(name, signature, runOnceLoaded)
680 var params = Array.prototype.slice.call(arguments, 3);
682 if (this._debugFrontend)
683 setImmediate(innerDispatch);
687 function innerDispatch()
689 // Single argument methods get dispatched with the param.
690 if (signature.length < 2) {
691 InspectorFrontendHost.events.dispatchEventToListeners(name, params[0]);
695 for (var i = 0; i < signature.length; ++i)
696 data[signature[i]] = params[i];
697 InspectorFrontendHost.events.dispatchEventToListeners(name, data);
703 * @param {?string} error
705 embedderMessageAck: function(id, error)
707 InspectorFrontendHost["embedderMessageAck"](id, error);
711 var InspectorFrontendAPI = new InspectorFrontendAPIImpl();