Title: [177791] trunk/Source/WebInspectorUI
Revision
177791
Author
jonowe...@apple.com
Date
2014-12-29 07:31:16 -0800 (Mon, 29 Dec 2014)

Log Message

Web Inspector: SourceCode.requestContent should return a promise
https://bugs.webkit.org/show_bug.cgi?id=135777

Reviewed by Brian Burg.

Change SourceCode.js to request content from the backend using Promises. Change Resource.js to use this new
approach when determining whether a resource load has finished. Change all calls to the older
SourceCode#requestContentFromBackendIfNeeded to simply use requestContent and use a catch function
if a content request error needs to be handled. Fix a bug where the appropriate error message for an
invalid resource wasn't showing in the resource content view.

* UserInterface/Controllers/AnalyzerManager.js:
(set WebInspector.AnalyzerManager.prototype.getAnalyzerMessagesForSourceCode.):
(set WebInspector.AnalyzerManager.prototype.getAnalyzerMessagesForSourceCode):
* UserInterface/Controllers/CSSStyleManager.js:
(WebInspector.CSSStyleManager.prototype._updateResourceContent.fetchedStyleSheetContent):
(WebInspector.CSSStyleManager.prototype._updateResourceContent.styleSheetReady):
* UserInterface/Models/CSSStyleSheet.js:
(WebInspector.CSSStyleSheet.prototype.requestContentFromBackend):
(WebInspector.CSSStyleSheet.prototype.canRequestContentFromBackend): Deleted.
* UserInterface/Models/DOMNodeStyles.js:
(WebInspector.DOMNodeStyles.prototype.changeStyleText):
* UserInterface/Models/Resource.js:
(WebInspector.Resource.prototype.canRequestContent):
(WebInspector.Resource.prototype.requestContentFromBackend):
(WebInspector.Resource.prototype.markAsFinished):
(WebInspector.Resource.prototype.markAsFailed):
(WebInspector.Resource.prototype.getImageSize):
(WebInspector.Resource.prototype.canRequestContentFromBackend): Deleted.
* UserInterface/Models/Script.js:
(WebInspector.Script.prototype.requestContentFromBackend):
(WebInspector.Script.prototype.requestScriptSyntaxTree.catch):
(WebInspector.Script.prototype.canRequestContentFromBackend): Deleted.
* UserInterface/Models/SourceCode.js:
(WebInspector.SourceCode):
(WebInspector.SourceCode.prototype.requestContent):
(WebInspector.SourceCode.prototype.requestContentFromBackend):
(WebInspector.SourceCode.prototype._processContent):
(WebInspector.SourceCode.prototype.canRequestContentFromBackend): Deleted.
(WebInspector.SourceCode.prototype.requestContentFromBackendIfNeeded): Deleted.
(WebInspector.SourceCode.prototype.servicePendingContentRequests): Deleted.
* UserInterface/Models/SourceMapResource.js:
(WebInspector.SourceMapResource):
(WebInspector.SourceMapResource.prototype.requestContentFromBackend.sourceMapResourceLoadError):
(WebInspector.SourceMapResource.prototype.requestContentFromBackend):
(WebInspector.SourceMapResource.prototype.canRequestContentFromBackend): Deleted.
(WebInspector.SourceMapResource.prototype.requestContentFromBackend.sourceMapResourceLoaded): Deleted.
* UserInterface/Views/ResourceContentView.js:
(WebInspector.ResourceContentView):
(WebInspector.ResourceContentView.prototype._contentAvailable):
(WebInspector.ResourceContentView.prototype._contentError):
* UserInterface/Views/SourceCodeTextEditor.js:
(WebInspector.SourceCodeTextEditor):
(WebInspector.SourceCodeTextEditor.prototype._contentAvailable):
(WebInspector.SourceCodeTextEditor.prototype._populateWithInlineScriptContent.scriptContentAvailable):
(WebInspector.SourceCodeTextEditor.prototype._populateWithInlineScriptContent):
(WebInspector.SourceCodeTextEditor.prototype._populateWithScriptContent):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (177790 => 177791)


