diff options
Diffstat (limited to 'Source/WebCore/inspector/front-end/DOMAgent.js')
-rw-r--r-- | Source/WebCore/inspector/front-end/DOMAgent.js | 134 |
1 files changed, 79 insertions, 55 deletions
diff --git a/Source/WebCore/inspector/front-end/DOMAgent.js b/Source/WebCore/inspector/front-end/DOMAgent.js index 3645bb9..cb28aba 100644 --- a/Source/WebCore/inspector/front-end/DOMAgent.js +++ b/Source/WebCore/inspector/front-end/DOMAgent.js @@ -223,12 +223,11 @@ WebInspector.DOMNode.prototype = { } } -WebInspector.DOMDocument = function(domAgent, defaultView, payload) +WebInspector.DOMDocument = function(domAgent, payload) { WebInspector.DOMNode.call(this, this, payload); this._listeners = {}; this._domAgent = domAgent; - this.defaultView = defaultView; } WebInspector.DOMDocument.prototype = { @@ -269,44 +268,48 @@ WebInspector.DOMDocument.prototype = { WebInspector.DOMDocument.prototype.__proto__ = WebInspector.DOMNode.prototype; - -WebInspector.DOMWindow = function(domAgent) -{ - this._domAgent = domAgent; +WebInspector.DOMAgent = function() { + this._idToDOMNode = null; + this._document = null; + InspectorBackend.registerDomainDispatcher("DOM", new WebInspector.DOMDispatcher(this)); } -WebInspector.DOMWindow.prototype = { - get document() - { - return this._domAgent.document; - }, - - get Node() +WebInspector.DOMAgent.prototype = { + requestDocument: function(callback) { - return WebInspector.DOMNode; + if (this._document) { + if (callback) + callback(this._document); + } else + this._documentUpdated(callback); }, - get Element() + pushNodeToFrontend: function(objectId, callback) { - return WebInspector.DOMNode; + function mycallback() + { + if (this._document) + DOMAgent.pushNodeToFrontend(objectId, callback); + else { + if (callback) + callback(0); + } + } + this.requestDocument(mycallback.bind(this)); }, - Object: function() - { - } -} - -WebInspector.DOMAgent = function() { - this._window = new WebInspector.DOMWindow(this); - this._idToDOMNode = null; - this.document = null; - InspectorBackend.registerDomainDispatcher("DOM", new WebInspector.DOMDispatcher(this)); -} - -WebInspector.DOMAgent.prototype = { - get domWindow() + pushNodeByPathToFrontend: function(path, callback) { - return this._window; + function mycallback() + { + if (this._document) + DOMAgent.pushNodeByPathToFrontend(path, callback); + else { + if (callback) + callback(0); + } + } + this.requestDocument(mycallback.bind(this)); }, getChildNodesAsync: function(parent, callback) @@ -319,25 +322,25 @@ WebInspector.DOMAgent.prototype = { function mycallback() { callback(parent.children); } - InspectorBackend.getChildNodes(parent.id, mycallback); + DOMAgent.getChildNodes(parent.id, mycallback); }, setAttributeAsync: function(node, name, value, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorBackend.setAttribute(node.id, name, value, mycallback); + DOMAgent.setAttribute(node.id, name, value, mycallback); }, removeAttributeAsync: function(node, name, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorBackend.removeAttribute(node.id, name, mycallback); + DOMAgent.removeAttribute(node.id, name, mycallback); }, setTextNodeValueAsync: function(node, text, callback) { var mycallback = this._didApplyDomChange.bind(this, node, callback); - InspectorBackend.setTextNodeValue(node.id, text, mycallback); + DOMAgent.setTextNodeValue(node.id, text, mycallback); }, _didApplyDomChange: function(node, callback, success) @@ -356,7 +359,7 @@ WebInspector.DOMAgent.prototype = { var node = this._idToDOMNode[nodeId]; node._setAttributesPayload(attrsArray); var event = {target: node}; - this.document._fireDomEvent("DOMAttrModified", event); + this._document._fireDomEvent("DOMAttrModified", event); }, _characterDataModified: function(nodeId, newValue) @@ -365,7 +368,7 @@ WebInspector.DOMAgent.prototype = { node._nodeValue = newValue; node.textContent = newValue; var event = { target : node }; - this.document._fireDomEvent("DOMCharacterDataModified", event); + this._document._fireDomEvent("DOMCharacterDataModified", event); }, nodeForId: function(nodeId) @@ -373,27 +376,43 @@ WebInspector.DOMAgent.prototype = { return this._idToDOMNode[nodeId]; }, + _documentUpdated: function(callback) + { + function mycallback(root) + { + this._setDocument(root); + if (callback) + callback(this._document); + } + DOMAgent.getDocument(mycallback.bind(this)); + }, + _setDocument: function(payload) { this._idToDOMNode = {}; if (payload && "id" in payload) { - this.document = new WebInspector.DOMDocument(this, this._window, payload); - this._idToDOMNode[payload.id] = this.document; - this._bindNodes(this.document.children); + this._document = new WebInspector.DOMDocument(this, payload); + this._idToDOMNode[payload.id] = this._document; + this._bindNodes(this._document.children); WebInspector.breakpointManager.restoreDOMBreakpoints(); } else - this.document = null; - WebInspector.panels.elements.setDocument(this.document); + this._document = null; + WebInspector.panels.elements.setDocument(this._document); }, _setDetachedRoot: function(payload) { - var root = new WebInspector.DOMNode(this.document, payload); + var root = new WebInspector.DOMNode(this._document, payload); this._idToDOMNode[payload.id] = root; }, _setChildNodes: function(parentId, payloads) { + if (!parentId && payloads.length) { + this._setDetachedRoot(payloads[0]); + return; + } + var parent = this._idToDOMNode[parentId]; parent._setChildrenPayload(payloads); this._bindNodes(parent.children); @@ -426,7 +445,7 @@ WebInspector.DOMAgent.prototype = { var node = parent._insertChild(prev, payload); this._idToDOMNode[node.id] = node; var event = { target : node, relatedNode : parent }; - this.document._fireDomEvent("DOMNodeInserted", event); + this._document._fireDomEvent("DOMNodeInserted", event); }, _childNodeRemoved: function(parentId, nodeId) @@ -435,7 +454,7 @@ WebInspector.DOMAgent.prototype = { var node = this._idToDOMNode[nodeId]; parent.removeChild_(node); var event = { target : node, relatedNode : parent }; - this.document._fireDomEvent("DOMNodeRemoved", event); + this._document._fireDomEvent("DOMNodeRemoved", event); delete this._idToDOMNode[nodeId]; this._removeBreakpoints(node); }, @@ -457,9 +476,9 @@ WebInspector.DOMDispatcher = function(domAgent) } WebInspector.DOMDispatcher.prototype = { - setDocument: function(payload) + documentUpdated: function() { - this._domAgent._setDocument(payload); + this._domAgent._documentUpdated(); }, attributesUpdated: function(nodeId, attrsArray) @@ -477,11 +496,6 @@ WebInspector.DOMDispatcher.prototype = { this._domAgent._setChildNodes(parentId, payloads); }, - setDetachedRoot: function(payload) - { - this._domAgent._setDetachedRoot(payload); - }, - childNodeCountUpdated: function(nodeId, newValue) { this._domAgent._childNodeCountUpdated(nodeId, newValue); @@ -495,6 +509,16 @@ WebInspector.DOMDispatcher.prototype = { childNodeRemoved: function(parentId, nodeId) { this._domAgent._childNodeRemoved(parentId, nodeId); + }, + + inspectElementRequested: function(nodeId) + { + WebInspector.updateFocusedNode(nodeId); + }, + + addNodesToSearchResult: function(nodeIds) + { + WebInspector.panels.elements.addNodesToSearchResult(nodeIds); } } @@ -511,7 +535,7 @@ WebInspector.ApplicationCacheDispatcher.getApplicationCachesAsync = function(cal callback(applicationCaches); } - InspectorBackend.getApplicationCaches(mycallback); + ApplicationCacheAgent.getApplicationCaches(mycallback); } WebInspector.ApplicationCacheDispatcher.prototype = { @@ -540,7 +564,7 @@ WebInspector.Cookies.getCookiesAsync = function(callback) callback(cookies, true); } - InspectorBackend.getCookies(mycallback); + InspectorAgent.getCookies(mycallback); } WebInspector.Cookies.buildCookiesFromString = function(rawCookieString) @@ -585,5 +609,5 @@ WebInspector.EventListeners.getEventListenersForNodeAsync = function(node, callb { if (!node) return; - InspectorBackend.getEventListenersForNode(node.id, callback); + DOMAgent.getEventListenersForNode(node.id, callback); } |