Title: [95522] trunk/Source/WebCore
Revision
95522
Author
podivi...@chromium.org
Date
2011-09-20 02:28:50 -0700 (Tue, 20 Sep 2011)

Log Message

Web Inspector: extract RawSourceCode source mapping logic to helper classes.
https://bugs.webkit.org/show_bug.cgi?id=67789

Reviewed by Pavel Feldman.

* inspector/front-end/SourceFile.js:
(WebInspector.RawSourceCode.prototype.get uiSourceCode):
(WebInspector.RawSourceCode.prototype.rawLocationToUILocation):
(WebInspector.RawSourceCode.prototype.uiLocationToRawLocation):
(WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent.didFormatContent):
(WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
(WebInspector.RawSourceCode.prototype._createSourceMapping):
(WebInspector.RawSourceCode.prototype._saveSourceMapping):
(WebInspector.RawSourceCode.PlainSourceMapping):
(WebInspector.RawSourceCode.PlainSourceMapping.prototype.rawLocationToUILocation):
(WebInspector.RawSourceCode.PlainSourceMapping.prototype.uiLocationToRawLocation):
(WebInspector.RawSourceCode.PlainSourceMapping.prototype.get uiSourceCode):
(WebInspector.RawSourceCode.FormattedSourceMapping):
(WebInspector.RawSourceCode.FormattedSourceMapping.prototype.rawLocationToUILocation):
(WebInspector.RawSourceCode.FormattedSourceMapping.prototype.uiLocationToRawLocation):
(WebInspector.RawSourceCode.FormattedSourceMapping.prototype.get uiSourceCode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (95521 => 95522)


--- trunk/Source/WebCore/ChangeLog	2011-09-20 08:58:54 UTC (rev 95521)
+++ trunk/Source/WebCore/ChangeLog	2011-09-20 09:28:50 UTC (rev 95522)
@@ -1,3 +1,27 @@
+2011-09-08  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: extract RawSourceCode source mapping logic to helper classes.
+        https://bugs.webkit.org/show_bug.cgi?id=67789
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/front-end/SourceFile.js:
+        (WebInspector.RawSourceCode.prototype.get uiSourceCode):
+        (WebInspector.RawSourceCode.prototype.rawLocationToUILocation):
+        (WebInspector.RawSourceCode.prototype.uiLocationToRawLocation):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent.didFormatContent):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
+        (WebInspector.RawSourceCode.prototype._createSourceMapping):
+        (WebInspector.RawSourceCode.prototype._saveSourceMapping):
+        (WebInspector.RawSourceCode.PlainSourceMapping):
+        (WebInspector.RawSourceCode.PlainSourceMapping.prototype.rawLocationToUILocation):
+        (WebInspector.RawSourceCode.PlainSourceMapping.prototype.uiLocationToRawLocation):
+        (WebInspector.RawSourceCode.PlainSourceMapping.prototype.get uiSourceCode):
+        (WebInspector.RawSourceCode.FormattedSourceMapping):
+        (WebInspector.RawSourceCode.FormattedSourceMapping.prototype.rawLocationToUILocation):
+        (WebInspector.RawSourceCode.FormattedSourceMapping.prototype.uiLocationToRawLocation):
+        (WebInspector.RawSourceCode.FormattedSourceMapping.prototype.get uiSourceCode):
+
 2011-09-20  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] WebProcess shouldn't use the GTK+ API

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


--- trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-09-20 08:58:54 UTC (rev 95521)
+++ trunk/Source/WebCore/inspector/front-end/SourceFile.js	2011-09-20 09:28:50 UTC (rev 95522)
@@ -67,7 +67,8 @@
 
     get uiSourceCode()
     {
-        return this._uiSourceCode;
+        // FIXME: clients should use sourceMapping directly.
+        return this._sourceMapping && this._sourceMapping.uiSourceCode;
     },
 
     setFormatted: function(formatted)
@@ -91,17 +92,14 @@
 
     rawLocationToUILocation: function(rawLocation)
     {
-        var location = this._mapping ? this._mapping.originalToFormatted(rawLocation) : rawLocation;
-        return new WebInspector.UILocation(this.uiSourceCode, location.lineNumber, location.columnNumber);
+        // FIXME: clients should use sourceMapping directly.
+        return this._sourceMapping.rawLocationToUILocation(rawLocation);
     },
 
     uiLocationToRawLocation: function(lineNumber, columnNumber)
     {
-        var rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
-        if (this._mapping)
-            rawLocation = this._mapping.formattedToOriginal(rawLocation);
-        rawLocation.scriptId = this._scriptForRawLocation(rawLocation.lineNumber, rawLocation.columnNumber).scriptId;
-        return rawLocation;
+        // FIXME: clients should use sourceMapping directly.
+        return this._sourceMapping.uiLocationToRawLocation(lineNumber, columnNumber);
     },
 
     _scriptForRawLocation: function(lineNumber, columnNumber)
