Web Inspector: SourceCode.requestContent should return a promise
authorjonowells@apple.com <jonowells@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Dec 2014 15:31:16 +0000 (15:31 +0000)
committerjonowells@apple.com <jonowells@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Dec 2014 15:31:16 +0000 (15:31 +0000)
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):

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js
Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js
Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js
Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js
Source/WebInspectorUI/UserInterface/Models/Resource.js
Source/WebInspectorUI/UserInterface/Models/Script.js
Source/WebInspectorUI/UserInterface/Models/SourceCode.js
Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js
Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js
Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js

index 4a314e9..a5d1bc6 100644 (file)
@@ -1,3 +1,63 @@
+2014-12-29  Jonathan Wells  <jonowells@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  <mitz@apple.com>
 
         <rdar://problem/19348208> REGRESSION (r177027): iOS builds use the wrong toolchain
index 9638bff..08cf162 100644 (file)
@@ -87,7 +87,7 @@ WebInspector.AnalyzerManager.prototype = {
                 return;
             }
 
-            function retrieveAnalyzerMessages()
+            function retrieveAnalyzerMessages(properties)
             {
                 var analyzerMessages = [];
                 var rawAnalyzerMessages = analyzer.verify(sourceCode.content, this._eslintConfig);
@@ -101,7 +101,7 @@ WebInspector.AnalyzerManager.prototype = {
                 resolve(analyzerMessages);
             }
 
-            sourceCode.requestContent(retrieveAnalyzerMessages.bind(this));
+            sourceCode.requestContent().then(retrieveAnalyzerMessages.bind(this));
         }.bind(this));
     },
 
index 7aa64ab..9e1c88b 100644 (file)
@@ -310,8 +310,11 @@ WebInspector.CSSStyleManager.prototype = {
     {
         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 @@ WebInspector.CSSStyleManager.prototype = {
 
         function styleSheetReady()
         {
-            styleSheet.requestContent(fetchedStyleSheetContent.bind(this));
+            styleSheet.requestContent().then(fetchedStyleSheetContent.bind(this));
         }
 
         function applyStyleSheetChanges()
index 51d9e6f..cddfa7f 100644 (file)
@@ -121,22 +121,15 @@ WebInspector.CSSStyleSheet.prototype = {
         CSSAgent.setStyleSheetText(this._id, this.currentRevision.content, contentDidChange.bind(this));
     },
 
-    canRequestContentFromBackend: function()
-    {
-        // We can request content if we have an id.
-        return !!this._id;
-    },
-
-    requestContentFromBackend: function(callback)
+    requestContentFromBackend: function()
     {
         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()
index 802e2b7..e3c7696 100644 (file)
@@ -405,8 +405,10 @@ WebInspector.DOMNodeStyles.prototype = {
             return;
         }
 
-        function fetchedStyleSheetContent(styleSheet, content)
+        function fetchedStyleSheetContent(parameters)
         {
+            var content = parameters.content;
+
             console.assert(style.styleSheetTextRange);
             if (!style.styleSheetTextRange)
                 return;
@@ -446,7 +448,7 @@ WebInspector.DOMNodeStyles.prototype = {
         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)
index f3bbdb0..4ca4d6a 100644 (file)
@@ -539,28 +539,23 @@ WebInspector.Resource.prototype = {
         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 @@ WebInspector.Resource.prototype = {
         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 @@ WebInspector.Resource.prototype = {
 
         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,9 +668,28 @@ WebInspector.Resource.prototype = {
         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 = this.contentURL;
-        }.bind(this));
+        this.requestContent().then(function(content) {
+            image.src = content.sourceCode.contentURL;
+        });
+    },
+
+    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)
index b4c9e29..8340c35 100644 (file)
@@ -110,22 +110,15 @@ WebInspector.Script.prototype = {
         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 @@ WebInspector.Script.prototype = {
             return;
         }
 
-        this.requestContent(function(error, sourceText) {
-            makeSyntaxTreeAndCallCallback(error ? null : sourceText);
+        this.requestContent().then(function(parameters) {
+            makeSyntaxTreeAndCallCallback(parameters.content);
+        }).catch(function(error) {
+            makeSyntaxTreeAndCallCallback(null);
         });
     },
 
index dbea019..a70719d 100644 (file)
@@ -27,13 +27,12 @@ WebInspector.SourceCode = function()
 {
     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.Object.addConstructorFunctions(WebInspector.SourceCode);
 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 @@ WebInspector.SourceCode.prototype = {
         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,75 +177,20 @@ WebInspector.SourceCode.prototype = {
         this._contentReceived = false;
     },
 
-    canRequestContentFromBackend: function()
-    {
-        // Implemented by subclasses.
-        console.error("Needs to be implemented by a subclass.");
-        return false;
-    },
-
-    requestContentFromBackend: function(callback)
+    requestContentFromBackend: function()
     {
         // 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);
+        return Promise.reject(new Error("Needs to be implemented by a subclass."));
     },
 
     // Private
 
-    _processContent: function(error, content, base64Encoded)
+    _processContent: function(parameters)
     {
-        if (error)
-            console.error(error);
-
-        this._contentRequestResponsePending = false;
-        this._contentReceived = true;
+        // Different backend APIs return one of `content, `body`, or `scriptSource`.
+        var content = parameters.content || parameters.body || parameters.scriptSource;
+        var base64Encoded = parameters.base64Encoded;
 
         var revision = this.revisionForRequestedContent;
 
@@ -262,7 +199,11 @@ WebInspector.SourceCode.prototype = {
         revision.contentIsBase64Encoded = base64Encoded || false;
         delete this._ignoreRevisionContentDidChangeEvent;
 
-        this.servicePendingContentRequests();
+        return Promise.resolve({
+            sourceCode: this,
+            content: content,
+            base64Encoded: base64Encoded
+        });
     }
 };
 
index 8d898a2..2968576 100644 (file)
@@ -31,7 +31,6 @@ WebInspector.SourceMapResource = function(url, sourceMap)
     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 @@ WebInspector.SourceMapResource.prototype = {
         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 @@ WebInspector.SourceMapResource.prototype = {
         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)
index 0b994ad..150bc59 100644 (file)
@@ -43,7 +43,7 @@ WebInspector.ResourceContentView = function(resource, styleClassName)
     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 @@ WebInspector.ResourceContentView.prototype = {
 
     // 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;
-
-            this.element.removeChildren();
-            this.element.appendChild(WebInspector.createMessageTextView(WebInspector.UIString("An error occurred trying to load the resource."), true));
+        // Content is ready to show, call the public method now.
+        this.contentAvailable(parameters.content, parameters.base64Encoded);
+    },
+
+    _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)
index f668213..9585da6 100644 (file)
@@ -70,7 +70,7 @@ WebInspector.SourceCodeTextEditor = function(sourceCode)
     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 @@ WebInspector.SourceCodeTextEditor.prototype = {
         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 @@ WebInspector.SourceCodeTextEditor.prototype = {
 
         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 @@ WebInspector.SourceCodeTextEditor.prototype = {
 
         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 @@ WebInspector.SourceCodeTextEditor.prototype = {
         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 @@ WebInspector.SourceCodeTextEditor.prototype = {
 
         this._requestingScriptContent = true;
 
-        scripts[0].requestContent(scriptContentAvailable.bind(this));
+        scripts[0].requestContent().then(scriptContentAvailable.bind(this));
     },
 
     _matchesSourceCodeLocation: function(sourceCodeLocation)