Title: [97151] trunk
Revision
97151
Author
podivi...@chromium.org
Date
2011-10-11 07:04:55 -0700 (Tue, 11 Oct 2011)

Log Message

Web Inspector: implement CompilerSourceMappingProvider.
https://bugs.webkit.org/show_bug.cgi?id=69423

Reviewed by Pavel Feldman.

Source/WebCore:

CompilerSourceMappingProvider implements a cross-domain communication channel for loading source mappings and source files.
Front-end page can't send XHRs to source mapping server directly due to SOP restrictions. Instead, we inject an invisible
iframe that is loaded from source mapping server and use window.postMessage to communicate with it. iframe has a different
origin and thus doesn't have access to front-end window.

Test: http/tests/inspector/compiler-source-mapping-provider.html

* inspector/front-end/CompilerSourceMappingProvider.js:
(WebInspector.CompilerSourceMappingProvider):
(WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping.frameLoaded.didLoadData):
(WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping.frameLoaded):
(WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping):
(WebInspector.CompilerSourceMappingProvider.prototype.loadSourceCode):
(WebInspector.CompilerSourceMappingProvider.prototype._sendRequest):
(WebInspector.CompilerSourceMappingProvider.prototype._onMessage):
(WebInspector.CompilerSourceMappingProvider.prototype._cancelRequest):
* inspector/front-end/inspector.js:
(WebInspector.installSourceMappingForTest):

LayoutTests:

* http/tests/inspector/compiler-source-mapping-provider-expected.txt: Added.
* http/tests/inspector/compiler-source-mapping-provider.html: Added.
* http/tests/inspector/resources/compiler-source-mapping-provider/app-map: Added.
* http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html: Added.
* http/tests/inspector/resources/compiler-source-mapping-provider/app.js: Added.
(window.onload):
(handleClick):
* http/tests/inspector/resources/compiler-source-mapping-provider/foo.js: Added.
(ClickHandler):
(ClickHandler.prototype.handle):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (97150 => 97151)


--- trunk/LayoutTests/ChangeLog	2011-10-11 13:30:56 UTC (rev 97150)
+++ trunk/LayoutTests/ChangeLog	2011-10-11 14:04:55 UTC (rev 97151)
@@ -1,3 +1,21 @@
+2011-10-05  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: implement CompilerSourceMappingProvider.
+        https://bugs.webkit.org/show_bug.cgi?id=69423
+
+        Reviewed by Pavel Feldman.
+
+        * http/tests/inspector/compiler-source-mapping-provider-expected.txt: Added.
+        * http/tests/inspector/compiler-source-mapping-provider.html: Added.
+        * http/tests/inspector/resources/compiler-source-mapping-provider/app-map: Added.
+        * http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html: Added.
+        * http/tests/inspector/resources/compiler-source-mapping-provider/app.js: Added.
+        (window.onload):
+        (handleClick):
+        * http/tests/inspector/resources/compiler-source-mapping-provider/foo.js: Added.
+        (ClickHandler):
+        (ClickHandler.prototype.handle):
+
 2011-10-11  Mike Reed  <r...@google.com>
 
         re-add support for GDI text behind a compile flag

