Changeset 117799 in webkit


Ignore:
Timestamp:
May 21, 2012 10:27:37 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: refactor revision history to not include resource itself.
https://bugs.webkit.org/show_bug.cgi?id=87026

Reviewed by Vsevolod Vlasov.

Source/WebCore:

This change makes resource contain pure revisions, it stops updating Resources upon free flow editing.

  • inspector/front-end/JavaScriptSource.js:

(WebInspector.JavaScriptSource.prototype.setFormatted.didGetContent.didFormatContent):
(WebInspector.JavaScriptSource.prototype.setFormatted.didGetContent):
(WebInspector.JavaScriptSource.prototype.setFormatted):

  • inspector/front-end/JavaScriptSourceFrame.js:

(WebInspector.JavaScriptSourceFrame.prototype.commitEditing):
(WebInspector.JavaScriptSourceFrame.prototype._onContentChanged):
(WebInspector.JavaScriptSourceFrame.prototype._didEditContent):

  • inspector/front-end/Resource.js:

(WebInspector.Resource.prototype.addRevision):
(WebInspector.Resource.prototype._innerRequestContent.callback):
(WebInspector.Resource.prototype._innerRequestContent):
(WebInspector.Resource.prototype.revertToOriginal):
(WebInspector.ResourceRevision.prototype.revertToThis):
(WebInspector.ResourceRevision.prototype.requestContent):
(WebInspector.ResourceRevision.prototype.searchInContent):
(WebInspector.ResourceRevision.prototype._persistRevision):

  • inspector/front-end/RevisionHistoryView.js:

(WebInspector.RevisionHistoryView):
(WebInspector.RevisionHistoryView.prototype._revisionAdded):
(WebInspector.RevisionHistoryTreeElement):

  • inspector/front-end/ScriptSnippetModel.js:

(WebInspector.ScriptSnippetModel.prototype.setScriptSnippetContent):

  • inspector/front-end/StylesPanel.js:

(WebInspector.StyleSourceFrame.prototype.commitEditing):
(WebInspector.StyleSourceFrame.prototype._didEditContent):
(WebInspector.StyleSourceFrame.prototype._onContentChanged):

  • inspector/front-end/UISourceCode.js:

(WebInspector.UISourceCode.prototype._revisionAdded):
(WebInspector.UISourceCode.prototype.contentChanged):
(WebInspector.UISourceCode.prototype.commitWorkingCopy):

  • inspector/front-end/inspector.js:

(WebInspector._doLoadedDoneWithCapabilities.get if):

