Web Inspector: extract ContentProvider into its own file, make NetworkRequest, Resoru...
authorpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Apr 2012 11:46:56 +0000 (11:46 +0000)
committerpfeldman@chromium.org <pfeldman@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Apr 2012 11:46:56 +0000 (11:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=83922

Reviewed by Yury Semikhatsky.

Source/WebCore:

We have two different types of requestContent methods: one on the source mapping level and one on the resource level.
There are also adapters between the two. I'm aligning it all to a single requestContent method declared in ContentProvider.

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.py:
* inspector/front-end/BreakpointsSidebarPane.js:
(WebInspector.JavaScriptBreakpointsSidebarPane.prototype.addBreakpoint.didRequestContent):
(WebInspector.JavaScriptBreakpointsSidebarPane.prototype.addBreakpoint):
* inspector/front-end/ContentProvider.js: Added.
(WebInspector.ContentProvider):
(WebInspector.ContentProvider.prototype.contentURL):
(WebInspector.ContentProvider.prototype.requestContent):
(WebInspector.ContentProvider.prototype.searchInContent):
(WebInspector.ContentProvider.SearchMatch):
* inspector/front-end/ContentProviders.js:
(WebInspector.ScriptContentProvider.prototype.contentURL):
(WebInspector.ScriptContentProvider.prototype.requestContent):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.contentURL):
(WebInspector.ConcatenatedScriptsContentProvider.prototype.requestContent):
(WebInspector.CompilerSourceMappingContentProvider.prototype.contentURL):
(WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent):
(WebInspector.StaticContentProvider.prototype.contentURL):
(WebInspector.StaticContentProvider.prototype.requestContent):
* inspector/front-end/DebuggerPresentationModel.js:
* inspector/front-end/ExtensionServer.js:
(WebInspector.ExtensionServer.prototype._getResourceContent):
* inspector/front-end/JavaScriptSourceFrame.js:
(WebInspector.JavaScriptSourceFrame.prototype.requestContent):
* inspector/front-end/NetworkItemView.js:
(WebInspector.RequestContentView.prototype._ensureInnerViewShown.callback):
(WebInspector.RequestContentView.prototype._ensureInnerViewShown):
* inspector/front-end/NetworkRequest.js:
(WebInspector.NetworkRequest.prototype.contentURL):
(WebInspector.NetworkRequest.prototype.requestContent):
(WebInspector.NetworkRequest.prototype.searchInContent):
(WebInspector.NetworkRequest.prototype.populateImageSource):
(WebInspector.NetworkRequest.prototype._innerRequestContent.onResourceContent):
(WebInspector.NetworkRequest.prototype._innerRequestContent):
* inspector/front-end/RawSourceCode.js:
(WebInspector.RawSourceCode.prototype._createContentProvider):
(WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
(WebInspector.RawSourceCode.prototype._createSourceMapping):
* inspector/front-end/Resource.js:
(WebInspector.Resource.prototype.contentURL):
(WebInspector.Resource.prototype.requestContent):
(WebInspector.Resource.prototype._innerRequestContent.callback):
(WebInspector.Resource.prototype._innerRequestContent):
(WebInspector.ResourceRevision.prototype.contentURL):
(WebInspector.ResourceRevision.prototype.requestContent.callbackWrapper):
(WebInspector.ResourceRevision.prototype.requestContent):
(WebInspector.ResourceRevision.prototype.searchInContent):
* inspector/front-end/ResourceView.js:
(WebInspector.ResourceSourceFrame.prototype.requestContent):
(WebInspector.ResourceSourceFrame.prototype._contentChanged):
(WebInspector.ResourceRevisionSourceFrame.prototype.requestContent):
* inspector/front-end/ScriptFormatter.js:
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype.requestVisibleScriptOutline):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.setContent):
* inspector/front-end/UISourceCode.js:
(WebInspector.UISourceCode):
(WebInspector.UISourceCode.prototype.requestContent):
(WebInspector.UISourceCode.prototype._didRequestContent):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/inspector.html:

LayoutTests:

* http/tests/inspector/compiler-script-mapping.html:
* inspector/debugger/content-providers-expected.txt:
* inspector/debugger/content-providers.html:
* inspector/debugger/raw-source-code.html:
* inspector/debugger/ui-source-code.html:

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

27 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/compiler-script-mapping.html
LayoutTests/inspector/debugger/content-providers-expected.txt
LayoutTests/inspector/debugger/content-providers.html
LayoutTests/inspector/debugger/raw-source-code.html
LayoutTests/inspector/debugger/ui-source-code.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/inspector/compile-front-end.py
Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js
Source/WebCore/inspector/front-end/ContentProvider.js [new file with mode: 0644]
Source/WebCore/inspector/front-end/ContentProviders.js
Source/WebCore/inspector/front-end/DebuggerPresentationModel.js
Source/WebCore/inspector/front-end/ExtensionServer.js
Source/WebCore/inspector/front-end/JavaScriptSourceFrame.js
Source/WebCore/inspector/front-end/NetworkItemView.js
Source/WebCore/inspector/front-end/NetworkRequest.js
Source/WebCore/inspector/front-end/RawSourceCode.js
Source/WebCore/inspector/front-end/Resource.js
Source/WebCore/inspector/front-end/ResourceView.js
Source/WebCore/inspector/front-end/ScriptFormatter.js
Source/WebCore/inspector/front-end/ScriptsPanel.js
Source/WebCore/inspector/front-end/SourceFrame.js
Source/WebCore/inspector/front-end/UISourceCode.js
Source/WebCore/inspector/front-end/WebKit.qrc
Source/WebCore/inspector/front-end/inspector.html

