Title: [92196] trunk
Revision
92196
Author
[email protected]
Date
2011-08-02 08:59:55 -0700 (Tue, 02 Aug 2011)

Log Message

Web Inspector: merge FormattedSourceFile into SourceFile.
https://bugs.webkit.org/show_bug.cgi?id=65411

Reviewed by Pavel Feldman.

Prepare for splitting SourceFile into RawSourceCode and UISourceCode:
 * merge FormattedSourceFile into SourceFile
 * rename SourceFile to RawSourceCode
 * hide formatter worker lazy creation in ScriptFormatter

Source/WebCore:

* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModel):
(WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation):
(WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation):
(WebInspector.DebuggerPresentationModel.prototype._addScript):
* inspector/front-end/ScriptFormatter.js:
(WebInspector.ScriptFormatter):
(WebInspector.ScriptFormatter.prototype._didFormatContent):
(WebInspector.ScriptFormatter.prototype.get _worker):
* inspector/front-end/SourceFile.js:
(WebInspector.RawSourceCode):
(WebInspector.RawSourceCode.prototype.setFormatted):
(WebInspector.RawSourceCode.prototype.createSourceMappingIfNeeded.didRequestContent):
(WebInspector.RawSourceCode.prototype.createSourceMappingIfNeeded):
(WebInspector.RawSourceCode.prototype._didRequestContent.didFormatContent):
(WebInspector.RawSourceCode.prototype._didRequestContent):
(WebInspector.RawSourceCode.prototype._invokeRequestContentCallbacks):

LayoutTests:

* inspector/debugger/source-file.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92195 => 92196)


--- trunk/LayoutTests/ChangeLog	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/LayoutTests/ChangeLog	2011-08-02 15:59:55 UTC (rev 92196)
@@ -1,3 +1,17 @@
+2011-07-30  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: merge FormattedSourceFile into SourceFile.
+        https://bugs.webkit.org/show_bug.cgi?id=65411
+
+        Reviewed by Pavel Feldman.
+
+        Prepare for splitting SourceFile into RawSourceCode and UISourceCode:
+         * merge FormattedSourceFile into SourceFile
+         * rename SourceFile to RawSourceCode
+         * hide formatter worker lazy creation in ScriptFormatter
+
+        * inspector/debugger/source-file.html:
+
 2011-08-01  Vsevolod Vlasov  <[email protected]>
 
         Web Inspector: [REGRESSION] Console evaluations leading to resource loading cause errors.

Modified: trunk/LayoutTests/inspector/debugger/source-file.html (92195 => 92196)