--- trunk/Source/WebInspectorUI/ChangeLog	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/ChangeLog	2014-12-29 15:31:16 UTC (rev 177791)
@@ -1,3 +1,63 @@
+2014-12-29  Jonathan Wells  <jonowe...@apple.com>
+
+        Web Inspector: SourceCode.requestContent should return a promise
+        https://bugs.webkit.org/show_bug.cgi?id=135777
+
+        Reviewed by Brian Burg.
+
+        Change SourceCode.js to request content from the backend using Promises. Change Resource.js to use this new
+        approach when determining whether a resource load has finished. Change all calls to the older
+        SourceCode#requestContentFromBackendIfNeeded to simply use requestContent and use a catch function
+        if a content request error needs to be handled. Fix a bug where the appropriate error message for an
+        invalid resource wasn't showing in the resource content view.
+
+        * UserInterface/Controllers/AnalyzerManager.js:
+        (set WebInspector.AnalyzerManager.prototype.getAnalyzerMessagesForSourceCode.):
+        (set WebInspector.AnalyzerManager.prototype.getAnalyzerMessagesForSourceCode):
+        * UserInterface/Controllers/CSSStyleManager.js:
+        (WebInspector.CSSStyleManager.prototype._updateResourceContent.fetchedStyleSheetContent):
+        (WebInspector.CSSStyleManager.prototype._updateResourceContent.styleSheetReady):
+        * UserInterface/Models/CSSStyleSheet.js:
+        (WebInspector.CSSStyleSheet.prototype.requestContentFromBackend):
+        (WebInspector.CSSStyleSheet.prototype.canRequestContentFromBackend): Deleted.
+        * UserInterface/Models/DOMNodeStyles.js:
+        (WebInspector.DOMNodeStyles.prototype.changeStyleText):
+        * UserInterface/Models/Resource.js:
+        (WebInspector.Resource.prototype.canRequestContent):
+        (WebInspector.Resource.prototype.requestContentFromBackend):
+        (WebInspector.Resource.prototype.markAsFinished):
+        (WebInspector.Resource.prototype.markAsFailed):
+        (WebInspector.Resource.prototype.getImageSize):
+        (WebInspector.Resource.prototype.canRequestContentFromBackend): Deleted.
+        * UserInterface/Models/Script.js:
+        (WebInspector.Script.prototype.requestContentFromBackend):
+        (WebInspector.Script.prototype.requestScriptSyntaxTree.catch):
+        (WebInspector.Script.prototype.canRequestContentFromBackend): Deleted.
+        * UserInterface/Models/SourceCode.js:
+        (WebInspector.SourceCode):
+        (WebInspector.SourceCode.prototype.requestContent):
+        (WebInspector.SourceCode.prototype.requestContentFromBackend):
+        (WebInspector.SourceCode.prototype._processContent):
+        (WebInspector.SourceCode.prototype.canRequestContentFromBackend): Deleted.
+        (WebInspector.SourceCode.prototype.requestContentFromBackendIfNeeded): Deleted.
+        (WebInspector.SourceCode.prototype.servicePendingContentRequests): Deleted.
+        * UserInterface/Models/SourceMapResource.js:
+        (WebInspector.SourceMapResource):
+        (WebInspector.SourceMapResource.prototype.requestContentFromBackend.sourceMapResourceLoadError):
+        (WebInspector.SourceMapResource.prototype.requestContentFromBackend):
+        (WebInspector.SourceMapResource.prototype.canRequestContentFromBackend): Deleted.
+        (WebInspector.SourceMapResource.prototype.requestContentFromBackend.sourceMapResourceLoaded): Deleted.
+        * UserInterface/Views/ResourceContentView.js:
+        (WebInspector.ResourceContentView):
+        (WebInspector.ResourceContentView.prototype._contentAvailable):
+        (WebInspector.ResourceContentView.prototype._contentError):
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WebInspector.SourceCodeTextEditor):
+        (WebInspector.SourceCodeTextEditor.prototype._contentAvailable):
+        (WebInspector.SourceCodeTextEditor.prototype._populateWithInlineScriptContent.scriptContentAvailable):
+        (WebInspector.SourceCodeTextEditor.prototype._populateWithInlineScriptContent):
+        (WebInspector.SourceCodeTextEditor.prototype._populateWithScriptContent):
+
 2014-12-26  Dan Bernstein  <m...@apple.com>
 
         <rdar://problem/19348208> REGRESSION (r177027): iOS builds use the wrong toolchain

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -87,7 +87,7 @@
                 return;
             }
 
