OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @template T | 6 * @template T |
7 */ | 7 */ |
8 SDK.SourceMapManager = class extends SDK.SDKObject { | 8 SDK.SourceMapManager = class extends Common.Object { |
9 /** | 9 /** |
10 * @param {!SDK.Target} target | 10 * @param {!SDK.Target} target |
11 */ | 11 */ |
12 constructor(target) { | 12 constructor(target) { |
13 super(target); | 13 super(); |
14 | 14 |
| 15 this._target = target; |
15 this._isEnabled = true; | 16 this._isEnabled = true; |
16 | 17 |
17 /** @type {!Map<!T, string>} */ | 18 /** @type {!Map<!T, string>} */ |
18 this._relativeSourceURL = new Map(); | 19 this._relativeSourceURL = new Map(); |
19 /** @type {!Map<!T, string>} */ | 20 /** @type {!Map<!T, string>} */ |
20 this._relativeSourceMapURL = new Map(); | 21 this._relativeSourceMapURL = new Map(); |
21 /** @type {!Map<!T, string>} */ | 22 /** @type {!Map<!T, string>} */ |
22 this._resolvedSourceMapURL = new Map(); | 23 this._resolvedSourceMapURL = new Map(); |
23 | 24 |
24 /** @type {!Map<string, !SDK.SourceMap>} */ | 25 /** @type {!Map<string, !SDK.SourceMap>} */ |
(...skipping 19 matching lines...) Expand all Loading... |
44 var relativeSourceMapURL = this._relativeSourceMapURL.get(client); | 45 var relativeSourceMapURL = this._relativeSourceMapURL.get(client); |
45 this.detachSourceMap(client); | 46 this.detachSourceMap(client); |
46 this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL); | 47 this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL); |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 /** | 51 /** |
51 * @param {!Common.Event} event | 52 * @param {!Common.Event} event |
52 */ | 53 */ |
53 _inspectedURLChanged(event) { | 54 _inspectedURLChanged(event) { |
54 if (event.data !== this.target()) | 55 if (event.data !== this._target) |
55 return; | 56 return; |
56 | 57 |
57 var clients = Array.from(this._resolvedSourceMapURL.keys()); | 58 var clients = Array.from(this._resolvedSourceMapURL.keys()); |
58 for (var client of clients) { | 59 for (var client of clients) { |
59 var relativeSourceURL = this._relativeSourceURL.get(client); | 60 var relativeSourceURL = this._relativeSourceURL.get(client); |
60 var relativeSourceMapURL = this._relativeSourceMapURL.get(client); | 61 var relativeSourceMapURL = this._relativeSourceMapURL.get(client); |
61 var resolvedSourceMapURL = this._resolvedSourceMapURL.get(client); | 62 var resolvedSourceMapURL = this._resolvedSourceMapURL.get(client); |
62 var sourceMapURL = this._resolveRelativeURLs(relativeSourceURL, relativeSo
urceMapURL).sourceMapURL; | 63 var sourceMapURL = this._resolveRelativeURLs(relativeSourceURL, relativeSo
urceMapURL).sourceMapURL; |
63 if (sourceMapURL !== resolvedSourceMapURL) { | 64 if (sourceMapURL !== resolvedSourceMapURL) { |
64 this.detachSourceMap(client); | 65 this.detachSourceMap(client); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 99 } |
99 | 100 |
100 /** | 101 /** |
101 * @param {string} sourceURL | 102 * @param {string} sourceURL |
102 * @param {string} sourceMapURL | 103 * @param {string} sourceMapURL |
103 * @return {!{sourceURL: ?string, sourceMapURL: ?string}} | 104 * @return {!{sourceURL: ?string, sourceMapURL: ?string}} |
104 */ | 105 */ |
105 _resolveRelativeURLs(sourceURL, sourceMapURL) { | 106 _resolveRelativeURLs(sourceURL, sourceMapURL) { |
106 // |sourceURL| can be a random string, but is generally an absolute path. | 107 // |sourceURL| can be a random string, but is generally an absolute path. |
107 // Complete it to inspected page url for relative links. | 108 // Complete it to inspected page url for relative links. |
108 var resolvedSourceURL = Common.ParsedURL.completeURL(this.target().inspected
URL(), sourceURL); | 109 var resolvedSourceURL = Common.ParsedURL.completeURL(this._target.inspectedU
RL(), sourceURL); |
109 var resolvedSourceMapURL = resolvedSourceURL ? Common.ParsedURL.completeURL(
resolvedSourceURL, sourceMapURL) : null; | 110 var resolvedSourceMapURL = resolvedSourceURL ? Common.ParsedURL.completeURL(
resolvedSourceURL, sourceMapURL) : null; |
110 return {sourceURL: resolvedSourceURL, sourceMapURL: resolvedSourceMapURL}; | 111 return {sourceURL: resolvedSourceURL, sourceMapURL: resolvedSourceMapURL}; |
111 } | 112 } |
112 | 113 |
113 /** | 114 /** |
114 * @param {!T} client | 115 * @param {!T} client |
115 * @param {string} sourceURL | 116 * @param {string} sourceURL |
116 * @param {?string} sourceMapURL | 117 * @param {?string} sourceMapURL |
117 */ | 118 */ |
118 attachSourceMap(client, sourceURL, sourceMapURL) { | 119 attachSourceMap(client, sourceURL, sourceMapURL) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 * @return {!Promise<?SDK.SourceMap>} | 151 * @return {!Promise<?SDK.SourceMap>} |
151 * @this {SDK.SourceMapManager} | 152 * @this {SDK.SourceMapManager} |
152 */ | 153 */ |
153 function onTextSourceMapLoaded(sourceMapURL, sourceMap) { | 154 function onTextSourceMapLoaded(sourceMapURL, sourceMap) { |
154 if (!sourceMap) | 155 if (!sourceMap) |
155 return Promise.resolve(/** @type {?SDK.SourceMap} */ (null)); | 156 return Promise.resolve(/** @type {?SDK.SourceMap} */ (null)); |
156 var factoryExtension = this._factoryForSourceMap(sourceMap); | 157 var factoryExtension = this._factoryForSourceMap(sourceMap); |
157 if (!factoryExtension) | 158 if (!factoryExtension) |
158 return Promise.resolve(/** @type {?SDK.SourceMap} */ (sourceMap)); | 159 return Promise.resolve(/** @type {?SDK.SourceMap} */ (sourceMap)); |
159 return factoryExtension.instance() | 160 return factoryExtension.instance() |
160 .then(factory => factory.editableSourceMap(this.target(), sourceMap)) | 161 .then(factory => factory.editableSourceMap(this._target, sourceMap)) |
161 .then(map => map || sourceMap) | 162 .then(map => map || sourceMap) |
162 .catchException(/** @type {?SDK.SourceMap} */ (null)); | 163 .catchException(/** @type {?SDK.SourceMap} */ (null)); |
163 } | 164 } |
164 | 165 |
165 /** | 166 /** |
166 * @param {string} sourceMapURL | 167 * @param {string} sourceMapURL |
167 * @param {?SDK.SourceMap} sourceMap | 168 * @param {?SDK.SourceMap} sourceMap |
168 * @this {SDK.SourceMapManager} | 169 * @this {SDK.SourceMapManager} |
169 */ | 170 */ |
170 function onSourceMap(sourceMapURL, sourceMap) { | 171 function onSourceMap(sourceMapURL, sourceMap) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 246 } |
246 }; | 247 }; |
247 | 248 |
248 SDK.SourceMapManager.Events = { | 249 SDK.SourceMapManager.Events = { |
249 SourceMapWillAttach: Symbol('SourceMapWillAttach'), | 250 SourceMapWillAttach: Symbol('SourceMapWillAttach'), |
250 SourceMapFailedToAttach: Symbol('SourceMapFailedToAttach'), | 251 SourceMapFailedToAttach: Symbol('SourceMapFailedToAttach'), |
251 SourceMapAttached: Symbol('SourceMapAttached'), | 252 SourceMapAttached: Symbol('SourceMapAttached'), |
252 SourceMapDetached: Symbol('SourceMapDetached'), | 253 SourceMapDetached: Symbol('SourceMapDetached'), |
253 SourceMapChanged: Symbol('SourceMapChanged') | 254 SourceMapChanged: Symbol('SourceMapChanged') |
254 }; | 255 }; |
OLD | NEW |