<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[177791] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/177791">177791</a></dd>
<dt>Author</dt> <dd>jonowells@apple.com</dd>
<dt>Date</dt> <dd>2014-12-29 07:31:16 -0800 (Mon, 29 Dec 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersAnalyzerManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsCSSStyleSheetjs">trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs">trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsResourcejs">trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsScriptjs">trunk/Source/WebInspectorUI/UserInterface/Models/Script.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsSourceCodejs">trunk/Source/WebInspectorUI/UserInterface/Models/SourceCode.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsSourceMapResourcejs">trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsResourceContentViewjs">trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsSourceCodeTextEditorjs">trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,63 @@
</span><ins>+2014-12-29  Jonathan Wells  &lt;jonowells@apple.com&gt;
+
+        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):
+
</ins><span class="cx"> 2014-12-26  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         &lt;rdar://problem/19348208&gt; REGRESSION (r177027): iOS builds use the wrong toolchain
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersAnalyzerManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/AnalyzerManager.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            function retrieveAnalyzerMessages()
</del><ins>+            function retrieveAnalyzerMessages(properties)
</ins><span class="cx">             {
</span><span class="cx">                 var analyzerMessages = [];
</span><span class="cx">                 var rawAnalyzerMessages = analyzer.verify(sourceCode.content, this._eslintConfig);
</span><span class="lines">@@ -101,7 +101,7 @@
</span><span class="cx">                 resolve(analyzerMessages);
</span><span class="cx">             }
</span><span class="cx"> 
</span><del>-            sourceCode.requestContent(retrieveAnalyzerMessages.bind(this));
</del><ins>+            sourceCode.requestContent().then(retrieveAnalyzerMessages.bind(this));
</ins><span class="cx">         }.bind(this));
</span><span class="cx">     },
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersCSSStyleManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/CSSStyleManager.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -310,8 +310,11 @@
</span><span class="cx">     {
</span><span class="cx">         console.assert(styleSheet);
</span><span class="cx"> 
</span><del>-        function fetchedStyleSheetContent(styleSheet, content)
</del><ins>+        function fetchedStyleSheetContent(parameters)
</ins><span class="cx">         {
</span><ins>+            var styleSheet = parameters.sourceCode;
+            var content = parameters.content;
+
</ins><span class="cx">             delete styleSheet.__pendingChangeTimeout;
</span><span class="cx"> 
</span><span class="cx">             console.assert(styleSheet.url);
</span><span class="lines">@@ -347,7 +350,7 @@
</span><span class="cx"> 
</span><span class="cx">         function styleSheetReady()
</span><span class="cx">         {
</span><del>-            styleSheet.requestContent(fetchedStyleSheetContent.bind(this));
</del><ins>+            styleSheet.requestContent().then(fetchedStyleSheetContent.bind(this));
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function applyStyleSheetChanges()
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsCSSStyleSheetjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/CSSStyleSheet.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -121,22 +121,15 @@
</span><span class="cx">         CSSAgent.setStyleSheetText(this._id, this.currentRevision.content, contentDidChange.bind(this));
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    canRequestContentFromBackend: function()
</del><ins>+    requestContentFromBackend: function()
</ins><span class="cx">     {
</span><del>-        // We can request content if we have an id.
-        return !!this._id;
-    },
-
-    requestContentFromBackend: function(callback)
-    {
</del><span class="cx">         if (!this._id) {
</span><del>-            // There is no identifier to request content with. Return false to cause the
</del><ins>+            // There is no identifier to request content with. Reject the promise to cause the
</ins><span class="cx">             // pending callbacks to get null content.
</span><del>-            return false;
</del><ins>+            return Promise.reject(new Error(&quot;There is no identifier to request content with.&quot;));
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        CSSAgent.getStyleSheetText(this._id, callback);
-        return true;
</del><ins>+        return CSSAgent.getStyleSheetText.promise(this._id);
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     noteContentDidChange: function()
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsDOMNodeStylesjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/DOMNodeStyles.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -405,8 +405,10 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function fetchedStyleSheetContent(styleSheet, content)
</del><ins>+        function fetchedStyleSheetContent(parameters)
</ins><span class="cx">         {
</span><ins>+            var content = parameters.content;
+
</ins><span class="cx">             console.assert(style.styleSheetTextRange);
</span><span class="cx">             if (!style.styleSheetTextRange)
</span><span class="cx">                 return;
</span><span class="lines">@@ -446,7 +448,7 @@
</span><span class="cx">         this._needsRefresh = true;
</span><span class="cx">         this._ignoreNextContentDidChangeForStyleSheet = style.ownerStyleSheet;
</span><span class="cx"> 
</span><del>-        style.ownerStyleSheet.requestContent(fetchedStyleSheetContent.bind(this));
</del><ins>+        style.ownerStyleSheet.requestContent().then(fetchedStyleSheetContent.bind(this));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     changeProperty: function(property, name, value, priority)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsResourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Resource.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -539,28 +539,23 @@
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    canRequestContentFromBackend: function()
</del><ins>+    canRequestContent: function()
</ins><span class="cx">     {
</span><span class="cx">         return this._finished;
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    requestContentFromBackend: function(callback)
</del><ins>+    requestContentFromBackend: function()
</ins><span class="cx">     {
</span><span class="cx">         // If we have the requestIdentifier we can get the actual response for this specific resource.
</span><span class="cx">         // Otherwise the content will be cached resource data, which might not exist anymore.
</span><del>-        if (this._requestIdentifier) {
-            NetworkAgent.getResponseBody(this._requestIdentifier, callback);
-            return true;
-        }
</del><ins>+        if (this._requestIdentifier)
+            return NetworkAgent.getResponseBody.promise(this._requestIdentifier);
</ins><span class="cx"> 
</span><del>-        if (this._parentFrame) {
-            PageAgent.getResourceContent(this._parentFrame.id, this._url, callback);
-            return true;
-        }
</del><ins>+        // There is no request identifier or frame to request content from.
+        if (this._parentFrame)
+            return PageAgent.getResourceContent.promise(this._parentFrame.id, this._url);
</ins><span class="cx"> 
</span><del>-        // There is no request identifier or frame to request content from. Return false to cause the
-        // pending callbacks to get null content.
-        return false;
</del><ins>+        return Promise.reject(new Error(&quot;Content request failed.&quot;));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     increaseSize: function(dataLength, elapsedTime)
</span><span class="lines">@@ -613,11 +608,11 @@
</span><span class="cx">         this._finished = true;
</span><span class="cx">         this._finishedOrFailedTimestamp = elapsedTime || NaN;
</span><span class="cx"> 
</span><ins>+        if (this._finishThenRequestContentPromise)
+            delete this._finishThenRequestContentPromise;
+
</ins><span class="cx">         this.dispatchEventToListeners(WebInspector.Resource.Event.LoadingDidFinish);
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
</span><del>-
-        if (this.canRequestContentFromBackend())
-            this.requestContentFromBackendIfNeeded();
</del><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     markAsFailed: function(canceled, elapsedTime)
</span><span class="lines">@@ -630,9 +625,6 @@
</span><span class="cx"> 
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.Resource.Event.LoadingDidFail);
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.Resource.Event.TimestampsDidChange);
</span><del>-
-        // Force the content requests to be serviced. They will get null as the content.
-        this.servicePendingContentRequests(true);
</del><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     revertMarkAsFinished: function()
</span><span class="lines">@@ -676,11 +668,30 @@
</span><span class="cx">         image.addEventListener(&quot;load&quot;, imageDidLoad.bind(this), false);
</span><span class="cx"> 
</span><span class="cx">         // Set the image source once we've obtained the base64-encoded URL for it.
</span><del>-        this.requestContent(function() {
-            image.src = this.contentURL;
-        }.bind(this));
</del><ins>+        this.requestContent().then(function(content) {
+            image.src = content.sourceCode.contentURL;
+        });
</ins><span class="cx">     },
</span><span class="cx"> 
</span><ins>+    requestContent: function()
+    {
+        if (this._finished)
+            return WebInspector.SourceCode.prototype.requestContent.call(this);
+
+        if (this._failed)
+            return Promise.reject(new Error(&quot;An error occurred trying to load the resource.&quot;));
+
+        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;
+    },
+
</ins><span class="cx">     associateWithScript: function(script)
</span><span class="cx">     {
</span><span class="cx">         if (!this._scripts)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsScriptjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Script.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -110,22 +110,15 @@
</span><span class="cx">         return this._scriptSyntaxTree;
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    canRequestContentFromBackend: function()
-    {
-        // We can request content if we have an id.
-        return !!this._id;
-    },
-
</del><span class="cx">     requestContentFromBackend: function(callback)
</span><span class="cx">     {
</span><span class="cx">         if (!this._id) {
</span><span class="cx">             // There is no identifier to request content with. Return false to cause the
</span><span class="cx">             // pending callbacks to get null content.
</span><del>-            return false;
</del><ins>+            return Promise.reject({ message: &quot;There is no identifier to request content with.&quot; });
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        DebuggerAgent.getScriptSource(this._id, callback);
-        return true;
</del><ins>+        return DebuggerAgent.getScriptSource.promise(this._id);
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     saveIdentityToCookie: function(cookie)
</span><span class="lines">@@ -155,8 +148,10 @@
</span><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        this.requestContent(function(error, sourceText) {
-            makeSyntaxTreeAndCallCallback(error ? null : sourceText);
</del><ins>+        this.requestContent().then(function(parameters) {
+            makeSyntaxTreeAndCallCallback(parameters.content);
+        }).catch(function(error) {
+            makeSyntaxTreeAndCallCallback(null);
</ins><span class="cx">         });
</span><span class="cx">     },
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsSourceCodejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/SourceCode.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -27,13 +27,12 @@
</span><span class="cx"> {
</span><span class="cx">     WebInspector.Object.call(this);
</span><span class="cx"> 
</span><del>-    this._pendingContentRequestCallbacks = [];
-
</del><span class="cx">     this._originalRevision = new WebInspector.SourceCodeRevision(this, null, false);
</span><span class="cx">     this._currentRevision = this._originalRevision;
</span><span class="cx"> 
</span><span class="cx">     this._sourceMaps = null;
</span><span class="cx">     this._formatterSourceMap = null;
</span><ins>+    this._requestContentPromise = null;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.Object.addConstructorFunctions(WebInspector.SourceCode);
</span><span class="lines">@@ -41,7 +40,9 @@
</span><span class="cx"> WebInspector.SourceCode.Event = {
</span><span class="cx">     ContentDidChange: &quot;source-code-content-did-change&quot;,
</span><span class="cx">     SourceMapAdded: &quot;source-code-source-map-added&quot;,
</span><del>-    FormatterDidChange: &quot;source-code-formatter-did-change&quot;
</del><ins>+    FormatterDidChange: &quot;source-code-formatter-did-change&quot;,
+    LoadingDidFinish: &quot;source-code-loading-did-finish&quot;,
+    LoadingDidFail: &quot;source-code-loading-did-fail&quot;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.SourceCode.prototype = {
</span><span class="lines">@@ -123,20 +124,11 @@
</span><span class="cx">         this.dispatchEventToListeners(WebInspector.SourceCode.Event.FormatterDidChange);
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    requestContent: function(callback)
</del><ins>+    requestContent: function()
</ins><span class="cx">     {
</span><del>-        console.assert(typeof callback === &quot;function&quot;);
-        if (typeof callback !== &quot;function&quot;)
-            return;
</del><ins>+        this._requestContentPromise = this._requestContentPromise || this.requestContentFromBackend().then(this._processContent.bind(this));
</ins><span class="cx"> 
</span><del>-        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();
</del><ins>+        return this._requestContentPromise;
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     createSourceCodeLocation: function(lineNumber, columnNumber)
</span><span class="lines">@@ -185,76 +177,21 @@
</span><span class="cx">         this._contentReceived = false;
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    canRequestContentFromBackend: function()
</del><ins>+    requestContentFromBackend: function()
</ins><span class="cx">     {
</span><span class="cx">         // Implemented by subclasses.
</span><span class="cx">         console.error(&quot;Needs to be implemented by a subclass.&quot;);
</span><del>-        return false;
</del><ins>+        return Promise.reject(new Error(&quot;Needs to be implemented by a subclass.&quot;));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><del>-    requestContentFromBackend: function(callback)
-    {
-        // Implemented by subclasses.
-        console.error(&quot;Needs to be implemented by a subclass.&quot;);
-    },
-
-    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 &lt; callbacks.length; ++i)
-            callbacks[i](this, this.content, this.contentIsBase64Encoded);
-    },
-
</del><span class="cx">     // Private
</span><span class="cx"> 
</span><del>-    _processContent: function(error, content, base64Encoded)
</del><ins>+    _processContent: function(parameters)
</ins><span class="cx">     {
</span><del>-        if (error)
-            console.error(error);
</del><ins>+        // Different backend APIs return one of `content, `body`, or `scriptSource`.
+        var content = parameters.content || parameters.body || parameters.scriptSource;
+        var base64Encoded = parameters.base64Encoded;
</ins><span class="cx"> 
</span><del>-        this._contentRequestResponsePending = false;
-        this._contentReceived = true;
-
</del><span class="cx">         var revision = this.revisionForRequestedContent;
</span><span class="cx"> 
</span><span class="cx">         this._ignoreRevisionContentDidChangeEvent = true;
</span><span class="lines">@@ -262,7 +199,11 @@
</span><span class="cx">         revision.contentIsBase64Encoded = base64Encoded || false;
</span><span class="cx">         delete this._ignoreRevisionContentDidChangeEvent;
</span><span class="cx"> 
</span><del>-        this.servicePendingContentRequests();
</del><ins>+        return Promise.resolve({
+            sourceCode: this,
+            content: content,
+            base64Encoded: base64Encoded
+        });
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsSourceMapResourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/SourceMapResource.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,7 +31,6 @@
</span><span class="cx">     console.assert(sourceMap);
</span><span class="cx"> 
</span><span class="cx">     this._sourceMap = sourceMap;
</span><del>-    this._contentRequested = false;
</del><span class="cx"> 
</span><span class="cx">     var inheritedMIMEType = this._sourceMap.originalSourceCode instanceof WebInspector.Resource ? this._sourceMap.originalSourceCode.syntheticMIMEType : null;
</span><span class="cx"> 
</span><span class="lines">@@ -75,50 +74,53 @@
</span><span class="cx">         return resourceURLComponents.path.substring(sourceMappingBasePathURLComponents.path.length, resourceURLComponents.length);
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    canRequestContentFromBackend: function()
-    {
-        return !this._contentRequested;
-    },
-
</del><span class="cx">     requestContentFromBackend: function(callback)
</span><span class="cx">     {
</span><del>-        this._contentRequested = true;
-
</del><span class="cx">         // Revert the markAsFinished that was done in the constructor.
</span><span class="cx">         this.revertMarkAsFinished();
</span><span class="cx"> 
</span><span class="cx">         var inlineContent = this._sourceMap.sourceContent(this.url);
</span><span class="cx">         if (inlineContent) {
</span><span class="cx">             // Force inline content to be asynchronous to match the expected load pattern.
</span><del>-            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));
</del><ins>+            // 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);
+        }
</ins><span class="cx"> 
</span><del>-            return true;
</del><ins>+        function sourceMapResourceLoadError(error, body, mimeType, statusCode)
+        {
+            this.markAsFailed();
+            return Promise.resolve({
+                error: error,
+                content: body.content,
+                mimeType: mimeType,
+                statusCode: statusCode
+            });
</ins><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function sourceMapResourceLoaded(error, body, mimeType, statusCode)
</del><ins>+        function sourceMapResourceLoaded(body, mimeType, statusCode)
</ins><span class="cx">         {
</span><span class="cx">             const base64encoded = false;
</span><span class="cx"> 
</span><del>-            if (error || statusCode &gt;= 400) {
-                this.markAsFailed();
-                callback(error, body, base64encoded);
-                return;
-            }
</del><ins>+            if (statusCode &gt;= 400)
+                return sourceMapResourceLoadError(error, body, mimeType, statusCode);
</ins><span class="cx"> 
</span><span class="cx">             // FIXME: Add support for picking the best MIME-type. Right now the file extension is the best bet.
</span><span class="cx">             // The constructor set MIME-type based on the file extension and we ignore mimeType here.
</span><span class="cx"> 
</span><span class="cx">             this.markAsFinished();
</span><span class="cx"> 
</span><del>-            callback(null, body, base64encoded);
</del><ins>+            return Promise.resolve({
+                content: body.content,
+                mimeType: mimeType,
+                base64encoded: base64encoded,
+                statusCode: statusCode
+            });
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (!NetworkAgent.loadResource) {
</span><span class="cx">             sourceMapResourceLoaded.call(this, &quot;error: no NetworkAgent.loadResource&quot;);
</span><del>-            return false;
</del><ins>+            return Promise.reject(new Error(&quot;No NetworkAgent.loadResource&quot;));
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         var frameIdentifier = null;
</span><span class="lines">@@ -128,9 +130,7 @@
</span><span class="cx">         if (!frameIdentifier)
</span><span class="cx">             frameIdentifier = WebInspector.frameResourceManager.mainFrame.id;
</span><span class="cx"> 
</span><del>-        NetworkAgent.loadResource(frameIdentifier, this.url, sourceMapResourceLoaded.bind(this));
-
-        return true;
</del><ins>+        return NetworkAgent.loadResource.promise(frameIdentifier, this.url).then(sourceMapResourceLoaded.bind(this)).catch(sourceMapResourceLoadError.bind(this));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     createSourceCodeLocation: function(lineNumber, columnNumber)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsResourceContentViewjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ResourceContentView.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -43,7 +43,7 @@
</span><span class="cx">     this.element.addEventListener(&quot;click&quot;, this._mouseWasClicked.bind(this), false);
</span><span class="cx"> 
</span><span class="cx">     // Request content last so the spinner will always be removed in case the content is immediately available.
</span><del>-    resource.requestContent(this._contentAvailable.bind(this));
</del><ins>+    resource.requestContent().then(this._contentAvailable.bind(this)).catch(this._contentError.bind(this));
</ins><span class="cx"> 
</span><span class="cx">     if (!this.managesOwnIssues) {
</span><span class="cx">         WebInspector.issueManager.addEventListener(WebInspector.IssueManager.Event.IssueWasAdded, this._issueWasAdded, this);
</span><span class="lines">@@ -86,21 +86,20 @@
</span><span class="cx"> 
</span><span class="cx">     // Private
</span><span class="cx"> 
</span><del>-    _contentAvailable: function(resource, content, base64Encoded)
</del><ins>+    _contentAvailable: function(parameters)
</ins><span class="cx">     {
</span><del>-        // 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(&quot;.message-text-view.error&quot;))
-                return;
</del><ins>+        // Content is ready to show, call the public method now.
+        this.contentAvailable(parameters.content, parameters.base64Encoded);
+    },
</ins><span class="cx"> 
</span><del>-            this.element.removeChildren();
-            this.element.appendChild(WebInspector.createMessageTextView(WebInspector.UIString(&quot;An error occurred trying to load the resource.&quot;), true));
</del><ins>+    _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(&quot;.message-text-view.error&quot;))
</ins><span class="cx">             return;
</span><del>-        }
</del><span class="cx"> 
</span><del>-        // Content is ready to show, call the public method now.
-        this.contentAvailable(content, base64Encoded);
</del><ins>+        this.element.removeChildren();
+        this.element.appendChild(WebInspector.createMessageTextView(WebInspector.UIString(error.message), true));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     _issueWasAdded: function(event)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsSourceCodeTextEditorjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js (177790 => 177791)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -70,7 +70,7 @@
</span><span class="cx">     else
</span><span class="cx">         this._sourceCode.addEventListener(WebInspector.SourceCode.Event.SourceMapAdded, this._sourceCodeSourceMapAdded, this);
</span><span class="cx"> 
</span><del>-    sourceCode.requestContent(this._contentAvailable.bind(this));
</del><ins>+    sourceCode.requestContent().then(this._contentAvailable.bind(this));
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: Cmd+L shorcut doesn't actually work.
</span><span class="cx">     new WebInspector.KeyboardShortcut(WebInspector.KeyboardShortcut.Modifier.Command, &quot;L&quot;, this.showGoToLineDialog.bind(this), this.element);
</span><span class="lines">@@ -436,8 +436,12 @@
</span><span class="cx">         this._contentDidPopulate();
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    _contentAvailable: function(sourceCode, content, base64Encoded)
</del><ins>+    _contentAvailable: function(parameters)
</ins><span class="cx">     {
</span><ins>+        var sourceCode = parameters.sourceCode;
+        var content = parameters.content;
+        var base64Encoded = parameters.base64Encoded;
+
</ins><span class="cx">         console.assert(sourceCode === this._sourceCode);
</span><span class="cx">         console.assert(!base64Encoded);
</span><span class="cx"> 
</span><span class="lines">@@ -639,7 +643,7 @@
</span><span class="cx"> 
</span><span class="cx">         this._inlineScriptContentPopulated = pendingRequestCount;
</span><span class="cx"> 
</span><del>-        function scriptContentAvailable(error, content)
</del><ins>+        function scriptContentAvailable(parameters)
</ins><span class="cx">         {
</span><span class="cx">             // Return early if we are still waiting for content from other scripts.
</span><span class="cx">             if (--pendingRequestCount)
</span><span class="lines">@@ -689,7 +693,7 @@
</span><span class="cx"> 
</span><span class="cx">         var boundScriptContentAvailable = scriptContentAvailable.bind(this);
</span><span class="cx">         for (var i = 0; i &lt; scripts.length; ++i)
</span><del>-            scripts[i].requestContent(boundScriptContentAvailable);
</del><ins>+            scripts[i].requestContent().then(boundScriptContentAvailable);
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     _populateWithScriptContent: function()
</span><span class="lines">@@ -707,8 +711,9 @@
</span><span class="cx">         console.assert(scripts[0].range.startLine === 0);
</span><span class="cx">         console.assert(scripts[0].range.startColumn === 0);
</span><span class="cx"> 
</span><del>-        function scriptContentAvailable(error, content)
</del><ins>+        function scriptContentAvailable(parameters)
</ins><span class="cx">         {
</span><ins>+            var content = parameters.content;
</ins><span class="cx">             delete this._requestingScriptContent;
</span><span class="cx"> 
</span><span class="cx">             // Abort if the full content populated while waiting for this async callback.
</span><span class="lines">@@ -723,7 +728,7 @@
</span><span class="cx"> 
</span><span class="cx">         this._requestingScriptContent = true;
</span><span class="cx"> 
</span><del>-        scripts[0].requestContent(scriptContentAvailable.bind(this));
</del><ins>+        scripts[0].requestContent().then(scriptContentAvailable.bind(this));
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     _matchesSourceCodeLocation: function(sourceCodeLocation)
</span></span></pre>
</div>
</div>

</body>
</html>