-            function retrieveAnalyzerMessages()
+            function retrieveAnalyzerMessages(properties)
             {
                 var analyzerMessages = [];
                 var rawAnalyzerMessages = analyzer.verify(sourceCode.content, this._eslintConfig);
@@ -101,7 +101,7 @@
                 resolve(analyzerMessages);
             }
 
-            sourceCode.requestContent(retrieveAnalyzerMessages.bind(this));
+            sourceCode.requestContent().then(retrieveAnalyzerMessages.bind(this));
         }.bind(this));
     },
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -310,8 +310,11 @@
     {
         console.assert(styleSheet);
 
-        function fetchedStyleSheetContent(styleSheet, content)
+        function fetchedStyleSheetContent(parameters)
         {
+            var styleSheet = parameters.sourceCode;
+            var content = parameters.content;
+
             delete styleSheet.__pendingChangeTimeout;
 
             console.assert(styleSheet.url);
@@ -347,7 +350,7 @@
 
         function styleSheetReady()
         {
-            styleSheet.requestContent(fetchedStyleSheetContent.bind(this));
+            styleSheet.requestContent().then(fetchedStyleSheetContent.bind(this));
         }
 
         function applyStyleSheetChanges()

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -121,22 +121,15 @@
         CSSAgent.setStyleSheetText(this._id, this.currentRevision.content, contentDidChange.bind(this));
     },
 
-    canRequestContentFromBackend: function()
+    requestContentFromBackend: function()
     {
-        // We can request content if we have an id.
-        return !!this._id;
-    },
-
-    requestContentFromBackend: function(callback)
-    {
         if (!this._id) {
-            // There is no identifier to request content with. Return false to cause the
+            // There is no identifier to request content with. Reject the promise to cause the
             // pending callbacks to get null content.
-            return false;
+            return Promise.reject(new Error("There is no identifier to request content with."));
         }
 
-        CSSAgent.getStyleSheetText(this._id, callback);
-        return true;
+        return CSSAgent.getStyleSheetText.promise(this._id);
     },
 
     noteContentDidChange: function()

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -405,8 +405,10 @@
             return;
         }
 
-        function fetchedStyleSheetContent(styleSheet, content)
+        function fetchedStyleSheetContent(parameters)
         {
+            var content = parameters.content;
+
             console.assert(style.styleSheetTextRange);
             if (!style.styleSheetTextRange)
                 return;
@@ -446,7 +448,7 @@
         this._needsRefresh = true;
         this._ignoreNextContentDidChangeForStyleSheet = style.ownerStyleSheet;
 
-        style.ownerStyleSheet.requestContent(fetchedStyleSheetContent.bind(this));
+        style.ownerStyleSheet.requestContent().then(fetchedStyleSheetContent.bind(this));
     },
 
     changeProperty: function(property, name, value, priority)

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -539,28 +539,23 @@
         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
     },
 
-    canRequestContentFromBackend: function()
+    canRequestContent: function()
     {
         return this._finished;
     },
 
-    requestContentFromBackend: function(callback)
+    requestContentFromBackend: function()
     {
         // If we have the requestIdentifier we can get the actual response for this specific resource.
         // Otherwise the content will be cached resource data, which might not exist anymore.
-        if (this._requestIdentifier) {
-            NetworkAgent.getResponseBody(this._requestIdentifier, callback);
-            return true;
-        }
+        if (this._requestIdentifier)
+            return NetworkAgent.getResponseBody.promise(this._requestIdentifier);
 
-        if (this._parentFrame) {
-            PageAgent.getResourceContent(this._parentFrame.id, this._url, callback);
-            return true;
-        }
+        // There is no request identifier or frame to request content from.
+        if (this._parentFrame)
+            return PageAgent.getResourceContent.promise(this._parentFrame.id, this._url);
 
-        // There is no request identifier or frame to request content from. Return false to cause the
-        // pending callbacks to get null content.
-        return false;
+        return Promise.reject(new Error("Content request failed."));
     },
 
     increaseSize: function(dataLength, elapsedTime)