index 45db3b3..8eef4ad 100644 (file)
@@ -1,3 +1,16 @@
+2012-04-13  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: extract ContentProvider into its own file, make NetworkRequest, Resoruce and others implement it.
+        https://bugs.webkit.org/show_bug.cgi?id=83922
+
+        Reviewed by Yury Semikhatsky.
+
+        * http/tests/inspector/compiler-script-mapping.html:
+        * inspector/debugger/content-providers-expected.txt:
+        * inspector/debugger/content-providers.html:
+        * inspector/debugger/raw-source-code.html:
+        * inspector/debugger/ui-source-code.html:
+
 2012-04-16  Takashi Toyoshima  <toyoshim@chromium.org>
 
        Unreviewed, fix a wrong expected.txt
index 34ccd6c..5249116 100644 (file)
@@ -145,13 +145,13 @@ function test()
 
             uiSourceCodeList[0].requestContent(didRequestContent1);
 
-            function didRequestContent1(mimeType, content)
+            function didRequestContent1(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals(0, content.indexOf("window.addEventListener"));
                 uiSourceCodeList[1].requestContent(didRequestContent2);
             }
 
-            function didRequestContent2(mimeType, content)
+            function didRequestContent2(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals(0, content.indexOf("function ClickHandler()"));
                 next();
@@ -181,7 +181,7 @@ function test()
 
             uiSourceCodeList[0].requestContent(didRequestContent);
 
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("<source content>", content);
                 next();
index 18cae5c..eef3a37 100644 (file)
@@ -27,7 +27,7 @@ function test()
             var mockScriptSource = "function foo() { return 0; }";
             var mockScript = createMockScript("foo.js", mockScriptSource);
             var contentProvider = new WebInspector.ScriptContentProvider(mockScript);
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("text/javascript", mimeType);
                 InspectorTest.assertEquals(mockScriptSource, content);
@@ -44,33 +44,13 @@ function test()
             scripts.push(createMockScript("3", "function bar() { return 0; }", [1, 70, 1, 98]));
             scripts.push(createMockScript("4", "this should not appear in displayed content", [0, 20, 0, 63]));
             var contentProvider = new WebInspector.ConcatenatedScriptsContentProvider(scripts);
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.addResult(content);
                 next();
             }
             contentProvider.requestContent(didRequestContent);
-        },
-
-        function testResourceContentProvider(next)
-        {
-            var mockResourceContent = "<script>var x = 0;</" + "script>";
-            var mockResource = {
-                requestContent: function(callback)
-                {
-                    InspectorTest.addResult("Request resource content.");
-                    callback(mockResourceContent);
-                }
-            };
-            var contentProvider = new WebInspector.ResourceContentProvider(mockResource);
-            function didRequestContent(mimeType, content)
-            {
-                InspectorTest.assertEquals("text/html", mimeType);
-                InspectorTest.assertEquals(mockResourceContent, content);
-                next();
-            }
-            contentProvider.requestContent(didRequestContent);
         }
     ]);
 };
index 6b6f132..e3319b3 100644 (file)
@@ -27,6 +27,7 @@ function test()
         WebInspector.resourceTreeModel._addFrame(new WebInspector.ResourceTreeFrame(WebInspector.resourceTreeModel, null, {id: "frame-id"}));
         var request = new WebInspector.NetworkRequest(requestId, url, "http://fake.url", "frame-id", "loader-id");
         request.type = type === "document" ? WebInspector.resourceTypes.Document : WebInspector.resourceTypes.Script;
+        request.mimeType = type === "document" ? "text/html" : "text/javascript";
 
         WebInspector.networkManager._dispatcher._startNetworkRequest(request);
         if (finished)
@@ -103,7 +104,7 @@ function test()
             InspectorTest.checkRawLocation(script, 10, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 10, 0));
             uiSourceCode.requestContent(didRequestContent);
 
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("text/javascript", mimeType);
                 InspectorTest.assertEquals("<script source>", content);
@@ -134,9 +135,9 @@ function test()
                 uiSourceCode.requestContent(didRequestContent);
             }
 
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.assertEquals("<resource content>", content);
 
                 rawSourceCode.addScript(script2);
@@ -159,9 +160,9 @@ function test()
             InspectorTest.assertEquals(false, uiSourceCode.isContentScript);
             uiSourceCode.requestContent(didRequestContent);
 
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.assertEquals("<resource content>", content);
 
                 rawSourceCode.addScript(script2);
@@ -194,9 +195,9 @@ function test()
                 uiSourceCode.requestContent(didRequestContentOneScript);
             }
 
-            function didRequestContentOneScript(mimeType, content)
+            function didRequestContentOneScript(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.assertEquals("  <script><script source 1></" + "script>", content);
 
                 rawSourceCode.forceUpdateSourceMapping();
@@ -212,9 +213,9 @@ function test()
                 uiSourceCode.requestContent(didRequestContentTwoScripts);
             }
 
