From 629abaa983be9623615f167d6384f648bd13480d Mon Sep 17 00:00:00 2001 From: lushnikov Date: Thu, 30 Mar 2017 17:17:09 -0700 Subject: [PATCH] DevTools: fix CSS sourcemap to be populated for multilpe sourcemaps scenario This patch fixes multiple issues: - there is a bug in SASSSourceMapping which adds sources only for the one sourcemap in frame - there was another bug in SourceMapManager which handled enabling/disabling wrong. BUG=none R=dgozman Review-Url: https://codereview.chromium.org/2787963002 Cr-Commit-Position: refs/heads/master@{#460947} --- front_end/bindings/SASSSourceMapping.js | 25 ++++++++++++++++++------- front_end/sdk/SourceMapManager.js | 3 +-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/front_end/bindings/SASSSourceMapping.js b/front_end/bindings/SASSSourceMapping.js index d7da206316..8bc0843ed1 100644 --- a/front_end/bindings/SASSSourceMapping.js +++ b/front_end/bindings/SASSSourceMapping.js @@ -51,7 +51,7 @@ Bindings.SASSSourceMapping = class { ]; /** @type {!Multimap} */ - this._frameIdToHeaders = new Multimap(); + this._sourceMapIdToHeaders = new Multimap(); } /** @@ -60,18 +60,28 @@ Bindings.SASSSourceMapping = class { _sourceMapAttachedForTest(sourceMap) { } + /** + * @param {string} frameId + * @param {string} sourceMapURL + * @return {string} + */ + static _sourceMapId(frameId, sourceMapURL) { + return frameId + ':' + sourceMapURL; + } + /** * @param {!Common.Event} event */ _sourceMapAttached(event) { 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); + var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url()); + if (this._sourceMapIdToHeaders.has(sourceMapId)) { + this._sourceMapIdToHeaders.set(sourceMapId, header); this._sourceMapAttachedForTest(sourceMap); return; } - this._frameIdToHeaders.set(header.frameId, header); + this._sourceMapIdToHeaders.set(sourceMapId, header); for (var sassURL of sourceMap.sourceURLs()) { var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.resourceTypes.SourceMapStyleSheet); @@ -88,10 +98,11 @@ Bindings.SASSSourceMapping = class { */ _sourceMapDetached(event) { 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); + var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url()); + this._sourceMapIdToHeaders.remove(sourceMapId, header); + if (this._sourceMapIdToHeaders.has(sourceMapId)) + return; for (var sassURL of sourceMap.sourceURLs()) this._networkProject.removeSourceMapFile(sassURL, header.frameId, false); Bindings.cssWorkspaceBinding.updateLocations(header); diff --git a/front_end/sdk/SourceMapManager.js b/front_end/sdk/SourceMapManager.js index 4b652c7e07..54c978fac3 100644 --- a/front_end/sdk/SourceMapManager.js +++ b/front_end/sdk/SourceMapManager.js @@ -43,8 +43,7 @@ SDK.SourceMapManager = class extends SDK.SDKObject { var relativeSourceURL = this._relativeSourceURL.get(client); var relativeSourceMapURL = this._relativeSourceMapURL.get(client); this.detachSourceMap(client); - if (isEnabled) - this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL); + this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL); } }