--- trunk/LayoutTests/inspector/debugger/source-file.html	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/LayoutTests/inspector/debugger/source-file.html	2011-08-02 15:59:55 UTC (rev 92196)
@@ -54,7 +54,7 @@
         function testPlainConvertLocation(next)
         {
             var script = new WebInspector.Script("1", "foo.js", 0, 0, 20, 80, undefined, undefined, false);
-            var sourceFile = new WebInspector.SourceFile("id", script);
+            var sourceFile = new WebInspector.RawSourceCode("id", script);
 
             checkUILocation(sourceFile, 10, 20, sourceFile.rawLocationToUILocation(rl(10, 20)));
             checkRawLocation(script, 30, 40, sourceFile.uiLocationToRawLocation(30, 40));
@@ -66,7 +66,7 @@
         {
             var script1 = new WebInspector.Script("1", "foo.js", 10, 20, 30, 40, undefined, undefined, false);
             var script2 = new WebInspector.Script("2", "foo.js", 50, 60, 70, 80, undefined, undefined, false);
-            var sourceFile = new WebInspector.SourceFile("id", script1);
+            var sourceFile = new WebInspector.RawSourceCode("id", script1);
             sourceFile.addScript(script2);
 
             checkUILocation(sourceFile, 20, 0, sourceFile.rawLocationToUILocation(rl(20, 0)));
@@ -81,7 +81,8 @@
         function testFormattedConvertLocation(next)
         {
             var script = new WebInspector.Script("1", "foo.js", 0, 0, 20, 80, undefined, undefined, false);
-            var sourceFile = new WebInspector.FormattedSourceFile("id", script, null, mockScriptFormatter);
+            var sourceFile = new WebInspector.RawSourceCode("id", script, mockScriptFormatter);
+            sourceFile.setFormatted(true);
 
             function didCreateSourceMapping()
             {
@@ -96,7 +97,8 @@
         {
             var script1 = new WebInspector.Script("1", "foo.js", 10, 20, 30, 40, undefined, undefined, false);
             var script2 = new WebInspector.Script("2", "foo.js", 50, 60, 70, 80, undefined, undefined, false);
-            var sourceFile = new WebInspector.FormattedSourceFile("id", script1, null, mockScriptFormatter);
+            var sourceFile = new WebInspector.RawSourceCode("id", script1, mockScriptFormatter);
+            sourceFile.setFormatted(true);
             sourceFile.addScript(script2);
 
             function didCreateSourceMapping()

Modified: trunk/Source/WebCore/ChangeLog (92195 => 92196)


--- trunk/Source/WebCore/ChangeLog	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/Source/WebCore/ChangeLog	2011-08-02 15:59:55 UTC (rev 92196)
@@ -1,3 +1,33 @@
+2011-07-30  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: merge FormattedSourceFile into SourceFile.
+        https://bugs.webkit.org/show_bug.cgi?id=65411
+
+        Reviewed by Pavel Feldman.
+
+        Prepare for splitting SourceFile into RawSourceCode and UISourceCode:
+         * merge FormattedSourceFile into SourceFile
+         * rename SourceFile to RawSourceCode
+         * hide formatter worker lazy creation in ScriptFormatter
+
+        * inspector/front-end/DebuggerPresentationModel.js:
+        (WebInspector.DebuggerPresentationModel):
+        (WebInspector.DebuggerPresentationModel.prototype._scriptLocationToUILocation):
+        (WebInspector.DebuggerPresentationModel.prototype._uiLocationToScriptLocation):
+        (WebInspector.DebuggerPresentationModel.prototype._addScript):
+        * inspector/front-end/ScriptFormatter.js:
+        (WebInspector.ScriptFormatter):
+        (WebInspector.ScriptFormatter.prototype._didFormatContent):
+        (WebInspector.ScriptFormatter.prototype.get _worker):
+        * inspector/front-end/SourceFile.js:
+        (WebInspector.RawSourceCode):
+        (WebInspector.RawSourceCode.prototype.setFormatted):
+        (WebInspector.RawSourceCode.prototype.createSourceMappingIfNeeded.didRequestContent):
+        (WebInspector.RawSourceCode.prototype.createSourceMappingIfNeeded):
+        (WebInspector.RawSourceCode.prototype._didRequestContent.didFormatContent):
+        (WebInspector.RawSourceCode.prototype._didRequestContent):
+        (WebInspector.RawSourceCode.prototype._invokeRequestContentCallbacks):
+
 2011-08-02  Mihnea Ovidenie  <[email protected]>
 
         [CSSRegions]Fix build after changeset 92106

Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (92195 => 92196)


--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js	2011-08-02 15:59:55 UTC (rev 92196)
@@ -30,6 +30,8 @@
 
 WebInspector.DebuggerPresentationModel = function()
 {
+    // FIXME: apply formatter from outside as a generic mapping.
+    this._formatter = new WebInspector.ScriptFormatter();
     this._sourceFiles = {};
     this._messages = [];
     this._anchors = [];
@@ -94,7 +96,7 @@
             callback(uiLocation.sourceFile.id, uiLocation.lineNumber);
         }
         // FIXME: force source formatting if needed. This will go away once formatting
-        // is fully encapsulated in SourceFile.
+        // is fully encapsulated in RawSourceCode class.
         sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
     },
 
@@ -108,7 +110,7 @@
             callback(rawLocation);
         }
         // FIXME: force source formatting if needed. This will go away once formatting
-        // is fully encapsulated in SourceFile.
+        // is fully encapsulated in RawSourceCode class.
         sourceFile.createSourceMappingIfNeeded(didCreateSourceMapping);
     },
 
@@ -157,10 +159,8 @@
             if (this._sourceFiles[sourceFileId] === sourceFile)
                 this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.SourceFileChanged, this._sourceFiles[sourceFileId]);
         }
-        if (!this._formatSourceFiles)
-            sourceFile = new WebInspector.SourceFile(sourceFileId, script, contentChanged.bind(this));
-        else
-            sourceFile = new WebInspector.FormattedSourceFile(sourceFileId, script, contentChanged.bind(this), this._formatter());
+        sourceFile = new WebInspector.RawSourceCode(sourceFileId, script, this._formatter, contentChanged.bind(this));
+        sourceFile.setFormatted(this._formatSourceFiles);
         this._sourceFiles[sourceFileId] = sourceFile;
 
         this._restoreBreakpoints(sourceFile);
@@ -288,13 +288,6 @@
             this._debuggerPaused();
     },
 
