• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2011 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
31var InspectorFrontendAPI = {
32    _pendingCommands: [],
33
34    // Methods called by the embedder on load, potentially before front-end is initialized.
35    //////////////////////////////////////////////////////////////////////////////////////////////////
36
37    showConsole: function()
38    {
39        InspectorFrontendAPI._runOnceLoaded(function() {
40            WebInspector.showPanel("console");
41        });
42    },
43
44    enterInspectElementMode: function()
45    {
46        InspectorFrontendAPI._runOnceLoaded(function() {
47            WebInspector.showPanel("elements");
48            if (WebInspector.inspectElementModeController)
49                WebInspector.inspectElementModeController.toggleSearch();
50        });
51    },
52
53    /**
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.
58     */
59    revealSourceLine: function(url, lineNumber, columnNumber)
60    {
61        InspectorFrontendAPI._runOnceLoaded(function() {
62            var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
63            if (uiSourceCode) {
64                WebInspector.showPanel("sources").showUISourceCode(uiSourceCode, lineNumber, columnNumber);
65                return;
66            }
67
68            /**
69             * @param {!WebInspector.Event} event
70             */
71            function listener(event)
72            {
73                var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
74                if (uiSourceCode.url === url) {
75                    WebInspector.showPanel("sources").showUISourceCode(uiSourceCode, lineNumber, columnNumber);
76                    WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener);
77                }
78            }
79
80            WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, listener);
81        });
82    },
83
84    /**
85     * @param {string} backgroundColor
86     * @param {string} color
87     */
88    setToolbarColors: function(backgroundColor, color)
89    {
90        WebInspector.setToolbarColors(backgroundColor, color);
91    },
92
93    /**
94     * @param {string} url
95     */
96    loadTimelineFromURL: function(url)
97    {
98        InspectorFrontendAPI._runOnceLoaded(function() {
99            /** @type {!WebInspector.TimelinePanel} */ (WebInspector.showPanel("timeline")).loadFromURL(url);
100        });
101    },
102
103    /**
104     * @param {boolean} useSoftMenu
105     */
106    setUseSoftMenu: function(useSoftMenu)
107    {
108        WebInspector.ContextMenu.setUseSoftMenu(useSoftMenu);
109    },
110
111    // FIXME: remove this legacy support.
112    setAttachedWindow: function(side)
113    {
114    },
115
116    // FIXME: remove this legacy support.
117    setDockSide: function(side)
118    {
119        WebInspector.dockController.setDockSide(side);
120    },
121
122    dispatchMessage: function(messageObject)
123    {
124        InspectorBackend.dispatch(messageObject);
125    },
126
127    // Callbacks to the methods called from within initialized front-end.
128    //////////////////////////////////////////////////////////////////////////////////////////////////
129
130    contextMenuItemSelected: function(id)
131    {
132        WebInspector.contextMenuItemSelected(id);
133    },
134
135    contextMenuCleared: function()
136    {
137        WebInspector.contextMenuCleared();
138    },
139
140    fileSystemsLoaded: function(fileSystems)
141    {
142        WebInspector.isolatedFileSystemDispatcher.fileSystemsLoaded(fileSystems);
143    },
144
145    fileSystemRemoved: function(fileSystemPath)
146    {
147        WebInspector.isolatedFileSystemDispatcher.fileSystemRemoved(fileSystemPath);
148    },
149
150    fileSystemAdded: function(errorMessage, fileSystem)
151    {
152        WebInspector.isolatedFileSystemDispatcher.fileSystemAdded(errorMessage, fileSystem);
153    },
154
155    indexingTotalWorkCalculated: function(requestId, fileSystemPath, totalWork)
156    {
157        var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
158        projectDelegate.indexingTotalWorkCalculated(requestId, totalWork);
159    },
160
161    indexingWorked: function(requestId, fileSystemPath, worked)
162    {
163        var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
164        projectDelegate.indexingWorked(requestId, worked);
165    },
166
167    indexingDone: function(requestId, fileSystemPath)
168    {
169        var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
170        projectDelegate.indexingDone(requestId);
171    },
172
173    searchCompleted: function(requestId, fileSystemPath, files)
174    {
175        var projectDelegate = WebInspector.fileSystemWorkspaceProvider.delegate(fileSystemPath);
176        projectDelegate.searchCompleted(requestId, files);
177    },
178
179    /**
180     * @param {string} url
181     */
182    savedURL: function(url)
183    {
184        WebInspector.fileManager.savedURL(url);
185    },
186
187    /**
188     * @param {string} url
189     */
190    canceledSaveURL: function(url)
191    {
192        WebInspector.fileManager.canceledSaveURL(url);
193    },
194
195    /**
196     * @param {string} url
197     */
198    appendedToURL: function(url)
199    {
200        WebInspector.fileManager.appendedToURL(url);
201    },
202
203    /**
204     * @param {number} id
205     * @param {?string} error
206     */
207    embedderMessageAck: function(id, error)
208    {
209        InspectorFrontendHost.embedderMessageAck(id, error);
210    },
211
212    // Called from within front-end
213    ///////////////////////////////
214
215    loadCompleted: function()
216    {
217        InspectorFrontendAPI._isLoaded = true;
218        for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
219            InspectorFrontendAPI._pendingCommands[i]();
220        InspectorFrontendAPI._pendingCommands = [];
221        if (window.opener)
222            window.opener.postMessage(["loadCompleted"], "*");
223    },
224
225    /**
226     * @param {!Object} queryParamsObject
227     */
228    dispatchQueryParameters: function(queryParamsObject)
229    {
230        if ("dispatch" in queryParamsObject)
231            InspectorFrontendAPI._dispatch(JSON.parse(window.decodeURI(queryParamsObject["dispatch"])));
232    },
233
234    // Testing harness support
235    //////////////////////////
236
237    evaluateForTest: function(callId, script)
238    {
239        WebInspector.evaluateForTestInFrontend(callId, script);
240    },
241
242    dispatchMessageAsync: function(messageObject)
243    {
244        WebInspector.dispatch(messageObject);
245    },
246
247    // Implementation details
248    /////////////////////////
249
250    _dispatch: function(signature)
251    {
252        InspectorFrontendAPI._runOnceLoaded(function() {
253            var methodName = signature.shift();
254            return InspectorFrontendAPI[methodName].apply(InspectorFrontendAPI, signature);
255        });
256    },
257
258    /**
259     * @param {function()} command
260     */
261    _runOnceLoaded: function(command)
262    {
263        if (InspectorFrontendAPI._isLoaded) {
264            command();
265            return;
266        }
267        InspectorFrontendAPI._pendingCommands.push(command);
268    }
269}
270
271function onMessageFromOpener(event)
272{
273    if (event.source === window.opener)
274        InspectorFrontendAPI._dispatch(event.data);
275}
276
277if (window.opener && window.dispatchStandaloneTestRunnerMessages)
278    window.addEventListener("message", onMessageFromOpener, true);
279