Title: [110445] trunk/Source/WebCore
Revision
110445
Author
[email protected]
Date
2012-03-12 10:43:51 -0700 (Mon, 12 Mar 2012)

Log Message

Web Inspector: extract ResourceScriptMapping from MainScriptMapping.
https://bugs.webkit.org/show_bug.cgi?id=80834

Reviewed by Vsevolod Vlasov.

* inspector/front-end/ScriptMapping.js:
(WebInspector.ResourceScriptMapping):
(WebInspector.ResourceScriptMapping.prototype._uiSourceCodeListChanged):
(WebInspector.ResourceScriptMapping.prototype.reset):
(WebInspector.MainScriptMapping):
(WebInspector.MainScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.MainScriptMapping.prototype.createLiveLocation):
(WebInspector.MainScriptMapping.prototype._registerLiveLocation):
(WebInspector.MainScriptMapping.prototype._unregisterLiveLocation):
(WebInspector.MainScriptMapping.prototype._updateLiveLocations):
(WebInspector.MainScriptMapping.prototype.uiSourceCodeList):
(WebInspector.MainScriptMapping.prototype.addScript):
(WebInspector.MainScriptMapping.prototype._handleUISourceCodeListChanged):
(WebInspector.MainScriptMapping.prototype.setFormatSource):
(WebInspector.MainScriptMapping.prototype.forceUpdateSourceMapping):
(WebInspector.MainScriptMapping.prototype.reset):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (110444 => 110445)


--- trunk/Source/WebCore/ChangeLog	2012-03-12 17:42:36 UTC (rev 110444)
+++ trunk/Source/WebCore/ChangeLog	2012-03-12 17:43:51 UTC (rev 110445)
@@ -1,3 +1,27 @@
+2012-03-12  Pavel Podivilov  <[email protected]>
+
+        Web Inspector: extract ResourceScriptMapping from MainScriptMapping.
+        https://bugs.webkit.org/show_bug.cgi?id=80834
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/front-end/ScriptMapping.js:
+        (WebInspector.ResourceScriptMapping):
+        (WebInspector.ResourceScriptMapping.prototype._uiSourceCodeListChanged):
+        (WebInspector.ResourceScriptMapping.prototype.reset):
+        (WebInspector.MainScriptMapping):
+        (WebInspector.MainScriptMapping.prototype.rawLocationToUILocation):
+        (WebInspector.MainScriptMapping.prototype.createLiveLocation):
+        (WebInspector.MainScriptMapping.prototype._registerLiveLocation):
+        (WebInspector.MainScriptMapping.prototype._unregisterLiveLocation):
+        (WebInspector.MainScriptMapping.prototype._updateLiveLocations):
+        (WebInspector.MainScriptMapping.prototype.uiSourceCodeList):
+        (WebInspector.MainScriptMapping.prototype.addScript):
+        (WebInspector.MainScriptMapping.prototype._handleUISourceCodeListChanged):
+        (WebInspector.MainScriptMapping.prototype.setFormatSource):
+        (WebInspector.MainScriptMapping.prototype.forceUpdateSourceMapping):
+        (WebInspector.MainScriptMapping.prototype.reset):
+
 2012-03-12  Pavel Feldman  <[email protected]>
 
         Web Inspector: recognize Float*Array and Int*Array as arrays.

Modified: trunk/Source/WebCore/inspector/front-end/ScriptMapping.js (110444 => 110445)


--- trunk/Source/WebCore/inspector/front-end/ScriptMapping.js	2012-03-12 17:42:36 UTC (rev 110444)
+++ trunk/Source/WebCore/inspector/front-end/ScriptMapping.js	2012-03-12 17:43:51 UTC (rev 110445)
@@ -65,9 +65,9 @@
 
 /**
  * @constructor
- * @extends {WebInspector.Object}
+ * @extends {WebInspector.ScriptMapping}
  */