-            function didRequestContentTwoScripts(mimeType, content)
+            function didRequestContentTwoScripts(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.assertEquals("  <script><script source 1></" + "script> <script><script source 2></" + "script>", content);
 
                 rawSourceCode.forceUpdateSourceMapping();
@@ -229,9 +230,9 @@ function test()
                 uiSourceCode.requestContent(didRequestContentRequest);
             }
 
-            function didRequestContentRequest(mimeType, content)
+            function didRequestContentRequest(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/html");
+                InspectorTest.assertEquals("text/html", mimeType);
                 InspectorTest.assertEquals("<resource content>", content);
 
                 rawSourceCode.addScript(script3);
@@ -254,7 +255,7 @@ function test()
             InspectorTest.checkRawLocation(script, 2, 0, rawSourceCode.uiLocationToRawLocation(uiSourceCode, 2, 0));
             uiSourceCode.requestContent(didRequestContent);
 
-            function didRequestContent(mimeType, content)
+            function didRequestContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("text/javascript", mimeType);
                 InspectorTest.assertEquals("<resource content>", content);
@@ -273,9 +274,9 @@ function test()
                 uiSourceCode.requestContent(didRequestFormattedContent);
             }
 
-            function didRequestFormattedContent(mimeType, content)
+            function didRequestFormattedContent(content, contentEncoded, mimeType)
             {
-                InspectorTest.assertEquals(mimeType, "text/javascript");
+                InspectorTest.assertEquals("text/javascript", mimeType);
                 InspectorTest.assertEquals("<formatted> <resource content>", content);
 
                 waitForUISourceCodeChangedEvent(rawSourceCode, requestNotFormattedContent);
@@ -291,7 +292,7 @@ function test()
                 uiSourceCode.requestContent(didRequestNotFormattedContent);
             }
 
-            function didRequestNotFormattedContent(mimeType, content)
+            function didRequestNotFormattedContent(content, contentEncoded, mimeType)
             {
                 InspectorTest.assertEquals("text/javascript", mimeType);
                 InspectorTest.assertEquals("<resource content>", content);
index 6e9a7a3..2b45d01 100644 (file)
@@ -10,7 +10,7 @@ function test()
         requestContent: function(callback)
         {
             InspectorTest.addResult("Content is requested from SourceCodeProvider.");
-            setTimeout(callback.bind(null, "text/javascript", "var x = 0;"), 0);
+            setTimeout(callback.bind(null, "var x = 0;", false, "text/javascript"), 0);
         }
     };
 
