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 WebInspector.ExtensionPanel = function(id, label, iconURL, options) 32 { 33 this.toolbarItemLabel = label; 34 this._addStyleRule(".toolbar-item." + id + " .toolbar-icon", "background-image: url(" + iconURL + ");"); 35 WebInspector.Panel.call(this, id); 36 } 37 38 WebInspector.ExtensionPanel.prototype = { 39 get defaultFocusedElement() 40 { 41 return this.sidebarTreeElement || this.element; 42 }, 43 44 updateMainViewWidth: function(width) 45 { 46 this.bodyElement.style.left = width + "px"; 47 this.resize(); 48 }, 49 50 searchCanceled: function(startingNewSearch) 51 { 52 WebInspector.extensionServer.notifySearchAction(this._id, "cancelSearch"); 53 WebInspector.Panel.prototype.searchCanceled.apply(this, arguments); 54 }, 55 56 performSearch: function(query) 57 { 58 WebInspector.extensionServer.notifySearchAction(this._id, "performSearch", query); 59 WebInspector.Panel.prototype.performSearch.apply(this, arguments); 60 }, 61 62 jumpToNextSearchResult: function() 63 { 64 WebInspector.extensionServer.notifySearchAction(this._id, "nextSearchResult"); 65 WebInspector.Panel.prototype.jumpToNextSearchResult.call(this); 66 }, 67 68 jumpToPreviousSearchResult: function() 69 { 70 WebInspector.extensionServer.notifySearchAction(this._id, "previousSearchResult"); 71 WebInspector.Panel.prototype.jumpToPreviousSearchResult.call(this); 72 }, 73 74 _addStyleRule: function(selector, body) 75 { 76 var style = document.createElement("style"); 77 style.textContent = selector + " { " + body + " }"; 78 document.head.appendChild(style); 79 } 80 } 81 82 WebInspector.ExtensionPanel.prototype.__proto__ = WebInspector.Panel.prototype; 83 84 WebInspector.ExtensionSidebarPane = function(title, id) 85 { 86 WebInspector.SidebarPane.call(this, title); 87 this._id = id; 88 } 89 90 WebInspector.ExtensionSidebarPane.prototype = { 91 setObject: function(object, title) 92 { 93 this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title); 94 }, 95 96 setExpression: function(expression, title) 97 { 98 RuntimeAgent.evaluate(expression, "extension-watch", false, this._onEvaluate.bind(this, title)); 99 }, 100 101 setPage: function(url) 102 { 103 this.bodyElement.removeChildren(); 104 WebInspector.extensionServer.createClientIframe(this.bodyElement, url); 105 // TODO: Consider doing this upon load event. 106 WebInspector.extensionServer.notifyExtensionSidebarUpdated(this._id); 107 }, 108 109 _onEvaluate: function(title, error, result) 110 { 111 if (!error) 112 this._setObject(WebInspector.RemoteObject.fromPayload(result), title); 113 }, 114 115 _setObject: function(object, title) 116 { 117 this.bodyElement.removeChildren(); 118 var section = new WebInspector.ObjectPropertiesSection(object, title, null, true); 119 if (!title) 120 section.headerElement.addStyleClass("hidden"); 121 section.expanded = true; 122 this.bodyElement.appendChild(section.element); 123 WebInspector.extensionServer.notifyExtensionSidebarUpdated(this._id); 124 } 125 } 126 127 WebInspector.ExtensionSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype; 128