-WebInspector.MainScriptMapping = function()
+WebInspector.ResourceScriptMapping = function()
 {
     this._rawSourceCodes = [];
     this._rawSourceCodeForScriptId = {};
@@ -76,14 +76,9 @@
     this._rawSourceCodeForUISourceCode = new Map();
     this._formatter = new WebInspector.ScriptFormatter();
     this._formatSource = false;
-    this._liveLocationsForScriptId = {};
 }
 
-WebInspector.MainScriptMapping.Events = {
-    UISourceCodeListChanged: "us-source-code-list-changed"
-}
-
-WebInspector.MainScriptMapping.prototype = {
+WebInspector.ResourceScriptMapping.prototype = {
     /**
      * @param {DebuggerAgent.Location} rawLocation
      * @return {WebInspector.UILocation}
@@ -107,36 +102,6 @@
     },
 
     /**
-     * @param {DebuggerAgent.Location} rawLocation
-     * @param {function(WebInspector.UILocation)} updateDelegate
-     * @return {WebInspector.LiveLocation}
-     */
-    createLiveLocation: function(rawLocation, updateDelegate)
-    {
-        return new WebInspector.LiveLocation(this, rawLocation, updateDelegate);
-    },
-
-    _registerLiveLocation: function(scriptId, liveLocation)
-    {
-        this._liveLocationsForScriptId[scriptId].push(liveLocation)
-        liveLocation._update();
-    },
-
-    _unregisterLiveLocation: function(scriptId, liveLocation)
-    {
-        this._liveLocationsForScriptId[scriptId].remove(liveLocation);
-    },
-
-    _updateLiveLocations: function(scriptIds)
-    {
-        for (var i = 0; i < scriptIds.length; ++i) {
-            var liveLocations = this._liveLocationsForScriptId[scriptIds[i]];
-            for (var j = 0; j < liveLocations.length; ++j)
-                liveLocations[j]._update();
-        }
-    },
-
-    /**
      * @return {Array.<WebInspector.UISourceCode>}
      */
     uiSourceCodeList: function()
@@ -155,8 +120,6 @@
      */
     addScript: function(script)
     {
-        this._liveLocationsForScriptId[script.scriptId] = [];
-
         var resource = null;
         var isInlineScript = false;
         if (script.isInlineScript()) {
@@ -209,12 +172,12 @@
             this._rawSourceCodeForUISourceCode.remove(removedItems[i]);
         for (var i = 0; i < addedItems.length; ++i)
             this._rawSourceCodeForUISourceCode.put(addedItems[i], rawSourceCode);
-        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, { removedItems: removedItems, addedItems: addedItems });
 
         var scriptIds = [];
         for (var i = 0; i < rawSourceCode._scripts.length; ++i)
             scriptIds.push(rawSourceCode._scripts[i].scriptId);
-        this._updateLiveLocations(scriptIds);
+        var data = { removedItems: removedItems, addedItems: addedItems, scriptIds: scriptIds };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
     },
 
     /**
@@ -261,6 +224,150 @@
         this._rawSourceCodeForURL = {};
         this._rawSourceCodeForDocumentURL = {};
         this._rawSourceCodeForUISourceCode.clear();
+    }
+}
+
+WebInspector.ResourceScriptMapping.prototype.__proto__ = WebInspector.ScriptMapping.prototype;
+
+/**
+ * @constructor
+ * @extends {WebInspector.Object}
+ */
+WebInspector.MainScriptMapping = function()
+{
+    this._mappings = [];
+    this._resourceMapping = new WebInspector.ResourceScriptMapping();
+    this._resourceMapping.addEventListener(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this);
+    this._mappings.push(this._resourceMapping);
+
+    this._mappingForScriptId = {};
+    this._mappingForUISourceCode = new Map();
+    this._liveLocationsForScriptId = {};
+}
+
+WebInspector.MainScriptMapping.Events = {
+    UISourceCodeListChanged: "us-source-code-list-changed"
+}
+
+WebInspector.MainScriptMapping.prototype = {
+    /**
+     * @param {DebuggerAgent.Location} rawLocation
+     * @return {WebInspector.UILocation}
+     */
+    rawLocationToUILocation: function(rawLocation)
+    {
+        return this._mappingForScriptId[rawLocation.scriptId].rawLocationToUILocation(rawLocation);
+    },
+
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     * @param {number} lineNumber
+     * @param {number} columnNumber
+     * @return {DebuggerAgent.Location}
+     */
+    uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
+    {
+        return this._mappingForUISourceCode.get(uiSourceCode).uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);
+    },
+
+    /**
+     * @param {DebuggerAgent.Location} rawLocation
+     * @param {function(WebInspector.UILocation)} updateDelegate
+     * @return {WebInspector.LiveLocation}
+     */
+    createLiveLocation: function(rawLocation, updateDelegate)
+    {
+        return new WebInspector.LiveLocation(this, rawLocation, updateDelegate);
+    },
+
+    _registerLiveLocation: function(scriptId, liveLocation)
+    {
+        this._liveLocationsForScriptId[scriptId].push(liveLocation)
+        liveLocation._update();
+    },
+
+    _unregisterLiveLocation: function(scriptId, liveLocation)
+    {
+        this._liveLocationsForScriptId[scriptId].remove(liveLocation);
+    },
+
+    _updateLiveLocations: function(scriptIds)
+    {
+        for (var i = 0; i < scriptIds.length; ++i) {
+            var liveLocations = this._liveLocationsForScriptId[scriptIds[i]];
+            for (var j = 0; j < liveLocations.length; ++j)
+                liveLocations[j]._update();
+        }
+    },
+
+    /**
+     * @return {Array.<WebInspector.UISourceCode>}
+     */
+    uiSourceCodeList: function()
+    {
+        var result = [];
+        for (var i = 0; i < this._mappings.length; ++i) {
+            var uiSourceCodeList = this._mappings[i].uiSourceCodeList();
+            for (var j = 0; j < uiSourceCodeList.length; ++j)
+                result.push(uiSourceCodeList[j]);
+        }
+        return result;
+    },
+
+    /**
+     * @param {WebInspector.Script} script
+     */
+    addScript: function(script)
+    {
+        this._liveLocationsForScriptId[script.scriptId] = [];
+
+        var mapping = this._resourceMapping;
+
+        this._mappingForScriptId[script.scriptId] = mapping;
+        mapping.addScript(script);
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _handleUISourceCodeListChanged: function(event)
+    {
+        var scriptMapping = /** @type {WebInspector.ScriptMapping} */ event.target;
+        var removedItems = /** @type {Array.<WebInspector.UISourceCode>} */ event.data["removedItems"];
+        var addedItems = /** @type {Array.<WebInspector.UISourceCode>} */ event.data["addedItems"];
+        var scriptIds = /** @type {Array.<number>} */ event.data["scriptIds"];
+
+        for (var i = 0; i < removedItems.length; ++i)
+            this._mappingForUISourceCode.remove(removedItems[i]);
+        for (var i = 0; i < addedItems.length; ++i)
+            this._mappingForUISourceCode.put(addedItems[i], scriptMapping);
+        this._updateLiveLocations(scriptIds);
+        this.dispatchEventToListeners(WebInspector.MainScriptMapping.Events.UISourceCodeListChanged, event.data);
+    },
+
+    /**
+     * @param {boolean} formatSource
+     */
+    setFormatSource: function(formatSource)
+    {
+        this._resourceMapping.setFormatSource(formatSource);
+    },
+
+    /**
+     * @param {DebuggerAgent.Location} rawLocation
+     */
+    forceUpdateSourceMapping: function(rawLocation)
+    {
+        if (this._mappingForScriptId[rawLocation.scriptId] === this._resourceMapping)
+            this._resourceMapping.forceUpdateSourceMapping(rawLocation);
+    },
+
+    reset: function()
+    {
+        for (var i = 0; i < this._mappings.length; ++i)
+            this._mappings[i].reset();
+        this._mappingForScriptId = {};
+        this._mappingForUISourceCode = new Map();
         this._liveLocationsForScriptId = {};
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to