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