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.
33 * @extends {WebInspector.View}
35 * @param {Element} parent
37 * @param {string} className
39 WebInspector.ExtensionView = function(id, parent, src, className)
41 WebInspector.View.call(this);
44 this._iframe = document.createElement("iframe");
45 this._iframe.addEventListener("load", this._onLoad.bind(this), false);
46 this._iframe.src = src;
47 this._iframe.className = className;
49 this.element.appendChild(this._iframe);
53 WebInspector.ExtensionView.prototype = {
56 if (typeof this._frameIndex === "number")
57 WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
62 if (typeof this._frameIndex === "number")
63 WebInspector.extensionServer.notifyViewHidden(this._id);
68 this._frameIndex = Array.prototype.indexOf.call(window.frames, this._iframe.contentWindow);
70 WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
74 WebInspector.ExtensionView.prototype.__proto__ = WebInspector.View.prototype;
78 * @extends {WebInspector.View}
81 WebInspector.ExtensionNotifierView = function(id)
83 WebInspector.View.call(this);
88 WebInspector.ExtensionNotifierView.prototype = {
91 WebInspector.extensionServer.notifyViewShown(this._id);
96 WebInspector.extensionServer.notifyViewHidden(this._id);
100 WebInspector.ExtensionNotifierView.prototype.__proto__ = WebInspector.View.prototype;
104 * @extends {WebInspector.Panel}
106 * @param {string} label
107 * @param {string} iconURL
109 WebInspector.ExtensionPanel = function(id, label, pageURL, iconURL)
111 WebInspector.Panel.call(this, id);
112 this.setHideOnDetach();
113 this._toolbarItemLabel = label;
114 this._statusBarItems = [];
117 this._addStyleRule(".toolbar-item." + id + " .toolbar-icon", "background-image: url(" + iconURL + ");");
118 this._addStyleRule(".toolbar-small .toolbar-item." + id + " .toolbar-icon", "background-position-x: -32px;");
120 new WebInspector.ExtensionView(id, this.element, pageURL, "extension panel");
123 WebInspector.ExtensionPanel.prototype = {
124 get toolbarItemLabel()
126 return this._toolbarItemLabel;
129 get defaultFocusedElement()
131 return this.sidebarTreeElement || this.element;
136 return this._statusBarItems;
140 * @param {Element} element
142 addStatusBarItem: function(element)
144 this._statusBarItems.push(element);
147 searchCanceled: function(startingNewSearch)
149 WebInspector.extensionServer.notifySearchAction(this._id, "cancelSearch");
150 WebInspector.Panel.prototype.searchCanceled.apply(this, arguments);
153 performSearch: function(query)
155 WebInspector.extensionServer.notifySearchAction(this._id, "performSearch", query);
156 WebInspector.Panel.prototype.performSearch.apply(this, arguments);
159 jumpToNextSearchResult: function()
161 WebInspector.extensionServer.notifySearchAction(this._id, "nextSearchResult");
162 WebInspector.Panel.prototype.jumpToNextSearchResult.call(this);
165 jumpToPreviousSearchResult: function()
167 WebInspector.extensionServer.notifySearchAction(this._id, "previousSearchResult");
168 WebInspector.Panel.prototype.jumpToPreviousSearchResult.call(this);
171 _addStyleRule: function(selector, body)
173 var style = document.createElement("style");
174 style.textContent = selector + " { " + body + " }";
175 document.head.appendChild(style);
179 WebInspector.ExtensionPanel.prototype.__proto__ = WebInspector.Panel.prototype;
184 * @param {string} iconURL
185 * @param {string=} tooltip
186 * @param {boolean=} disabled
188 WebInspector.ExtensionButton = function(id, iconURL, tooltip, disabled)
191 this.element = document.createElement("button");
192 this.element.className = "status-bar-item extension";
193 this.element.addEventListener("click", this._onClicked.bind(this), false);
194 this.update(iconURL, tooltip, disabled);
197 WebInspector.ExtensionButton.prototype = {
199 * @param {string} iconURL
200 * @param {string=} tooltip
201 * @param {boolean=} disabled
203 update: function(iconURL, tooltip, disabled)
205 if (typeof iconURL === "string")
206 this.element.style.backgroundImage = "url(" + iconURL + ")";
207 if (typeof tooltip === "string")
208 this.element.title = tooltip;
209 if (typeof disabled === "boolean")
210 this.element.disabled = disabled;
213 _onClicked: function()
215 WebInspector.extensionServer.notifyButtonClicked(this._id);
221 * @extends {WebInspector.SidebarPane}
222 * @param {string} title
225 WebInspector.ExtensionSidebarPane = function(title, id)
227 WebInspector.SidebarPane.call(this, title);
231 WebInspector.ExtensionSidebarPane.prototype = {
233 * @param {Object} object
234 * @param {string} title
235 * @param {function(?string=)} callback
237 setObject: function(object, title, callback)
239 this._createObjectPropertiesView();
240 this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title, callback);
244 * @param {string} expression
245 * @param {string} title
246 * @param {function(?string=)} callback
248 setExpression: function(expression, title, callback)
250 this._createObjectPropertiesView();
251 RuntimeAgent.evaluate(expression, "extension-watch", true, undefined, undefined, undefined, this._onEvaluate.bind(this, title, callback));
255 * @param {string} url
257 setPage: function(url)
259 if (this._objectPropertiesView) {
260 this._objectPropertiesView.detach();
261 delete this._objectPropertiesView;
263 if (this._extensionView)
264 this._extensionView.detach(true);
266 this._extensionView = new WebInspector.ExtensionView(this._id, this.bodyElement, url, "extension");
270 * @param {string} height
272 setHeight: function(height)
274 this.bodyElement.style.height = height;
278 * @param {string} title
279 * @param {function(?string=)} callback
280 * @param {Protocol.Error} error
281 * @param {Object} result
282 * @param {boolean} wasThrown
284 _onEvaluate: function(title, callback, error, result, wasThrown)
287 callback(error.toString());
289 this._setObject(WebInspector.RemoteObject.fromPayload(result), title, callback);
292 _createObjectPropertiesView: function()
294 if (this._objectPropertiesView)
296 if (this._extensionView) {
297 this._extensionView.detach(true);
298 delete this._extensionView;
300 this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this._id);
301 this._objectPropertiesView.show(this.bodyElement);
305 * @param {Object} object
306 * @param {string} title
307 * @param {function(?string=)} callback
309 _setObject: function(object, title, callback)
311 // This may only happen if setPage() was called while we were evaluating the expression.
312 if (!this._objectPropertiesView) {
313 callback("operation cancelled");
316 this._objectPropertiesView.element.removeChildren();
317 var section = new WebInspector.ObjectPropertiesSection(object, title);
319 section.headerElement.addStyleClass("hidden");
320 section.expanded = true;
321 section.editable = false;
322 this._objectPropertiesView.element.appendChild(section.element);
327 WebInspector.ExtensionSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;