Added: trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider-expected.txt (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider-expected.txt	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,8 @@
+Tests CompilerSourceMappingProvider class.
+
+
+Running: testLoad
+
+Running: testTimeout
+log: Request timed out.
+
Property changes on: trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider.html (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider.html	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,58 @@
+<html>
+<head>
+<script src=""
+
+<script>
+
+function test()
+{
+    InspectorTest.runTestSuite([
+        function testLoad(next)
+        {
+            var provider = new WebInspector.CompilerSourceMappingProvider("http://localhost:8000/inspector/resources/compiler-source-mapping-provider/app-map");
+            var sourceMapping;
+            provider.loadSourceMapping(didLoadSourceMapping);
+            function didLoadSourceMapping(sourceMappingArg)
+            {
+                sourceMapping = sourceMappingArg;
+                var sources = sourceMapping.sources();
+                InspectorTest.assertEquals(2, sources.length);
+                InspectorTest.assertEquals("app.js", sources[0]);
+                InspectorTest.assertEquals("foo.js", sources[1]);
+                provider.loadSourceCode(sourceMapping.sources()[0], didLoadSourceCode);
+            }
+
+            function didLoadSourceCode(content)
+            {
+                InspectorTest.assertEquals(0, content.indexOf("window._onload_ = function()"));
+                provider.loadSourceCode(sourceMapping.sources()[1], didLoadSourceCode2);
+            }
+
+            function didLoadSourceCode2(content)
+            {
+                InspectorTest.assertEquals(0, content.indexOf("function ClickHandler()"));
+                next();
+            }
+        },
+
+        function testTimeout(next)
+        {
+            var provider = new WebInspector.CompilerSourceMappingProvider("http://localhost:8000/does-not-exist");
+            provider.loadSourceMapping(didLoadSourceMapping);
+            function didLoadSourceMapping(sourceMapping)
+            {
+                InspectorTest.assertEquals(null, sourceMapping);
+                next();
+            }
+        }
+    ]);
+};
+
+</script>
+
+</head>
+
+<body _onload_="runTest()">
+<p>Tests CompilerSourceMappingProvider class.</p>
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/inspector/compiler-source-mapping-provider.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,8 @@
+{
+"version":3,
+"file":"./app-map",
+"lineCount":2,
+"mappings":"AACAA,MAAAC,OAAA,CAAwBC,QAAA,EACxB,CACI,IAAIC,EAAMC,QAAAC,cAAsB,CAAC,KAAD,CAChCF,EAAAG,YAAA,CAAkB,KAClBH,EAAAI,iBAAoB,CAAC,OAAD,CAAUC,WAAV,CAAuB,CAAA,CAAvB,CACpBJ,SAAAK,KAAAC,YAAyB,CAACP,CAAD,CAErBQ,EAAAA,CAAMP,QAAAC,cAAsB,CAAC,KAAD,CAChCM,EAAAL,YAAA,CAAkB,ocAClBF;QAAAK,KAAAC,YAAyB,CAACC,CAAD,CAR7B,CAWSH,SAAAA,YAAW,CAACI,CAAD,CACpB,CAEIC,CAD8BC,IAAZC,YAClBF,QAAc,CAACD,CAAD,CAFlB,CCbSG,QAAAA,aAAY,EACrB,EAGAA,YAAAC,UAAAH,OAAA,CAAwCI,QAAA,CAACL,CAAD,CACxC,CACI,IAAIM,EAAUd,QAAAC,cAAsB,CAAC,KAAD,CACpCa,EAAAZ,YAAA,CAAsBM,CAAAO,UACtBf,SAAAK,KAAAC,YAAyB,CAACQ,CAAD,CAH7B;",
+"sources":["app.js","foo.js"],
+"names":["window","onload","window.onload","foo","document","createElement","textContent","addEventListener","handleClick","body","appendChild","bar","event","handle","handler","ClickHandler","prototype","ClickHandler.prototype.handle","element","timeStamp"]
+}

Added: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,20 @@
+<script>
+window.addEventListener("message", handleMessage, false);
+
+function handleMessage(event)
+{
+    var url = ""
+    var request = new XMLHttpRequest();
+    request.open("GET", url, true);
+    request._onreadystatechange_ = function()
+    {
+        if (request.readyState !== 4)
+            return;
+        if (request.status === 200)
+            event.source.postMessage({ id: event.data.id, result: request.responseText }, event.origin);
+        else
+            event.source.postMessage({ id: event.data.id, error: request.statusText }, event.origin);
+    }
+    request.send();
+}
+</script>
Property changes on: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app-map.html
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app.js (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app.js	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,17 @@
+window._onload_ = function()
+{
+    var foo = document.createElement('div');
+    foo.textContent = 'foo';
+    foo.addEventListener('click', handleClick, true);
+    document.body.appendChild(foo);
+
+    var bar = document.createElement('div');
+    bar.textContent = 'barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr';
+    document.body.appendChild(bar);
+}
+
+function handleClick(event)
+{
+    var handler = new ClickHandler();
+    handler.handle(event);
+}
Property changes on: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/app.js
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/foo.js (0 => 97151)


--- trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/foo.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/foo.js	2011-10-11 14:04:55 UTC (rev 97151)
@@ -0,0 +1,10 @@
+function ClickHandler()
+{
+}
+
+ClickHandler.prototype.handle = function(event)
+{
+    var element = document.createElement('div');
+    element.textContent = event.timeStamp;
+    document.body.appendChild(element);
+}
Property changes on: trunk/LayoutTests/http/tests/inspector/resources/compiler-source-mapping-provider/foo.js
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (97150 => 97151)


--- trunk/Source/WebCore/ChangeLog	2011-10-11 13:30:56 UTC (rev 97150)
+++ trunk/Source/WebCore/ChangeLog	2011-10-11 14:04:55 UTC (rev 97151)
@@ -1,3 +1,29 @@
+2011-10-05  Pavel Podivilov  <podivi...@chromium.org>
+
+        Web Inspector: implement CompilerSourceMappingProvider.
+        https://bugs.webkit.org/show_bug.cgi?id=69423
+
+        Reviewed by Pavel Feldman.
+
+        CompilerSourceMappingProvider implements a cross-domain communication channel for loading source mappings and source files.
+        Front-end page can't send XHRs to source mapping server directly due to SOP restrictions. Instead, we inject an invisible
+        iframe that is loaded from source mapping server and use window.postMessage to communicate with it. iframe has a different
+        origin and thus doesn't have access to front-end window.
+
+        Test: http/tests/inspector/compiler-source-mapping-provider.html
+
+        * inspector/front-end/CompilerSourceMappingProvider.js:
+        (WebInspector.CompilerSourceMappingProvider):
+        (WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping.frameLoaded.didLoadData):
+        (WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping.frameLoaded):
+        (WebInspector.CompilerSourceMappingProvider.prototype.loadSourceMapping):
+        (WebInspector.CompilerSourceMappingProvider.prototype.loadSourceCode):
+        (WebInspector.CompilerSourceMappingProvider.prototype._sendRequest):
+        (WebInspector.CompilerSourceMappingProvider.prototype._onMessage):
+        (WebInspector.CompilerSourceMappingProvider.prototype._cancelRequest):
+        * inspector/front-end/inspector.js:
+        (WebInspector.installSourceMappingForTest):
+
 2011-10-11  Mike Reed  <r...@google.com>
 
         re-add support for GDI text behind a compile flag

Modified: trunk/Source/WebCore/inspector/front-end/CompilerSourceMappingProvider.js (97150 => 97151)


--- trunk/Source/WebCore/inspector/front-end/CompilerSourceMappingProvider.js	2011-10-11 13:30:56 UTC (rev 97150)
+++ trunk/Source/WebCore/inspector/front-end/CompilerSourceMappingProvider.js	2011-10-11 14:04:55 UTC (rev 97151)
@@ -30,19 +30,102 @@
 
 /**
  * @constructor
+ * @param {string} sourceMappingURL
  */
-WebInspector.CompilerSourceMappingProvider = function()
+WebInspector.CompilerSourceMappingProvider = function(sourceMappingURL)
 {
+    if (!this._initialized) {
+        window.addEventListener("message", this._onMessage, true);
+        WebInspector.CompilerSourceMappingProvider.prototype._initialized = true;
+    }
+    this._sourceMappingURL = sourceMappingURL;
+    this._frameURL = this._sourceMappingURL + ".html";
 }
 
 WebInspector.CompilerSourceMappingProvider.prototype = {
+    /**
+     * @param {function(WebInspector.CompilerSourceMapping)} callback
+     */
     loadSourceMapping: function(callback)
     {
-        // FIXME: load the map from source map server.
+        this._frame = document.createElement("iframe");
+        this._frame.src = ""
+        function frameLoaded()
+        {
+            function didLoadData(error, result)
+            {
+                if (error) {
+                    console.log(error);
+                    callback(null);
+                    return;
+                }
+
+                var payload;
+                try {
+                    payload = JSON.parse(result);
+                } catch (e) {
+                    console.log("Failed to parse JSON.");
+                }
+
+                if (payload)
+                    callback(new WebInspector.ClosureCompilerSourceMapping(payload));
+                else
+                    callback(null);
+            }
+            this._sendRequest("loadData", [this._sourceMappingURL], didLoadData);
+        }
+        this._frame.addEventListener("load", frameLoaded.bind(this), true);
+        // FIXME: remove iframe from the document when it is not needed anymore.
+        document.body.appendChild(this._frame);
     },
 
-    loadSourceCode: function(sourceURL, callback)
+    /**
+     * @param {string} sourceURL
+     * @param {function(string)} callback
+     * @param {number} timeout
+     */
+    loadSourceCode: function(sourceURL, callback, timeout)
     {
-        // FIXME: load source code from source map server.
-    }
+        function didSendRequest(error, result)
+        {
+            if (error) {
+                console.log(error);
+                callback("");
+                return;
+            }
+            callback(result);
+        }
+        this._sendRequest("loadData", [sourceURL], didSendRequest, timeout);
+    },
+
+    _sendRequest: function(method, parameters, callback, timeout)
+    {
+        var requestId = this._requestId++;
+        var timerId = setTimeout(this._cancelRequest.bind(this, requestId), timeout || 50);
+        this._requests[requestId] = { callback: callback, timerId: timerId };
+        var requestData = { id: requestId, method: method, params: parameters };
+        this._frame.contentWindow.postMessage(requestData, this._frameURL);
+    },
+
+    _onMessage: function(event)
+    {
+        var requestId = event.data.id;
+        var requests = WebInspector.CompilerSourceMappingProvider.prototype._requests;
+        var request = requests[requestId];
+        if (!request)
+            return;
+        delete requests[requestId];
+        clearTimeout(request.timerId);
+        request.callback(event.data.error, event.data.result);
+    },
+
+    _cancelRequest: function(requestId)
+    {
+        var request = this._requests[requestId];
+        delete this._requests[requestId];
+        request.callback("Request timed out.", null);
+    },
+
+    _requestId: 0,
+    _requests: {}
 }

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


--- trunk/Source/WebCore/inspector/front-end/inspector.js	2011-10-11 13:30:56 UTC (rev 97150)
+++ trunk/Source/WebCore/inspector/front-end/inspector.js	2011-10-11 14:04:55 UTC (rev 97151)
@@ -1330,3 +1330,11 @@
         this._historyIterator = this._history.length - 1;
     }
 }
+
+WebInspector.installSourceMappingForTest = function(url)
+{
+    // FIXME: remove this method when it's possible to set compiler source mappings via UI.
+    var provider = new WebInspector.CompilerSourceMappingProvider(url);
+    var uiSourceCode = WebInspector.panels.scripts.visibleView._delegate._uiSourceCode;
+    uiSourceCode.rawSourceCode.setCompilerSourceMappingProvider(provider);
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to