@@ -613,11 +608,11 @@
         this._finished = true;
         this._finishedOrFailedTimestamp = elapsedTime || NaN;
 
+        if (this._finishThenRequestContentPromise)
+            delete this._finishThenRequestContentPromise;
+
         this.dispatchEventToListeners(WebInspector.Resource.Event.LoadingDidFinish);
         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
-
-        if (this.canRequestContentFromBackend())
-            this.requestContentFromBackendIfNeeded();
     },
 
     markAsFailed: function(canceled, elapsedTime)
@@ -630,9 +625,6 @@
 
         this.dispatchEventToListeners(WebInspector.Resource.Event.LoadingDidFail);
         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
-
-        // Force the content requests to be serviced. They will get null as the content.
-        this.servicePendingContentRequests(true);
     },
 
     revertMarkAsFinished: function()
@@ -676,11 +668,30 @@
         image.addEventListener("load", imageDidLoad.bind(this), false);
 
         // Set the image source once we've obtained the base64-encoded URL for it.
-        this.requestContent(function() {
-            image.src = ""
-        }.bind(this));
+        this.requestContent().then(function(content) {
+            image.src = ""
+        });
     },
 
+    requestContent: function()
+    {
+        if (this._finished)
+            return WebInspector.SourceCode.prototype.requestContent.call(this);
+
+        if (this._failed)
+            return Promise.reject(new Error("An error occurred trying to load the resource."));
+
+        if (!this._finishThenRequestContentPromise) {
+            var listener = new WebInspector.EventListener(this, true);
+            this._finishThenRequestContentPromise = new Promise(function (resolve, reject) {
+                this.addEventListener(WebInspector.Resource.Event.LoadingDidFinish, resolve);
+                this.addEventListener(WebInspector.Resource.Event.LoadingDidFail, reject);
+            }.bind(this)).then(WebInspector.SourceCode.prototype.requestContent.bind(this));
+        }
+
+        return this._finishThenRequestContentPromise;
+    },
+
     associateWithScript: function(script)
     {
         if (!this._scripts)

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Script.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/Script.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Script.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -110,22 +110,15 @@
         return this._scriptSyntaxTree;
     },
 
-    canRequestContentFromBackend: function()
-    {
-        // We can request content if we have an id.
-        return !!this._id;
-    },
-
     requestContentFromBackend: function(callback)
     {
         if (!this._id) {
             // There is no identifier to request content with. Return false to cause the
             // pending callbacks to get null content.
-            return false;
+            return Promise.reject({ message: "There is no identifier to request content with." });
         }
 
-        DebuggerAgent.getScriptSource(this._id, callback);
-        return true;
+        return DebuggerAgent.getScriptSource.promise(this._id);
     },
 
     saveIdentityToCookie: function(cookie)
@@ -155,8 +148,10 @@
             return;
         }
 
-        this.requestContent(function(error, sourceText) {
-            makeSyntaxTreeAndCallCallback(error ? null : sourceText);
+        this.requestContent().then(function(parameters) {
+            makeSyntaxTreeAndCallCallback(parameters.content);
+        }).catch(function(error) {
+            makeSyntaxTreeAndCallCallback(null);
         });
     },
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/SourceCode.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/SourceCode.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/SourceCode.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -27,13 +27,12 @@
 {
     WebInspector.Object.call(this);
 
-    this._pendingContentRequestCallbacks = [];
-
     this._originalRevision = new WebInspector.SourceCodeRevision(this, null, false);
     this._currentRevision = this._originalRevision;
 
     this._sourceMaps = null;
     this._formatterSourceMap = null;
+    this._requestContentPromise = null;
 };
 
 WebInspector.Object.addConstructorFunctions(WebInspector.SourceCode);
@@ -41,7 +40,9 @@
 WebInspector.SourceCode.Event = {
     ContentDidChange: "source-code-content-did-change",
     SourceMapAdded: "source-code-source-map-added",
-    FormatterDidChange: "source-code-formatter-did-change"
+    FormatterDidChange: "source-code-formatter-did-change",
+    LoadingDidFinish: "source-code-loading-did-finish",
+    LoadingDidFail: "source-code-loading-did-fail"
 };
 
 WebInspector.SourceCode.prototype = {
@@ -123,20 +124,11 @@
         this.dispatchEventToListeners(WebInspector.SourceCode.Event.FormatterDidChange);
     },
 
-    requestContent: function(callback)
+    requestContent: function()
     {
-        console.assert(typeof callback === "function");
-        if (typeof callback !== "function")
-            return;
+        this._requestContentPromise = this._requestContentPromise || this.requestContentFromBackend().then(this._processContent.bind(this));
 
-        this._pendingContentRequestCallbacks.push(callback);
-
-        if (this._contentReceived) {
-            // Call _servicePendingContentRequests on a timeout to force callbacks to be asynchronous.
-            if (!this._servicePendingContentRequestsTimeoutIdentifier)
-                this._servicePendingContentRequestsTimeoutIdentifier = setTimeout(this.servicePendingContentRequests.bind(this), 0);
-        } else if (this.canRequestContentFromBackend())
-            this.requestContentFromBackendIfNeeded();
+        return this._requestContentPromise;
     },
 
     createSourceCodeLocation: function(lineNumber, columnNumber)
@@ -185,76 +177,21 @@
         this._contentReceived = false;
     },
 
-    canRequestContentFromBackend: function()
+    requestContentFromBackend: function()
     {
         // Implemented by subclasses.
         console.error("Needs to be implemented by a subclass.");
-        return false;
+        return Promise.reject(new Error("Needs to be implemented by a subclass."));
     },
 
-    requestContentFromBackend: function(callback)
-    {
-        // Implemented by subclasses.
-        console.error("Needs to be implemented by a subclass.");
-    },
-
-    requestContentFromBackendIfNeeded: function()
-    {
-        console.assert(this.canRequestContentFromBackend());
-        if (!this.canRequestContentFromBackend())
-            return;
-
-        if (!this._pendingContentRequestCallbacks.length)
-            return;
-
-        if (this._contentRequestResponsePending)
-            return;
-
-        this._contentRequestResponsePending = true;
-
-        if (this.requestContentFromBackend(this._processContent.bind(this)))
-            return;
-
-        // Since requestContentFromBackend returned false, just call _processContent,
-        // which will cause the pending callbacks to get null content.
-        this._processContent();
-    },
-
-    servicePendingContentRequests: function(force)
-    {
-        if (this._servicePendingContentRequestsTimeoutIdentifier) {
-            clearTimeout(this._servicePendingContentRequestsTimeoutIdentifier);
-            delete this._servicePendingContentRequestsTimeoutIdentifier;
-        }
-
-        // Force the content requests to be sent. To do this correctly we also force
-        // _contentReceived to be true so future calls to requestContent go through.
-        if (force)
-            this._contentReceived = true;
-
-        console.assert(this._contentReceived);
-        if (!this._contentReceived)
-            return;
-
-        // Move the callbacks into a local and clear _pendingContentRequestCallbacks so
-        // callbacks that might call requestContent again will not modify the array.
-        var callbacks = this._pendingContentRequestCallbacks;
-        this._pendingContentRequestCallbacks = [];
-
-        for (var i = 0; i < callbacks.length; ++i)
-            callbacks[i](this, this.content, this.contentIsBase64Encoded);
-    },
-
     // Private
 
