Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / extensions / ExtensionPanel.js
blob313362eb98dbcd514765d2619d50b2a8cb0fea5c
1 /*
2 * Copyright (C) 2012 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
6 * met:
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.
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 /**
32 * @constructor
33 * @implements {WebInspector.Searchable}
34 * @extends {WebInspector.Panel}
35 * @param {!WebInspector.ExtensionServer} server
36 * @param {string} panelName
37 * @param {string} id
38 * @param {string} pageURL
40 WebInspector.ExtensionPanel = function(server, panelName, id, pageURL)
42 WebInspector.Panel.call(this, panelName);
43 this._server = server;
44 this._id = id;
45 this.setHideOnDetach();
46 this._panelToolbar = new WebInspector.Toolbar(this.element);
47 this._panelToolbar.element.classList.add("hidden");
49 this._searchableView = new WebInspector.SearchableView(this);
50 this._searchableView.show(this.element);
52 var extensionView = new WebInspector.ExtensionView(server, this._id, pageURL, "extension");
53 extensionView.show(this._searchableView.element);
54 this.setDefaultFocusedElement(extensionView.defaultFocusedElement());
57 WebInspector.ExtensionPanel.prototype = {
58 /**
59 * @override
60 * @return {!Element}
62 defaultFocusedElement: function()
64 return WebInspector.Widget.prototype.defaultFocusedElement.call(this);
67 /**
68 * @param {!WebInspector.ToolbarItem} item
70 addToolbarItem: function(item)
72 this._panelToolbar.element.classList.remove("hidden");
73 this._panelToolbar.appendToolbarItem(item);
76 /**
77 * @override
79 searchCanceled: function()
81 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.SearchAction.CancelSearch);
82 this._searchableView.updateSearchMatchesCount(0);
85 /**
86 * @override
87 * @return {!WebInspector.SearchableView}
89 searchableView: function()
91 return this._searchableView;
94 /**
95 * @override
96 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
97 * @param {boolean} shouldJump
98 * @param {boolean=} jumpBackwards
100 performSearch: function(searchConfig, shouldJump, jumpBackwards)
102 var query = searchConfig.query;
103 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.SearchAction.PerformSearch, query);
107 * @override
109 jumpToNextSearchResult: function()
111 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.SearchAction.NextSearchResult);
115 * @override
117 jumpToPreviousSearchResult: function()
119 this._server.notifySearchAction(this._id, WebInspector.extensionAPI.panels.SearchAction.PreviousSearchResult);
123 * @override
124 * @return {boolean}
126 supportsCaseSensitiveSearch: function()
128 return false;
132 * @override
133 * @return {boolean}
135 supportsRegexSearch: function()
137 return false;
140 __proto__: WebInspector.Panel.prototype
144 * @constructor
145 * @param {!WebInspector.ExtensionServer} server
146 * @param {string} id
147 * @param {string} iconURL
148 * @param {string=} tooltip
149 * @param {boolean=} disabled
151 WebInspector.ExtensionButton = function(server, id, iconURL, tooltip, disabled)
153 this._id = id;
155 this._toolbarButton = new WebInspector.ToolbarButton("", "extension");
156 this._toolbarButton.addEventListener("click", server.notifyButtonClicked.bind(server, this._id));
157 this.update(iconURL, tooltip, disabled);
160 WebInspector.ExtensionButton.prototype = {
162 * @param {string} iconURL
163 * @param {string=} tooltip
164 * @param {boolean=} disabled
166 update: function(iconURL, tooltip, disabled)
168 if (typeof iconURL === "string")
169 this._toolbarButton.setBackgroundImage(iconURL);
170 if (typeof tooltip === "string")
171 this._toolbarButton.setTitle(tooltip);
172 if (typeof disabled === "boolean")
173 this._toolbarButton.setEnabled(!disabled);
177 * @return {!WebInspector.ToolbarButton}
179 toolbarButton: function()
181 return this._toolbarButton;
186 * @constructor
187 * @extends {WebInspector.SidebarPane}
188 * @param {!WebInspector.ExtensionServer} server
189 * @param {string} panelName
190 * @param {string} title
191 * @param {string} id
193 WebInspector.ExtensionSidebarPane = function(server, panelName, title, id)
195 WebInspector.SidebarPane.call(this, title);
196 this._panelName = panelName;
197 this._server = server;
198 this._id = id;
201 WebInspector.ExtensionSidebarPane.prototype = {
203 * @return {string}
205 id: function()
207 return this._id;
211 * @return {string}
213 panelName: function()
215 return this._panelName;
219 * @param {!Object} object
220 * @param {string} title
221 * @param {function(?string=)} callback
223 setObject: function(object, title, callback)
225 this._createObjectPropertiesView();
226 this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title, callback);
230 * @param {string} expression
231 * @param {string} title
232 * @param {!Object} evaluateOptions
233 * @param {string} securityOrigin
234 * @param {function(?string=)} callback
236 setExpression: function(expression, title, evaluateOptions, securityOrigin, callback)
238 this._createObjectPropertiesView();
239 this._server.evaluate(expression, true, false, evaluateOptions, securityOrigin, this._onEvaluate.bind(this, title, callback));
243 * @param {string} url
245 setPage: function(url)
247 if (this._objectPropertiesView) {
248 this._objectPropertiesView.detach();
249 delete this._objectPropertiesView;
251 if (this._extensionView)
252 this._extensionView.detach(true);
254 this._extensionView = new WebInspector.ExtensionView(this._server, this._id, url, "extension fill");
255 this._extensionView.show(this.element);
257 if (!this.element.style.height)
258 this.setHeight("150px");
262 * @param {string} height
264 setHeight: function(height)
266 this.element.style.height = height;
270 * @param {string} title
271 * @param {function(?string=)} callback
272 * @param {?Protocol.Error} error
273 * @param {?WebInspector.RemoteObject} result
274 * @param {boolean=} wasThrown
276 _onEvaluate: function(title, callback, error, result, wasThrown)
278 if (error)
279 callback(error.toString());
280 else
281 this._setObject(/** @type {!WebInspector.RemoteObject} */ (result), title, callback);
284 _createObjectPropertiesView: function()
286 if (this._objectPropertiesView)
287 return;
288 if (this._extensionView) {
289 this._extensionView.detach(true);
290 delete this._extensionView;
292 this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this._server, this._id);
293 this._objectPropertiesView.show(this.element);
297 * @param {!WebInspector.RemoteObject} object
298 * @param {string} title
299 * @param {function(?string=)} callback
301 _setObject: function(object, title, callback)
303 // This may only happen if setPage() was called while we were evaluating the expression.
304 if (!this._objectPropertiesView) {
305 callback("operation cancelled");
306 return;
308 this._objectPropertiesView.element.removeChildren();
309 var section = new WebInspector.ObjectPropertiesSection(object, title);
310 if (!title)
311 section.titleLessMode();
312 section.expand();
313 section.editable = false;
314 this._objectPropertiesView.element.appendChild(section.element);
315 callback();
318 __proto__: WebInspector.SidebarPane.prototype