Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / InspectorFrontendAPI.js
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
31 var 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.inspectorView.showPanel("console");
41         });
42     },
43
44     enterInspectElementMode: function()
45     {
46         InspectorFrontendAPI._runOnceLoaded(function() {
47             WebInspector.inspectorView.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.Revealer.reveal(uiSourceCode.uiLocation(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.Revealer.reveal(uiSourceCode.uiLocation(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.inspectorView.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     dispatchMessage: function(messageObject)
112     {
113         InspectorBackend.connection().dispatch(messageObject);
114     },
115
116     // Callbacks to the methods called from within initialized front-end.
117     //////////////////////////////////////////////////////////////////////////////////////////////////
118
119     contextMenuItemSelected: function(id)
120     {
121         WebInspector.contextMenuItemSelected(id);
122     },
123
124     contextMenuCleared: function()
125     {
126         WebInspector.contextMenuCleared();
127     },
128
129     fileSystemsLoaded: function(fileSystems)
130     {
131         WebInspector.isolatedFileSystemDispatcher.fileSystemsLoaded(fileSystems);
132     },
133
134     fileSystemRemoved: function(fileSystemPath)
135     {
136         WebInspector.isolatedFileSystemDispatcher.fileSystemRemoved(fileSystemPath);
137     },
138
139     fileSystemAdded: function(errorMessage, fileSystem)
140     {
141         WebInspector.isolatedFileSystemDispatcher.fileSystemAdded(errorMessage, fileSystem);
142     },
143
144     /**
145      * @param {number} requestId
146      * @param {string} fileSystemPath
147      * @param {number} totalWork
148      */
149     indexingTotalWorkCalculated: function(requestId, fileSystemPath, totalWork)
150     {
151         WebInspector.fileSystemWorkspaceBinding.indexingTotalWorkCalculated(requestId, fileSystemPath, totalWork);
152     },
153
154     /**
155      * @param {number} requestId
156      * @param {string} fileSystemPath
157      * @param {number} worked
158      */
159     indexingWorked: function(requestId, fileSystemPath, worked)
160     {
161         WebInspector.fileSystemWorkspaceBinding.indexingWorked(requestId, fileSystemPath, worked);
162     },
163
164     /**
165      * @param {number} requestId
166      * @param {string} fileSystemPath
167      */
168     indexingDone: function(requestId, fileSystemPath)
169     {
170         WebInspector.fileSystemWorkspaceBinding.indexingDone(requestId, fileSystemPath);
171     },
172
173     /**
174      * @param {number} requestId
175      * @param {string} fileSystemPath
176      * @param {!Array.<string>} files
177      */
178     searchCompleted: function(requestId, fileSystemPath, files)
179     {
180         WebInspector.fileSystemWorkspaceBinding.searchCompleted(requestId, fileSystemPath, files);
181     },
182
183     /**
184      * @param {!InspectorFrontendAPI.ForwardedKeyboardEvent} event
185      */
186     keyEventUnhandled: function(event)
187     {
188         InspectorFrontendAPI._runOnceLoaded(function() {
189             WebInspector.forwardedEventHandler.keyEventReceived(event.type, event.keyIdentifier, event.keyCode, event.modifiers);
190         });
191     },
192
193     /**
194      * @param {!Array.<!Adb.Device>} targets
195      */
196     populateRemoteDevices: function(targets)
197     {
198         // FIXME: this needs to be changed for the sake of modularity.
199         WebInspector.devicesModel.populateRemoteDevices(targets);
200     },
201
202     /**
203      * @param {string} url
204      */
205     savedURL: function(url)
206     {
207         WebInspector.fileManager.savedURL(url);
208     },
209
210     /**
211      * @param {string} url
212      */
213     canceledSaveURL: function(url)
214     {
215         WebInspector.fileManager.canceledSaveURL(url);
216     },
217
218     /**
219      * @param {string} url
220      */
221     appendedToURL: function(url)
222     {
223         WebInspector.fileManager.appendedToURL(url);
224     },
225
226     /**
227      * @param {number} id
228      * @param {?string} error
229      */
230     embedderMessageAck: function(id, error)
231     {
232         InspectorFrontendHost.embedderMessageAck(id, error);
233     },
234
235     // Called from within front-end
236     ///////////////////////////////
237
238     loadCompleted: function()
239     {
240         InspectorFrontendAPI._isLoaded = true;
241         for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
242             InspectorFrontendAPI._pendingCommands[i]();
243         InspectorFrontendAPI._pendingCommands = [];
244         if (window.opener)
245             window.opener.postMessage(["loadCompleted"], "*");
246     },
247
248     // Implementation details
249     /////////////////////////
250
251     /**
252      * @param {function()} command
253      */
254     _runOnceLoaded: function(command)
255     {
256         if (InspectorFrontendAPI._isLoaded) {
257             command();
258             return;
259         }
260         InspectorFrontendAPI._pendingCommands.push(command);
261     }
262 }
263
264 /** @typedef {!Object.<{type: string, keyCode: (number|undefined), keyIdentifier: (string|undefined), modifiers: (number|undefined)}>} */
265 InspectorFrontendAPI.ForwardedKeyboardEvent;
266
267 if (top !== window) {
268     top.InspectorFrontendAPI = window.InspectorFrontendAPI;
269 }