-    _processContent: function(error, content, base64Encoded)
+    _processContent: function(parameters)
     {
-        if (error)
-            console.error(error);
+        // Different backend APIs return one of `content, `body`, or `scriptSource`.
+        var content = parameters.content || parameters.body || parameters.scriptSource;
+        var base64Encoded = parameters.base64Encoded;
 
-        this._contentRequestResponsePending = false;
-        this._contentReceived = true;
-
         var revision = this.revisionForRequestedContent;
 
         this._ignoreRevisionContentDidChangeEvent = true;
@@ -262,7 +199,11 @@
         revision.contentIsBase64Encoded = base64Encoded || false;
         delete this._ignoreRevisionContentDidChangeEvent;
 
-        this.servicePendingContentRequests();
+        return Promise.resolve({
+            sourceCode: this,
+            content: content,
+            base64Encoded: base64Encoded
+        });
     }
 };
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -31,7 +31,6 @@
     console.assert(sourceMap);
 
     this._sourceMap = sourceMap;
-    this._contentRequested = false;
 
     var inheritedMIMEType = this._sourceMap.originalSourceCode instanceof WebInspector.Resource ? this._sourceMap.originalSourceCode.syntheticMIMEType : null;
 
@@ -75,50 +74,53 @@
         return resourceURLComponents.path.substring(sourceMappingBasePathURLComponents.path.length, resourceURLComponents.length);
     },
 
-    canRequestContentFromBackend: function()
-    {
-        return !this._contentRequested;
-    },
-
     requestContentFromBackend: function(callback)
     {
-        this._contentRequested = true;
-
         // Revert the markAsFinished that was done in the constructor.
         this.revertMarkAsFinished();
 
         var inlineContent = this._sourceMap.sourceContent(this.url);
         if (inlineContent) {
             // Force inline content to be asynchronous to match the expected load pattern.
-            setTimeout(function() {
-                // FIXME: We don't know the MIME-type for inline content. Guess by analyzing the content?
-                sourceMapResourceLoaded.call(this, null, inlineContent, this.mimeType, 200);
-            }.bind(this));
+            // FIXME: We don't know the MIME-type for inline content. Guess by analyzing the content?
+            // Returns a promise.
+            return sourceMapResourceLoaded.call(this, null, inlineContent, this.mimeType, 200);
+        }
 
-            return true;
+        function sourceMapResourceLoadError(error, body, mimeType, statusCode)
+        {
+            this.markAsFailed();
+            return Promise.resolve({
+                error: error,
+                content: body.content,
+                mimeType: mimeType,
+                statusCode: statusCode
+            });
         }
 
-        function sourceMapResourceLoaded(error, body, mimeType, statusCode)
+        function sourceMapResourceLoaded(body, mimeType, statusCode)
         {
             const base64encoded = false;
 
-            if (error || statusCode >= 400) {
-                this.markAsFailed();
-                callback(error, body, base64encoded);
-                return;
-            }
+            if (statusCode >= 400)
+                return sourceMapResourceLoadError(error, body, mimeType, statusCode);
 
             // FIXME: Add support for picking the best MIME-type. Right now the file extension is the best bet.
             // The constructor set MIME-type based on the file extension and we ignore mimeType here.
 
             this.markAsFinished();
 
-            callback(null, body, base64encoded);
+            return Promise.resolve({
+                content: body.content,
+                mimeType: mimeType,
+                base64encoded: base64encoded,
+                statusCode: statusCode
+            });
         }
 
         if (!NetworkAgent.loadResource) {
             sourceMapResourceLoaded.call(this, "error: no NetworkAgent.loadResource");
-            return false;
+            return Promise.reject(new Error("No NetworkAgent.loadResource"));
         }
 
         var frameIdentifier = null;
@@ -128,9 +130,7 @@
         if (!frameIdentifier)
             frameIdentifier = WebInspector.frameResourceManager.mainFrame.id;
 
-        NetworkAgent.loadResource(frameIdentifier, this.url, sourceMapResourceLoaded.bind(this));
-
-        return true;
+        return NetworkAgent.loadResource.promise(frameIdentifier, this.url).then(sourceMapResourceLoaded.bind(this)).catch(sourceMapResourceLoadError.bind(this));
     },
 
     createSourceCodeLocation: function(lineNumber, columnNumber)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -43,7 +43,7 @@
     this.element.addEventListener("click", this._mouseWasClicked.bind(this), false);
 
     // Request content last so the spinner will always be removed in case the content is immediately available.