@@ -18,7 +18,7 @@ function test()
         function testUISourceCode(next)
         {
             var uiSourceCode = new WebInspector.UISourceCode("id", "url", contentProvider);
-            function didRequestContent(callNumber, mimeType, content)
+            function didRequestContent(callNumber, content, contentEncoded, mimeType)
             {
                 InspectorTest.addResult("Callback " + callNumber + " is invoked.");
                 InspectorTest.assertEquals("text/javascript", mimeType);
@@ -26,7 +26,7 @@ function test()
 
                 if (callNumber === 3) {
                     // Check that sourceCodeProvider.requestContent won't be called anymore.
-                    uiSourceCode.requestContent(function(mimeType, content)
+                    uiSourceCode.requestContent(function(content, contentEncoded, mimeType)
                     {
                         InspectorTest.assertEquals("text/javascript", mimeType);
                         InspectorTest.assertEquals("var x = 0;", content);
index dc72175..3b32c0c 100644 (file)
@@ -1,3 +1,78 @@
+2012-04-13  Pavel Feldman  <pfeldman@chromium.org>
+
+        Web Inspector: extract ContentProvider into its own file, make NetworkRequest, Resoruce and others implement it.
+        https://bugs.webkit.org/show_bug.cgi?id=83922
+
+        Reviewed by Yury Semikhatsky.
+
+        We have two different types of requestContent methods: one on the source mapping level and one on the resource level.
+        There are also adapters between the two. I'm aligning it all to a single requestContent method declared in ContentProvider.
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/compile-front-end.py:
+        * inspector/front-end/BreakpointsSidebarPane.js:
+        (WebInspector.JavaScriptBreakpointsSidebarPane.prototype.addBreakpoint.didRequestContent):
+        (WebInspector.JavaScriptBreakpointsSidebarPane.prototype.addBreakpoint):
+        * inspector/front-end/ContentProvider.js: Added.
+        (WebInspector.ContentProvider):
+        (WebInspector.ContentProvider.prototype.contentURL):
+        (WebInspector.ContentProvider.prototype.requestContent):
+        (WebInspector.ContentProvider.prototype.searchInContent):
+        (WebInspector.ContentProvider.SearchMatch):
+        * inspector/front-end/ContentProviders.js:
+        (WebInspector.ScriptContentProvider.prototype.contentURL):
+        (WebInspector.ScriptContentProvider.prototype.requestContent):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.contentURL):
+        (WebInspector.ConcatenatedScriptsContentProvider.prototype.requestContent):
+        (WebInspector.CompilerSourceMappingContentProvider.prototype.contentURL):
+        (WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent):
+        (WebInspector.StaticContentProvider.prototype.contentURL):
+        (WebInspector.StaticContentProvider.prototype.requestContent):
+        * inspector/front-end/DebuggerPresentationModel.js:
+        * inspector/front-end/ExtensionServer.js:
+        (WebInspector.ExtensionServer.prototype._getResourceContent):
+        * inspector/front-end/JavaScriptSourceFrame.js:
+        (WebInspector.JavaScriptSourceFrame.prototype.requestContent):
+        * inspector/front-end/NetworkItemView.js:
+        (WebInspector.RequestContentView.prototype._ensureInnerViewShown.callback):
+        (WebInspector.RequestContentView.prototype._ensureInnerViewShown):
+        * inspector/front-end/NetworkRequest.js:
+        (WebInspector.NetworkRequest.prototype.contentURL):
+        (WebInspector.NetworkRequest.prototype.requestContent):
+        (WebInspector.NetworkRequest.prototype.searchInContent):
+        (WebInspector.NetworkRequest.prototype.populateImageSource):
+        (WebInspector.NetworkRequest.prototype._innerRequestContent.onResourceContent):
+        (WebInspector.NetworkRequest.prototype._innerRequestContent):
+        * inspector/front-end/RawSourceCode.js:
+        (WebInspector.RawSourceCode.prototype._createContentProvider):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping):
+        * inspector/front-end/Resource.js:
+        (WebInspector.Resource.prototype.contentURL):
+        (WebInspector.Resource.prototype.requestContent):
+        (WebInspector.Resource.prototype._innerRequestContent.callback):
+        (WebInspector.Resource.prototype._innerRequestContent):
+        (WebInspector.ResourceRevision.prototype.contentURL):
+        (WebInspector.ResourceRevision.prototype.requestContent.callbackWrapper):
+        (WebInspector.ResourceRevision.prototype.requestContent):
+        (WebInspector.ResourceRevision.prototype.searchInContent):
+        * inspector/front-end/ResourceView.js:
+        (WebInspector.ResourceSourceFrame.prototype.requestContent):
+        (WebInspector.ResourceSourceFrame.prototype._contentChanged):
+        (WebInspector.ResourceRevisionSourceFrame.prototype.requestContent):
+        * inspector/front-end/ScriptFormatter.js:
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype.requestVisibleScriptOutline):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.setContent):
+        * inspector/front-end/UISourceCode.js:
+        (WebInspector.UISourceCode):
+        (WebInspector.UISourceCode.prototype.requestContent):
+        (WebInspector.UISourceCode.prototype._didRequestContent):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/inspector.html:
+
 2012-04-16  Jason Liu  <jason.liu@torchmobile.com.cn>
 
         [BlackBerry] Missing readyState 2 when a XMLHttpRequest calls xmlhttp.open("HEAD","notExist.html",true).
index 0d670ad..8bc9d4f 100644 (file)
             'inspector/front-end/ConsoleModel.js',
             'inspector/front-end/ConsolePanel.js',
             'inspector/front-end/ConsoleView.js',
+            'inspector/front-end/ContentProvider.js',
             'inspector/front-end/ContentProviders.js',
             'inspector/front-end/ContextMenu.js',
             'inspector/front-end/CookieItemsView.js',
index 88e0d5e..5c94290 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\inspector\front-end\ContentProvider.js"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\inspector\front-end\ContentProviders.js"
                                        >
                                </File>
index 5ce21e9..6651ece 100755 (executable)
@@ -62,6 +62,7 @@ modules = [
             "Color.js",
             "CompilerScriptMapping.js",
             "ConsoleModel.js",
+            "ContentProvider.js",
             "ContentProviders.js",
             "CookieParser.js",
             "CSSCompletions.js",
index 3d641d3..39eb2d1 100644 (file)
@@ -74,7 +74,13 @@ WebInspector.JavaScriptBreakpointsSidebarPane.prototype = {
         var snippetElement = document.createElement("div");
         snippetElement.className = "source-text monospace";
         element.appendChild(snippetElement);
-        function didRequestContent(mimeType, content)
+
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function didRequestContent(content, contentEncoded, mimeType)
         {
             var lineEndings = content.lineEndings();
             if (breakpoint.lineNumber < lineEndings.length)
diff --git a/Source/WebCore/inspector/front-end/ContentProvider.js b/Source/WebCore/inspector/front-end/ContentProvider.js
new file mode 100644 (file)
index 0000000..d0cb6ce
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @interface
+ */
+WebInspector.ContentProvider = function() { }
+
+WebInspector.ContentProvider.prototype = {
+    /**
+     * @return {?string}
+     */
+    contentURL: function() { },
+
+    /**
+     * @param {function(?string,boolean,string)} callback
+     */
+    requestContent: function(callback) { },
+
+    /**
+     * @param {string} query
+     * @param {boolean} caseSensitive
+     * @param {boolean} isRegex
+     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
+     */
+    searchInContent: function(query, caseSensitive, isRegex, callback) { }
+}
+
+/**
+ * @constructor
+ * @param {number} lineNumber
+ * @param {string} lineContent
+ */
+WebInspector.ContentProvider.SearchMatch = function(lineNumber, lineContent) {
+    this.lineNumber = lineNumber;
+    this.lineContent = lineContent;
+}
index 439f2c5..6f074a8 100644 (file)
@@ -31,6 +31,7 @@
 /**
  * @constructor
  * @implements {WebInspector.ContentProvider}
+ * @param {WebInspector.Script} script
  */
 WebInspector.ScriptContentProvider = function(script)
 {
@@ -40,13 +41,21 @@ WebInspector.ScriptContentProvider = function(script)
 
 WebInspector.ScriptContentProvider.prototype = {
     /**
-     * @param {function(string,string)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return this._script.sourceURL;
+    },
+
+    /**
+     * @param {function(?string,boolean,string)} callback
      */
     requestContent: function(callback)
     {
         function didRequestSource(source)
         {
-            callback(this._mimeType, source);
+            callback(source, false, this._mimeType);
         }
         this._script.requestSource(didRequestSource.bind(this));
     },
@@ -68,6 +77,7 @@ WebInspector.ScriptContentProvider.prototype.__proto__ = WebInspector.ContentPro
 /**
  * @constructor
  * @implements {WebInspector.ContentProvider}
+ * @param {Array.<WebInspector.Script>} scripts
  */
 WebInspector.ConcatenatedScriptsContentProvider = function(scripts)
 {
@@ -109,7 +119,15 @@ WebInspector.ConcatenatedScriptsContentProvider.prototype = {
     },
 
     /**
-     * @param {function(string,string)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return null;
+    },
+
+    /**
+     * @param {function(?string,boolean,string)} callback
      */
     requestContent: function(callback)
     {
@@ -119,7 +137,7 @@ WebInspector.ConcatenatedScriptsContentProvider.prototype = {
         {
             sources.push(source);
             if (sources.length == scripts.length)
-                callback(this._mimeType, this._concatenateScriptsContent(scripts, sources));
+                callback(this._concatenateScriptsContent(scripts, sources), false, this._mimeType);
         }
         for (var i = 0; i < scripts.length; ++i)
             scripts[i].requestSource(didRequestSource.bind(this));
@@ -205,44 +223,6 @@ WebInspector.ConcatenatedScriptsContentProvider.prototype.__proto__ = WebInspect
 /**
  * @constructor
  * @implements {WebInspector.ContentProvider}
- * @param {WebInspector.Resource} resource
- */
-WebInspector.ResourceContentProvider = function(resource)
-{
-    this._mimeType = resource.type === WebInspector.resourceTypes.Script ? "text/javascript" : "text/html";
-    this._resource = resource;
-};
-
-WebInspector.ResourceContentProvider.prototype = {
-    /**
-     * @param {function(string,string)} callback
-     */
-    requestContent: function(callback)
-    {
-        function didRequestContent(content)
-        {
-            callback(this._mimeType, content);
-        }
-        this._resource.requestContent(didRequestContent.bind(this));
-    },
-
-    /**
-     * @param {string} query
-     * @param {boolean} caseSensitive
-     * @param {boolean} isRegex
-     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
-     */
-    searchInContent: function(query, caseSensitive, isRegex, callback)
-    {
-        this._resource.searchInContent(query, caseSensitive, isRegex, callback);
-    }
-}
-
-WebInspector.ResourceContentProvider.prototype.__proto__ = WebInspector.ContentProvider.prototype;
-
-/**
- * @constructor
- * @implements {WebInspector.ContentProvider}
  */
 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL)
 {
@@ -252,7 +232,15 @@ WebInspector.CompilerSourceMappingContentProvider = function(sourceURL)
 
 WebInspector.CompilerSourceMappingContentProvider.prototype = {
     /**
-     * @param {function(string,string)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return this._sourceURL;
+    },
+
+    /**
+     * @param {function(?string,boolean,string)} callback
      */
     requestContent: function(callback)
     {
@@ -263,7 +251,7 @@ WebInspector.CompilerSourceMappingContentProvider.prototype = {
         } catch(e) {
             console.error(e.message);
         }
-        callback(this._mimeType, sourceCode);
+        callback(sourceCode, false, this._mimeType);
     },
 
     /**
@@ -292,11 +280,19 @@ WebInspector.StaticContentProvider = function(mimeType, content)
 
 WebInspector.StaticContentProvider.prototype = {
     /**
-     * @param {function(string,string)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return null;
+    },
+
+    /**
+     * @param {function(?string,boolean,string)} callback
      */
     requestContent: function(callback)
     {
-        callback(this._mimeType, this._content);
+        callback(this._content, false, this._mimeType);
     },
 
     /**
index a17e71e..abe475b 100644 (file)
@@ -810,8 +810,9 @@ WebInspector.DebuggerPresentationModelResourceBinding.prototype = {
      * @param {function(?string)} userCallback
      * @param {?string} oldContent
      * @param {boolean} oldContentEncoded
+     * @param {string} mimeType
      */
-    _setContentWithInitialContent: function(uiSourceCode, content, userCallback, oldContent, oldContentEncoded)
+    _setContentWithInitialContent: function(uiSourceCode, content, userCallback, oldContent, oldContentEncoded, mimeType)
     {
         /**
          * @this {WebInspector.DebuggerPresentationModelResourceBinding}
index 4b4feae..699a5eb 100644 (file)
@@ -439,10 +439,15 @@ WebInspector.ExtensionServer.prototype = {
 
     _getResourceContent: function(resource, message, port)
     {
-        function onContentAvailable(content, encoded)
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function onContentAvailable(content, contentEncoded, mimeType)
         {
             var response = {
-                encoding: encoded ? "base64" : "",
+                encoding: contentEncoded ? "base64" : "",
                 content: content
             };
             this._dispatchCallback(message.requestId, port, response);
index b75b75c..29dc672 100644 (file)
@@ -68,13 +68,20 @@ WebInspector.JavaScriptSourceFrame.prototype = {
         this._popoverHelper.hidePopover();
     },
 
-    // SourceFrame overrides
+    /**
+     * @param {function(?string, boolean, string)} callback
+     */
     requestContent: function(callback)
     {
-        function mycallback(mimeType, content)
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function mycallback(content, contentEncoded, mimeType)
         {
             this._originalContent = content;
-            callback(mimeType, content);
+            callback(content, contentEncoded, mimeType);
         }
         this._uiSourceCode.requestContent(mycallback.bind(this));
     },
index 68e490c..a28cdec 100644 (file)
@@ -128,7 +128,12 @@ WebInspector.RequestContentView.prototype = {
             return;
         this._innerViewShowRequested = true;
 
-        function callback()
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function callback(content, contentEncoded, mimeType)
         {
             this._innerViewShowRequested = false;
             this.contentLoaded();
index 96441db..c971b2b 100644 (file)
@@ -31,7 +31,7 @@
 /**
  * @constructor
  * @extends {WebInspector.Object}
- *
+ * @implements {WebInspector.ContentProvider}
  * @param {NetworkAgent.RequestId} requestId
  * @param {string} url
  * @param {string} documentURL
@@ -673,7 +673,15 @@ WebInspector.NetworkRequest.prototype = {
     },
 
     /**
-     * @param {function(?string, boolean)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return this._url;
+    },
+
+    /**
+     * @param {function(?string, boolean, string)} callback
      */
     requestContent: function(callback)
     {
@@ -681,11 +689,11 @@ WebInspector.NetworkRequest.prototype = {
         // Since WebSockets are potentially long-living, fail requests immediately
         // to prevent caller blocking until resource is marked as finished.
         if (this.type === WebInspector.resourceTypes.WebSocket) {
-            callback(null, false);
+            callback(null, false, this._mimeType);
             return;
         }
         if (typeof this._content !== "undefined") {
-            callback(this.content, this._contentEncoded);
+            callback(this.content, this._contentEncoded, this._mimeType);
             return;
         }
         this._pendingContentCallbacks.push(callback);
@@ -694,6 +702,17 @@ WebInspector.NetworkRequest.prototype = {
     },
 
     /**
+     * @param {string} query
+     * @param {boolean} caseSensitive
+     * @param {boolean} isRegex
+     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
+     */
+    searchInContent: function(query, caseSensitive, isRegex, callback)
+    {
+        callback([]);
+    },
+
+    /**
      * @return {boolean}
      */
     isHttpFamily: function()
@@ -730,27 +749,23 @@ WebInspector.NetworkRequest.prototype = {
      */
     populateImageSource: function(image)
     {
-        function onResourceContent()
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function onResourceContent(content, contentEncoded, mimeType)
         {
-            image.src = this._contentURL();
+            const maxDataUrlSize = 1024 * 1024;
+            // If resource content is not available or won't fit a data URL, fall back to using original URL.
+            if (this._content == null || this._content.length > maxDataUrlSize)
+                return this.url;
+            image.src = "data:" + this.mimeType + (this._contentEncoded ? ";base64," : ",") + this._content;
         }
 
         this.requestContent(onResourceContent.bind(this));
     },
 
-    /**
-     * @return {string}
-     */
-    _contentURL: function()
-    {
-        const maxDataUrlSize = 1024 * 1024;
-        // If resource content is not available or won't fit a data URL, fall back to using original URL.
-        if (this._content == null || this._content.length > maxDataUrlSize)
-            return this.url;
-
-        return "data:" + this.mimeType + (this._contentEncoded ? ";base64," : ",") + this._content;
-    },
-
     _innerRequestContent: function()
     {
         if (this._contentRequested)
@@ -768,7 +783,7 @@ WebInspector.NetworkRequest.prototype = {
             this._contentEncoded = contentEncoded;
             var callbacks = this._pendingContentCallbacks.slice();
             for (var i = 0; i < callbacks.length; ++i)
-                callbacks[i](this._content, this._contentEncoded);
+                callbacks[i](this._content, this._contentEncoded, this._mimeType);
             this._pendingContentCallbacks.length = 0;
             delete this._contentRequested;
         }
index d76e536..41a5042 100644 (file)
@@ -165,7 +165,7 @@ WebInspector.RawSourceCode.prototype = {
     _createContentProvider: function()
     {
         if (this._resource)
-            return new WebInspector.ResourceContentProvider(this._resource);
+            return this._resource;
         if (this._scripts.length === 1 && !this._scripts[0].lineOffset && !this._scripts[0].columnOffset)
             return new WebInspector.ScriptContentProvider(this._scripts[0]);
         return new WebInspector.ConcatenatedScriptsContentProvider(this._scripts);
@@ -186,10 +186,11 @@ WebInspector.RawSourceCode.prototype = {
 
         /**
          * @this {WebInspector.RawSourceCode}
+         * @param {?string} content
+         * @param {boolean} contentEncoded
          * @param {string} mimeType
-         * @param {string} content
          */
-        function didRequestContent(mimeType, content)
+        function didRequestContent(content, contentEncoded, mimeType)
         {
             /**
              * @this {WebInspector.RawSourceCode}
@@ -203,7 +204,7 @@ WebInspector.RawSourceCode.prototype = {
                 var sourceMapping = new WebInspector.RawSourceCode.FormattedSourceMapping(this, uiSourceCode, mapping);
                 callback(sourceMapping);
             }
-            this._formatter.formatContent(mimeType, content, didFormatContent.bind(this));
+            this._formatter.formatContent(mimeType, content || "", didFormatContent.bind(this));
         }
         originalContentProvider.requestContent(didRequestContent.bind(this));
     },
index 7924cb0..17a499e 100644 (file)
@@ -29,7 +29,7 @@
 /**
  * @constructor
  * @extends {WebInspector.Object}
- *
+ * @implements {WebInspector.ContentProvider}
  * @param {?WebInspector.NetworkRequest} request
  * @param {string} url
  * @param {string} documentURL
@@ -360,12 +360,20 @@ WebInspector.Resource.prototype = {
     },
 
     /**
-     * @param {function(?string, boolean)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return this._url;
+    },
+
+    /**
+     * @param {function(?string, boolean, string)} callback
      */
     requestContent: function(callback)
     {
         if (typeof this._content !== "undefined") {
-            callback(this._content, !!this._contentEncoded);
+            callback(this._content, !!this._contentEncoded, this.mimeType);
             return;
         }
 
@@ -377,7 +385,7 @@ WebInspector.Resource.prototype = {
      * @param {string} query
      * @param {boolean} caseSensitive
      * @param {boolean} isRegex
-     * @param {function(Array.<PageAgent.SearchMatch>)} callback
+     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
      */
     searchInContent: function(query, caseSensitive, isRegex, callback)
     {
@@ -440,7 +448,7 @@ WebInspector.Resource.prototype = {
             this._originalContent = content;
             var callbacks = this._pendingContentCallbacks.slice();
             for (var i = 0; i < callbacks.length; ++i)
-                callbacks[i](this._content, this._contentEncoded);
+                callbacks[i](this._content, this._contentEncoded, this.mimeType);
             this._pendingContentCallbacks.length = 0;
             delete this._contentRequested;
         }
@@ -452,6 +460,7 @@ WebInspector.Resource.prototype.__proto__ = WebInspector.Object.prototype;
 
 /**
  * @constructor
+ * @implements {WebInspector.ContentProvider}
  * @param {WebInspector.Resource} resource
  * @param {string|undefined} content
  * @param {number} timestamp
@@ -498,19 +507,27 @@ WebInspector.ResourceRevision.prototype = {
     },
 
     /**
-     * @param {function(?string)} callback
+     * @return {?string}
+     */
+    contentURL: function()
+    {
+        return this._resource.url;
+    },
+
+    /**
+     * @param {function(?string, boolean, string)} callback
      */
     requestContent: function(callback)
     {
         if (typeof this._content === "string") {
-            callback(this._content);
+            callback(this._content, false, this.resource.mimeType);
             return;
         }
 
         // If we are here, this is initial revision. First, look up content fetched over the wire.
         if (typeof this.resource._originalContent === "string") {
             this._content = this._resource._originalContent;
-            callback(this._content);
+            callback(this._content, false, this.resource.mimeType);
             return;
         }
 
@@ -521,10 +538,21 @@ WebInspector.ResourceRevision.prototype = {
          */
         function callbackWrapper(error, content, contentEncoded)
         {
-            callback(error ? null : content);
+            callback(error ? null : content, contentEncoded, this.resource.mimeType);
         }
 
-        PageAgent.getResourceContent(this._resource.frameId, this._resource.url, callbackWrapper);
+        PageAgent.getResourceContent(this._resource.frameId, this._resource.url, callbackWrapper.bind(this));
+    },
+
+    /**
+     * @param {string} query
+     * @param {boolean} caseSensitive
+     * @param {boolean} isRegex
+     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
+     */
+    searchInContent: function(query, caseSensitive, isRegex, callback)
+    {
+        callback([]);
     }
 }
 
index b108f3c..fab145a 100644 (file)
@@ -109,20 +109,27 @@ WebInspector.ResourceSourceFrame.prototype = {
         return this._resource;
     },
 
+    /**
+     * @param {function(?string,boolean,string)} callback
+     */
     requestContent: function(callback)
     {
-        function contentLoaded(text)
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function callbackWrapper(content, contentEncoded, mimeType)
         {
-            var mimeType = WebInspector.ResourceSourceFrame._mimeTypeForResource(this._resource);
-            callback(mimeType, text);
+            // Canonicalize mimeType.
+            callback(content, contentEncoded, WebInspector.ResourceSourceFrame._mimeTypeForResource(this._resource));
         }
-
-        this.resource.requestContent(contentLoaded.bind(this));
+        this.resource.requestContent(callbackWrapper.bind(this));
     },
 
     _contentChanged: function(event)
     {
-        this.setContent(WebInspector.ResourceSourceFrame._mimeTypeForResource[this._resource], this._resource.content);
+        this.setContent(this._resource.content, false, WebInspector.ResourceSourceFrame._mimeTypeForResource(this._resource));
     }
 }
 
@@ -210,15 +217,12 @@ WebInspector.ResourceRevisionSourceFrame.prototype = {
         return this._revision.resource;
     },
 
+    /**
+     * @param {function(?string,boolean,string)} callback
+     */
     requestContent: function(callback)
     {
-        function contentLoaded(text)
-        {
-            var mimeType = WebInspector.ResourceSourceFrame._mimeTypeForResource(this.resource);
-            callback(mimeType, text);
-        }
-
-        this._revision.requestContent(contentLoaded.bind(this));
+        this._revision.requestContent(callback);
     },
 }
 
index 2f2cac5..ff2fd90 100644 (file)
@@ -66,7 +66,7 @@ WebInspector.ScriptFormatter.positionToLocation = function(lineEndings, position
 WebInspector.ScriptFormatter.prototype = {
     /**
      * @param {string} mimeType
-     * @param {string} content
+     * @param {?string} content
      * @param {function(string, WebInspector.FormattedSourceMapping)} callback
      */
     formatContent: function(mimeType, content, callback)
index caeb1ca..1ad86d5 100644 (file)
@@ -492,7 +492,13 @@ WebInspector.ScriptsPanel.prototype = {
 
     requestVisibleScriptOutline: function()
     {
-        function contentCallback(mimeType, content)
+        
+        /**
+         * @param {?string} content
+         * @param {boolean} contentEncoded
+         * @param {string} mimeType
+         */
+        function contentCallback(content, contentEncoded, mimeType)
         {
             if (this._outlineWorker)
                 this._outlineWorker.terminate();
index a6a996a..18f7707 100644 (file)
@@ -118,6 +118,9 @@ WebInspector.SourceFrame.prototype = {
         }
     },
 
+    /**
+     * @param {function(?string, boolean, string)} callback
+     */
     requestContent: function(callback)
     {
     },
@@ -207,12 +210,17 @@ WebInspector.SourceFrame.prototype = {
     {
     },
 
-    setContent: function(mimeType, content)
+    /**
+     * @param {?string} content
+     * @param {boolean} contentEncoded
+     * @param {string} mimeType
+     */
+    setContent: function(content, contentEncoded, mimeType)
     {
         this._textViewer.mimeType = mimeType;
 
         this._loaded = true;
-        this._textModel.setText(content);
+        this._textModel.setText(content || "");
 
         this._textViewer.beginUpdates();
 
index 52d3cf5..09e57bc 100644 (file)
@@ -43,7 +43,7 @@ WebInspector.UISourceCode = function(id, url, contentProvider)
     this.isContentScript = false;
     this.isEditable = false;
     /**
-     * @type Array.<function(string,string)>
+     * @type Array.<function(?string,boolean,string)>
      */
     this._requestContentCallbacks = [];
 }
@@ -74,12 +74,12 @@ WebInspector.UISourceCode.prototype = {
     },
 
     /**
-     * @param {function(string,string)} callback
+     * @param {function(?string,boolean,string)} callback
      */
     requestContent: function(callback)
     {
         if (this._contentLoaded) {
-            callback(this._mimeType, this._content);
+            callback(this._content, false, this._mimeType);
             return;
         }
 
@@ -197,17 +197,18 @@ WebInspector.UISourceCode.prototype = {
     },
 
     /**
+     * @param {?string} content
+     * @param {boolean} contentEncoded
      * @param {string} mimeType
-     * @param {string} content
      */
-    _didRequestContent: function(mimeType, content)
+    _didRequestContent: function(content, contentEncoded, mimeType)
     {
         this._contentLoaded = true;
         this._mimeType = mimeType;
         this._content = content;
 
         for (var i = 0; i < this._requestContentCallbacks.length; ++i)
-            this._requestContentCallbacks[i](mimeType, content);
+            this._requestContentCallbacks[i](content, contentEncoded, mimeType);
         this._requestContentCallbacks = [];
     },
 
@@ -223,32 +224,3 @@ WebInspector.UISourceCode.prototype = {
 }
 
 WebInspector.UISourceCode.prototype.__proto__ = WebInspector.Object.prototype;
-
-/**
- * @interface
- */
-WebInspector.ContentProvider = function() { }
-WebInspector.ContentProvider.prototype = {
-    /**
-     * @param {function(string,string)} callback
-     */
-    requestContent: function(callback) { },
-
-    /**
-     * @param {string} query
-     * @param {boolean} caseSensitive
-     * @param {boolean} isRegex
-     * @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
-     */
-    searchInContent: function(query, caseSensitive, isRegex, callback) { }
-}
-
-/**
- * @constructor
- * @param {number} lineNumber
- * @param {string} lineContent
- */
-WebInspector.ContentProvider.SearchMatch = function(lineNumber, lineContent) {
-    this.lineNumber = lineNumber;
-    this.lineContent = lineContent;
-}
index a61ecb8..2516500 100644 (file)
@@ -21,6 +21,7 @@
     <file>ConsoleModel.js</file>
     <file>ConsolePanel.js</file>
     <file>ConsoleView.js</file>
+    <file>ContentProvider.js</file>
     <file>ContentProviders.js</file>
     <file>ContextMenu.js</file>
     <file>CookieItemsView.js</file>
index 32e2856..0f0f4eb 100644 (file)
@@ -64,6 +64,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     <script type="text/javascript" src="InspectorView.js"></script>
     <script type="text/javascript" src="AdvancedSearchController.js"></script>
     <script type="text/javascript" src="TimelineGrid.js"></script>    
+    <script type="text/javascript" src="ContentProvider.js"></script>
     <script type="text/javascript" src="Resource.js"></script>
     <script type="text/javascript" src="NetworkRequest.js"></script>
     <script type="text/javascript" src="CSSStyleModel.js"></script>