Web Inspector: StyleSource should set content using CSSStyleModelResourceBinding...
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jul 2012 12:13:19 +0000 (12:13 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Jul 2012 12:13:19 +0000 (12:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89891

Reviewed by Pavel Feldman.

StyleSource now calls CSS resource binding directly.
CSS resource binding now adds resource revision only after setStyleSheetText call returns from backend.
Resource.revertAndClearHistory is now clearing history asynchronously
since Resource.setContent adds revision that should be removed as well.

* inspector/front-end/CSSStyleModel.js:
(WebInspector.CSSStyleModel.prototype.getViaInspectorResourceForRule):
(WebInspector.CSSStyleModel.prototype.resourceBinding):
(WebInspector.CSSStyleModelResourceBinding.prototype.setStyleContent.innerCallback):
(WebInspector.CSSStyleModelResourceBinding.prototype.setStyleContent):
(WebInspector.CSSStyleModelResourceBinding.prototype.setContent):
* inspector/front-end/Resource.js:
(WebInspector.Resource.prototype.revertAndClearHistory):
(WebInspector.Resource.prototype.revertAndClearHistory.clearHistory):
* inspector/front-end/RevisionHistoryView.js:
(WebInspector.RevisionHistoryView.prototype._createResourceItem):
* inspector/front-end/StylesPanel.js:
(WebInspector.StyleSource.prototype.workingCopyCommitted):
(WebInspector.StyleSource.prototype.workingCopyChanged):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121672 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/CSSStyleModel.js
Source/WebCore/inspector/front-end/Resource.js
Source/WebCore/inspector/front-end/RevisionHistoryView.js
Source/WebCore/inspector/front-end/StylesPanel.js

index 9655aef..c2e61bb 100644 (file)
@@ -1,3 +1,30 @@
+2012-06-26  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: StyleSource should set content using CSSStyleModelResourceBinding directly.
+        https://bugs.webkit.org/show_bug.cgi?id=89891
+
+        Reviewed by Pavel Feldman.
+
+        StyleSource now calls CSS resource binding directly.
+        CSS resource binding now adds resource revision only after setStyleSheetText call returns from backend.
+        Resource.revertAndClearHistory is now clearing history asynchronously
+        since Resource.setContent adds revision that should be removed as well.
+
+        * inspector/front-end/CSSStyleModel.js:
+        (WebInspector.CSSStyleModel.prototype.getViaInspectorResourceForRule):
+        (WebInspector.CSSStyleModel.prototype.resourceBinding):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.setStyleContent.innerCallback):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.setStyleContent):
+        (WebInspector.CSSStyleModelResourceBinding.prototype.setContent):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.revertAndClearHistory):
+        (WebInspector.Resource.prototype.revertAndClearHistory.clearHistory):
+        * inspector/front-end/RevisionHistoryView.js:
+        (WebInspector.RevisionHistoryView.prototype._createResourceItem):
+        * inspector/front-end/StylesPanel.js:
+        (WebInspector.StyleSource.prototype.workingCopyCommitted):
+        (WebInspector.StyleSource.prototype.workingCopyChanged):
+
 2012-07-02  Taiju Tsuiki  <tzik@chromium.org>
 
         Web Inspector: Add DirectoryContentView for FileSystemView
index 67c0b00..fc15cd4 100644 (file)
@@ -335,6 +335,14 @@ WebInspector.CSSStyleModel.prototype = {
             return;
         }
         this._resourceBinding._requestViaInspectorResource(rule.id.styleSheetId, callback);
+    },
+
+    /**
+     * @return {WebInspector.CSSStyleModelResourceBinding}
+     */
+    resourceBinding: function()
+    {
+        return this._resourceBinding;
     }
 }
 