LayoutTests:

  • http/tests/inspector/network/network-request-revision-content.html:
  • inspector/styles/styles-history-expected.txt:
  • inspector/styles/styles-history.html:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r117792 r117799  
     12012-05-21  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: refactor revision history to not include resource itself.
     4        https://bugs.webkit.org/show_bug.cgi?id=87026
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        * http/tests/inspector/network/network-request-revision-content.html:
     9        * inspector/styles/styles-history-expected.txt:
     10        * inspector/styles/styles-history.html:
     11
    1122012-05-21  Stephen Chenney  <schenney@chromium.org>
    213
  • trunk/LayoutTests/http/tests/inspector/network/network-request-revision-content.html

    r114116 r117799  
    2424    }
    2525
    26     function step3()
     26    function step3(content)
    2727    {
    2828        InspectorTest.addResult(resource.url);
    29         InspectorTest.addResult(resource.content);
     29        InspectorTest.addResult(content);
    3030        InspectorTest.completeTest();
    3131    }
  • trunk/LayoutTests/inspector/styles/styles-history-expected.txt

    r111677 r117799  
    66Running: testSetResourceContentMinor
    77History length: 0
    8 Item <tip>:
    9 body {
    10   margin: 10px;
    11   padding: 10px;
    12 }
    13 
    148
    159Running: testSetResourceContentMajor
    1610History length: 1
    1711Item 0:
    18 body {
    19   margin: 10px;
    20   padding: 10px;
    21 }
    22 
    23 Item <tip>:
    2412body {
    2513  margin: 20px;
     
    3119Item 0:
    3220body {
    33   margin: 10px;
    34   padding: 10px;
    35 }
    36 
    37 Item <tip>:
    38 body {
    3921  margin: 20px;
    4022  padding: 10px;
     
    4527Item 0:
    4628body {
    47   margin: 10px;
    48   padding: 10px;
    49 }
    50 
    51 Item 1:
    52 body {
    5329  margin: 20px;
    5430  padding: 10px;
    5531}
    56 Item <tip>:
     32Item 1:
    5733body {
    5834  margin:30px;
  • trunk/LayoutTests/inspector/styles/styles-history.html

    r111677 r117799  
    9797        {
    9898            InspectorTest.addResult("History length: " + styleResource.history.length);
    99             for (var i = 0; i < styleResource.history.length; ++i)
    100                 styleResource.history[i].requestContent(dumpRevision.bind(this, i, null));
    101             styleResource.requestContent(dumpRevision.bind(this, "<tip>", next));
     99            for (var i = 0; i < styleResource.history.length; ++i) {
     100                InspectorTest.addResult("Item " + i + ":");
     101                InspectorTest.addResult(styleResource.history[i].content);
     102            }
     103            next();
    102104        }
    103105        return result;
    104     }
    105 
    106     function dumpRevision(index, next, content)
    107     {
    108         InspectorTest.addResult("Item " + index + ":");
    109         InspectorTest.addResult(content);
    110         if (next)
    111             next();
    112106    }
    113107}
  • trunk/Source/WebCore/ChangeLog

    r117798 r117799  
     12012-05-21  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: refactor revision history to not include resource itself.
     4        https://bugs.webkit.org/show_bug.cgi?id=87026
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        This change makes resource contain pure revisions, it stops updating Resources upon free flow editing.
     9
     10        * inspector/front-end/JavaScriptSource.js:
     11        (WebInspector.JavaScriptSource.prototype.setFormatted.didGetContent.didFormatContent):
     12        (WebInspector.JavaScriptSource.prototype.setFormatted.didGetContent):
     13        (WebInspector.JavaScriptSource.prototype.setFormatted):
     14        * inspector/front-end/JavaScriptSourceFrame.js:
     15        (WebInspector.JavaScriptSourceFrame.prototype.commitEditing):
     16        (WebInspector.JavaScriptSourceFrame.prototype._onContentChanged):
     17        (WebInspector.JavaScriptSourceFrame.prototype._didEditContent):
     18        * inspector/front-end/Resource.js:
     19        (WebInspector.Resource.prototype.addRevision):
     20        (WebInspector.Resource.prototype._innerRequestContent.callback):
     21        (WebInspector.Resource.prototype._innerRequestContent):
     22        (WebInspector.Resource.prototype.revertToOriginal):
     23        (WebInspector.ResourceRevision.prototype.revertToThis):
     24        (WebInspector.ResourceRevision.prototype.requestContent):
     25        (WebInspector.ResourceRevision.prototype.searchInContent):
     26        (WebInspector.ResourceRevision.prototype._persistRevision):
     27        * inspector/front-end/RevisionHistoryView.js:
     28        (WebInspector.RevisionHistoryView):
     29        (WebInspector.RevisionHistoryView.prototype._revisionAdded):
     30        (WebInspector.RevisionHistoryTreeElement):
     31        * inspector/front-end/ScriptSnippetModel.js:
     32        (WebInspector.ScriptSnippetModel.prototype.setScriptSnippetContent):
     33        * inspector/front-end/StylesPanel.js:
     34        (WebInspector.StyleSourceFrame.prototype.commitEditing):
     35        (WebInspector.StyleSourceFrame.prototype._didEditContent):
     36        (WebInspector.StyleSourceFrame.prototype._onContentChanged):
     37        * inspector/front-end/UISourceCode.js:
     38        (WebInspector.UISourceCode.prototype._revisionAdded):
     39        (WebInspector.UISourceCode.prototype.contentChanged):
     40        (WebInspector.UISourceCode.prototype.commitWorkingCopy):
     41        * inspector/front-end/inspector.js:
     42        (WebInspector._doLoadedDoneWithCapabilities.get if):
     43
    1442012-05-21  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    245
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSource.js

    r117781 r117799  
    103103            if (!formatted) {
    104104                this._togglingFormatter = true;
    105                 this.contentChanged(content || "");
     105                this.contentChanged(content || "", mimeType);
    106106                delete this._togglingFormatter;
    107107                this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
     
    122122            {
    123123                this._togglingFormatter = true;
    124                 this.contentChanged(formattedContent);
     124                this.contentChanged(formattedContent, mimeType);
    125125                delete this._togglingFormatter;
    126126                this._formatterMapping = formatterMapping;
  • trunk/Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js

    r117781 r117799  
    9393    commitEditing: function(text)
    9494    {
    95         this._editingContent = true;
     95        this._isCommittingEditing = true;
    9696        this._uiSourceCode.commitWorkingCopy(this._didEditContent.bind(this));
    9797    },
     
    102102    _onContentChanged: function(event)
    103103    {
    104         if (this._editingContent)
    105             return;
    106         var oldContent = /** @type {string} */ event.data.oldContent;
     104        if (this._isCommittingEditing)
     105            return;
    107106        var content = /** @type {string} */ event.data.content;
    108107
     
    177176    _didEditContent: function(error)
    178177    {
    179         delete this._editingContent;
     178        delete this._isCommittingEditing;
    180179
    181180        if (error) {
  • trunk/Source/WebCore/inspector/front-end/Resource.js

    r117750 r117799  
    115115
    116116/**
    117  * @param {WebInspector.Resource} resource
     117 * @param {WebInspector.ResourceRevision} revision
    118118 */
    119 WebInspector.Resource.persistRevision = function(resource)
     119WebInspector.Resource.persistRevision = function(revision)
    120120{
    121121    if (!window.localStorage)
    122122        return;
    123123
     124    var resource = revision.resource;
    124125    var url = resource.url;
    125126    var loaderId = resource.loaderId;
    126     var timestamp = resource._contentTimestamp.getTime();
     127    var timestamp = revision.timestamp.getTime();
    127128    var key = "resource-history|" + url + "|" + loaderId + "|" + timestamp;
    128     var content = resource._content;
     129    var content = revision._content;
    129130
    130131    var registry = WebInspector.Resource._resourceRevisionRegistry();
     
    302303
    303304    /**
    304      * @return {Date}
    305      */
    306     get contentTimestamp()
    307     {
    308         return this._contentTimestamp;
    309     },
    310 
    311     /**
    312305     * @return {boolean}
    313306     */
     
    337330
    338331    /**
    339      * @param {string} newContent
     332     * @param {string} content
    340333     * @param {Date=} timestamp
    341334     * @param {boolean=} restoringHistory
    342335     */
    343     addRevision: function(newContent, timestamp, restoringHistory)
    344     {
    345         var revision = new WebInspector.ResourceRevision(this, this._content, this._contentTimestamp);
     336    addRevision: function(content, timestamp, restoringHistory)
     337    {
     338        if (this.history.length) {
     339            var lastRevision = this.history[this.history.length - 1];
     340            if (lastRevision._content === content)
     341                return;
     342        }
     343        var revision = new WebInspector.ResourceRevision(this, content, timestamp || new Date());
    346344        this.history.push(revision);
    347 
    348         this._content = newContent;
    349         this._contentTimestamp = timestamp || new Date();
    350345
    351346        this.dispatchEventToListeners(WebInspector.Resource.Events.RevisionAdded, revision);
    352347        if (!restoringHistory)
    353             this._persistRevision();
    354         WebInspector.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceContentCommitted, { resource: this, content: newContent });
    355     },
    356 
    357     _persistRevision: function()
    358     {
    359         WebInspector.Resource.persistRevision(this);
     348            revision._persistRevision();
     349        WebInspector.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceContentCommitted, { resource: this, content: content });
    360350    },
    361351
     
    459449            this._content = error ? null : content;
    460450            this._contentEncoded = contentEncoded;
    461             this._originalContent = content;
    462451            var callbacks = this._pendingContentCallbacks.slice();
    463452            for (var i = 0; i < callbacks.length; ++i)
     
    467456        }
    468457        PageAgent.getResourceContent(this.frameId, this.url, callback.bind(this));
     458    },
     459
     460    revertToOriginal: function()
     461    {
     462        function revert(content)
     463        {
     464            this.setContent(content, true, function() {});
     465        }
     466        this.requestContent(revert.bind(this));
    469467    }
    470468}
     
    477475 * @param {WebInspector.Resource} resource
    478476 * @param {?string|undefined} content
    479  * @param {number} timestamp
     477 * @param {Date} timestamp
    480478 */
    481479WebInspector.ResourceRevision = function(resource, content, timestamp)
     
    496494
    497495    /**
    498      * @return {number}
     496     * @return {Date}
    499497     */
    500498    get timestamp()
     
    516514        {
    517515            if (this._resource._content !== content)
    518                 this._resource.setContent(content, true);
     516                this._resource.setContent(content, true, function() {});
    519517        }
    520518        this.requestContent(revert.bind(this));
     
    542540    requestContent: function(callback)
    543541    {
    544         if (typeof this._content === "string") {
    545             callback(this._content, false, this.resource.mimeType);
    546             return;
    547         }
    548 
    549         // If we are here, this is initial revision. First, look up content fetched over the wire.
    550         if (typeof this.resource._originalContent === "string") {
    551             this._content = this._resource._originalContent;
    552             callback(this._content, false, this.resource.mimeType);
    553             return;
    554         }
    555 
    556         /**
    557          * @param {?Protocol.Error} error
    558          * @param {string} content
    559          * @param {boolean} contentEncoded
    560          */
    561         function callbackWrapper(error, content, contentEncoded)
    562         {
    563             callback(error ? null : content, contentEncoded, this.resource.mimeType);
    564         }
    565 
    566         PageAgent.getResourceContent(this._resource.frameId, this._resource.url, callbackWrapper.bind(this));
     542        callback(this._content || "", false, this.resource.mimeType);
    567543    },
    568544
     
    576552    {
    577553        callback([]);
     554    },
     555
     556    _persistRevision: function()
     557    {
     558        WebInspector.Resource.persistRevision(this);
    578559    }
    579560}
  • trunk/Source/WebCore/inspector/front-end/RevisionHistoryView.js

    r117750 r117799  
    5151    } else {
    5252        var olElement = this.element.createChild("ol");
    53         var treeOutline = new TreeOutline(olElement);
     53        this._treeOutline = new TreeOutline(olElement);
    5454        revisionCount = this._resource.history.length;
    55 
    56         var historyItem = new WebInspector.RevisionHistoryTreeElement(this._resource);
    57         historyItem.selectable = false;
    58         treeOutline.appendChild(historyItem);
    5955
    6056        for (var i = revisionCount - 1; i >= 0; --i) {
    6157            var revision = this._resource.history[i];
    62             historyItem = new WebInspector.RevisionHistoryTreeElement(this._resource, i);
    63             historyItem.selectable = false;
    64             treeOutline.appendChild(historyItem);
    65         }
     58            var historyItem = new WebInspector.RevisionHistoryTreeElement(revision, this._resource.history[i - 1]);
     59            this._treeOutline.appendChild(historyItem);
     60        }
     61
     62        var baseItem = new TreeElement("", null, false);
     63        baseItem.selectable = false;
     64        this._treeOutline.appendChild(baseItem);
     65
     66        var revertToOriginal = baseItem.listItemElement.createChild("span", "revision-history-link");
     67        revertToOriginal.textContent = WebInspector.UIString("revert to original");
     68        revertToOriginal.addEventListener("click", this._resource.revertToOriginal.bind(this._resource));
    6669    }
    6770
     
    98101
    99102WebInspector.RevisionHistoryView.prototype = {
    100     _revisionAdded: function()
    101     {
    102         WebInspector.RevisionHistoryView.showHistory(this._uiSourceCode);
     103    _revisionAdded: function(event)
     104    {
     105        if (this._resource.history.length === 1) {
     106            WebInspector.RevisionHistoryView.showHistory(this._uiSourceCode);
     107            return;
     108        }
     109        var historyLength = this._resource.history.length;
     110        var historyItem = new WebInspector.RevisionHistoryTreeElement(this._resource.history[historyLength - 1], this._resource.history[historyLength - 2]);
     111        this._treeOutline.insertChild(historyItem, 0);
    103112    },
    104113
     
    116125 * @constructor
    117126 * @extends {TreeElement}
    118  * @param {WebInspector.Resource} resource
    119  * @param {number=} revisionOrdinal
    120  */
    121 WebInspector.RevisionHistoryTreeElement = function(resource, revisionOrdinal)
    122 {
    123     this._resource = resource;
    124 
     127 * @param {WebInspector.ResourceRevision} revision
     128 * @param {WebInspector.ResourceRevision=} baseRevision
     129 */
     130WebInspector.RevisionHistoryTreeElement = function(revision, baseRevision)
     131{
    125132    var titleElement = document.createElement("span");
    126     if (isNaN(revisionOrdinal)) {
    127         this._revision = resource;
    128         this._baseRevision = resource.history[resource.history.length - 1];
    129 
    130         titleElement.textContent = resource.contentTimestamp.toLocaleTimeString();
    131     } else {
    132         this._revision = resource.history[revisionOrdinal];
    133         this._baseRevision = resource.history[revisionOrdinal - 1];
    134 
    135         titleElement.textContent = revisionOrdinal ? resource.history[revisionOrdinal].timestamp.toLocaleTimeString() : WebInspector.UIString("(original)");
    136         function revert()
    137         {
    138             this._revision.revertToThis();
    139         }
    140 
    141         var revertElement = titleElement.createChild("span", "revision-history-link");
    142         revertElement.textContent = WebInspector.UIString("revert to this");
    143         revertElement.addEventListener("click", revert.bind(this), false);
    144     }
    145     TreeElement.call(this, titleElement, null, revisionOrdinal !== 0);
     133    titleElement.textContent = revision.timestamp.toLocaleTimeString();
     134
     135    TreeElement.call(this, titleElement, null, true);
     136    this.selectable = false;
     137
     138    this._revision = revision;
     139    this._baseRevision = baseRevision;
     140
     141    var revertElement = titleElement.createChild("span", "revision-history-link");
     142    revertElement.textContent = WebInspector.UIString("revert to this");
     143    revertElement.addEventListener("click", this._revision.revertToThis.bind(this._revision), false);
    146144}
    147145
     
    154152
    155153        this.childrenListElement.addStyleClass("source-code");
    156         this._baseRevision.requestContent(step1.bind(this));
     154        if (this._baseRevision)
     155            this._baseRevision.requestContent(step1.bind(this));
     156        else
     157            this._revision.resource.requestContent(step1.bind(this));
    157158
    158159        function step1(baseContent)
  • trunk/Source/WebCore/inspector/front-end/ScriptSnippetModel.js

    r117781 r117799  
    114114        var snippet = this._snippetStorage.snippetForId(snippetJavaScriptSource.snippetId);
    115115        snippet.content = newContent;
    116         snippetJavaScriptSource.contentChanged(newContent);
     116        snippetJavaScriptSource.contentChanged(newContent, "text/javascript");
    117117    },
    118118
  • trunk/Source/WebCore/inspector/front-end/StylesPanel.js

    r117781 r117799  
    146146    commitEditing: function(text)
    147147    {
     148        this._isCommittingEditing = true;
    148149        this._styleSource.commitWorkingCopy(this._didEditContent.bind(this));
    149150    },
     
    160161            return;
    161162        }
     163        delete this._isCommittingEditing;
    162164    },
    163165
     
    174176    _onContentChanged: function(event)
    175177    {
    176         this.setContent(this._styleSource.resource().content, false, "text/stylesheet");
     178        if (!this._isCommittingEditing)
     179            this.setContent(this._styleSource.content() || "", false, "text/css");
    177180    },
    178181
  • trunk/Source/WebCore/inspector/front-end/UISourceCode.js

    r117781 r117799  
    137137    _revisionAdded: function(event)
    138138    {
    139         this.contentChanged(this.resource().content || "");
     139        var revision = /** @type {WebInspector.ResourceRevision} */ event.data;
     140        this.contentChanged(revision.content || "", this._resource.canonicalMimeType());
    140141    },
    141142
    142143    /**
    143144     * @param {string} newContent
    144      */
    145     contentChanged: function(newContent)
     145     * @param {string} mimeType
     146     */
     147    contentChanged: function(newContent, mimeType)
    146148    {
    147149        if (this._committingWorkingCopy)
    148150            return;
    149151
    150         var oldContent = this._contentLoaded ? this._content : undefined;
    151152        this._content = newContent;
     153        this._mimeType = mimeType;
     154        this._contentLoaded = true;
    152155        delete this._workingCopy;
    153         this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ContentChanged, {oldContent: oldContent, content: newContent});
     156        this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ContentChanged, {content: newContent});
    154157    },
    155158
     
    205208            delete this._committingWorkingCopy;
    206209            if (!error)
    207                 this.contentChanged(newContent);
     210                this.contentChanged(newContent, this._mimeType);
    208211            callback(error);
    209212        }
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r117746 r117799  
    417417    this.breakpointManager = new WebInspector.BreakpointManager(WebInspector.settings.breakpoints, this.debuggerModel);
    418418
     419    WebInspector.CSSCompletions.requestCSSNameCompletions();
     420
    419421    this.drawer = new WebInspector.Drawer();
    420422    this.consoleView = new WebInspector.ConsoleView(WebInspector.WorkerManager.isWorkerFrontend());
     
    445447        this._requestZoom();
    446448
    447     WebInspector.CSSCompletions.requestCSSNameCompletions();
    448449    this._createPanels();
    449450    this._createGlobalStatusBarItems();
Note: See TracChangeset for help on using the changeset viewer.