2 * Copyright (C) 2011 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.
31 var InspectorFrontendAPI = {
34 // Methods called by the embedder on load, potentially before front-end is initialized.
35 //////////////////////////////////////////////////////////////////////////////////////////////////
37 showConsole: function()
39 InspectorFrontendAPI._runOnceLoaded(function() {
40 WebInspector.inspectorView.showPanel("console");
44 enterInspectElementMode: function()
46 InspectorFrontendAPI._runOnceLoaded(function() {
47 WebInspector.inspectorView.showPanel("elements");
48 if (WebInspector.inspectElementModeController)
49 WebInspector.inspectElementModeController.toggleSearch();
54 * Focus on a particular line in the specified resource.
55 * @param {string} url The url to the resource.
56 * @param {number} lineNumber The line number to focus on.
57 * @param {number} columnNumber The column number to focus on.
59 revealSourceLine: function(url, lineNumber, columnNumber)
61 InspectorFrontendAPI._runOnceLoaded(function() {
62 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
64 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
69 * @param {!WebInspector.Event} event
71 function listener(event)
73 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
74 if (uiSourceCode.url === url) {
75 WebInspector.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
76 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener);
80 WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener);
85 * @param {string} backgroundColor
86 * @param {string} color
88 setToolbarColors: function(backgroundColor, color)
90 WebInspector.setToolbarColors(backgroundColor, color);
96 loadTimelineFromURL: function(url)
98 InspectorFrontendAPI._runOnceLoaded(function() {
99 /** @type {!WebInspector.TimelinePanel} */ (WebInspector.inspectorView.showPanel("timeline")).loadFromURL(url);
104 * @param {boolean} useSoftMenu
106 setUseSoftMenu: function(useSoftMenu)
108 WebInspector.ContextMenu.setUseSoftMenu(useSoftMenu);
111 dispatchMessage: function(messageObject)
113 InspectorBackend.connection().dispatch(messageObject);
116 // Callbacks to the methods called from within initialized front-end.
117 //////////////////////////////////////////////////////////////////////////////////////////////////
119 contextMenuItemSelected: function(id)
121 WebInspector.contextMenuItemSelected(id);
124 contextMenuCleared: function()
126 WebInspector.contextMenuCleared();
129 fileSystemsLoaded: function(fileSystems)
131 WebInspector.isolatedFileSystemDispatcher.fileSystemsLoaded(fileSystems);
134 fileSystemRemoved: function(fileSystemPath)
136 WebInspector.isolatedFileSystemDispatcher.fileSystemRemoved(fileSystemPath);
139 fileSystemAdded: function(errorMessage, fileSystem)
141 WebInspector.isolatedFileSystemDispatcher.fileSystemAdded(errorMessage, fileSystem);
145 * @param {number} requestId
146 * @param {string} fileSystemPath
147 * @param {number} totalWork
149 indexingTotalWorkCalculated: function(requestId, fileSystemPath, totalWork)
151 WebInspector.fileSystemWorkspaceBinding.indexingTotalWorkCalculated(requestId, fileSystemPath, totalWork);
155 * @param {number} requestId
156 * @param {string} fileSystemPath
157 * @param {number} worked
159 indexingWorked: function(requestId, fileSystemPath, worked)
161 WebInspector.fileSystemWorkspaceBinding.indexingWorked(requestId, fileSystemPath, worked);
165 * @param {number} requestId
166 * @param {string} fileSystemPath
168 indexingDone: function(requestId, fileSystemPath)
170 WebInspector.fileSystemWorkspaceBinding.indexingDone(requestId, fileSystemPath);
174 * @param {number} requestId
175 * @param {string} fileSystemPath
176 * @param {!Array.<string>} files
178 searchCompleted: function(requestId, fileSystemPath, files)
180 WebInspector.fileSystemWorkspaceBinding.searchCompleted(requestId, fileSystemPath, files);
184 * @param {!InspectorFrontendAPI.ForwardedKeyboardEvent} event
186 keyEventUnhandled: function(event)
188 InspectorFrontendAPI._runOnceLoaded(function() {
189 WebInspector.forwardedEventHandler.keyEventReceived(event.type, event.keyIdentifier, event.keyCode, event.modifiers);
194 * @param {!Array.<!Adb.Device>} targets
196 populateRemoteDevices: function(targets)
198 // FIXME: this needs to be changed for the sake of modularity.
199 WebInspector.devicesModel.populateRemoteDevices(targets);
203 * @param {string} url
205 savedURL: function(url)
207 WebInspector.fileManager.savedURL(url);
211 * @param {string} url
213 canceledSaveURL: function(url)
215 WebInspector.fileManager.canceledSaveURL(url);
219 * @param {string} url
221 appendedToURL: function(url)
223 WebInspector.fileManager.appendedToURL(url);
228 * @param {?string} error
230 embedderMessageAck: function(id, error)
232 InspectorFrontendHost.embedderMessageAck(id, error);
235 // Called from within front-end
236 ///////////////////////////////
238 loadCompleted: function()
240 InspectorFrontendAPI._isLoaded = true;
241 for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
242 InspectorFrontendAPI._pendingCommands[i]();
243 InspectorFrontendAPI._pendingCommands = [];
245 window.opener.postMessage(["loadCompleted"], "*");
248 // Implementation details
249 /////////////////////////
252 * @param {function()} command
254 _runOnceLoaded: function(command)
256 if (InspectorFrontendAPI._isLoaded) {
260 InspectorFrontendAPI._pendingCommands.push(command);
264 /** @typedef {!Object.<{type: string, keyCode: (number|undefined), keyIdentifier: (string|undefined), modifiers: (number|undefined)}>} */
265 InspectorFrontendAPI.ForwardedKeyboardEvent;
267 if (top !== window) {
268 top.InspectorFrontendAPI = window.InspectorFrontendAPI;