-    resource.requestContent(this._contentAvailable.bind(this));
+    resource.requestContent().then(this._contentAvailable.bind(this)).catch(this._contentError.bind(this));
 
     if (!this.managesOwnIssues) {
         WebInspector.issueManager.addEventListener(WebInspector.IssueManager.Event.IssueWasAdded, this._issueWasAdded, this);
@@ -86,21 +86,20 @@
 
     // Private
 
-    _contentAvailable: function(resource, content, base64Encoded)
+    _contentAvailable: function(parameters)
     {
-        // Check for failed loads.
-        if (this.resource.failed) {
-            // Don't show an error message if there is already an error message showing (like one added by addIssue.)
-            if (this.element.querySelector(".message-text-view.error"))
-                return;
+        // Content is ready to show, call the public method now.
+        this.contentAvailable(parameters.content, parameters.base64Encoded);
+    },
 
-            this.element.removeChildren();
-            this.element.appendChild(WebInspector.createMessageTextView(WebInspector.UIString("An error occurred trying to load the resource."), true));
+    _contentError: function(error)
+    {
+        // Don't show an error message if there is already an error message showing (like one added by addIssue.)
+        if (this.element.querySelector(".message-text-view.error"))
             return;
-        }
 
-        // Content is ready to show, call the public method now.
-        this.contentAvailable(content, base64Encoded);
+        this.element.removeChildren();
+        this.element.appendChild(WebInspector.createMessageTextView(WebInspector.UIString(error.message), true));
     },
 
     _issueWasAdded: function(event)

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (177790 => 177791)


--- trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2014-12-29 14:46:39 UTC (rev 177790)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js	2014-12-29 15:31:16 UTC (rev 177791)
@@ -70,7 +70,7 @@
     else
         this._sourceCode.addEventListener(WebInspector.SourceCode.Event.SourceMapAdded, this._sourceCodeSourceMapAdded, this);
 
-    sourceCode.requestContent(this._contentAvailable.bind(this));
+    sourceCode.requestContent().then(this._contentAvailable.bind(this));
 
     // FIXME: Cmd+L shorcut doesn't actually work.
     new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Command, "L", this.showGoToLineDialog.bind(this), this.element);
@@ -436,8 +436,12 @@
         this._contentDidPopulate();
     },
 
-    _contentAvailable: function(sourceCode, content, base64Encoded)
+    _contentAvailable: function(parameters)
     {
+        var sourceCode = parameters.sourceCode;
+        var content = parameters.content;
+        var base64Encoded = parameters.base64Encoded;
+
         console.assert(sourceCode === this._sourceCode);
         console.assert(!base64Encoded);
 
@@ -639,7 +643,7 @@
 
         this._inlineScriptContentPopulated = pendingRequestCount;
 
-        function scriptContentAvailable(error, content)
+        function scriptContentAvailable(parameters)
         {
             // Return early if we are still waiting for content from other scripts.
             if (--pendingRequestCount)
@@ -689,7 +693,7 @@
 
         var boundScriptContentAvailable = scriptContentAvailable.bind(this);
         for (var i = 0; i < scripts.length; ++i)
-            scripts[i].requestContent(boundScriptContentAvailable);
+            scripts[i].requestContent().then(boundScriptContentAvailable);
     },
 
     _populateWithScriptContent: function()
@@ -707,8 +711,9 @@
         console.assert(scripts[0].range.startLine === 0);
         console.assert(scripts[0].range.startColumn === 0);
 
-        function scriptContentAvailable(error, content)
+        function scriptContentAvailable(parameters)
         {
+            var content = parameters.content;
             delete this._requestingScriptContent;
 
             // Abort if the full content populated while waiting for this async callback.
@@ -723,7 +728,7 @@
 
         this._requestingScriptContent = true;
 
-        scripts[0].requestContent(scriptContentAvailable.bind(this));
+        scripts[0].requestContent().then(scriptContentAvailable.bind(this));
     },
 
     _matchesSourceCodeLocation: function(sourceCodeLocation)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to