Changeset 83969 in webkit


Ignore:
Timestamp:
Apr 15, 2011 7:08:31 AM (13 years ago)
Author:
pfeldman@chromium.org
Message:

2011-04-15 Pavel Feldman <pfeldman@google.com>

Reviewed by Yury Semikhatsky.

Web Inspector: make resource revisions use dedicated type (not Resource clone).
https://bugs.webkit.org/show_bug.cgi?id=58659

  • inspector/front-end/CSSStyleModel.js: (WebInspector.CSSStyleModel.prototype.setStyleSheetText):
  • inspector/front-end/Resource.js: (WebInspector.Resource.prototype.addRevision): (WebInspector.Resource.prototype._innerRequestContent.onResourceContent): (WebInspector.Resource.prototype._innerRequestContent): (WebInspector.ResourceRevision): (WebInspector.ResourceRevision.prototype.get resource): (WebInspector.ResourceRevision.prototype.get timestamp): (WebInspector.ResourceRevision.prototype.get content): (WebInspector.ResourceRevision.prototype.revertToThis): (WebInspector.ResourceRevision.prototype.requestContent.mycallback): (WebInspector.ResourceRevision.prototype.requestContent):
  • inspector/front-end/ResourceView.js: (WebInspector.ResourceView.resourceViewTypeMatchesResource): (WebInspector.ResourceView.resourceViewForResource): (WebInspector.ResourceView.recreateResourceView): (WebInspector.ResourceView.existingResourceViewForResource): (WebInspector.RevisionSourceFrame): (WebInspector.RevisionSourceFrame.prototype.get resource): (WebInspector.RevisionSourceFrame.prototype.isContentEditable): (WebInspector.RevisionSourceFrame.prototype.requestContent):
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourcesPanel.prototype._showResourceView): (WebInspector.ResourcesPanel.prototype._showRevisionView): (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup.step1): (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup.step2): (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup): (WebInspector.ResourceRevisionTreeElement): (WebInspector.ResourceRevisionTreeElement.prototype.get itemURL): (WebInspector.ResourceRevisionTreeElement.prototype.onselect): (WebInspector.ResourceRevisionTreeElement.prototype._ondragstart): (WebInspector.ResourceRevisionTreeElement.prototype._handleContextMenuEvent):
  • inspector/front-end/SourceFrame.js: (WebInspector.SourceFrame.prototype._ensureContentLoaded): (WebInspector.SourceFrame.prototype.requestContent): (WebInspector.SourceFrame.prototype.commitEditing.didEditContent): (WebInspector.SourceFrame.prototype.commitEditing):
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83968 r83969  
     12011-04-15  Pavel Feldman  <pfeldman@google.com>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        Web Inspector: make resource revisions use dedicated type (not Resource clone).
     6        https://bugs.webkit.org/show_bug.cgi?id=58659
     7
     8        * inspector/front-end/CSSStyleModel.js:
     9        (WebInspector.CSSStyleModel.prototype.setStyleSheetText):
     10        * inspector/front-end/Resource.js:
     11        (WebInspector.Resource.prototype.addRevision):
     12        (WebInspector.Resource.prototype._innerRequestContent.onResourceContent):
     13        (WebInspector.Resource.prototype._innerRequestContent):
     14        (WebInspector.ResourceRevision):
     15        (WebInspector.ResourceRevision.prototype.get resource):
     16        (WebInspector.ResourceRevision.prototype.get timestamp):
     17        (WebInspector.ResourceRevision.prototype.get content):
     18        (WebInspector.ResourceRevision.prototype.revertToThis):
     19        (WebInspector.ResourceRevision.prototype.requestContent.mycallback):
     20        (WebInspector.ResourceRevision.prototype.requestContent):
     21        * inspector/front-end/ResourceView.js:
     22        (WebInspector.ResourceView.resourceViewTypeMatchesResource):
     23        (WebInspector.ResourceView.resourceViewForResource):
     24        (WebInspector.ResourceView.recreateResourceView):
     25        (WebInspector.ResourceView.existingResourceViewForResource):
     26        (WebInspector.RevisionSourceFrame):
     27        (WebInspector.RevisionSourceFrame.prototype.get resource):
     28        (WebInspector.RevisionSourceFrame.prototype.isContentEditable):
     29        (WebInspector.RevisionSourceFrame.prototype.requestContent):
     30        * inspector/front-end/ResourcesPanel.js:
     31        (WebInspector.ResourcesPanel.prototype._showResourceView):
     32        (WebInspector.ResourcesPanel.prototype._showRevisionView):
     33        (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup.step1):
     34        (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup.step2):
     35        (WebInspector.ResourcesPanel.prototype._fetchAndApplyDiffMarkup):
     36        (WebInspector.ResourceRevisionTreeElement):
     37        (WebInspector.ResourceRevisionTreeElement.prototype.get itemURL):
     38        (WebInspector.ResourceRevisionTreeElement.prototype.onselect):
     39        (WebInspector.ResourceRevisionTreeElement.prototype._ondragstart):
     40        (WebInspector.ResourceRevisionTreeElement.prototype._handleContextMenuEvent):
     41        * inspector/front-end/SourceFrame.js:
     42        (WebInspector.SourceFrame.prototype._ensureContentLoaded):
     43        (WebInspector.SourceFrame.prototype.requestContent):
     44        (WebInspector.SourceFrame.prototype.commitEditing.didEditContent):
     45        (WebInspector.SourceFrame.prototype.commitEditing):
     46
    1472011-04-15  Alexander Pavlov  <apavlov@chromium.org>
    248
  • trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js

    r83962 r83969  
    188188        {
    189189             if (!error)
    190                  this._fireStyleSheetChanged(this.id, majorChange);
     190                 this._fireStyleSheetChanged(styleSheetId, majorChange);
    191191
    192192             if (userCallback)
  • trunk/Source/WebCore/inspector/front-end/Resource.js

    r83962 r83969  
    724724    addRevision: function(newContent)
    725725    {
    726         var revisionResource = new WebInspector.Resource(null, this.url);
    727         revisionResource.frameId = this.frameId;
    728         revisionResource.loaderId = this.loaderId;
    729         revisionResource.documentURL = this.documentURL;
    730         revisionResource.type = this.type;
    731         revisionResource.loader = this.loader;
    732         revisionResource.timestamp = this.timestamp;
    733         revisionResource._content = this._content;
    734         revisionResource._actualResource = this;
    735 
    736         if (this.finished)
    737             revisionResource.finished = true;
    738         else {
    739             function finished()
    740             {
    741                 this.removeEventListener("finished", finished);
    742                 revisionResource.finished = true;
    743             }
    744             this.addEventListener("finished", finished.bind(this));
    745         }
    746 
    747         if (!this._baseRevision)
    748             this._baseRevision = revisionResource;
    749         else
    750             revisionResource._baseRevision = this._baseRevision;
     726        var revision = new WebInspector.ResourceRevision(this, this._content, this._contentTimestamp);
     727        this.history.push(revision);
    751728
    752729        this._content = newContent;
    753         this.timestamp = new Date();
    754 
    755         this.history.push(revisionResource);
    756         this.dispatchEventToListeners(WebInspector.Resource.Events.RevisionAdded, revisionResource);
    757     },
    758 
    759     revertToThis: function()
    760     {
    761         if (!this._actualResource)
    762             return;
    763 
    764         function callback(content)
    765         {
    766             if (content)
    767                 this._actualResource.setContent(content, true);
    768         }
    769         this.requestContent(callback.bind(this));
    770     },
    771 
    772     get baseRevision()
    773     {
    774         return this._baseRevision;
     730        this._contentTimestamp = new Date();
     731
     732        this.dispatchEventToListeners(WebInspector.Resource.Events.RevisionAdded, revision);
    775733    },
    776734
     
    831789        {
    832790            this._content = data;
     791            this._originalContent = data;
    833792            var callbacks = this._pendingContentCallbacks.slice();
    834793            for (var i = 0; i < callbacks.length; ++i)
     
    843802WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype;
    844803
     804WebInspector.ResourceRevision = function(resource, content, timestamp)
     805{
     806    this._resource = resource;
     807    this._content = content;
     808    this._timestamp = timestamp;
     809}
     810
     811WebInspector.ResourceRevision.prototype = {
     812    get resource()
     813    {
     814        return this._resource;
     815    },
     816
     817    get timestamp()
     818    {
     819        return this._timestamp;
     820    },
     821
     822    get content()
     823    {
     824        return this._content;
     825    },
     826
     827    revertToThis: function()
     828    {
     829        function revert(content)
     830        {
     831            this._resource.setContent(content, true);
     832        }
     833        this.requestContent(revert.bind(this));
     834    },
     835
     836    requestContent: function(callback)
     837    {
     838        if (typeof this._content === "string") {
     839            callback(this._content);
     840            return;
     841        }
     842
     843        // If we are here, this is initial revision. First, look up content fetched over the wire.
     844        if (typeof this.resource._originalContent === "string") {
     845            this._content = this._resource._originalContent;
     846            callback(this._content);
     847            return;
     848        }
     849
     850        // If unsuccessful, request the content.
     851        function mycallback(content)
     852        {
     853            this._content = content;
     854            callback(content);
     855        }
     856        WebInspector.networkManager.requestContent(this._resource, false, mycallback.bind(this));
     857    }
     858}
    845859
    846860WebInspector.ResourceDomainModelBinding = function()
  • trunk/Source/WebCore/inspector/front-end/ResourceView.js

    r83962 r83969  
    6363WebInspector.ResourceView.resourceViewTypeMatchesResource = function(resource)
    6464{
    65     var resourceView = resource._resourcesView;
     65    var resourceView = resource._resourceView;
    6666    switch (resource.category) {
    6767    case WebInspector.resourceCategories.documents:
     
    8383    if (!resource)
    8484        return null;
    85     if (!resource._resourcesView)
    86         resource._resourcesView = WebInspector.ResourceView.createResourceView(resource);
    87     return resource._resourcesView;
     85    if (!resource._resourceView)
     86        resource._resourceView = WebInspector.ResourceView.createResourceView(resource);
     87    return resource._resourceView;
    8888}
    8989
     
    9292    var newView = WebInspector.ResourceView.createResourceView(resource);
    9393
    94     var oldView = resource._resourcesView;
     94    var oldView = resource._resourceView;
    9595    var oldViewParentNode = oldView.visible ? oldView.element.parentNode : null;
    9696    var scrollTop = oldView.scrollTop;
    9797
    98     resource._resourcesView.detach();
    99     delete resource._resourcesView;
    100 
    101     resource._resourcesView = newView;
     98    resource._resourceView.detach();
     99    delete resource._resourceView;
     100
     101    resource._resourceView = newView;
    102102
    103103    if (oldViewParentNode)
     
    113113    if (!resource)
    114114        return null;
    115     return resource._resourcesView;
     115    return resource._resourceView;
    116116}
    117117
     
    167167    },
    168168
    169     _requestContent: function(callback)
     169    requestContent: function(callback)
    170170    {
    171171        function contentLoaded(text)
     
    179179
    180180WebInspector.ResourceSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;
     181
     182WebInspector.RevisionSourceFrame = function(revision)
     183{
     184    WebInspector.SourceFrame.call(this, new WebInspector.SourceFrameDelegate(), revision.resource.url);
     185    this._revision = revision;
     186}
     187
     188WebInspector.RevisionSourceFrame.prototype = {
     189    get resource()
     190    {
     191        return this._revision.resource;
     192    },
     193
     194    isContentEditable: function()
     195    {
     196        return false;
     197    },
     198
     199    requestContent: function(callback)
     200    {
     201        function contentLoaded(text)
     202        {
     203            var mimeType = WebInspector.ResourceSourceFrame.DefaultMIMETypeForResourceType[this._revision.resource.type] || this._revision.resource.mimeType;
     204            callback(mimeType, text);
     205        }
     206        this._revision.requestContent(contentLoaded.bind(this));
     207    }
     208}
     209
     210WebInspector.RevisionSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;
  • trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js

    r83962 r83969  
    404404    {
    405405        var view = WebInspector.ResourceView.resourceViewForResource(resource);
    406 
    407         // Consider rendering diff markup here.
    408         if (resource.baseRevision && view instanceof WebInspector.SourceFrame) {
    409             function callback(baseContent)
    410             {
    411                 if (baseContent)
    412                     this._applyDiffMarkup(view, baseContent, resource.content);
    413             }
    414             resource.baseRevision.requestContent(callback.bind(this));
    415         }
     406        this._fetchAndApplyDiffMarkup(view, resource);
    416407        this._innerShowView(view);
     408    },
     409
     410    _showRevisionView: function(revision)
     411    {
     412        if (!revision._view)
     413            revision._view = new WebInspector.RevisionSourceFrame(revision);
     414        var view = revision._view;
     415        this._fetchAndApplyDiffMarkup(view, revision.resource, revision);
     416        this._innerShowView(view);
     417    },
     418
     419    _fetchAndApplyDiffMarkup: function(view, resource, revision)
     420    {
     421        var baseRevision = resource.history[0];
     422        if (!baseRevision)
     423            return;
     424        if (!(view instanceof WebInspector.SourceFrame))
     425            return;
     426
     427        baseRevision.requestContent(step1.bind(this));
     428
     429        function step1(baseContent)
     430        {
     431            (revision ? revision : resource).requestContent(step2.bind(this, baseContent));
     432        }
     433
     434        function step2(baseContent, revisionContent)
     435        {
     436            this._applyDiffMarkup(view, baseContent, revisionContent);
     437        }
    417438    },
    418439
     
    12531274{
    12541275    var title = revision.timestamp ? revision.timestamp.toLocaleTimeString() : WebInspector.UIString("(original)");
    1255     WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, title, ["resource-sidebar-tree-item", "resources-category-" + revision.category.name]);
     1276    WebInspector.BaseStorageTreeElement.call(this, storagePanel, null, title, ["resource-sidebar-tree-item", "resources-category-" + revision.resource.category.name]);
    12561277    if (revision.timestamp)
    12571278        this.tooltip = revision.timestamp.toLocaleString();
    1258     this._resource = revision;
     1279    this._revision = revision;
    12591280}
    12601281
    12611282WebInspector.ResourceRevisionTreeElement.prototype = {
     1283    get itemURL()
     1284    {
     1285        return this._revision.resource.url;
     1286    },
     1287
    12621288    onattach: function()
    12631289    {
     
    12711297    {
    12721298        WebInspector.BaseStorageTreeElement.prototype.onselect.call(this);
    1273         this._storagePanel._showResourceView(this._resource);
     1299        this._storagePanel._showRevisionView(this._revision);
    12741300    },
    12751301
    12761302    _ondragstart: function(event)
    12771303    {
    1278         event.dataTransfer.setData("text/plain", this._resource.content);
    1279         event.dataTransfer.effectAllowed = "copy";
    1280         return true;
     1304        if (this._revision.content) {
     1305            event.dataTransfer.setData("text/plain", this._revision.content);
     1306            event.dataTransfer.effectAllowed = "copy";
     1307            return true;
     1308        }
    12811309    },
    12821310
     
    12841312    {
    12851313        var contextMenu = new WebInspector.ContextMenu();
    1286         contextMenu.appendItem(WebInspector.UIString("Revert to this revision"), this._resource.revertToThis.bind(this._resource));
     1314        contextMenu.appendItem(WebInspector.UIString("Revert to this revision"), this._revision.revertToThis.bind(this._revision));
    12871315        contextMenu.show(event);
    12881316    }
  • trunk/Source/WebCore/inspector/front-end/SourceFrame.js

    r83951 r83969  
    120120        if (!this._contentRequested) {
    121121            this._contentRequested = true;
    122             this._requestContent(this._initializeTextViewer.bind(this));
    123         }
    124     },
    125 
    126     _requestContent: function(callback)
     122            this.requestContent(this._initializeTextViewer.bind(this));
     123        }
     124    },
     125
     126    requestContent: function(callback)
    127127    {
    128128        this._delegate.requestContent(callback);
     
    904904        {
    905905            if (error) {
    906                 WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
    907                 WebInspector.showConsole();
     906                if (error.data && error.data[0]) {
     907                    WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
     908                    WebInspector.showConsole();
     909                }
    908910                callback(error);
    909911                return;
Note: See TracChangeset for help on using the changeset viewer.