2010-12-01 Ilya Tikhonovsky <loislo@chromium.org>
[WebKit-https.git] / WebCore / inspector / front-end / DOMAgent.js
index 9b386c3..24e29ec 100644 (file)
@@ -60,6 +60,8 @@ WebInspector.DOMNode = function(doc, payload) {
     this.style = null;
     this._matchedCSSRules = [];
 
+    this.breakpoints = {};
+
     if (this.nodeType === Node.ELEMENT_NODE) {
         // HTML and BODY from internal iframes should not overwrite top-level ones.
         if (!this.ownerDocument.documentElement && this.nodeName === "HTML")
@@ -78,6 +80,8 @@ WebInspector.DOMNode = function(doc, payload) {
         this.name = payload.name;
         this.value = payload.value;
     }
+
+    InspectorBackend.registerDomainDispatcher("DOM", this);
 }
 
 WebInspector.DOMNode.prototype = {
@@ -98,13 +102,7 @@ WebInspector.DOMNode.prototype = {
     set nodeValue(value) {
         if (this.nodeType != Node.TEXT_NODE)
             return;
-        var self = this;
-        var callback = function()
-        {
-            self._nodeValue = value;
-            self.textContent = value;
-        };
-        this.ownerDocument._domAgent.setTextNodeValueAsync(this, value, callback);
+        this.ownerDocument._domAgent.setTextNodeValueAsync(this, value, function() {});
     },
 
     getAttribute: function(name)
@@ -155,28 +153,6 @@ WebInspector.DOMNode.prototype = {
         return path.join(",");
     },
 
-    setBreakpoint: function(type)
-    {
-        return WebInspector.domBreakpointManager.setBreakpoint(this.id, type, true, this.path());
-    },
-
-    hasBreakpoint: function(type)
-    {
-        return !!WebInspector.domBreakpointManager.findBreakpoint(this.id, type);
-    },
-
-    removeBreakpoint: function(type)
-    {
-        var breakpoint = WebInspector.domBreakpointManager.findBreakpoint(this.id, type);
-        if (breakpoint)
-            breakpoint.remove();
-    },
-
-    removeBreakpoints: function()
-    {
-        WebInspector.domBreakpointManager.removeBreakpointsForNode(this.id);
-    },
-
     _setAttributesPayload: function(attrs)
     {
         this.attributes = [];
@@ -384,6 +360,15 @@ WebInspector.DOMAgent.prototype = {
         this.document._fireDomEvent("DOMAttrModified", event);
     },
 
+    _characterDataModified: function(nodeId, newValue)
+    {
+        var node = this._idToDOMNode[nodeId];
+        node._nodeValue = newValue;
+        node.textContent = newValue;
+        var event = { target : node };
+        this.document._fireDomEvent("DOMCharacterDataModified", event);
+    },
+
     nodeForId: function(nodeId)
     {
         return this._idToDOMNode[nodeId];
@@ -396,7 +381,7 @@ WebInspector.DOMAgent.prototype = {
             this.document = new WebInspector.DOMDocument(this, this._window, payload);
             this._idToDOMNode[payload.id] = this.document;
             this._bindNodes(this.document.children);
-            WebInspector.domBreakpointManager.restoreBreakpoints();
+            WebInspector.breakpointManager.restoreDOMBreakpoints();
         } else
             this.document = null;
         WebInspector.panels.elements.setDocument(this.document);
@@ -458,12 +443,13 @@ WebInspector.DOMAgent.prototype = {
 
     _removeBreakpoints: function(node)
     {
-        node.removeBreakpoints();
+        for (var type in node.breakpoints)
+            node.breakpoints[type].remove();
         if (!node.children)
             return;
         for (var i = 0; i < node.children.length; ++i)
             this._removeBreakpoints(node.children[i]);
-     }
+    }
 }
 
 WebInspector.ApplicationCache = {}
@@ -516,17 +502,12 @@ WebInspector.Cookies.buildCookiesFromString = function(rawCookieString)
 
 WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
 {
-    var match = resourceURL.match(WebInspector.GenericURLRegExp);
-    if (!match)
+    var url = resourceURL.asParsedURL();
+    if (!url || !this.cookieDomainMatchesResourceDomain(cookie.domain, url.host))
         return false;
-    // See WebInspector.URLRegExp for definitions of the group index constants.
-    if (!this.cookieDomainMatchesResourceDomain(cookie.domain, match[2]))
-        return false;
-    var resourcePort = match[3] ? match[3] : undefined;
-    var resourcePath = match[4] ? match[4] : '/';
-    return (resourcePath.indexOf(cookie.path) === 0
-        && (!cookie.port || resourcePort == cookie.port)
-        && (!cookie.secure || match[1].toLowerCase() === 'https'));
+    return (url.path.indexOf(cookie.path) === 0
+        && (!cookie.port || url.port == cookie.port)
+        && (!cookie.secure || url.scheme === "https"));
 }
 
 WebInspector.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceDomain)
@@ -545,150 +526,14 @@ WebInspector.EventListeners.getEventListenersForNodeAsync = function(node, callb
     InspectorBackend.getEventListenersForNode(node.id, callback);
 }
 
-WebInspector.CSSStyleDeclaration = function(payload)
-{
-    this.id = payload.id;
-    this.parentStyleSheetId = payload.parentStyleSheetId;
-    this.width = payload.width;
-    this.height = payload.height;
-    this.__disabledProperties = {};
-    this.__disabledPropertyValues = {};
-    this.__disabledPropertyPriorities = {};
-    if (payload.disabled) {
-        for (var i = 0; i < payload.disabled.length; ++i) {
-            var property = payload.disabled[i];
-            this.__disabledProperties[property.name] = true;
-            this.__disabledPropertyValues[property.name] = property.value;
-            this.__disabledPropertyPriorities[property.name] = property.priority;
-        }
-    }
-
-    this._shorthandValues = payload.shorthandValues;
-    this._propertyMap = {};
-    this._longhandProperties = {};
-    this.length = payload.properties.length;
-
-    for (var i = 0; i < this.length; ++i) {
-        var property = payload.properties[i];
-        var name = property.name;
-        this[i] = name;
-        this._propertyMap[name] = property;
-
-        // Index longhand properties.
-        if (property.shorthand) {
-            var longhands = this._longhandProperties[property.shorthand];
-            if (!longhands) {
-                longhands = [];
-                this._longhandProperties[property.shorthand] = longhands;
-            }
-            longhands.push(name);
-        }
-    }
-}
-
-WebInspector.CSSStyleDeclaration.parseStyle = function(payload)
-{
-    return new WebInspector.CSSStyleDeclaration(payload);
-}
-
-WebInspector.CSSStyleDeclaration.parseRule = function(payload)
+WebInspector.attributesUpdated = function()
 {
-    var rule = {};
-    rule.id = payload.id;
-    rule.selectorText = payload.selectorText;
-    rule.style = new WebInspector.CSSStyleDeclaration(payload.style);
-    rule.style.parentRule = rule;
-    rule.isUserAgent = payload.isUserAgent;
-    rule.isUser = payload.isUser;
-    rule.isViaInspector = payload.isViaInspector;
-    rule.sourceLine = payload.sourceLine;
-    rule.documentURL = payload.documentURL;
-    if (payload.parentStyleSheet)
-        rule.parentStyleSheet = { href: payload.parentStyleSheet.href };
-
-    return rule;
-}
-
-WebInspector.CSSStyleDeclaration.prototype = {
-    getPropertyValue: function(name)
-    {
-        var property = this._propertyMap[name];
-        return property ? property.value : "";
-    },
-
-    getPropertyPriority: function(name)
-    {
-        var property = this._propertyMap[name];
-        return property ? property.priority : "";
-    },
-
-    getPropertyShorthand: function(name)
-    {
-        var property = this._propertyMap[name];
-        return property ? property.shorthand : "";
-    },
-
-    isPropertyImplicit: function(name)
-    {
-        var property = this._propertyMap[name];
-        return property ? property.implicit : "";
-    },
-
-    styleTextWithShorthands: function()
-    {
-        var cssText = "";
-        var foundProperties = {};
-        for (var i = 0; i < this.length; ++i) {
-            var individualProperty = this[i];
-            var shorthandProperty = this.getPropertyShorthand(individualProperty);
-            var propertyName = (shorthandProperty || individualProperty);
-
-            if (propertyName in foundProperties)
-                continue;
-
-            if (shorthandProperty) {
-                var value = this.getShorthandValue(shorthandProperty);
-                var priority = this.getShorthandPriority(shorthandProperty);
-            } else {
-                var value = this.getPropertyValue(individualProperty);
-                var priority = this.getPropertyPriority(individualProperty);
-            }
-
-            foundProperties[propertyName] = true;
-
-            cssText += propertyName + ": " + value;
-            if (priority)
-                cssText += " !" + priority;
-            cssText += "; ";
-        }
-
-        return cssText;
-    },
-
-    getLonghandProperties: function(name)
-    {
-        return this._longhandProperties[name] || [];
-    },
-
-    getShorthandValue: function(shorthandProperty)
-    {
-        return this._shorthandValues[shorthandProperty];
-    },
-
-    getShorthandPriority: function(shorthandProperty)
-    {
-        var priority = this.getPropertyPriority(shorthandProperty);
-        if (priority)
-            return priority;
-
-        var longhands = this._longhandProperties[shorthandProperty];
-        return longhands ? this.getPropertyPriority(longhands[0]) : null;
-    }
+    this.domAgent._attributesUpdated.apply(this.domAgent, arguments);
 }
 
-WebInspector.attributesUpdated = function()
+WebInspector.characterDataModified = function()
 {
-    this.domAgent._attributesUpdated.apply(this.domAgent, arguments);
+    this.domAgent._characterDataModified.apply(this.domAgent, arguments);
 }
 
 WebInspector.setDocument = function()
@@ -720,159 +565,3 @@ WebInspector.childNodeRemoved = function()
 {
     this.domAgent._childNodeRemoved.apply(this.domAgent, arguments);
 }
-
-WebInspector.DOMBreakpointManager = function()
-{
-    this._breakpoints = {};
-    this._pathCache = {};
-}
-
-WebInspector.DOMBreakpointManager.prototype = {
-    setBreakpoint: function(nodeId, type, enabled, path)
-    {
-        if (!(nodeId in this._breakpoints))
-            this._breakpoints[nodeId] = {};
-        else if (type in this._breakpoints[nodeId])
-            return;
-
-        var breakpoint = new WebInspector.DOMBreakpoint(nodeId, type, enabled);
-        this._breakpoints[nodeId][type] = breakpoint;
-        breakpoint.addEventListener("removed", this._breakpointRemoved, this);
-
-        if (!(nodeId in this._pathCache))
-            this._pathCache[nodeId] = path;
-
-        this.dispatchEventToListeners("dom-breakpoint-added", breakpoint);
-    },
-
-    findBreakpoint: function(nodeId, type)
-    {
-        var nodeBreakpoints = this._breakpoints[nodeId];
-        if (nodeBreakpoints && type in nodeBreakpoints)
-            return nodeBreakpoints[type];
-    },
-
-    removeBreakpointsForNode: function(nodeId)
-    {
-        var nodeBreakpoints = this._breakpoints[nodeId];
-        for (var type in nodeBreakpoints)
-            nodeBreakpoints[type].remove();
-    },
-
-    _breakpointRemoved: function(event)
-    {
-        var breakpoint = event.target;
-
-        var nodeBreakpoints = this._breakpoints[breakpoint.nodeId];
-        delete nodeBreakpoints[breakpoint.type];
-        for (var type in nodeBreakpoints)
-            return;
-
-        delete this._breakpoints[breakpoint.nodeId];
-        delete this._pathCache[breakpoint.nodeId];
-    },
-
-    restoreBreakpoints: function()
-    {
-        var breakpoints = this._breakpoints;
-        this._breakpoints = {};
-        var pathCache = this._pathCache;
-        this._pathCache = {};
-
-        for (var oldNodeId in breakpoints) {
-            var path = pathCache[oldNodeId];
-            InspectorBackend.pushNodeByPathToFrontend(path, restoreBreakpointsForNode.bind(this, breakpoints[oldNodeId], path));
-        }
-
-        function restoreBreakpointsForNode(nodeBreakpoints, path, nodeId)
-        {
-            if (!nodeId)
-                return;
-            for (var type in nodeBreakpoints) {
-                var breakpoint = nodeBreakpoints[type];
-                this.setBreakpoint(nodeId, breakpoint.type, breakpoint.enabled, path);
-            }
-        }
-    }
-}
-
-WebInspector.DOMBreakpointManager.prototype.__proto__ = WebInspector.Object.prototype;
-
-WebInspector.DOMBreakpoint = function(nodeId, type, enabled)
-{
-    this._nodeId = nodeId;
-    this._type = type;
-    this._enabled = enabled;
-
-    if (this.enabled)
-        InspectorBackend.setDOMBreakpoint(this.nodeId, this.type);
-}
-
-WebInspector.DOMBreakpoint.Types = {
-    SubtreeModified: 0,
-    AttributeModified: 1,
-    NodeRemoved: 2
-};
-
-WebInspector.DOMBreakpoint.labelForType = function(type)
-{
-    if (!WebInspector.DOMBreakpoint._labels) {
-        WebInspector.DOMBreakpoint._labels = {};
-        WebInspector.DOMBreakpoint._labels[WebInspector.DOMBreakpoint.Types.SubtreeModified] = WebInspector.UIString("Subtree Modified");
-        WebInspector.DOMBreakpoint._labels[WebInspector.DOMBreakpoint.Types.AttributeModified] = WebInspector.UIString("Attribute Modified");
-        WebInspector.DOMBreakpoint._labels[WebInspector.DOMBreakpoint.Types.NodeRemoved] = WebInspector.UIString("Node Removed");
-    }
-    return WebInspector.DOMBreakpoint._labels[type];
-}
-
-WebInspector.DOMBreakpoint.contextMenuLabelForType = function(type)
-{
-    if (!WebInspector.DOMBreakpoint._contextMenuLabels) {
-        WebInspector.DOMBreakpoint._contextMenuLabels = {};
-        WebInspector.DOMBreakpoint._contextMenuLabels[WebInspector.DOMBreakpoint.Types.SubtreeModified] = WebInspector.UIString("Break on Subtree Modifications");
-        WebInspector.DOMBreakpoint._contextMenuLabels[WebInspector.DOMBreakpoint.Types.AttributeModified] = WebInspector.UIString("Break on Attributes Modifications");
-        WebInspector.DOMBreakpoint._contextMenuLabels[WebInspector.DOMBreakpoint.Types.NodeRemoved] = WebInspector.UIString("Break on Node Removal");
-    }
-    return WebInspector.DOMBreakpoint._contextMenuLabels[type];
-}
-
-WebInspector.DOMBreakpoint.prototype = {
-    get nodeId()
-    {
-        return this._nodeId;
-    },
-
-    get type()
-    {
-        return this._type;
-    },
-
-    get enabled()
-    {
-        return this._enabled;
-    },
-
-    set enabled(enabled)
-    {
-        if (this._enabled === enabled)
-            return;
-
-        this._enabled = enabled;
-        if (this.enabled)
-            InspectorBackend.setDOMBreakpoint(this.nodeId, this.type);
-        else
-            InspectorBackend.removeDOMBreakpoint(this.nodeId, this.type);
-
-        this.dispatchEventToListeners("enable-changed");
-    },
-
-    remove: function()
-    {
-        if (this.enabled)
-            InspectorBackend.removeDOMBreakpoint(this.nodeId, this.type);
-        this.dispatchEventToListeners("removed");
-    }
-}
-
-WebInspector.DOMBreakpoint.prototype.__proto__ = WebInspector.Object.prototype;
-