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
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.
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);
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 = {
57 * @param {!WebInspector.Event} event
59 _setNode: function(event
)
61 this._node
= /** @type {?WebInspector.DOMNode} */(event
.data
);
68 * @return {!Promise.<?>}
72 if (this._lastRequestedNode
) {
73 this._lastRequestedNode
.target().runtimeAgent().releaseObjectGroup(WebInspector
.PropertiesWidget
._objectGroupName
);
74 delete this._lastRequestedNode
;
78 this.element
.removeChildren();
80 return Promise
.resolve();
83 this._lastRequestedNode
= this._node
;
84 return this._node
.resolveToObjectPromise(WebInspector
.PropertiesWidget
._objectGroupName
)
85 .then(nodeResolved
.bind(this))
88 * @param {?WebInspector.RemoteObject} object
89 * @this {WebInspector.PropertiesWidget}
91 function nodeResolved(object
)
97 * @suppressReceiverCheck
103 var result
= { __proto__
: null };
106 result
[counter
++] = proto
;
107 proto
= proto
.__proto__
;
111 var promise
= object
.callFunctionPromise(protoList
).then(nodePrototypesReady
.bind(this));
117 * @param {!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefined)}} result
118 * @this {WebInspector.PropertiesWidget}
120 function nodePrototypesReady(result
)
122 if (!result
.object
|| result
.wasThrown
)
125 var promise
= result
.object
.getOwnPropertiesPromise().then(fillSection
.bind(this));
126 result
.object
.release();
131 * @param {!{properties: ?Array.<!WebInspector.RemoteObjectProperty>, internalProperties: ?Array.<!WebInspector.RemoteObjectProperty>}} result
132 * @this {WebInspector.PropertiesWidget}
134 function fillSection(result
)
136 if (!result
|| !result
.properties
)
139 var properties
= result
.properties
;
141 var sections
= this.sections
|| [];
142 for (var i
= 0; i
< sections
.length
; ++i
)
143 expanded
.push(sections
[i
].expanded
);
145 this.element
.removeChildren();
148 // Get array of property user-friendly names.
149 for (var i
= 0; i
< properties
.length
; ++i
) {
150 if (!parseInt(properties
[i
].name
, 10))
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])
166 * @param {!WebInspector.Event} event
168 _onNodeChange: function(event
)
172 var data
= event
.data
;
173 var node
= /** @type {!WebInspector.DOMNode} */ (data
instanceof WebInspector
.DOMNode
? data
: data
.node
);
174 if (this._node
!== node
)
179 __proto__
: WebInspector
.ThrottledWidget
.prototype