Title: [139860] trunk
Revision
139860
Author
[email protected]
Date
2013-01-16 02:26:36 -0800 (Wed, 16 Jan 2013)

Log Message

Web Inspector: Introduce file mapping allowing to map network loaded scripts and stylesheets to file system files.
https://bugs.webkit.org/show_bug.cgi?id=106795

Reviewed by Pavel Feldman.

Source/WebCore:

Introduced file mapping for inspector.
FileMapping is essentially an array of MappingEntries where each MappingEntry is a pair of urlPrefix and pathPrefix.
When scripts and stylesheets are mapped to uiSourceCodes FileMapping methods are used to establish
prefix based matching with file system uiSourceCodes if possible.

Test: inspector/file-mapping.html

* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* inspector/compile-front-end.py:
* inspector/front-end/CompilerScriptMapping.js:
(WebInspector.CompilerScriptMapping):
(WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
(WebInspector.CompilerScriptMapping.prototype.uiLocationToRawLocation):
(WebInspector.CompilerScriptMapping.prototype.get addScript.get this):
(WebInspector.CompilerScriptMapping.prototype.get addScript):
(WebInspector.CompilerScriptMapping.prototype._bindUISourceCode):
(WebInspector.CompilerScriptMapping.prototype._uiSourceCodeAddedToWorkspace):
* inspector/front-end/FileMapping.js: Added.
(WebInspector.FileMapping):
(WebInspector.FileMapping.prototype.hasMappingForURL):
(WebInspector.FileMapping.prototype.uriForURL):
(WebInspector.FileMapping.prototype.urlForURI):
(WebInspector.FileMapping.prototype.setMappings):
(WebInspector.FileMapping.prototype.mappings):
(WebInspector.FileMapping.prototype._deserialize):
(WebInspector.FileMapping.prototype._serialize):
(WebInspector.FileMapping.MappingEntry):
(WebInspector.FileMapping.MappingEntry.deserialize):
(WebInspector.FileMapping.MappingEntry.prototype.matchesURL):
(WebInspector.FileMapping.MappingEntry.prototype.matchesURI):
(WebInspector.FileMapping.MappingEntry.prototype.uriForURL):
(WebInspector.FileMapping.MappingEntry.prototype.urlForURI):
(WebInspector.FileMapping.MappingEntry.prototype.serialize):
* inspector/front-end/NetworkUISourceCodeProvider.js:
(WebInspector.NetworkUISourceCodeProvider.prototype._addFile):
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping.prototype._workspaceUISourceCodeForScript):
(WebInspector.ResourceScriptMapping.prototype._scriptsForUISourceCode):
* inspector/front-end/ResourceUtils.js:
(WebInspector.displayNameForURL):
* inspector/front-end/SASSSourceMapping.js:
(WebInspector.SASSSourceMapping):
(WebInspector.SASSSourceMapping.prototype._reloadCSS):
(_addURLMapping):
(rawLocationToUILocation):
(_reset):
(WebInspector.SASSSourceMapping.MappingEntry):
* inspector/front-end/StylesSourceMapping.js:
(WebInspector.StylesSourceMapping):
(WebInspector.StylesSourceMapping.prototype.rawLocationToUILocation):
(WebInspector.StylesSourceMapping.prototype._uiSourceCodeAddedToWorkspace):
(WebInspector.StylesSourceMapping.prototype._projectWillReset):
(WebInspector.StyleContentBinding.prototype.):
(WebInspector.StyleContentBinding.prototype._innerStyleSheetChanged):
* inspector/front-end/WebKit.qrc:
* inspector/front-end/Workspace.js:
* inspector/front-end/inspector.html:
* inspector/front-end/inspector.js:

LayoutTests:

* inspector/file-mapping-expected.txt: Added.
* inspector/file-mapping.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (139859 => 139860)


--- trunk/LayoutTests/ChangeLog	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/LayoutTests/ChangeLog	2013-01-16 10:26:36 UTC (rev 139860)
@@ -1,5 +1,15 @@
 2013-01-15  Vsevolod Vlasov  <[email protected]>
 
+        Web Inspector: Introduce file mapping allowing to map network loaded scripts and stylesheets to file system files.
+        https://bugs.webkit.org/show_bug.cgi?id=106795
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/file-mapping-expected.txt: Added.
+        * inspector/file-mapping.html: Added.
+
+2013-01-15  Vsevolod Vlasov  <[email protected]>
+
         Web Inspector: Introduce UISourceCode.originURL().
         https://bugs.webkit.org/show_bug.cgi?id=106909
 

