Commit 314a2aec authored by lushnikov's avatar lushnikov Committed by Commit bot

DevTools: carefully cleanup CSS sourcemaps

This patch starts to cleanup CSS sourcemaps as they get detached from
host stylesheets.

BUG=670180
R=dgozman

Review-Url: https://codereview.chromium.org/2779703004
Cr-Commit-Position: refs/heads/master@{#460596}
parent 7bc6c9af
......@@ -75,8 +75,9 @@ Workspace: 18 uiSourceCodes.
[+] _test_detachShadow1.js
Running: detachShadow2
Removed: 0 uiSourceCodes
Workspace: 20 uiSourceCodes.
Removed: 1 uiSourceCodes
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
Workspace: 19 uiSourceCodes.
debugger:///VM[XXX] bindings-test.js
debugger:///VM[XXX] inspector-test.js
debugger:///VM[XXX] shadowdom-bindings.html
......@@ -88,7 +89,6 @@ Workspace: 20 uiSourceCodes.
debugger:///VM[XXX] _test_detachShadow1.js
[+] debugger:///VM[XXX] _test_detachShadow2.js
http://127.0.0.1:8000/inspector/bindings/bindings-test.js
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-typescript.ts
http://127.0.0.1:8000/inspector/bindings/shadowdom-bindings.html
http://127.0.0.1:8000/inspector/inspector-test.js
......
......@@ -61,7 +61,6 @@ top
bindings
resources
sourcemap-typescript.ts
sourcemap-sass.scss
shadowdom-navigator.html
bindings-test.js
inspector-test.js
......
......@@ -39,11 +39,12 @@ Workspace: 22 uiSourceCodes.
[+] _test_create-iframe2.js
Running: detachFrame1
Removed: 3 uiSourceCodes
Removed: 4 uiSourceCodes
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-frame.html
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-script.js
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-style.css
Workspace: 21 uiSourceCodes.
Workspace: 20 uiSourceCodes.
debugger:///VM[XXX] bindings-test.js
debugger:///VM[XXX] inspector-test.js
debugger:///VM[XXX] sourcemap-bindings-multiple-frames.html
......@@ -56,7 +57,6 @@ Workspace: 21 uiSourceCodes.
http://127.0.0.1:8000/inspector/bindings/bindings-test.js
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-frame.html
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-script.js
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-style.css
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-typescript.ts
......@@ -67,11 +67,12 @@ Workspace: 21 uiSourceCodes.
[+] _test_detachFrame1.js
Running: detachFrame2
Removed: 3 uiSourceCodes
Removed: 4 uiSourceCodes
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-frame.html
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-script.js
[-] http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-style.css
Workspace: 20 uiSourceCodes.
Workspace: 18 uiSourceCodes.
debugger:///VM[XXX] bindings-test.js
debugger:///VM[XXX] inspector-test.js
debugger:///VM[XXX] sourcemap-bindings-multiple-frames.html
......@@ -83,8 +84,6 @@ Workspace: 20 uiSourceCodes.
debugger:///VM[XXX] _test_detachFrame1.js
[+] debugger:///VM[XXX] _test_detachFrame2.js
http://127.0.0.1:8000/inspector/bindings/bindings-test.js
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-sass.scss
http://127.0.0.1:8000/inspector/bindings/resources/sourcemap-typescript.ts
http://127.0.0.1:8000/inspector/bindings/sourcemap-bindings-multiple-frames.html
http://127.0.0.1:8000/inspector/inspector-test.js
......
......@@ -27,10 +27,10 @@ InspectorTest.loadASTMapping = function(header, callback)
sourceMapManager.addEventListener(SDK.SourceMapManager.Events.SourceMapAttached, onAttached);
function onAttached(event) {
if (event.data !== header)
if (event.data.client !== header)
return;
sourceMapManager.removeEventListener(SDK.SourceMapManager.Events.SourceMapAttached, onAttached);
var sourceMap = sourceMapManager.sourceMapForClient(header);
var sourceMap = event.data.sourceMap;
callback(sourceMap.editable()? sourceMap : null);
}
}
......
......@@ -24,8 +24,8 @@ function test()
function onSourceMapAttached(event)
{
var header = event.data;
var sourceMap = InspectorTest.cssModel.sourceMapManager().sourceMapForClient(header);
var header = event.data.client;
var sourceMap = event.data.sourceMap;
InspectorTest.addResult("SourceMap is editable: " + sourceMap.editable());
InspectorTest.completeTest();
}
......
......@@ -197,12 +197,23 @@ Bindings.NetworkProject = class extends SDK.SDKObject {
return uiSourceCode;
}
/**
* @param {string} url
* @param {string} frameId
* @param {boolean} isContentScript
*/
removeSourceMapFile(url, frameId, isContentScript) {
this._removeFileForURL(url, frameId, isContentScript);
}
/**
* @param {string} frameId
* @param {string} url
* @param {boolean} isContentScript
*/
_removeFileForURL(frameId, url) {
var project = this._workspaceProjects.get(Bindings.NetworkProject.projectId(this.target(), frameId, false));
_removeFileForURL(url, frameId, isContentScript) {
var project =
this._workspaceProjects.get(Bindings.NetworkProject.projectId(this.target(), frameId, isContentScript));
if (!project)
return;
project.removeFile(url);
......@@ -285,7 +296,7 @@ Bindings.NetworkProject = class extends SDK.SDKObject {
if (header.isInline && !header.hasSourceURL && header.origin !== 'inspector')
return;
this._removeFileForURL(header.frameId, header.resourceURL());
this._removeFileForURL(header.resourceURL(), header.frameId, false);
}
/**
......
......@@ -49,6 +49,9 @@ Bindings.SASSSourceMapping = class {
this._sourceMapManager.addEventListener(
SDK.SourceMapManager.Events.SourceMapChanged, this._sourceMapChanged, this)
];
/** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */
this._frameIdToHeaders = new Multimap();
}
/**
......@@ -61,8 +64,15 @@ Bindings.SASSSourceMapping = class {
* @param {!Common.Event} event
*/
_sourceMapAttached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
var sourceMap = this._sourceMapManager.sourceMapForClient(header);
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
if (this._frameIdToHeaders.has(header.frameId)) {
this._frameIdToHeaders.set(header.frameId, header);
this._sourceMapAttachedForTest(sourceMap);
return;
}
this._frameIdToHeaders.set(header.frameId, header);
for (var sassURL of sourceMap.sourceURLs()) {
var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.resourceTypes.SourceMapStyleSheet);
var embeddedContent = sourceMap.embeddedContentByURL(sassURL);
......@@ -77,7 +87,13 @@ Bindings.SASSSourceMapping = class {
* @param {!Common.Event} event
*/
_sourceMapDetached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data);
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
this._frameIdToHeaders.remove(header.frameId, header);
if (this._frameIdToHeaders.has(header.frameId))
return;
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
for (var sassURL of sourceMap.sourceURLs())
this._networkProject.removeSourceMapFile(sassURL, header.frameId, false);
Bindings.cssWorkspaceBinding.updateLocations(header);
}
......
......@@ -184,7 +184,9 @@ SDK.SourceMapManager = class extends SDK.SDKObject {
*/
function attach(sourceMapURL, client) {
this._sourceMapURLToClients.set(sourceMapURL, client);
this.dispatchEventToListeners(SDK.SourceMapManager.Events.SourceMapAttached, client);
var sourceMap = this._sourceMapByURL.get(sourceMapURL);
this.dispatchEventToListeners(
SDK.SourceMapManager.Events.SourceMapAttached, {client: client, sourceMap: sourceMap});
}
}
......@@ -220,9 +222,11 @@ SDK.SourceMapManager = class extends SDK.SDKObject {
return;
}
this._sourceMapURLToClients.remove(sourceMapURL, client);
var sourceMap = this._sourceMapByURL.get(sourceMapURL);
if (!this._sourceMapURLToClients.has(sourceMapURL))
this._sourceMapByURL.delete(sourceMapURL);
this.dispatchEventToListeners(SDK.SourceMapManager.Events.SourceMapDetached, client);
this.dispatchEventToListeners(
SDK.SourceMapManager.Events.SourceMapDetached, {client: client, sourceMap: sourceMap});
}
_sourceMapLoadedForTest() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment