Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/DOMModel.js

Issue 2450663004: DevTools: do not allow using 'this' before call into super. (Closed)
Patch Set: rebaselined Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 15 matching lines...) Expand all
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 /** 32 /**
33 * @constructor 33 * @constructor
34 * @extends {WebInspector.SDKObject} 34 * @extends {WebInspector.SDKObject}
35 * @param {!WebInspector.DOMModel} domModel 35 * @param {!WebInspector.DOMModel} domModel
36 */
37 WebInspector.DOMNode = function(domModel)
38 {
39 WebInspector.SDKObject.call(this, domModel.target());
40 this._domModel = domModel;
41 };
42
43 /**
44 * @param {!WebInspector.DOMModel} domModel
36 * @param {?WebInspector.DOMDocument} doc 45 * @param {?WebInspector.DOMDocument} doc
37 * @param {boolean} isInShadowTree 46 * @param {boolean} isInShadowTree
38 * @param {!DOMAgent.Node} payload 47 * @param {!DOMAgent.Node} payload
48 * @return {!WebInspector.DOMNode}
39 */ 49 */
40 WebInspector.DOMNode = function(domModel, doc, isInShadowTree, payload) 50 WebInspector.DOMNode.create = function(domModel, doc, isInShadowTree, payload)
41 { 51 {
42 WebInspector.SDKObject.call(this, domModel.target()); 52 var node = new WebInspector.DOMNode(domModel);
43 this._domModel = domModel; 53 node._init(doc, isInShadowTree, payload);
44 this._agent = domModel._agent; 54 return node;
45 this.ownerDocument = doc; 55 }
46 this._isInShadowTree = isInShadowTree;
47
48 this.id = payload.nodeId;
49 domModel._idToDOMNode[this.id] = this;
50 this._nodeType = payload.nodeType;
51 this._nodeName = payload.nodeName;
52 this._localName = payload.localName;
53 this._nodeValue = payload.nodeValue;
54 this._pseudoType = payload.pseudoType;
55 this._shadowRootType = payload.shadowRootType;
56 this._frameOwnerFrameId = payload.frameId || null;
57 this._xmlVersion = payload.xmlVersion;
58
59 this._shadowRoots = [];
60
61 this._attributes = [];
62 this._attributesMap = {};
63 if (payload.attributes)
64 this._setAttributesPayload(payload.attributes);
65
66 /** @type {!Map<string, ?>} */
67 this._markers = new Map();
68 this._subtreeMarkerCount = 0;
69
70 this._childNodeCount = payload.childNodeCount || 0;
71 this._children = null;
72
73 this.nextSibling = null;
74 this.previousSibling = null;
75 this.firstChild = null;
76 this.lastChild = null;
77 this.parentNode = null;
78
79 if (payload.shadowRoots) {
80 for (var i = 0; i < payload.shadowRoots.length; ++i) {
81 var root = payload.shadowRoots[i];
82 var node = new WebInspector.DOMNode(this._domModel, this.ownerDocume nt, true, root);
83 this._shadowRoots.push(node);
84 node.parentNode = this;
85 }
86 }
87
88 if (payload.templateContent) {
89 this._templateContent = new WebInspector.DOMNode(this._domModel, this.ow nerDocument, true, payload.templateContent);
90 this._templateContent.parentNode = this;
91 }
92
93 if (payload.importedDocument) {
94 this._importedDocument = new WebInspector.DOMNode(this._domModel, this.o wnerDocument, true, payload.importedDocument);
95 this._importedDocument.parentNode = this;
96 }
97
98 if (payload.distributedNodes)
99 this._setDistributedNodePayloads(payload.distributedNodes);
100
101 if (payload.children)
102 this._setChildrenPayload(payload.children);
103
104 this._setPseudoElements(payload.pseudoElements);
105
106 if (payload.contentDocument) {
107 this._contentDocument = new WebInspector.DOMDocument(domModel, payload.c ontentDocument);
108 this._children = [this._contentDocument];
109 this._renumber();
110 }
111
112 if (this._nodeType === Node.ELEMENT_NODE) {
113 // HTML and BODY from internal iframes should not overwrite top-level on es.
114 if (this.ownerDocument && !this.ownerDocument.documentElement && this._n odeName === "HTML")
115 this.ownerDocument.documentElement = this;
116 if (this.ownerDocument && !this.ownerDocument.body && this._nodeName === "BODY")
117 this.ownerDocument.body = this;
118 } else if (this._nodeType === Node.DOCUMENT_TYPE_NODE) {
119 this.publicId = payload.publicId;
120 this.systemId = payload.systemId;
121 this.internalSubset = payload.internalSubset;
122 } else if (this._nodeType === Node.ATTRIBUTE_NODE) {
123 this.name = payload.name;
124 this.value = payload.value;
125 }
126 };
127 56
128 /** 57 /**
129 * @enum {string} 58 * @enum {string}
130 */ 59 */
131 WebInspector.DOMNode.PseudoElementNames = { 60 WebInspector.DOMNode.PseudoElementNames = {
132 Before: "before", 61 Before: "before",
133 After: "after" 62 After: "after"
134 }; 63 };
135 64
136 /** 65 /**
137 * @enum {string} 66 * @enum {string}
138 */ 67 */
139 WebInspector.DOMNode.ShadowRootTypes = { 68 WebInspector.DOMNode.ShadowRootTypes = {
140 UserAgent: "user-agent", 69 UserAgent: "user-agent",
141 Open: "open", 70 Open: "open",
142 Closed: "closed" 71 Closed: "closed"
143 }; 72 };
144 73
145 /** @typedef {{name: string, value: string, _node: WebInspector.DOMNode}} */ 74 /** @typedef {{name: string, value: string, _node: WebInspector.DOMNode}} */
146 WebInspector.DOMNode.Attribute; 75 WebInspector.DOMNode.Attribute;
147 76
148 WebInspector.DOMNode.prototype = { 77 WebInspector.DOMNode.prototype = {
149 /** 78 /**
79 * @param {?WebInspector.DOMDocument} doc
80 * @param {boolean} isInShadowTree
81 * @param {!DOMAgent.Node} payload
82 */
83 _init: function(doc, isInShadowTree, payload)
84 {
85 this._agent = this._domModel._agent;
86 this.ownerDocument = doc;
87 this._isInShadowTree = isInShadowTree;
88
89 this.id = payload.nodeId;
90 this._domModel._idToDOMNode[this.id] = this;
91 this._nodeType = payload.nodeType;
92 this._nodeName = payload.nodeName;
93 this._localName = payload.localName;
94 this._nodeValue = payload.nodeValue;
95 this._pseudoType = payload.pseudoType;
96 this._shadowRootType = payload.shadowRootType;
97 this._frameOwnerFrameId = payload.frameId || null;
98 this._xmlVersion = payload.xmlVersion;
99
100 this._shadowRoots = [];
101
102 this._attributes = [];
103 this._attributesMap = {};
104 if (payload.attributes)
105 this._setAttributesPayload(payload.attributes);
106
107 /** @type {!Map<string, ?>} */
108 this._markers = new Map();
109 this._subtreeMarkerCount = 0;
110
111 this._childNodeCount = payload.childNodeCount || 0;
112 this._children = null;
113
114 this.nextSibling = null;
115 this.previousSibling = null;
116 this.firstChild = null;
117 this.lastChild = null;
118 this.parentNode = null;
119
120 if (payload.shadowRoots) {
121 for (var i = 0; i < payload.shadowRoots.length; ++i) {
122 var root = payload.shadowRoots[i];
123 var node = WebInspector.DOMNode.create(this._domModel, this.owne rDocument, true, root);
124 this._shadowRoots.push(node);
125 node.parentNode = this;
126 }
127 }
128
129 if (payload.templateContent) {
130 this._templateContent = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, true, payload.templateContent);
131 this._templateContent.parentNode = this;
132 }
133
134 if (payload.importedDocument) {
135 this._importedDocument = WebInspector.DOMNode.create(this._domModel, this.ownerDocument, true, payload.importedDocument);
136 this._importedDocument.parentNode = this;
137 }
138
139 if (payload.distributedNodes)
140 this._setDistributedNodePayloads(payload.distributedNodes);
141
142 if (payload.children)
143 this._setChildrenPayload(payload.children);
144
145 this._setPseudoElements(payload.pseudoElements);
146
147 if (payload.contentDocument) {
148 this._contentDocument = new WebInspector.DOMDocument(this._domModel, payload.contentDocument);
149 this._children = [this._contentDocument];
150 this._renumber();
151 }
152
153 if (this._nodeType === Node.ELEMENT_NODE) {
154 // HTML and BODY from internal iframes should not overwrite top-leve l ones.
155 if (this.ownerDocument && !this.ownerDocument.documentElement && thi s._nodeName === "HTML")
156 this.ownerDocument.documentElement = this;
157 if (this.ownerDocument && !this.ownerDocument.body && this._nodeName === "BODY")
158 this.ownerDocument.body = this;
159 } else if (this._nodeType === Node.DOCUMENT_TYPE_NODE) {
160 this.publicId = payload.publicId;
161 this.systemId = payload.systemId;
162 this.internalSubset = payload.internalSubset;
163 } else if (this._nodeType === Node.ATTRIBUTE_NODE) {
164 this.name = payload.name;
165 this.value = payload.value;
166 }
167 },
168
169 /**
150 * @return {!WebInspector.DOMModel} 170 * @return {!WebInspector.DOMModel}
151 */ 171 */
152 domModel: function() 172 domModel: function()
153 { 173 {
154 return this._domModel; 174 return this._domModel;
155 }, 175 },
156 176
157 /** 177 /**
158 * @return {?Array.<!WebInspector.DOMNode>} 178 * @return {?Array.<!WebInspector.DOMNode>}
159 */ 179 */
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 return attributesChanged; 655 return attributesChanged;
636 }, 656 },
637 657
638 /** 658 /**
639 * @param {!WebInspector.DOMNode} prev 659 * @param {!WebInspector.DOMNode} prev
640 * @param {!DOMAgent.Node} payload 660 * @param {!DOMAgent.Node} payload
641 * @return {!WebInspector.DOMNode} 661 * @return {!WebInspector.DOMNode}
642 */ 662 */
643 _insertChild: function(prev, payload) 663 _insertChild: function(prev, payload)
644 { 664 {
645 var node = new WebInspector.DOMNode(this._domModel, this.ownerDocument, this._isInShadowTree, payload); 665 var node = WebInspector.DOMNode.create(this._domModel, this.ownerDocumen t, this._isInShadowTree, payload);
646 this._children.splice(this._children.indexOf(prev) + 1, 0, node); 666 this._children.splice(this._children.indexOf(prev) + 1, 0, node);
647 this._renumber(); 667 this._renumber();
648 return node; 668 return node;
649 }, 669 },
650 670
651 /** 671 /**
652 * @param {!WebInspector.DOMNode} node 672 * @param {!WebInspector.DOMNode} node
653 */ 673 */
654 _removeChild: function(node) 674 _removeChild: function(node)
655 { 675 {
(...skipping 20 matching lines...) Expand all
676 */ 696 */
677 _setChildrenPayload: function(payloads) 697 _setChildrenPayload: function(payloads)
678 { 698 {
679 // We set children in the constructor. 699 // We set children in the constructor.
680 if (this._contentDocument) 700 if (this._contentDocument)
681 return; 701 return;
682 702
683 this._children = []; 703 this._children = [];
684 for (var i = 0; i < payloads.length; ++i) { 704 for (var i = 0; i < payloads.length; ++i) {
685 var payload = payloads[i]; 705 var payload = payloads[i];
686 var node = new WebInspector.DOMNode(this._domModel, this.ownerDocume nt, this._isInShadowTree, payload); 706 var node = WebInspector.DOMNode.create(this._domModel, this.ownerDoc ument, this._isInShadowTree, payload);
687 this._children.push(node); 707 this._children.push(node);
688 } 708 }
689 this._renumber(); 709 this._renumber();
690 }, 710 },
691 711
692 /** 712 /**
693 * @param {!Array.<!DOMAgent.Node>|undefined} payloads 713 * @param {!Array.<!DOMAgent.Node>|undefined} payloads
694 */ 714 */
695 _setPseudoElements: function(payloads) 715 _setPseudoElements: function(payloads)
696 { 716 {
697 this._pseudoElements = new Map(); 717 this._pseudoElements = new Map();
698 if (!payloads) 718 if (!payloads)
699 return; 719 return;
700 720
701 for (var i = 0; i < payloads.length; ++i) { 721 for (var i = 0; i < payloads.length; ++i) {
702 var node = new WebInspector.DOMNode(this._domModel, this.ownerDocume nt, this._isInShadowTree, payloads[i]); 722 var node = WebInspector.DOMNode.create(this._domModel, this.ownerDoc ument, this._isInShadowTree, payloads[i]);
703 node.parentNode = this; 723 node.parentNode = this;
704 this._pseudoElements.set(node.pseudoType(), node); 724 this._pseudoElements.set(node.pseudoType(), node);
705 } 725 }
706 }, 726 },
707 727
708 /** 728 /**
709 * @param {!Array.<!DOMAgent.BackendNode>} payloads 729 * @param {!Array.<!DOMAgent.BackendNode>} payloads
710 */ 730 */
711 _setDistributedNodePayloads: function(payloads) 731 _setDistributedNodePayloads: function(payloads)
712 { 732 {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 }; 1089 };
1070 1090
1071 /** 1091 /**
1072 * @extends {WebInspector.DOMNode} 1092 * @extends {WebInspector.DOMNode}
1073 * @constructor 1093 * @constructor
1074 * @param {!WebInspector.DOMModel} domModel 1094 * @param {!WebInspector.DOMModel} domModel
1075 * @param {!DOMAgent.Node} payload 1095 * @param {!DOMAgent.Node} payload
1076 */ 1096 */
1077 WebInspector.DOMDocument = function(domModel, payload) 1097 WebInspector.DOMDocument = function(domModel, payload)
1078 { 1098 {
1079 WebInspector.DOMNode.call(this, domModel, this, false, payload); 1099 WebInspector.DOMNode.call(this, domModel);
1100 this._init(this, false, payload);
1080 this.documentURL = payload.documentURL || ""; 1101 this.documentURL = payload.documentURL || "";
1081 this.baseURL = payload.baseURL || ""; 1102 this.baseURL = payload.baseURL || "";
1082 this._listeners = {}; 1103 this._listeners = {};
1083 }; 1104 };
1084 1105
1085 WebInspector.DOMDocument.prototype = { 1106 WebInspector.DOMDocument.prototype = {
1086 __proto__: WebInspector.DOMNode.prototype 1107 __proto__: WebInspector.DOMNode.prototype
1087 }; 1108 };
1088 1109
1089 /** 1110 /**
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 }, 1487 },
1467 1488
1468 /** 1489 /**
1469 * @param {!DOMAgent.Node} payload 1490 * @param {!DOMAgent.Node} payload
1470 */ 1491 */
1471 _setDetachedRoot: function(payload) 1492 _setDetachedRoot: function(payload)
1472 { 1493 {
1473 if (payload.nodeName === "#document") 1494 if (payload.nodeName === "#document")
1474 new WebInspector.DOMDocument(this, payload); 1495 new WebInspector.DOMDocument(this, payload);
1475 else 1496 else
1476 new WebInspector.DOMNode(this, null, false, payload); 1497 WebInspector.DOMNode.create(this, null, false, payload);
1477 }, 1498 },
1478 1499
1479 /** 1500 /**
1480 * @param {!DOMAgent.NodeId} parentId 1501 * @param {!DOMAgent.NodeId} parentId
1481 * @param {!Array.<!DOMAgent.Node>} payloads 1502 * @param {!Array.<!DOMAgent.Node>} payloads
1482 */ 1503 */
1483 _setChildNodes: function(parentId, payloads) 1504 _setChildNodes: function(parentId, payloads)
1484 { 1505 {
1485 if (!parentId && payloads.length) { 1506 if (!parentId && payloads.length) {
1486 this._setDetachedRoot(payloads[0]); 1507 this._setDetachedRoot(payloads[0]);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 1555
1535 /** 1556 /**
1536 * @param {!DOMAgent.NodeId} hostId 1557 * @param {!DOMAgent.NodeId} hostId
1537 * @param {!DOMAgent.Node} root 1558 * @param {!DOMAgent.Node} root
1538 */ 1559 */
1539 _shadowRootPushed: function(hostId, root) 1560 _shadowRootPushed: function(hostId, root)
1540 { 1561 {
1541 var host = this._idToDOMNode[hostId]; 1562 var host = this._idToDOMNode[hostId];
1542 if (!host) 1563 if (!host)
1543 return; 1564 return;
1544 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root ); 1565 var node = WebInspector.DOMNode.create(this, host.ownerDocument, true, r oot);
1545 node.parentNode = host; 1566 node.parentNode = host;
1546 this._idToDOMNode[node.id] = node; 1567 this._idToDOMNode[node.id] = node;
1547 host._shadowRoots.unshift(node); 1568 host._shadowRoots.unshift(node);
1548 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); 1569 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node);
1549 this._scheduleMutationEvent(node); 1570 this._scheduleMutationEvent(node);
1550 }, 1571 },
1551 1572
1552 /** 1573 /**
1553 * @param {!DOMAgent.NodeId} hostId 1574 * @param {!DOMAgent.NodeId} hostId
1554 * @param {!DOMAgent.NodeId} rootId 1575 * @param {!DOMAgent.NodeId} rootId
(...skipping 14 matching lines...) Expand all
1569 1590
1570 /** 1591 /**
1571 * @param {!DOMAgent.NodeId} parentId 1592 * @param {!DOMAgent.NodeId} parentId
1572 * @param {!DOMAgent.Node} pseudoElement 1593 * @param {!DOMAgent.Node} pseudoElement
1573 */ 1594 */
1574 _pseudoElementAdded: function(parentId, pseudoElement) 1595 _pseudoElementAdded: function(parentId, pseudoElement)
1575 { 1596 {
1576 var parent = this._idToDOMNode[parentId]; 1597 var parent = this._idToDOMNode[parentId];
1577 if (!parent) 1598 if (!parent)
1578 return; 1599 return;
1579 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p seudoElement); 1600 var node = WebInspector.DOMNode.create(this, parent.ownerDocument, false , pseudoElement);
1580 node.parentNode = parent; 1601 node.parentNode = parent;
1581 this._idToDOMNode[node.id] = node; 1602 this._idToDOMNode[node.id] = node;
1582 console.assert(!parent._pseudoElements.get(node.pseudoType())); 1603 console.assert(!parent._pseudoElements.get(node.pseudoType()));
1583 parent._pseudoElements.set(node.pseudoType(), node); 1604 parent._pseudoElements.set(node.pseudoType(), node);
1584 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); 1605 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node);
1585 this._scheduleMutationEvent(node); 1606 this._scheduleMutationEvent(node);
1586 }, 1607 },
1587 1608
1588 /** 1609 /**
1589 * @param {!DOMAgent.NodeId} parentId 1610 * @param {!DOMAgent.NodeId} parentId
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 }; 2331 };
2311 2332
2312 /** 2333 /**
2313 * @param {!WebInspector.Target} target 2334 * @param {!WebInspector.Target} target
2314 * @return {?WebInspector.DOMModel} 2335 * @return {?WebInspector.DOMModel}
2315 */ 2336 */
2316 WebInspector.DOMModel.fromTarget = function(target) 2337 WebInspector.DOMModel.fromTarget = function(target)
2317 { 2338 {
2318 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); 2339 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel));
2319 }; 2340 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698