@@ -940,6 +948,35 @@ WebInspector.CSSStyleModelResourceBinding = function(cssModel)
 
 WebInspector.CSSStyleModelResourceBinding.prototype = {
     /**
+     * @param {WebInspector.StyleSource} styleSource
+     * @param {string} content
+     * @param {boolean} majorChange
+     * @param {function(?string)} userCallback
+     */
+    setStyleContent: function(styleSource, content, majorChange, userCallback)
+    {
+        var resource = styleSource.resource();
+        if (this._styleSheetIdForResource(resource)) {
+            this._innerSetContent(resource, content, majorChange, innerCallback, null);
+            return;
+        }
+        this._loadStyleSheetHeaders(this._innerSetContent.bind(this, resource, content, majorChange, innerCallback));
+        
+        function innerCallback(error)
+        {
+            if (error) {
+                userCallback(error);
+                return;
+            }
+
+            if (majorChange)
+                resource.addRevision(content);
+
+            userCallback(null);
+        }
+    },
+
+    /**
      * @param {WebInspector.Resource} resource
      * @param {string} content
      * @param {boolean} majorChange
@@ -947,14 +984,12 @@ WebInspector.CSSStyleModelResourceBinding.prototype = {
      */
     setContent: function(resource, content, majorChange, userCallback)
     {
-        if (majorChange && resource.type === WebInspector.resourceTypes.Stylesheet)
-            resource.addRevision(content);
-
-        if (this._styleSheetIdForResource(resource)) {
-            this._innerSetContent(resource, content, majorChange, userCallback, null);
+        var styleSource = /** @type {WebInspector.StyleSource} */ resource.uiSourceCode();
+        if (!styleSource) {
+            userCallback("Resource is not editable");
             return;
         }
-        this._loadStyleSheetHeaders(this._innerSetContent.bind(this, resource, content, majorChange, userCallback));
+        this.setStyleContent(styleSource, content, majorChange, userCallback);
     },
 
     /**
index 99836c2..8e30275 100644 (file)
@@ -500,14 +500,20 @@ WebInspector.Resource.prototype = {
         this.requestContent(revert.bind(this));
     },
 
-    revertAndClearHistory: function()
+    revertAndClearHistory: function(callback)
     {
         function revert(content)
         {
-            this.setContent(content, true, function() {});
+            this.setContent(content, true, clearHistory.bind(this));
+        }
+
+        function clearHistory()
+        {
             WebInspector.Resource._clearResourceHistory(this);
             this.history = [];
+            callback();
         }
+
         this.requestContent(revert.bind(this));
     },
 
index c429045..25a90e7 100644 (file)
@@ -112,17 +112,26 @@ WebInspector.RevisionHistoryView.prototype = {
         revertToOriginal.textContent = WebInspector.UIString("apply original content");
         revertToOriginal.addEventListener("click", resource.revertToOriginal.bind(resource));
 
-        function clearHistory()
+        var clearHistoryElement = resourceItem.listItemElement.createChild("span", "revision-history-link");
+        clearHistoryElement.textContent = WebInspector.UIString("revert");
+        clearHistoryElement.addEventListener("click", this._clearHistory.bind(this, resource));
+        return resourceItem;
+    },
+
+    /**
+     * @param {WebInspector.Resource} resource
+     */
+    _clearHistory: function(resource)
+    {
+        resource.revertAndClearHistory(historyCleared.bind(this));
+
+        function historyCleared()
         {
-            resource.revertAndClearHistory();
+            var resourceItem = this._resourceItems.get(resource);
             this._treeOutline.removeChild(resourceItem);
             this._resourceItems.remove(resource);
         }
 
-        var clearHistoryElement = resourceItem.listItemElement.createChild("span", "revision-history-link");
-        clearHistoryElement.textContent = WebInspector.UIString("revert");
-        clearHistoryElement.addEventListener("click", clearHistory.bind(this));
-        return resourceItem;
     },
 
     _revisionAdded: function(event)
index 316969d..5a7ad4a 100644 (file)
@@ -103,14 +103,14 @@ WebInspector.StyleSource.prototype = {
      */
     workingCopyCommitted: function(callback)
     {  
-        this._resource.setContent(this.workingCopy(), true, callback);
+        WebInspector.cssModel.resourceBinding().setStyleContent(this, this.workingCopy(), true, callback);
     },
 
     workingCopyChanged: function()
     {  
         function commitIncrementalEdit()
         {
-            this._resource.setContent(this.workingCopy(), false, function() {});
+            WebInspector.cssModel.resourceBinding().setStyleContent(this, this.workingCopy(), false, function() {});
         }
         const updateTimeout = 200;
         this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);