-    _formatter: function()
-    {
-        if (!this._scriptFormatter)
-            this._scriptFormatter = new WebInspector.ScriptFormatter();
-        return this._scriptFormatter;
-    },
-
     _consoleMessageAdded: function(event)
     {
         var message = event.data;

Modified: trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js (92195 => 92196)


--- trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/Source/WebCore/inspector/front-end/ScriptFormatter.js	2011-08-02 15:59:55 UTC (rev 92196)
@@ -30,8 +30,6 @@
 
 WebInspector.ScriptFormatter = function()
 {
-    this._worker = new Worker("ScriptFormatterWorker.js");
-    this._worker._onmessage_ = this._didFormatContent.bind(this);
     this._tasks = [];
 }
 
@@ -68,6 +66,15 @@
         var formattedContent = event.data.content;
         var sourceMapping = new WebInspector.FormattedSourceMapping(originalContent.lineEndings(), formattedContent.lineEndings(), event.data.mapping);
         task.callback(formattedContent, sourceMapping);
+    },
+
+    get _worker()
+    {
+        if (!this._cachedWorker) {
+            this._cachedWorker = new Worker("ScriptFormatterWorker.js");
+            this._cachedWorker._onmessage_ = this._didFormatContent.bind(this);
+        }
+        return this._cachedWorker;
     }
 }
 

Modified: trunk/Source/WebCore/inspector/front-end/SourceFile.js (92195 => 92196)


--- trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-08-02 15:58:53 UTC (rev 92195)
+++ trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-08-02 15:59:55 UTC (rev 92196)
@@ -28,9 +28,13 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.SourceFile = function(id, script, contentChangedDelegate)
+// RawSourceCode represents _javascript_ resource or HTML resource with inlined scripts
+// as it came from network.
+WebInspector.RawSourceCode = function(id, script, formatter, contentChangedDelegate)
 {
     this._scripts = [script];
+    this._formatter = formatter;
+    this._formatted = false;
     this._contentChangedDelegate = contentChangedDelegate;
     if (script.sourceURL)
         this._resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
@@ -46,7 +50,7 @@
         this._resource.addEventListener("finished", this.reload.bind(this));
 }
 
-WebInspector.SourceFile.prototype = {
+WebInspector.RawSourceCode.prototype = {
     addScript: function(script)
     {
         this._scripts.push(script);
@@ -82,6 +86,12 @@
         return closestScript;
     },
 
+    setFormatted: function(formatted)
+    {
+        // FIXME: this should initiate formatting and trigger events to update ui.
+        this._formatted = formatted;
+    },
+
     requestContent: function(callback)
     {
         if (this._contentLoaded) {
@@ -106,8 +116,17 @@
 
     createSourceMappingIfNeeded: function(callback)
     {
-        // Plain source without mapping.
-        callback();
+        if (!this._formatted) {
+            callback();
+            return;
+        }
+
+        function didRequestContent()
+        {
+            callback();
+        }
+        // Force content formatting to obtain the mapping.
+        this.requestContent(didRequestContent.bind(this));
     },
 
     forceLoadContent: function(script)
@@ -239,6 +258,21 @@
 
     _didRequestContent: function(mimeType, content)
     {
+        if (!this._formatted) {
+            this._invokeRequestContentCallbacks(mimeType, content);
+            return;
+        }
+
+        function didFormatContent(formattedContent, mapping)
+        {
+            this._mapping = mapping;
+            this._invokeRequestContentCallbacks(mimeType, formattedContent);
+        }
+        this._formatter.formatContent(mimeType, content, didFormatContent.bind(this));
+    },
+
+    _invokeRequestContentCallbacks: function(mimeType, content)
+    {
         this._contentLoaded = true;
         this._contentRequested = false;
         this._mimeType = mimeType;
@@ -257,33 +291,3 @@
         return this._resource && !this._resource.finished;
     }
 }
-
-WebInspector.FormattedSourceFile = function(sourceFileId, script, contentChangedDelegate, formatter)
-{
-    WebInspector.SourceFile.call(this, sourceFileId, script, contentChangedDelegate);
-    this._formatter = formatter;
-}
-
-WebInspector.FormattedSourceFile.prototype = {
-    createSourceMappingIfNeeded: function(callback)
-    {
-        function didRequestContent()
-        {
-            callback();
-        }
-        // Force content formatting to obtain the mapping.
-        this.requestContent(didRequestContent.bind(this));
-    },
-
-    _didRequestContent: function(mimeType, text)
-    {
-        function didFormatContent(formattedText, mapping)
-        {
-            this._mapping = mapping;
-            WebInspector.SourceFile.prototype._didRequestContent.call(this, mimeType, formattedText);
-        }
-        this._formatter.formatContent(mimeType, text, didFormatContent.bind(this));
-    }
-}
-
-WebInspector.FormattedSourceFile.prototype.__proto__ = WebInspector.SourceFile.prototype;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to