@@ -160,7 +158,9 @@
     _createSourceMapping: function(originalContentProvider, callback)
     {
         if (!this._formatted) {
-            callback(originalContentProvider, null);
+            var uiSourceCode = new WebInspector.UISourceCode(this.id, this.url, this.isContentScript, this, originalContentProvider);
+            var sourceMapping = new WebInspector.RawSourceCode.PlainSourceMapping(this, uiSourceCode);
+            callback(sourceMapping);
             return;
         }
 
@@ -169,19 +169,21 @@
             function didFormatContent(formattedContent, mapping)
             {
                 var contentProvider = new WebInspector.StaticContentProvider(mimeType, formattedContent)
-                callback(contentProvider, mapping);
+                var uiSourceCode = new WebInspector.UISourceCode("deobfuscated:" + this.id, this.url, this.isContentScript, this, contentProvider);
+                var sourceMapping = new WebInspector.RawSourceCode.FormattedSourceMapping(this, uiSourceCode, mapping);
+                callback(sourceMapping);
             }
             this._formatter.formatContent(mimeType, content, didFormatContent.bind(this));
         }
         originalContentProvider.requestContent(didRequestContent.bind(this));
     },
 
-    _saveSourceMapping: function(contentProvider, mapping)
+    _saveSourceMapping: function(sourceMapping)
     {
-        var oldUISourceCode = this._uiSourceCode;
-        var uiSourceCodeId = (this._formatted ? "deobfuscated:" : "") + (this._scripts[0].sourceURL || this._scripts[0].scriptId);
-        this._uiSourceCode = new WebInspector.UISourceCode(uiSourceCodeId, this.url, this.isContentScript, this, contentProvider);
-        this._mapping = mapping;
+        var oldUISourceCode;
+        if (this._sourceMapping)
+            oldUISourceCode = this._sourceMapping.uiSourceCode;
+        this._sourceMapping = sourceMapping;
         this.dispatchEventToListeners(WebInspector.RawSourceCode.Events.SourceMappingUpdated, { oldUISourceCode: oldUISourceCode });
     }
 }
@@ -192,6 +194,65 @@
 /**
  * @constructor
  */
+WebInspector.RawSourceCode.PlainSourceMapping = function(rawSourceCode, uiSourceCode)
+{
+    this._rawSourceCode = rawSourceCode;
+    this._uiSourceCode = uiSourceCode;
+}
+
+WebInspector.RawSourceCode.PlainSourceMapping.prototype = {
+    rawLocationToUILocation: function(rawLocation)
+    {
+        return new WebInspector.UILocation(this._uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber);
+    },
+
+    uiLocationToRawLocation: function(lineNumber, columnNumber)
+    {
+        var rawLocation = { lineNumber: lineNumber, columnNumber: columnNumber };
+        rawLocation.scriptId = this._rawSourceCode._scriptForRawLocation(rawLocation.lineNumber, rawLocation.columnNumber).scriptId;
+        return rawLocation;
+    },
+
+    get uiSourceCode()
+    {
+        return this._uiSourceCode;
+    }
+}
+
+/**
+ * @constructor
+ */
+WebInspector.RawSourceCode.FormattedSourceMapping = function(rawSourceCode, uiSourceCode, mapping)
+{
+    this._rawSourceCode = rawSourceCode;
+    this._uiSourceCode = uiSourceCode;
+    this._mapping = mapping;
+}
+
+WebInspector.RawSourceCode.FormattedSourceMapping.prototype = {
+    rawLocationToUILocation: function(rawLocation)
+    {
+        var location = this._mapping.originalToFormatted(rawLocation);
+        return new WebInspector.UILocation(this._uiSourceCode, location.lineNumber, location.columnNumber);
+    },
+
+    uiLocationToRawLocation: function(lineNumber, columnNumber)
+    {
+        var rawLocation = this._mapping.formattedToOriginal({ lineNumber: lineNumber, columnNumber: columnNumber });
+        rawLocation.scriptId = this._rawSourceCode._scriptForRawLocation(rawLocation.lineNumber, rawLocation.columnNumber).scriptId;
+        return rawLocation;
+    },
+
+    get uiSourceCode()
+    {
+        return this._uiSourceCode;
+    }
+}
+
+
+/**
+ * @constructor
+ */
 WebInspector.UILocation = function(uiSourceCode, lineNumber, columnNumber)
 {
     this.uiSourceCode = uiSourceCode;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to