Added: trunk/LayoutTests/inspector/file-mapping-expected.txt (0 => 139860)


--- trunk/LayoutTests/inspector/file-mapping-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/file-mapping-expected.txt	2013-01-16 10:26:36 UTC (rev 139860)
@@ -0,0 +1,16 @@
+Tests FileMapping
+
+uri:/home/example.com
+uri:/home/example.com/
+uri:/var/www/index.html
+uri:/var/www/foo/index.html
+https://localhost
+http://example.com
+http://www.example.com
+http://www.example.com/
+http://localhost/index.html
+http://localhost/foo/index.html
+null
+null
+All mappings were correct.
+
Property changes on: trunk/LayoutTests/inspector/file-mapping-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/file-mapping.html (0 => 139860)


--- trunk/LayoutTests/inspector/file-mapping.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/file-mapping.html	2013-01-16 10:26:36 UTC (rev 139860)
@@ -0,0 +1,62 @@
+<html>
+<head>
+<script src=""
+<script>
+function test()
+{
+    function MockFileSystemMapping() {}
+    MockFileSystemMapping.prototype = {
+        uriForPath: function(path) {
+            return "uri:" + path;
+        }
+    };
+    
+    function createMockMappingEntry(urlPrefix, pathPrefix)
+    {
+        var result = {};
+        result.urlPrefix = urlPrefix;
+        result.pathPrefix = pathPrefix;
+        return result;
+    }
+
+    // At first fill file mapping with entries.
+    var fileMapping = new WebInspector.FileMapping(new MockFileSystemMapping());
+    var mappingEntries = [];
+    mappingEntries.push(createMockMappingEntry("http://localhost", "/var/www"));
+    mappingEntries.push(createMockMappingEntry("http://www.example.com", "/home/example.com"));
+    fileMapping.setMappings(mappingEntries);
+
+    // Then create another file mapping to make sure it is correctly restored from the settings.
+    fileMapping = new WebInspector.FileMapping(new MockFileSystemMapping());
+
+    // Now test all FileMapping methods.
+    InspectorTest.assertTrue(fileMapping.hasMappingForURL("http://www.example.com"), "fileMapping.hasMappingForURL failed.");
+    InspectorTest.assertTrue(fileMapping.hasMappingForURL("http://www.example.com/"), "fileMapping.hasMappingForURL failed.");
+    InspectorTest.assertTrue(fileMapping.hasMappingForURL("http://localhost/index.html"), "fileMapping.hasMappingForURL failed.");
+    InspectorTest.assertTrue(fileMapping.hasMappingForURL("http://localhost/foo/index.html"), "fileMapping.hasMappingForURL failed.");
+    InspectorTest.assertTrue(!fileMapping.hasMappingForURL("https://localhost"), "fileMapping.hasMappingForURL failed.");
+    InspectorTest.assertTrue(!fileMapping.hasMappingForURL("http://example.com"), "fileMapping.hasMappingForURL failed.");
+
+    InspectorTest.addResult(fileMapping.uriForURL("http://www.example.com"));
+    InspectorTest.addResult(fileMapping.uriForURL("http://www.example.com/"));
+    InspectorTest.addResult(fileMapping.uriForURL("http://localhost/index.html"));
+    InspectorTest.addResult(fileMapping.uriForURL("http://localhost/foo/index.html"));
+    InspectorTest.addResult(fileMapping.uriForURL("https://localhost"));
+    InspectorTest.addResult(fileMapping.uriForURL("http://example.com"));
+
+    InspectorTest.addResult(fileMapping.urlForURI("uri:/home/example.com"));
+    InspectorTest.addResult(fileMapping.urlForURI("uri:/home/example.com/"));
+    InspectorTest.addResult(fileMapping.urlForURI("uri:/var/www/index.html"));
+    InspectorTest.addResult(fileMapping.urlForURI("uri:/var/www/foo/index.html"));
+    InspectorTest.addResult(fileMapping.urlForURI("https://localhost"));
+    InspectorTest.addResult(fileMapping.urlForURI("http://example.com"));
+
+    InspectorTest.addResult("All mappings were correct.");
+    InspectorTest.completeTest();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests FileMapping</p>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/file-mapping.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (139859 => 139860)


--- trunk/Source/WebCore/ChangeLog	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/ChangeLog	2013-01-16 10:26:36 UTC (rev 139860)
@@ -1,5 +1,72 @@
 2013-01-15  Vsevolod Vlasov  <[email protected]>
 
+        Web Inspector: Introduce file mapping allowing to map network loaded scripts and stylesheets to file system files.
+        https://bugs.webkit.org/show_bug.cgi?id=106795
+
+        Reviewed by Pavel Feldman.
+
+        Introduced file mapping for inspector.
+        FileMapping is essentially an array of MappingEntries where each MappingEntry is a pair of urlPrefix and pathPrefix.
+        When scripts and stylesheets are mapped to uiSourceCodes FileMapping methods are used to establish
+        prefix based matching with file system uiSourceCodes if possible.
+
+        Test: inspector/file-mapping.html
+
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/compile-front-end.py:
+        * inspector/front-end/CompilerScriptMapping.js:
+        (WebInspector.CompilerScriptMapping):
+        (WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation):
+        (WebInspector.CompilerScriptMapping.prototype.uiLocationToRawLocation):
+        (WebInspector.CompilerScriptMapping.prototype.get addScript.get this):
+        (WebInspector.CompilerScriptMapping.prototype.get addScript):
+        (WebInspector.CompilerScriptMapping.prototype._bindUISourceCode):
+        (WebInspector.CompilerScriptMapping.prototype._uiSourceCodeAddedToWorkspace):
+        * inspector/front-end/FileMapping.js: Added.
+        (WebInspector.FileMapping):
+        (WebInspector.FileMapping.prototype.hasMappingForURL):
+        (WebInspector.FileMapping.prototype.uriForURL):
+        (WebInspector.FileMapping.prototype.urlForURI):
+        (WebInspector.FileMapping.prototype.setMappings):
+        (WebInspector.FileMapping.prototype.mappings):
+        (WebInspector.FileMapping.prototype._deserialize):
+        (WebInspector.FileMapping.prototype._serialize):
+        (WebInspector.FileMapping.MappingEntry):
+        (WebInspector.FileMapping.MappingEntry.deserialize):
+        (WebInspector.FileMapping.MappingEntry.prototype.matchesURL):
+        (WebInspector.FileMapping.MappingEntry.prototype.matchesURI):
+        (WebInspector.FileMapping.MappingEntry.prototype.uriForURL):
+        (WebInspector.FileMapping.MappingEntry.prototype.urlForURI):
+        (WebInspector.FileMapping.MappingEntry.prototype.serialize):
+        * inspector/front-end/NetworkUISourceCodeProvider.js:
+        (WebInspector.NetworkUISourceCodeProvider.prototype._addFile):
+        * inspector/front-end/ResourceScriptMapping.js:
+        (WebInspector.ResourceScriptMapping.prototype._workspaceUISourceCodeForScript):
+        (WebInspector.ResourceScriptMapping.prototype._scriptsForUISourceCode):
+        * inspector/front-end/ResourceUtils.js:
+        (WebInspector.displayNameForURL):
+        * inspector/front-end/SASSSourceMapping.js:
+        (WebInspector.SASSSourceMapping):
+        (WebInspector.SASSSourceMapping.prototype._reloadCSS):
+        (_addURLMapping):
+        (rawLocationToUILocation):
+        (_reset):
+        (WebInspector.SASSSourceMapping.MappingEntry):
+        * inspector/front-end/StylesSourceMapping.js:
+        (WebInspector.StylesSourceMapping):
+        (WebInspector.StylesSourceMapping.prototype.rawLocationToUILocation):
+        (WebInspector.StylesSourceMapping.prototype._uiSourceCodeAddedToWorkspace):
+        (WebInspector.StylesSourceMapping.prototype._projectWillReset):
+        (WebInspector.StyleContentBinding.prototype.):
+        (WebInspector.StyleContentBinding.prototype._innerStyleSheetChanged):
+        * inspector/front-end/WebKit.qrc:
+        * inspector/front-end/Workspace.js:
+        * inspector/front-end/inspector.html:
+        * inspector/front-end/inspector.js:
+
+2013-01-15  Vsevolod Vlasov  <[email protected]>
+
         Web Inspector: Introduce UISourceCode.originURL().
         https://bugs.webkit.org/show_bug.cgi?id=106909
 

Modified: trunk/Source/WebCore/WebCore.gypi (139859 => 139860)


--- trunk/Source/WebCore/WebCore.gypi	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/WebCore.gypi	2013-01-16 10:26:36 UTC (rev 139860)
@@ -5147,6 +5147,7 @@
             'inspector/front-end/ExtensionServer.js',
             'inspector/front-end/ExtensionView.js',
             'inspector/front-end/FileManager.js',
+            'inspector/front-end/FileMapping.js',
             'inspector/front-end/FileSystemMapping.js',
             'inspector/front-end/FileSystemModel.js',
             'inspector/front-end/FileUtils.js',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (139859 => 139860)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2013-01-16 10:26:36 UTC (rev 139860)
@@ -76717,6 +76717,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\inspector\front-end\FileMapping.js"
+					>
+				</File>
+				<File
 					RelativePath="..\inspector\front-end\FileSystemMapping.js"
 					>
 				</File>

Modified: trunk/Source/WebCore/inspector/compile-front-end.py (139859 => 139860)


--- trunk/Source/WebCore/inspector/compile-front-end.py	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/compile-front-end.py	2013-01-16 10:26:36 UTC (rev 139860)
@@ -76,6 +76,7 @@
             "DebuggerModel.js",
             "DebuggerScriptMapping.js",
             "FileManager.js",
+            "FileMapping.js",
             "FileSystemMapping.js",
             "FileSystemModel.js",
             "FileUtils.js",

Modified: trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -37,6 +37,7 @@
 WebInspector.CompilerScriptMapping = function(workspace, networkWorkspaceProvider)
 {
     this._workspace = workspace;
+    this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
     this._networkWorkspaceProvider = networkWorkspaceProvider;
     /** @type {Object.<string, WebInspector.PositionBasedSourceMap>} */
     this._sourceMapForSourceMapURL = {};
@@ -62,7 +63,11 @@
         var entry = sourceMap.findEntry(lineNumber, columnNumber);
         if (entry.length === 2)
             return null;
-        var uiSourceCode = this._workspace.uiSourceCodeForURL(entry[2]);
+        var url = ""
+        var uri = WebInspector.fileMapping.uriForURL(url);
+        var uiSourceCode = this._workspace.uiSourceCodeForURI(uri);
+        if (!uiSourceCode)
+            return null;
         return new WebInspector.UILocation(uiSourceCode, entry[3], entry[4]);
     },
 
@@ -74,7 +79,11 @@
      */
     uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
     {
+        if (!uiSourceCode.url)
+            return null;
         var sourceMap = this._sourceMapForURL[uiSourceCode.url];
+        if (!sourceMap)
+            return null;
         var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber);
         return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]);
     },
