Changeset 83962 in webkit


Ignore:
Timestamp:
Apr 15, 2011 5:39:32 AM (13 years ago)
Author:
pfeldman@chromium.org
Message:

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

Reviewed by Yury Semikhatsky.

Web Inspector: refactor resource setContent / revisions infrastructure to get
rid of onRevert callback.
https://bugs.webkit.org/show_bug.cgi?id=58649

Instead, we will have DomainModel/Resource binding responsible for changing
underlying model upon resource changes and vice versa.

  • inspector/Inspector.json:
  • inspector/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::getStyleSheet): (WebCore::InspectorCSSAgent::getStyleSheetText): (WebCore::InspectorCSSAgent::setStyleSheetText): (WebCore::InspectorCSSAgent::setPropertyText): (WebCore::InspectorCSSAgent::toggleProperty): (WebCore::InspectorCSSAgent::setRuleSelector): (WebCore::InspectorCSSAgent::assertStyleSheetForId):
  • inspector/InspectorCSSAgent.h:
  • inspector/front-end/CSSStyleModel.js: (WebInspector.CSSStyleModel): (WebInspector.CSSStyleModel.prototype.setRuleSelector): (WebInspector.CSSStyleModel.prototype.addRule): (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged.callback): (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged): (WebInspector.CSSStyleModel.prototype.setStyleSheetText): (WebInspector.CSSStyleDeclaration.prototype.insertPropertyAt): (WebInspector.CSSProperty.prototype.setText): (WebInspector.CSSProperty.prototype.setText.callback): (WebInspector.CSSProperty.prototype.setDisabled.callback): (WebInspector.CSSProperty.prototype.setDisabled): (WebInspector.CSSStyleSheet.prototype.setText): (WebInspector.CSSStyleModelResourceBinding): (WebInspector.CSSStyleModelResourceBinding.prototype.setContent): (WebInspector.CSSStyleModelResourceBinding.prototype._frameNavigated): (WebInspector.CSSStyleModelResourceBinding.prototype._innerSetContent): (WebInspector.CSSStyleModelResourceBinding.prototype._loadStyleSheetHeaders): (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged.setContent): (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged):
  • inspector/front-end/DebuggerPresentationModel.js: (WebInspector.DebuggerPresentationModel): (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didEditScriptSource): (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didReceiveSource): (WebInspector.DebuggerPresentationModel.prototype.editScriptSource): (WebInspector.DebuggerPresentationModelResourceBinding): (WebInspector.DebuggerPresentationModelResourceBinding.prototype.canSetContent): (WebInspector.DebuggerPresentationModelResourceBinding.prototype.setContent):
  • inspector/front-end/Object.js: (WebInspector.Object.prototype.hasEventListeners):
  • inspector/front-end/Resource.js: (WebInspector.Resource): (WebInspector.Resource.registerDomainModelBinding): (WebInspector.Resource.prototype.isEditable): (WebInspector.Resource.prototype.setContent): (WebInspector.Resource.prototype.addRevision): (WebInspector.Resource.prototype.revertToThis.callback): (WebInspector.Resource.prototype.revertToThis): (WebInspector.ResourceDomainModelBinding): (WebInspector.ResourceDomainModelBinding.prototype.canSetContent): (WebInspector.ResourceDomainModelBinding.prototype.setContent):
  • inspector/front-end/ResourceView.js: (WebInspector.ResourceView.createResourceView): (WebInspector.ResourceView.resourceViewTypeMatchesResource): (WebInspector.ResourceSourceFrame.prototype.isContentEditable): (WebInspector.ResourceSourceFrame.prototype.editContent): (WebInspector.ResourceSourceFrame.prototype.endEditing): (WebInspector.ResourceSourceFrame.prototype._clearIncrementalUpdateTimer): (WebInspector.ResourceSourceFrame.prototype._requestContent):
  • inspector/front-end/ResourcesPanel.js: (WebInspector.ResourcesPanel.prototype._resourceAdded): (WebInspector.FrameResourceTreeElement): (WebInspector.FrameResourceTreeElement.prototype._populateRevisions): (WebInspector.FrameResourceTreeElement.prototype._revisionAdded): (WebInspector.FrameResourceTreeElement.prototype._appendRevision):
  • inspector/front-end/inspector.html:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/styles/get-set-stylesheet-text.html

    r83843 r83962  
    4040    function testSetText(next)
    4141    {
    42         function callback(success)
     42        function callback(error)
    4343        {
    44             if (!success) {
    45                 InspectorTest.addError("Failed to set stylesheet text");
     44            if (error) {
     45                InspectorTest.addResult("Failed to set stylesheet text: " + error);
    4646                return;
    4747            }
     
    6060        {
    6161            if (error) {
    62                 InspectorTest.addError("error: " + error);
     62                InspectorTest.addResult("error: " + error);
    6363                return;
    6464            }
  • trunk/LayoutTests/inspector/styles/styles-new-API.html

    r82578 r83962  
    1818        {
    1919            if (error) {
    20                 InspectorTest.addError("error: " + error);
     20                InspectorTest.addResult("error: " + error);
    2121                return;
    2222            }
     
    298298    {
    299299        if (error) {
    300             InspectorTest.addError("error: " + error);
     300            InspectorTest.addResult("error: " + error);
    301301            return;
    302302        }
     
    305305        {
    306306            if (error) {
    307                 InspectorTest.addError("error: " + error);
     307                InspectorTest.addResult("error: " + error);
    308308                return;
    309309            }
  • trunk/Source/WebCore/ChangeLog

    r83960 r83962  
     12011-04-15  Pavel Feldman  <pfeldman@google.com>
     2
     3        Reviewed by Yury Semikhatsky.
     4
     5        Web Inspector: refactor resource setContent / revisions infrastructure to get
     6        rid of onRevert callback.
     7        https://bugs.webkit.org/show_bug.cgi?id=58649
     8
     9        Instead, we will have DomainModel/Resource binding responsible for changing
     10        underlying model upon resource changes and vice versa.
     11
     12        * inspector/Inspector.json:
     13        * inspector/InspectorCSSAgent.cpp:
     14        (WebCore::InspectorCSSAgent::getStyleSheet):
     15        (WebCore::InspectorCSSAgent::getStyleSheetText):
     16        (WebCore::InspectorCSSAgent::setStyleSheetText):
     17        (WebCore::InspectorCSSAgent::setPropertyText):
     18        (WebCore::InspectorCSSAgent::toggleProperty):
     19        (WebCore::InspectorCSSAgent::setRuleSelector):
     20        (WebCore::InspectorCSSAgent::assertStyleSheetForId):
     21        * inspector/InspectorCSSAgent.h:
     22        * inspector/front-end/CSSStyleModel.js:
     23        (WebInspector.CSSStyleModel):
     24        (WebInspector.CSSStyleModel.prototype.setRuleSelector):
     25        (WebInspector.CSSStyleModel.prototype.addRule):
     26        (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged.callback):
     27        (WebInspector.CSSStyleModel.prototype._fireStyleSheetChanged):
     28        (WebInspector.CSSStyleModel.prototype.setStyleSheetText):
     29        (WebInspector.CSSStyleDeclaration.prototype.insertPropertyAt):
     30        (WebInspector.CSSProperty.prototype.setText):
     31        (WebInspector.CSSProperty.prototype.setText.callback):
     32        (WebInspector.CSSProperty.prototype.setDisabled.callback):
     33        (WebInspector.CSSProperty.prototype.setDisabled):
     34        (WebInspector.CSSStyleSheet.prototype.setText):
     35        (WebInspector.CSSStyleModelResourceBinding):
     36        (WebInspector.CSSStyleModelResourceBinding.prototype.setContent):
     37        (WebInspector.CSSStyleModelResourceBinding.prototype._frameNavigated):
     38        (WebInspector.CSSStyleModelResourceBinding.prototype._innerSetContent):
     39        (WebInspector.CSSStyleModelResourceBinding.prototype._loadStyleSheetHeaders):
     40        (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged.setContent):
     41        (WebInspector.CSSStyleModelResourceBinding.prototype._styleSheetChanged):
     42        * inspector/front-end/DebuggerPresentationModel.js:
     43        (WebInspector.DebuggerPresentationModel):
     44        (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didEditScriptSource):
     45        (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didReceiveSource):
     46        (WebInspector.DebuggerPresentationModel.prototype.editScriptSource):
     47        (WebInspector.DebuggerPresentationModelResourceBinding):
     48        (WebInspector.DebuggerPresentationModelResourceBinding.prototype.canSetContent):
     49        (WebInspector.DebuggerPresentationModelResourceBinding.prototype.setContent):
     50        * inspector/front-end/Object.js:
     51        (WebInspector.Object.prototype.hasEventListeners):
     52        * inspector/front-end/Resource.js:
     53        (WebInspector.Resource):
     54        (WebInspector.Resource.registerDomainModelBinding):
     55        (WebInspector.Resource.prototype.isEditable):
     56        (WebInspector.Resource.prototype.setContent):
     57        (WebInspector.Resource.prototype.addRevision):
     58        (WebInspector.Resource.prototype.revertToThis.callback):
     59        (WebInspector.Resource.prototype.revertToThis):
     60        (WebInspector.ResourceDomainModelBinding):
     61        (WebInspector.ResourceDomainModelBinding.prototype.canSetContent):
     62        (WebInspector.ResourceDomainModelBinding.prototype.setContent):
     63        * inspector/front-end/ResourceView.js:
     64        (WebInspector.ResourceView.createResourceView):
     65        (WebInspector.ResourceView.resourceViewTypeMatchesResource):
     66        (WebInspector.ResourceSourceFrame.prototype.isContentEditable):
     67        (WebInspector.ResourceSourceFrame.prototype.editContent):
     68        (WebInspector.ResourceSourceFrame.prototype.endEditing):
     69        (WebInspector.ResourceSourceFrame.prototype._clearIncrementalUpdateTimer):
     70        (WebInspector.ResourceSourceFrame.prototype._requestContent):
     71        * inspector/front-end/ResourcesPanel.js:
     72        (WebInspector.ResourcesPanel.prototype._resourceAdded):
     73        (WebInspector.FrameResourceTreeElement):
     74        (WebInspector.FrameResourceTreeElement.prototype._populateRevisions):
     75        (WebInspector.FrameResourceTreeElement.prototype._revisionAdded):
     76        (WebInspector.FrameResourceTreeElement.prototype._appendRevision):
     77        * inspector/front-end/inspector.html:
     78
    1792011-04-15  Andrey Kosyakov  <caseq@chromium.org>
    280
  • trunk/Source/WebCore/inspector/Inspector.json

    r83950 r83962  
    11661166                ],
    11671167                "returns": [
    1168                     { "name": "url", "type": "string", "description": "The stylesheet resource URL." },
    11691168                    { "name": "text", "type": "string", "description": "The stylesheet text." }
    11701169                ],
     
    11761175                    { "name": "styleSheetId", "type": "string" },
    11771176                    { "name": "text", "type": "string" }
    1178                 ],
    1179                 "returns": [
    1180                     { "name": "success", "type": "boolean", "description": "Whether the modification was successful." }
    11811177                ],
    11821178                "description": "Sets the new stylesheet text, thereby invalidating all existing <code>CSSStyleId</code>'s and <code>CSSRuleId</code>'s contained by this stylesheet."
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r82581 r83962  
    278278void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& styleSheetId, RefPtr<InspectorObject>* styleSheetObject)
    279279{
    280     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId);
     280    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
    281281    if (!inspectorStyleSheet)
    282282        return;
     
    285285}
    286286
    287 void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String& styleSheetId, String* url, String* result)
    288 {
    289     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId);
    290     if (!inspectorStyleSheet)
    291         return;
    292     *url = inspectorStyleSheet->finalURL();
     287void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String& styleSheetId, String* result)
     288{
     289    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
     290    if (!inspectorStyleSheet)
     291        return;
     292
    293293    inspectorStyleSheet->text(result);
    294294}
    295295
    296 void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text, bool* success)
    297 {
    298     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, styleSheetId);
    299     if (!inspectorStyleSheet) {
    300         *success = false;
    301         return;
    302     }
    303 
    304     *success = inspectorStyleSheet->setText(text);
    305     if (*success)
     296void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text)
     297{
     298    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId);
     299    if (!inspectorStyleSheet)
     300        return;
     301
     302    if (inspectorStyleSheet->setText(text))
    306303        inspectorStyleSheet->reparseStyleSheet(text);
     304    else
     305        *errorString = "Internal error setting style sheet text.";
    307306}
    308307
     
    312311    ASSERT(!compoundId.isEmpty());
    313312
    314     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());
     313    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId());
    315314    if (!inspectorStyleSheet)
    316315        return;
     
    326325    ASSERT(!compoundId.isEmpty());
    327326
    328     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());
     327    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId());
    329328    if (!inspectorStyleSheet)
    330329        return;
     
    340339    ASSERT(!compoundId.isEmpty());
    341340
    342     InspectorStyleSheet* inspectorStyleSheet = styleSheetForId(errorString, compoundId.styleSheetId());
     341    InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId());
    343342    if (!inspectorStyleSheet)
    344343        return;
     
    472471}
    473472
    474 InspectorStyleSheet* InspectorCSSAgent::styleSheetForId(ErrorString* errorString, const String& styleSheetId)
     473InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* errorString, const String& styleSheetId)
    475474{
    476475    IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleSheetId);
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.h

    r82433 r83962  
    6767    void getAllStyleSheets(ErrorString*, RefPtr<InspectorArray>* styleSheetInfos);
    6868    void getStyleSheet(ErrorString*, const String& styleSheetId, RefPtr<InspectorObject>* result);
    69     void getStyleSheetText(ErrorString*, const String& styleSheetId, String* url, String* result);
    70     void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text, bool* success);
     69    void getStyleSheetText(ErrorString*, const String& styleSheetId, String* result);
     70    void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text);
    7171    void setPropertyText(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, const String& text, bool overwrite, RefPtr<InspectorObject>* result);
    7272    void toggleProperty(ErrorString*, const RefPtr<InspectorObject>& styleId, int propertyIndex, bool disable, RefPtr<InspectorObject>* result);
     
    8888    InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*);
    8989    InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent);
    90     InspectorStyleSheet* styleSheetForId(ErrorString*, const String&);
     90    InspectorStyleSheet* assertStyleSheetForId(ErrorString*, const String&);
    9191    String detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
    9292
  • trunk/Source/WebCore/inspector/front-end/CSSStyleModel.js

    r83843 r83962  
    3131WebInspector.CSSStyleModel = function()
    3232{
     33    new WebInspector.CSSStyleModelResourceBinding(this);
    3334}
    3435
     
    3940        result.push(WebInspector.CSSRule.parsePayload(ruleArray[i]));
    4041    return result;
     42}
     43
     44WebInspector.CSSStyleModel.Events = {
     45    StyleSheetChanged: 0
    4146}
    4247
     
    125130            var rule = WebInspector.CSSRule.parsePayload(rulePayload);
    126131            successCallback(rule, doesAffectSelectedNode);
    127             this._styleSheetChanged(rule.id.styleSheetId, true);
     132            this._fireStyleSheetChanged(rule.id.styleSheetId, true);
    128133        }
    129134
     
    147152            var rule = WebInspector.CSSRule.parsePayload(rulePayload);
    148153            successCallback(rule, doesAffectSelectedNode);
    149             this._styleSheetChanged(rule.id.styleSheetId, true);
     154            this._fireStyleSheetChanged(rule.id.styleSheetId, true);
    150155        }
    151156
     
    162167    },
    163168
    164     _styleSheetChanged: function(styleSheetId, majorChange)
     169    _fireStyleSheetChanged: function(styleSheetId, majorChange)
    165170    {
    166171        if (!majorChange || !styleSheetId)
    167172            return;
    168173
    169         function callback(error, href, content)
     174        function callback(error, content)
    170175        {
    171176            if (error)
    172177                return;
    173             var resource = WebInspector.resourceForURL(href);
    174             if (resource && resource.type === WebInspector.Resource.Type.Stylesheet) {
    175                 resource.setContent(content, this._onRevert.bind(this, styleSheetId));
    176                 this.dispatchEventToListeners("stylesheet changed");
    177             }
    178         }
    179         CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this));
    180     },
    181 
    182     _onRevert: function(styleSheetId, contentToRevertTo)
    183     {
    184         function callback(error, success)
    185         {
    186             if (error)
    187                 return;
    188             this._styleSheetChanged(styleSheetId, true);
    189         }
    190         CSSAgent.setStyleSheetText(styleSheetId, contentToRevertTo, callback.bind(this));
     178
     179            this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged, { styleSheetId: styleSheetId, content: content, majorChange: majorChange });
     180        }
     181        if (this.hasEventListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged))
     182            CSSAgent.getStyleSheetText(styleSheetId, callback.bind(this));
     183    },
     184
     185    setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback)
     186    {
     187        function callback(error)
     188        {
     189             if (!error)
     190                 this._fireStyleSheetChanged(this.id, majorChange);
     191
     192             if (userCallback)
     193                 userCallback(error);
     194        }
     195        CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this));
    191196    }
    192197}
     
    366371            else {
    367372                userCallback(WebInspector.CSSStyleDeclaration.parsePayload(payload));
    368                 WebInspector.cssModel._styleSheetChanged(this.id.styleSheetId, true);
     373                WebInspector.cssModel._fireStyleSheetChanged(this.id.styleSheetId, true);
    369374            }
    370375        }
     
    487492        {
    488493            if (style)
    489                 WebInspector.cssModel._styleSheetChanged(style.id.styleSheetId, majorChange);
     494                WebInspector.cssModel._fireStyleSheetChanged(style.id.styleSheetId, majorChange);
    490495            if (userCallback)
    491496                userCallback(style);
     
    503508                    return;
    504509                } else
    505                     WebInspector.cssModel._styleSheetChanged(style.id.styleSheetId, majorChange);
     510                    WebInspector.cssModel._fireStyleSheetChanged(style.id.styleSheetId, majorChange);
    506511                if (userCallback)
    507512                    userCallback(style);
     
    541546                var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload);
    542547                userCallback(style);
    543                 WebInspector.cssModel._styleSheetChanged(this.ownerStyle.id.styleSheetId, false);
     548                WebInspector.cssModel._fireStyleSheetChanged(this.ownerStyle.id.styleSheetId, false);
    544549            }
    545550        }
     
    584589    setText: function(newText, majorChange, userCallback)
    585590    {
    586         function callback(error, isChangeSuccessful)
     591        function callback(error)
    587592        {
    588593             if (userCallback)
    589                  userCallback(isChangeSuccessful);
    590              if (isChangeSuccessful)
    591                  WebInspector.cssModel._styleSheetChanged(this.id, majorChange);
     594                 userCallback(error);
     595             if (!error)
     596                 WebInspector.cssModel._fireStyleSheetChanged(this.id, majorChange);
    592597        }
    593598
     
    595600    }
    596601}
     602
     603WebInspector.CSSStyleModelResourceBinding = function(cssModel)
     604{
     605    this._cssModel = cssModel;
     606    this._urlToStyleSheetId = {};
     607    this._styleSheetIdToURL = {};
     608    this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetChanged, this);
     609    WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
     610    WebInspector.Resource.registerDomainModelBinding(WebInspector.Resource.Type.Stylesheet, this);
     611}
     612
     613WebInspector.CSSStyleModelResourceBinding.prototype = {
     614    setContent: function(resource, content, majorChange, userCallback)
     615    {
     616        if (this._urlToStyleSheetId[resource.url]) {
     617            this._innerSetContent(resource.url, content, majorChange, userCallback);
     618            return;
     619        }
     620        this._loadStyleSheetHeaders(this._innerSetContent.bind(this, resource.url, content, majorChange, userCallback));
     621    },
     622
     623    _frameNavigated: function(event)
     624    {
     625        var frameId = event.data;
     626        if (!frameId) {
     627            // Main frame navigation - clear history.
     628            this._urlToStyleSheetId = {};
     629            this._styleSheetIdToURL = {};
     630        }
     631    },
     632
     633    _innerSetContent: function(url, content, majorChange, userCallback, error)
     634    {
     635        if (error) {
     636            userCallback(error);
     637            return;
     638        }
     639
     640        var styleSheetId = this._urlToStyleSheetId[url];
     641        if (!styleSheetId) {
     642            if (userCallback)
     643                userCallback("No stylesheet found: " + url);
     644            return;
     645        }
     646        this._cssModel.setStyleSheetText(styleSheetId, content, majorChange, userCallback);
     647    },
     648
     649    _loadStyleSheetHeaders: function(callback)
     650    {
     651        function didGetAllStyleSheets(error, infos)
     652        {
     653            if (error) {
     654                callback(error);
     655                return;
     656            }
     657
     658            for (var i = 0; i < infos.length; ++i) {
     659                var info = infos[i];
     660                this._urlToStyleSheetId[info.sourceURL] = info.styleSheetId;
     661                this._styleSheetIdToURL[info.styleSheetId] = info.sourceURL;
     662            }
     663            callback();
     664        }
     665        CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
     666    },
     667
     668    _styleSheetChanged: function(event)
     669    {
     670        var styleSheetId = event.data.styleSheetId;
     671        function setContent()
     672        {
     673            var url = this._styleSheetIdToURL[styleSheetId];
     674            if (!url)
     675                return;
     676   
     677            var resource = WebInspector.resourceForURL(url);
     678            if (!resource)
     679                return;
     680
     681            var majorChange = event.data.majorChange;
     682            if (majorChange)
     683                resource.addRevision(event.data.content);
     684        }
     685
     686        if (!this._styleSheetIdToURL[styleSheetId]) {
     687            this._loadStyleSheetHeaders(setContent.bind(this));
     688            return;
     689        }
     690        setContent.call(this);
     691    }
     692}
     693
     694WebInspector.CSSStyleModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
  • trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js

    r83719 r83962  
    4646    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
    4747    WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Reset, this._debuggerReset, this);
     48
     49    new WebInspector.DebuggerPresentationModelResourceBinding(this);
    4850}
    4951
     
    141143        var script = this._scriptForSourceFileId(sourceFileId);
    142144        var sourceFile = this._sourceFiles[sourceFileId];
    143         var oldSource = sourceFile.content;
    144         function didEditScriptSource(error)
     145
     146        function didEditScriptSource(oldSource, error)
    145147        {
    146148            if (!error) {
    147149                sourceFile.content = newSource;
    148                 this._updateResourceContent(sourceFile, oldSource, newSource);
     150
     151                var resource = WebInspector.resourceForURL(sourceFile.url);
     152                if (resource)
     153                    resource.addRevision(newSource);
    149154            }
    150155
     
    154159                this._debuggerPaused();
    155160        }
    156         WebInspector.debuggerModel.editScriptSource(script.sourceID, newSource, didEditScriptSource.bind(this));
    157     },
    158 
    159     _updateResourceContent: function(sourceFile, oldSource, newSource)
    160     {
    161         var resource = WebInspector.resourceForURL(sourceFile.url);
    162         if (!resource)
    163             return;
    164 
    165         function didEditScriptSource(error)
    166         {
    167             this._updateBreakpointsAfterLiveEdit(sourceFile.id, oldSource, newSource);
    168             sourceFile.reload();
    169         }
    170         var revertHandle = this.editScriptSource.bind(this, sourceFile.id, oldSource, didEditScriptSource.bind(this));
    171         resource.setContent(newSource, revertHandle);
     161
     162        var oldSource = sourceFile.requestContent(didReceiveSource.bind(this));
     163        function didReceiveSource(oldSource)
     164        {
     165            WebInspector.debuggerModel.editScriptSource(script.sourceID, newSource, didEditScriptSource.bind(this, oldSource));
     166        }
    172167    },
    173168
     
    713708    }
    714709}
     710
     711WebInspector.DebuggerPresentationModelResourceBinding = function(model)
     712{
     713    this._presentationModel = model;
     714    WebInspector.Resource.registerDomainModelBinding(WebInspector.Resource.Type.Script, this);
     715}
     716
     717WebInspector.DebuggerPresentationModelResourceBinding.prototype = {
     718    canSetContent: function(resource)
     719    {
     720        var sourceFile = this._presentationModel._sourceFileForScript(resource.url)
     721        if (!sourceFile)
     722            return false;
     723        return this._presentationModel.canEditScriptSource(sourceFile.id);
     724    },
     725
     726    setContent: function(resource, content, majorChange, userCallback)
     727    {
     728        if (!majorChange)
     729            return;
     730
     731        var sourceFile = this._presentationModel._sourceFileForScript(resource.url);
     732        if (!sourceFile) {
     733            userCallback("Resource is not editable");
     734            return;
     735        }
     736
     737        resource.requestContent(this._setContentWithInitialContent.bind(this, sourceFile, content, userCallback));
     738    },
     739
     740    _setContentWithInitialContent: function(sourceFile, content, userCallback, oldContent)
     741    {
     742        function callback(error)
     743        {
     744            if (userCallback)
     745                userCallback(error);
     746            if (!error) {
     747                this._presentationModel._updateBreakpointsAfterLiveEdit(sourceFile.id, oldContent, content);
     748                sourceFile.reload();
     749            }
     750        }
     751        this._presentationModel.editScriptSource(sourceFile.id, content, callback.bind(this));
     752    }
     753}
     754
     755WebInspector.DebuggerPresentationModelResourceBinding.prototype.__proto__ = WebInspector.ResourceDomainModelBinding.prototype;
  • trunk/Source/WebCore/inspector/front-end/Object.js

    r61954 r83962  
    5858    },
    5959
     60    hasEventListeners: function(eventType)
     61    {
     62        if (!("_listeners" in this) || !(eventType in this._listeners))
     63            return false;
     64        return true;
     65    },
     66
    6067    dispatchEventToListeners: function(eventType, eventData)
    6168    {
  • trunk/Source/WebCore/inspector/front-end/Resource.js

    r83950 r83962  
    3434    this._category = WebInspector.resourceCategories.other;
    3535    this._pendingContentCallbacks = [];
     36    this.history = [];
    3637}
    3738
     
    99100        }
    100101    }
     102}
     103
     104WebInspector.Resource._domainModelBindings = [];
     105
     106WebInspector.Resource.registerDomainModelBinding = function(type, binding)
     107{
     108    WebInspector.Resource._domainModelBindings[type] = binding;
     109}
     110
     111WebInspector.Resource.Events = {
     112    RevisionAdded: 0
    101113}
    102114
     
    691703    },
    692704
    693     isResourceRevision: function()
    694     {
    695         return !!this._actualResource;
    696     },
    697 
    698     setContent: function(newContent, onRevert)
     705    isEditable: function()
     706    {
     707        if (this._actualResource)
     708            return false;
     709        var binding = WebInspector.Resource._domainModelBindings[this.type];
     710        return binding && binding.canSetContent(this);
     711    },
     712
     713    setContent: function(newContent, majorChange, callback)
     714    {
     715        if (!this.isEditable(this)) {
     716            if (callback)
     717                callback("Resource is not editable");
     718            return;
     719        }
     720        var binding = WebInspector.Resource._domainModelBindings[this.type];
     721        binding.setContent(this, newContent, majorChange, callback);
     722    },
     723
     724    addRevision: function(newContent)
    699725    {
    700726        var revisionResource = new WebInspector.Resource(null, this.url);
     727        revisionResource.frameId = this.frameId;
     728        revisionResource.loaderId = this.loaderId;
     729        revisionResource.documentURL = this.documentURL;
    701730        revisionResource.type = this.type;
    702731        revisionResource.loader = this.loader;
     
    704733        revisionResource._content = this._content;
    705734        revisionResource._actualResource = this;
    706         revisionResource._fireOnRevert = onRevert;
    707735
    708736        if (this.finished)
     
    722750            revisionResource._baseRevision = this._baseRevision;
    723751
    724         var data = { revision: revisionResource };
    725752        this._content = newContent;
    726753        this.timestamp = new Date();
    727754
    728         this.dispatchEventToListeners("content-changed", data);
     755        this.history.push(revisionResource);
     756        this.dispatchEventToListeners(WebInspector.Resource.Events.RevisionAdded, revisionResource);
    729757    },
    730758
    731759    revertToThis: function()
    732760    {
    733         if (!this._actualResource || !this._fireOnRevert)
     761        if (!this._actualResource)
    734762            return;
    735763
     
    737765        {
    738766            if (content)
    739                 this._fireOnRevert(content);
     767                this._actualResource.setContent(content, true);
    740768        }
    741769        this.requestContent(callback.bind(this));
     
    814842
    815843WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype;
     844
     845
     846WebInspector.ResourceDomainModelBinding = function()
     847{
     848}
     849
     850WebInspector.ResourceDomainModelBinding.prototype = {
     851    canSetContent: function()
     852    {
     853        // Implemented by the domains.
     854        return true;
     855    },
     856
     857    setContent: function(resource, content, majorChange, callback)
     858    {
     859        // Implemented by the domains.
     860    }
     861}
  • trunk/Source/WebCore/inspector/front-end/ResourceView.js

    r83843 r83962  
    5050    case WebInspector.resourceCategories.scripts:
    5151    case WebInspector.resourceCategories.xhr:
     52    case WebInspector.resourceCategories.stylesheets:
    5253        return new WebInspector.ResourceSourceFrame(resource);
    53     case WebInspector.resourceCategories.stylesheets:
    54         return new WebInspector.CSSSourceFrame(resource);
    5554    case WebInspector.resourceCategories.images:
    5655        return new WebInspector.ImageView(resource);
     
    6968    case WebInspector.resourceCategories.scripts:
    7069    case WebInspector.resourceCategories.xhr:
     70    case WebInspector.resourceCategories.stylesheets:
    7171        return resourceView.__proto__ === WebInspector.ResourceSourceFrame.prototype;
    72     case WebInspector.resourceCategories.stylesheets:
    73         return resourceView.__proto__ === WebInspector.CSSSourceFrame.prototype;
    7472    case WebInspector.resourceCategories.images:
    7573        return resourceView.__proto__ === WebInspector.ImageView.prototype;
     
    141139    isContentEditable: function()
    142140    {
    143         return false;
     141        return this._resource.isEditable();
     142    },
     143
     144    editContent: function(newText, callback)
     145    {
     146        this._clearIncrementalUpdateTimer();
     147        var majorChange = true;
     148        this._resource.setContent(newText, majorChange, callback);
     149    },
     150
     151    endEditing: function(oldRange, newRange)
     152    {
     153        function commitIncrementalEdit()
     154        {
     155            var majorChange = false;
     156            this._resource.setContent(this._textModel.text, majorChange, function() {});
     157        }
     158        const updateTimeout = 200;
     159        this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);
     160    },
     161
     162    _clearIncrementalUpdateTimer: function()
     163    {
     164        if (this._incrementalUpdateTimer)
     165            clearTimeout(this._incrementalUpdateTimer);
     166        delete this._incrementalUpdateTimer;
    144167    },
    145168
     
    156179
    157180WebInspector.ResourceSourceFrame.prototype.__proto__ = WebInspector.SourceFrame.prototype;
    158 
    159 
    160 WebInspector.CSSSourceFrame = function(resource)
    161 {
    162     WebInspector.ResourceSourceFrame.call(this, resource);
    163     this._loadStyleSheet();
    164 }
    165 
    166 WebInspector.CSSSourceFrame.prototype = {
    167     isContentEditable: function()
    168     {
    169         return !!this._styleSheet && !this._resource.isResourceRevision();
    170     },
    171 
    172     _loadStyleSheet: function()
    173     {
    174         function didGetAllStyleSheets(error, infos)
    175         {
    176             if (error)
    177                 return;
    178 
    179             var stylesheetId;
    180             for (var i = 0; i < infos.length; ++i) {
    181                 var info = infos[i];
    182                 if (info.sourceURL === this._resource.url) {
    183                     stylesheetId = info.styleSheetId;
    184                     break;
    185                 }
    186             }
    187             if (!stylesheetId)
    188                 return;
    189 
    190             function didCreateForId(styleSheet)
    191             {
    192                 this._styleSheet = styleSheet;
    193             }
    194             WebInspector.CSSStyleSheet.createForId(stylesheetId, didCreateForId.bind(this));
    195         }
    196         CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
    197     },
    198 
    199     editContent: function(newText, callback)
    200     {
    201         if (!this._styleSheet) {
    202             callback("Stylesheet not found.");
    203             return;
    204         }
    205 
    206         this._resetIncrementalUpdateTimer();
    207 
    208         function didSetText(success)
    209         {
    210             var error;
    211             if (!success)
    212                 error = "Failed to save modified stylesheet " + this._resource.url;
    213             callback(error);
    214         }
    215         this._styleSheet.setText(newText, true, didSetText.bind(this));
    216     },
    217 
    218     endEditing: function(oldRange, newRange)
    219     {
    220         function commitIncrementalEdit()
    221         {
    222             var majorChange = false;
    223             this._styleSheet.setText(this._textModel.text, majorChange);
    224         }
    225         const updateTimeout = 200;
    226         this._incrementalUpdateTimer = setTimeout(commitIncrementalEdit.bind(this), updateTimeout);
    227     },
    228 
    229     _resetIncrementalUpdateTimer: function()
    230     {
    231         if (this._incrementalUpdateTimer)
    232             clearTimeout(this._incrementalUpdateTimer);
    233         delete this._incrementalUpdateTimer;
    234     }
    235 }
    236 
    237 WebInspector.CSSSourceFrame.prototype.__proto__ = WebInspector.ResourceSourceFrame.prototype;
  • trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js

    r83845 r83962  
    261261        // Insert in the alphabetical order, first frames, then resources. Document resource goes first.
    262262        var children = frameTreeElement.children;
    263         for (var i = 0; i < children.length; ++i) {
     263        var i;
     264        for (i = 0; i < children.length; ++i) {
    264265            var child = children[i];
    265266            if (!(child instanceof WebInspector.FrameResourceTreeElement))
    266267                continue;
    267268
    268             if (resource.type === WebInspector.Resource.Type.Document ||
    269                     (child._resource.type !== WebInspector.Resource.Type.Document && child._resource.displayName.localeCompare(resource.displayName) > 0)) {
    270                 frameTreeElement.insertChild(resourceTreeElement, i);
    271                 return;
    272             }
    273         }
    274         frameTreeElement.appendChild(resourceTreeElement);
     269            if (resource.type === WebInspector.Resource.Type.Document || (child._resource.type !== WebInspector.Resource.Type.Document && child._resource.displayName.localeCompare(resource.displayName) > 0))
     270                break;
     271        }
     272        frameTreeElement.insertChild(resourceTreeElement, i);
     273        resourceTreeElement._populateRevisions();
    275274    },
    276275
     
    992991    this._resource = resource;
    993992    this._resource.addEventListener("errors-warnings-updated", this._errorsWarningsUpdated, this);
    994     this._resource.addEventListener("content-changed", this._contentChanged, this);
     993    this._resource.addEventListener(WebInspector.Resource.Events.RevisionAdded, this._revisionAdded, this);
    995994    this.tooltip = resource.url;
    996995}
     
    11041103    },
    11051104
    1106     _contentChanged: function(event)
    1107     {
    1108         this.insertChild(new WebInspector.ResourceRevisionTreeElement(this._storagePanel, event.data.revision), 0);
     1105    _populateRevisions: function()
     1106    {
     1107        for (var i = 0; i < this._resource.history.length; ++i)
     1108            this._appendRevision(this._resource.history[i]);
     1109    },
     1110
     1111    _revisionAdded: function(event)
     1112    {
     1113        this._appendRevision(event.data);
     1114    },
     1115
     1116    _appendRevision: function(revision)
     1117    {
     1118        this.insertChild(new WebInspector.ResourceRevisionTreeElement(this._storagePanel, revision), 0);
    11091119        var oldView = WebInspector.ResourceView.existingResourceViewForResource(this._resource);
    11101120        if (oldView) {
  • trunk/Source/WebCore/inspector/front-end/inspector.html

    r83864 r83962  
    4747    <script type="text/javascript" src="Object.js"></script>
    4848    <script type="text/javascript" src="Settings.js"></script>
    49     <script type="text/javascript" src="CSSStyleModel.js"></script>
    5049    <script type="text/javascript" src="Checkbox.js"></script>
    5150    <script type="text/javascript" src="ContextMenu.js"></script>
     
    6261    <script type="text/javascript" src="TimelineGrid.js"></script>   
    6362    <script type="text/javascript" src="Resource.js"></script>
     63    <script type="text/javascript" src="CSSStyleModel.js"></script>
    6464    <script type="text/javascript" src="NetworkManager.js"></script>
    6565    <script type="text/javascript" src="ResourceTreeModel.js"></script>
Note: See TracChangeset for help on using the changeset viewer.