Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / elements / PropertiesWidget.js
blob6b4578c0a69ce46e0335de054bdf62c547f77ec1
1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2014 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 /**
31 * @constructor
32 * @extends {WebInspector.ThrottledWidget}
34 WebInspector.PropertiesWidget = function()
36 WebInspector.ThrottledWidget.call(this);
38 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.AttrModified, this._onNodeChange, this);
39 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.AttrRemoved, this._onNodeChange, this);
40 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.CharacterDataModified, this._onNodeChange, this);
41 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspector.DOMModel.Events.ChildNodeCountUpdated, this._onNodeChange, this);
42 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._setNode, this);
45 /**
46 * @return {!WebInspector.ElementsSidebarViewWrapperPane}
48 WebInspector.PropertiesWidget.createSidebarWrapper = function()
50 return new WebInspector.ElementsSidebarViewWrapperPane(WebInspector.UIString("Properties"), new WebInspector.PropertiesWidget());
53 WebInspector.PropertiesWidget._objectGroupName = "properties-sidebar-pane";
55 WebInspector.PropertiesWidget.prototype = {
56 /**
57 * @param {!WebInspector.Event} event
59 _setNode: function(event)
61 this._node = /** @type {?WebInspector.DOMNode} */(event.data);
62 this.update();
65 /**
66 * @override
67 * @protected
68 * @return {!Promise.<?>}
70 doUpdate: function()
72 if (this._lastRequestedNode) {
73 this._lastRequestedNode.target().runtimeAgent().releaseObjectGroup(WebInspector.PropertiesWidget._objectGroupName);
74 delete this._lastRequestedNode;
77 if (!this._node) {
78 this.element.removeChildren();
79 this.sections = [];
80 return Promise.resolve();
83 this._lastRequestedNode = this._node;
84 return this._node.resolveToObjectPromise(WebInspector.PropertiesWidget._objectGroupName)
85 .then(nodeResolved.bind(this))
87 /**
88 * @param {?WebInspector.RemoteObject} object
89 * @this {WebInspector.PropertiesWidget}
91 function nodeResolved(object)
93 if (!object)
94 return;
96 /**
97 * @suppressReceiverCheck
98 * @this {*}
100 function protoList()
102 var proto = this;
103 var result = { __proto__: null };
104 var counter = 1;
105 while (proto) {
106 result[counter++] = proto;
107 proto = proto.__proto__;
109 return result;
111 var promise = object.callFunctionPromise(protoList).then(nodePrototypesReady.bind(this));
112 object.release();
113 return promise;
117 * @param {!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)}} result
118 * @this {WebInspector.PropertiesWidget}
120 function nodePrototypesReady(result)
122 if (!result.object || result.wasThrown)
123 return;
125 var promise = result.object.getOwnPropertiesPromise().then(fillSection.bind(this));
126 result.object.release();
127 return promise;
131 * @param {!{properties: ?Array.<!WebInspector.RemoteObjectProperty>, internalProperties: ?Array.<!WebInspector.RemoteObjectProperty>}} result
132 * @this {WebInspector.PropertiesWidget}
134 function fillSection(result)
136 if (!result || !result.properties)
137 return;
139 var properties = result.properties;
140 var expanded = [];
141 var sections = this.sections || [];
142 for (var i = 0; i < sections.length; ++i)
143 expanded.push(sections[i].expanded);
145 this.element.removeChildren();
146 this.sections = [];
148 // Get array of property user-friendly names.
149 for (var i = 0; i < properties.length; ++i) {
150 if (!parseInt(properties[i].name, 10))
151 continue;
152 var property = properties[i].value;
153 var title = property.description;
154 title = title.replace(/Prototype$/, "");
155 var section = new WebInspector.ObjectPropertiesSection(property, title);
156 section.element.classList.add("properties-widget-section");
157 this.sections.push(section);
158 this.element.appendChild(section.element);
159 if (expanded[this.sections.length - 1])
160 section.expand();
166 * @param {!WebInspector.Event} event
168 _onNodeChange: function(event)
170 if (!this._node)
171 return;
172 var data = event.data;
173 var node = /** @type {!WebInspector.DOMNode} */ (data instanceof WebInspector.DOMNode ? data : data.node);
174 if (this._node !== node)
175 return;
176 this.update();
179 __proto__: WebInspector.ThrottledWidget.prototype