@@ -95,26 +104,50 @@
         var sourceURLs = sourceMap.sources();
         for (var i = 0; i < sourceURLs.length; ++i) {
             var sourceURL = sourceURLs[i];
-            if (this._workspace.uiSourceCodeForURL(sourceURL))
+            var uri = WebInspector.fileMapping.uriForURL(sourceURL);
+            if (this._sourceMapForURL[sourceURL])
                 continue;
             this._sourceMapForURL[sourceURL] = sourceMap;
-            var sourceContent = sourceMap.sourceContent(sourceURL);
-            var contentProvider;
-            if (sourceContent)
-                contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, sourceContent);
-            else
-                contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
-            var uiSourceCode = this._networkWorkspaceProvider.addFileForURL(sourceURL, contentProvider, true);
-            uiSourceCode.setSourceMapping(this);
-            uiSourceCode.isContentScript = script.isContentScript;
+            if (!WebInspector.fileMapping.hasMappingForURL(sourceURL) && !this._workspace.uiSourceCodeForURI(uri)) {
+                var sourceContent = sourceMap.sourceContent(sourceURL);
+                var contentProvider;
+                if (sourceContent)
+                    contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, sourceContent);
+                else
+                    contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
+                this._networkWorkspaceProvider.addFileForURL(sourceURL, contentProvider, true);
+            }
+            var uiSourceCode = this._workspace.uiSourceCodeForURI(uri);
+            if (uiSourceCode) {
+                this._bindUISourceCode(this._workspace.uiSourceCodeForURI(uri));
+                uiSourceCode.isContentScript = script.isContentScript;
+            }
         }
-
         this._sourceMapForScriptId[script.scriptId] = sourceMap;
         this._scriptForSourceMap.put(sourceMap, script);
         script.pushSourceMapping(this);
     },
 
     /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
+     */
+    _bindUISourceCode: function(uiSourceCode)
+    {
+        uiSourceCode.setSourceMapping(this);
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _uiSourceCodeAddedToWorkspace: function(event)
+    {
+        var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
+        if (!uiSourceCode.url || !this._sourceMapForURL[uiSourceCode.url])
+            return;
+        this._bindUISourceCode(uiSourceCode);
+    },
+
+    /**
      * @param {WebInspector.Script} script
      * @return {WebInspector.PositionBasedSourceMap}
      */

Added: trunk/Source/WebCore/inspector/front-end/FileMapping.js (0 => 139860)


--- trunk/Source/WebCore/inspector/front-end/FileMapping.js	                        (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/FileMapping.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -0,0 +1,207 @@
+/*
+ * 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.
+ */
+
+/**
+ * @constructor
+ * @param {WebInspector.FileSystemMapping} fileSystemMapping
+ */
+WebInspector.FileMapping = function(fileSystemMapping)
+{
+    this._fileSystemMapping = fileSystemMapping;
+    this._mappingEntriesSetting = WebInspector.settings.createSetting("fileMappingEntries", []);
+    /** @type {Array.<WebInspector.FileMapping.MappingEntry>} */
+    this._mappingEntries = [];
+    this._deserialize(/** @type {Array.<WebInspector.FileMapping.MappingEntry>} */ (this._mappingEntriesSetting.get()));
+}
+
+/** @typedef {{urlPrefix: string, pathPrefix: string}} */
+WebInspector.FileMapping.SerializedMappingEntry;
+
+WebInspector.FileMapping.prototype = {
+    /**
+     * @param {string} url
+     * @return {boolean}
+     */
+    hasMappingForURL: function(url)
+    {
+        for (var i = 0; i < this._mappingEntries.length; ++i) {
+            if (this._mappingEntries[i].matchesURL(url))
+                return true;
+        }
+        return false;
+    },
+    
+    /**
+     * @param {string} url
+     * @return {string}
+     */
+    uriForURL: function(url)
+    {
+        for (var i = 0; i < this._mappingEntries.length; ++i) {
+            var uri = this._mappingEntries[i].uriForURL(url);
+            if (typeof uri === "string")
+                return uri;
+        }
+        // FIXME: FileMapping should be network project aware. It should return correct uri for network project uiSourceCodes.
+        return url;
+    },
+    
+    /**
+     * @param {string} uri
+     * @return {?string}
+     */
+    urlForURI: function(uri)
+    {
+        for (var i = 0; i < this._mappingEntries.length; ++i) {
+            if (this._mappingEntries[i].matchesURI(uri))
+                return this._mappingEntries[i].urlForURI(uri);
+        }
+        return null;
+    },
+
+    /**
+     * @param {Array.<WebInspector.FileMapping.SerializedMappingEntry>} serializedMappingEntries
+     */
+    setMappings: function(serializedMappingEntries)
+    {
+        this._deserialize(serializedMappingEntries);
+        this._serialize();
+    },
+
+    /**
+     * @return {Array.<WebInspector.FileMapping.MappingEntry>}
+     */
+    mappings: function()
+    {
+        return this._mappingEntries.slice();
+    },
+
+    /**
+     * @param {Array.<WebInspector.FileMapping.SerializedMappingEntry>} serializedMappingEntries
+     */
+    _deserialize: function(serializedMappingEntries)
+    {
+        this._mappingEntries = [];
+        for (var i = 0; i < serializedMappingEntries.length; ++i)
+            this._mappingEntries.push(WebInspector.FileMapping.MappingEntry.deserialize(serializedMappingEntries[i], this._fileSystemMapping));
+    },
+
+    _serialize: function()
+    {
+        var savedEntries = [];
+        for (var i = 0; i < this._mappingEntries.length; ++i)
+            savedEntries.push(this._mappingEntries[i].serialize());
+        this._mappingEntriesSetting.set(savedEntries);
+    },
+
+    __proto__: WebInspector.Object.prototype
+}
+
+/**
+ * @constructor
+ * @param {string} urlPrefix
+ * @param {string} pathPrefix
+ * @param {?string} uriPrefix
+ */
+WebInspector.FileMapping.MappingEntry = function(urlPrefix, pathPrefix, uriPrefix)
+{
+    this._urlPrefix = urlPrefix;
+    this._pathPrefix = pathPrefix;
+    this._uriPrefix = uriPrefix;
+}
+
+/**
+ * @param {WebInspector.FileMapping.SerializedMappingEntry} serializedMappingEntry
+ * @param {WebInspector.FileSystemMapping} fileSystemMapping
+ */
+WebInspector.FileMapping.MappingEntry.deserialize = function(serializedMappingEntry, fileSystemMapping)
+{
+    var uriPrefix = fileSystemMapping.uriForPath(serializedMappingEntry.pathPrefix);
+    return new WebInspector.FileMapping.MappingEntry(serializedMappingEntry.urlPrefix, serializedMappingEntry.pathPrefix, uriPrefix);
+}
+
+WebInspector.FileMapping.MappingEntry.prototype = {
+    /**
+     * @param {string} url
+     * @return {boolean}
+     */
+    matchesURL: function(url)
+    {
+        return url.indexOf(this._urlPrefix) === 0;
+    },
+    
+    /**
+     * @param {string} uri
+     * @return {boolean}
+     */
+    matchesURI: function(uri)
+    {
+        if (!this._uriPrefix)
+            return false;
+        return uri.indexOf(this._uriPrefix) === 0;
+    },
+    
+    /**
+     * @param {string} url
+     * @return {?string}
+     */
+    uriForURL: function(url)
+    {
+        if (this._uriPrefix && this.matchesURL(url))
+            return this._uriPrefix + url.substring(this._urlPrefix.length);
+        return null;
+    },
+    
+    /**
+     * @param {string} uri
+     * @return {?string}
+     */
+    urlForURI: function(uri)
+    {
+        if (this.matchesURI(uri))
+            return this._urlPrefix + uri.substring(this._uriPrefix.length);
+        return null;
+    },
+    
+    /**
+     * @return {Object}
+     */
+    serialize: function()
+    {
+        return { urlPrefix: this._urlPrefix, pathPrefix: this._pathPrefix };
+    },
+
+    __proto__: WebInspector.Object.prototype
+}
+
+/**
+ * @type {?WebInspector.FileMapping}
+ */
+WebInspector.fileMapping = null;
Property changes on: trunk/Source/WebCore/inspector/front-end/FileMapping.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/NetworkUISourceCodeProvider.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -114,6 +114,9 @@
      */
     _addFile: function(url, contentProvider, isContentScript)
     {
+        if (WebInspector.fileMapping.hasMappingForURL(url))
+            return;
+
         var type = contentProvider.contentType();
         if (type !== WebInspector.resourceTypes.Stylesheet && type !== WebInspector.resourceTypes.Document && type !== WebInspector.resourceTypes.Script)
             return;

Modified: trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -138,7 +138,8 @@
         // FIXME: workaround for script.isDynamicScript() being unreliable.
         if (!script.isInlineScript() && this._inlineScriptsForSourceURL[script.sourceURL])
             return null;
-        return this._workspace.uiSourceCodeForURL(script.sourceURL);
+        var uri = WebInspector.fileMapping.uriForURL(script.sourceURL);
+        return this._workspace.uiSourceCodeForURI(uri);
     },
 
     /**
@@ -158,6 +159,8 @@
         default:
             return [];
         }
+        if (!uiSourceCode.url)
+            return [];
         var scriptsForSourceURL = isInlineScript ? this._inlineScriptsForSourceURL : this._nonInlineScriptsForSourceURL;
         return scriptsForSourceURL[uiSourceCode.url] || [];
     },

Modified: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -58,7 +58,8 @@
     if (resource)
         return resource.displayName;
 
-    var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
+    var uri = WebInspector.fileMapping.uriForURL(url);
+    var uiSourceCode = WebInspector.workspace.uiSourceCodeForURI(uri);
     if (uiSourceCode)
         return uiSourceCode.parsedURL.displayName;
 

Modified: trunk/Source/WebCore/inspector/front-end/SASSSourceMapping.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/SASSSourceMapping.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/SASSSourceMapping.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -38,7 +38,7 @@
 {
     this._workspace = workspace;
     this._networkWorkspaceProvider = networkWorkspaceProvider;
-    this._uiLocations = {};
+    this._mappingEntries = {};
     this._cssURLsForSASSURL = {};
     this._timeoutForURL = {};
     WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
@@ -67,6 +67,7 @@
      */
     _fileSaveFinished: function(event)
     {
+        // FIXME: add support for FileMapping.
         var sassURL = /** @type {string} */ (event.data);
         function callback()
         {
@@ -92,7 +93,8 @@
 
     _reloadCSS: function(url)
     {
-        var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
+        var uri = WebInspector.fileMapping.uriForURL(url);
+        var uiSourceCode = this._workspace.uiSourceCodeForURI(uri);
         if (!uiSourceCode)
             return;
         var newContent = InspectorFrontendHost.loadResourceSynchronously(url);
@@ -151,18 +153,18 @@
      * @param {string} rawURL
      * @param {number} rawLine
      */
-    _bindUISourceCode: function(url, line, rawURL, rawLine)
+    _addURLMapping: function(url, line, rawURL, rawLine)
     {
-        var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
-        if (!uiSourceCode) {
+        var uri = WebInspector.fileMapping.uriForURL(url);
+        if (!WebInspector.fileMapping.hasMappingForURL(url) && !this._workspace.uiSourceCodeForURI(uri)) {
             var content = InspectorFrontendHost.loadResourceSynchronously(url);
             var contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Stylesheet, content, "text/x-scss");
-            uiSourceCode = this._networkWorkspaceProvider.addFileForURL(url, contentProvider, true);
-            WebInspector.cssModel.setSourceMapping(rawURL, this);
+            this._networkWorkspaceProvider.addFileForURL(url, contentProvider, true);
         }
         var rawLocationString = rawURL + ":" + (rawLine + 1);  // Next line after mapping metainfo
-        this._uiLocations[rawLocationString] = new WebInspector.UILocation(uiSourceCode, line - 1, 0);
+        this._mappingEntries[rawLocationString] = new WebInspector.SASSSourceMapping.MappingEntry(uri, line - 1, 0);
         this._addCSSURLforSASSURL(rawURL, url);
+        WebInspector.cssModel.setSourceMapping(rawURL, this);
     },
 
     /**
@@ -189,10 +191,18 @@
     rawLocationToUILocation: function(rawLocation)
     {
         var location = /** @type WebInspector.CSSLocation */ (rawLocation);
-        var uiLocation = this._uiLocations[location.url + ":" + location.lineNumber];
+        var mappingEntry = this._mappingEntries[location.url + ":" + location.lineNumber];
+        var uiLocation = null;
+        if (mappingEntry) {
+            var uiSourceCode = this._workspace.uiSourceCodeForURI(mappingEntry.uri);
+            if (uiSourceCode)
+                uiLocation = new WebInspector.UILocation(uiSourceCode, mappingEntry.lineNumber, mappingEntry.columnNumber);
+        }
         if (!uiLocation) {
-            var uiSourceCode = this._workspace.uiSourceCodeForURL(location.url);
-            uiLocation = new WebInspector.UILocation(uiSourceCode, location.lineNumber, 0);
+            var uri = WebInspector.fileMapping.uriForURL(location.url);
+            var uiSourceCode = this._workspace.uiSourceCodeForURI(uri);
+            if (uiSourceCode)
+                uiLocation = new WebInspector.UILocation(uiSourceCode, location.lineNumber, 0);
         }
         return uiLocation;
     },
@@ -211,8 +221,20 @@
 
     _reset: function()
     {
-        this._uiLocations = {};
+        this._mappingEntries = {};
         this._populate();
     }
 }
 
+/**
+ * @constructor
+ * @param {string} uri
+ * @param {number} lineNumber
+ */
+WebInspector.SASSSourceMapping.MappingEntry = function(uri, lineNumber, columnNumber)
+{
+    this.uri = uri;
+    this.lineNumber = lineNumber;
+    this.columnNumber = columnNumber;
+}
+

Modified: trunk/Source/WebCore/inspector/front-end/StylesSourceMapping.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/StylesSourceMapping.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/StylesSourceMapping.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -39,7 +39,7 @@
     this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
     this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
 
-    this._uiSourceCodeForURL = {};
+    this._mappedURLs = {};
 }
 
 WebInspector.StylesSourceMapping.prototype = {
@@ -50,7 +50,8 @@
     rawLocationToUILocation: function(rawLocation)
     {
         var location = /** @type WebInspector.CSSLocation */ (rawLocation);
-        var uiSourceCode = this._uiSourceCodeForURL[location.url];
+        var uri = WebInspector.fileMapping.uriForURL(location.url);
+        var uiSourceCode = this._workspace.uiSourceCodeForURI(uri);
         return new WebInspector.UILocation(uiSourceCode, location.lineNumber, 0);
     },
 
@@ -68,22 +69,13 @@
     _uiSourceCodeAddedToWorkspace: function(event)
     {
         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
-        if (!uiSourceCode.url || this._uiSourceCodeForURL[uiSourceCode.url])
-            return;
         if (uiSourceCode.contentType() !== WebInspector.resourceTypes.Stylesheet)
             return;
-        if (!WebInspector.resourceForURL(uiSourceCode.url))
+        if (!uiSourceCode.url || !WebInspector.resourceForURL(uiSourceCode.url))
             return;
-
-        this._addUISourceCode(uiSourceCode);
-    },
-
-    /**
-     * @param {WebInspector.UISourceCode} uiSourceCode
-     */
-    _addUISourceCode: function(uiSourceCode)
-    {
-        this._uiSourceCodeForURL[uiSourceCode.url] = uiSourceCode;
+        if (this._mappedURLs[uiSourceCode.url])
+            return;
+        this._mappedURLs[uiSourceCode.url] = true;
         uiSourceCode.setSourceMapping(this);
         var styleFile = new WebInspector.StyleFile(uiSourceCode);
         uiSourceCode.setStyleFile(styleFile);
@@ -95,7 +87,7 @@
         var project = event.data;
         var uiSourceCodes = project.uiSourceCodes();
         for (var i = 0; i < uiSourceCodes; ++i)
-            delete this._uiSourceCodeForURL[uiSourceCodes[i].url];
+            delete this._mappedURLs[uiSourceCodes[i].url];
     }
 }
 
@@ -266,7 +258,8 @@
             if (typeof styleSheetURL !== "string")
                 return;
 
-            var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(styleSheetURL);
+            var uri = WebInspector.fileMapping.uriForURL(styleSheetURL);
+            var uiSourceCode = WebInspector.workspace.uiSourceCodeForURI(uri);
             if (!uiSourceCode)
                 return;
 

Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc	2013-01-16 10:26:36 UTC (rev 139860)
@@ -74,6 +74,7 @@
     <file>ExtensionView.js</file>
     <file>FileContentView.js</file>
     <file>FileManager.js</file>
+    <file>FileMapping.js</file>
     <file>FileSystemMapping.js</file>
     <file>FileSystemModel.js</file>
     <file>FileSystemView.js</file>

Modified: trunk/Source/WebCore/inspector/front-end/Workspace.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/Workspace.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/Workspace.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -188,19 +188,6 @@
     },
 
     /**
-     * @param {string} url
-     * @return {?WebInspector.UISourceCode}
-     */
-    uiSourceCodeForURL: function(url)
-    {
-        for (var i = 0; i < this._uiSourceCodes.length; ++i) {
-            if (this._uiSourceCodes[i].url ="" url)
-                return this._uiSourceCodes[i];
-        }
-        return null;
-    },
-
-    /**
      * @param {string} originURL
      * @return {?WebInspector.UISourceCode}
      */
@@ -301,15 +288,6 @@
     },
 
     /**
-     * @param {string} url
-     * @return {?WebInspector.UISourceCode}
-     */
-    uiSourceCodeForURL: function(url)
-    {
-        return this._projects[WebInspector.projectNames.Network].uiSourceCodeForURL(url);
-    },
-
-    /**
      * @param {string} uri
      * @return {?WebInspector.UISourceCode}
      */

Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/inspector.html	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html	2013-01-16 10:26:36 UTC (rev 139860)
@@ -139,6 +139,7 @@
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
+    <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""
     <script type="text/_javascript_" src=""

Modified: trunk/Source/WebCore/inspector/front-end/inspector.js (139859 => 139860)


--- trunk/Source/WebCore/inspector/front-end/inspector.js	2013-01-16 10:19:13 UTC (rev 139859)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js	2013-01-16 10:26:36 UTC (rev 139860)
@@ -432,6 +432,7 @@
 
     this.isolatedFileSystemModel = new WebInspector.IsolatedFileSystemModel();
     this.isolatedFileSystemDispatcher = new WebInspector.IsolatedFileSystemDispatcher(this.isolatedFileSystemModel);
+    this.fileMapping = new WebInspector.FileMapping(this.isolatedFileSystemModel.mapping());
     this.workspace = new WebInspector.Workspace();
     this.networkWorkspaceProvider = new WebInspector.SimpleWorkspaceProvider(this.workspace);
     this.workspace.addProject(WebInspector.projectNames.Network, this.networkWorkspaceProvider);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to