Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 /** | 30 /** |
| 31 * @implements {SDK.TargetManager.Observer} | 31 * @implements {SDK.TargetManager.Observer} |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 Bindings.NetworkProjectManager = class { | 34 Bindings.NetworkProjectManager = class extends Common.Object { |
| 35 /** | 35 /** |
| 36 * @param {!SDK.TargetManager} targetManager | 36 * @param {!SDK.TargetManager} targetManager |
| 37 * @param {!Workspace.Workspace} workspace | 37 * @param {!Workspace.Workspace} workspace |
| 38 */ | 38 */ |
| 39 constructor(targetManager, workspace) { | 39 constructor(targetManager, workspace) { |
| 40 super(); | |
| 40 this._workspace = workspace; | 41 this._workspace = workspace; |
| 41 targetManager.observeTargets(this); | 42 targetManager.observeTargets(this); |
| 42 } | 43 } |
| 43 | 44 |
| 44 /** | 45 /** |
| 45 * @override | 46 * @override |
| 46 * @param {!SDK.Target} target | 47 * @param {!SDK.Target} target |
| 47 */ | 48 */ |
| 48 targetAdded(target) { | 49 targetAdded(target) { |
| 49 new Bindings.NetworkProject(target, this._workspace, target.model(SDK.Resour ceTreeModel)); | 50 new Bindings.NetworkProject(target, this._workspace, target.model(SDK.Resour ceTreeModel)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 /** | 53 /** |
| 53 * @override | 54 * @override |
| 54 * @param {!SDK.Target} target | 55 * @param {!SDK.Target} target |
| 55 */ | 56 */ |
| 56 targetRemoved(target) { | 57 targetRemoved(target) { |
| 57 Bindings.NetworkProject.forTarget(target)._dispose(); | 58 Bindings.NetworkProject.forTarget(target)._dispose(); |
| 58 } | 59 } |
| 59 }; | 60 }; |
| 60 | 61 |
| 62 Bindings.NetworkProjectManager.Events = { | |
| 63 FrameAttributionChanged: Symbol('FrameAttributionChanged') | |
|
dgozman
2017/05/11 23:55:16
Make it two events.
lushnikov
2017/05/12 01:18:00
Done.
| |
| 64 }; | |
| 65 | |
| 61 /** | 66 /** |
| 62 * @unrestricted | 67 * @unrestricted |
| 63 */ | 68 */ |
| 64 Bindings.NetworkProject = class { | 69 Bindings.NetworkProject = class { |
| 65 /** | 70 /** |
| 66 * @param {!SDK.Target} target | 71 * @param {!SDK.Target} target |
| 67 * @param {!Workspace.Workspace} workspace | 72 * @param {!Workspace.Workspace} workspace |
| 68 * @param {?SDK.ResourceTreeModel} resourceTreeModel | 73 * @param {?SDK.ResourceTreeModel} resourceTreeModel |
| 69 */ | 74 */ |
| 70 constructor(target, workspace, resourceTreeModel) { | 75 constructor(target, workspace, resourceTreeModel) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 /** | 126 /** |
| 122 * @param {!SDK.Target} target | 127 * @param {!SDK.Target} target |
| 123 * @return {!Bindings.NetworkProject} | 128 * @return {!Bindings.NetworkProject} |
| 124 */ | 129 */ |
| 125 static forTarget(target) { | 130 static forTarget(target) { |
| 126 return target[Bindings.NetworkProject._networkProjectSymbol]; | 131 return target[Bindings.NetworkProject._networkProjectSymbol]; |
| 127 } | 132 } |
| 128 | 133 |
| 129 /** | 134 /** |
| 130 * @param {!Workspace.UISourceCode} uiSourceCode | 135 * @param {!Workspace.UISourceCode} uiSourceCode |
| 131 * @return {?Set<string>} | 136 * @param {string} frameId |
| 132 */ | 137 */ |
| 133 static frameAttribution(uiSourceCode) { | 138 static setInitialFrameAttribution(uiSourceCode, frameId) { |
|
dgozman
2017/05/11 23:55:15
Where is the "copy from" parameter?
lushnikov
2017/05/12 01:18:00
It's not needed until we migrate ResourceScriptMap
| |
| 134 var frameId = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; | 139 var attribution = new Map(); |
| 135 return frameId ? new Set([frameId]) : null; | 140 attribution.set(frameId, 1); |
| 141 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = attribution; | |
| 136 } | 142 } |
| 137 | 143 |
| 138 /** | 144 /** |
| 145 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 146 * @param {string} frameId | |
| 147 */ | |
| 148 static addFrameAttribution(uiSourceCode, frameId) { | |
| 149 var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributio nSymbol]; | |
| 150 var count = frameAttribution.get(frameId) || 0; | |
| 151 frameAttribution.set(frameId, count + 1); | |
| 152 if (count !== 0) | |
| 153 return; | |
| 154 | |
| 155 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); | |
| 156 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); | |
| 157 var frame = resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null ; | |
| 158 if (!frame) | |
| 159 return; | |
| 160 | |
| 161 var data = {uiSourceCode: uiSourceCode, added: frame, removed: null}; | |
| 162 Bindings.networkProjectManager.dispatchEventToListeners( | |
| 163 Bindings.NetworkProjectManager.Events.FrameAttributionChanged, data); | |
| 164 } | |
| 165 | |
| 166 /** | |
| 167 * @param {!Workspace.UISourceCode} uiSourceCode | |
| 168 * @param {string} frameId | |
| 169 */ | |
| 170 static removeFrameAttribution(uiSourceCode, frameId) { | |
| 171 var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributio nSymbol]; | |
| 172 var count = frameAttribution.get(frameId); | |
| 173 console.assert( | |
| 174 count, `Failed to remove frame attribution for url = ${uiSourceCode.url( )} and frameId = ${frameId}`); | |
|
dgozman
2017/05/11 23:55:16
This is slowing things down unnecessary.
lushnikov
2017/05/12 01:18:00
Done.
| |
| 175 frameAttribution.set(frameId, count - 1); | |
| 176 if (count !== 1) | |
| 177 return; | |
| 178 frameAttribution.delete(frameId); | |
| 179 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); | |
| 180 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); | |
| 181 var frame = resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null ; | |
| 182 if (!frame) | |
|
dgozman
2017/05/11 23:55:16
This is sketchy - you will not send a removed even
lushnikov
2017/05/12 01:18:00
Done.
| |
| 183 return; | |
| 184 | |
| 185 var data = {uiSourceCode: uiSourceCode, added: null, removed: frame}; | |
| 186 Bindings.networkProjectManager.dispatchEventToListeners( | |
| 187 Bindings.NetworkProjectManager.Events.FrameAttributionChanged, data); | |
| 188 } | |
| 189 | |
| 190 /** | |
| 139 * @param {!Workspace.UISourceCode} uiSourceCode | 191 * @param {!Workspace.UISourceCode} uiSourceCode |
| 140 * @return {?SDK.Target} target | 192 * @return {?SDK.Target} target |
| 141 */ | 193 */ |
| 142 static targetForUISourceCode(uiSourceCode) { | 194 static targetForUISourceCode(uiSourceCode) { |
| 143 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null ; | 195 return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null ; |
| 144 } | 196 } |
| 145 | 197 |
| 146 /** | 198 /** |
| 199 * @param {!Workspace.Project} project | |
| 200 * @param {!SDK.Target} target | |
| 201 */ | |
| 202 static setTargetForProject(project, target) { | |
| 203 project[Bindings.NetworkProject._targetSymbol] = target; | |
| 204 } | |
| 205 | |
| 206 /** | |
| 147 * @param {!Workspace.UISourceCode} uiSourceCode | 207 * @param {!Workspace.UISourceCode} uiSourceCode |
| 148 * @return {!Array<!SDK.ResourceTreeFrame>} | 208 * @return {!Array<!SDK.ResourceTreeFrame>} |
| 149 */ | 209 */ |
| 150 static framesForUISourceCode(uiSourceCode) { | 210 static framesForUISourceCode(uiSourceCode) { |
| 151 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); | 211 var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| 152 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); | 212 var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
| 153 var frameIds = Bindings.NetworkProject.frameAttribution(uiSourceCode); | 213 var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymb ol]; |
| 154 if (!resourceTreeModel || !frameIds) | 214 if (!resourceTreeModel || !attribution) |
| 155 return []; | 215 return []; |
| 156 var frames = Array.from(frameIds).map(frameId => resourceTreeModel.frameForI d(frameId)); | 216 var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel .frameForId(frameId)); |
| 157 return frames.filter(frame => !!frame); | 217 return frames.filter(frame => !!frame); |
| 158 } | 218 } |
| 159 | 219 |
| 160 /** | 220 /** |
| 161 * @param {!Workspace.UISourceCode} uiSourceCode | 221 * @param {!Workspace.UISourceCode} uiSourceCode |
| 162 * @return {string} | 222 * @return {string} |
| 163 */ | 223 */ |
| 164 static uiSourceCodeMimeType(uiSourceCode) { | 224 static uiSourceCodeMimeType(uiSourceCode) { |
| 165 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) | 225 if (uiSourceCode[Bindings.NetworkProject._scriptSymbol] || uiSourceCode[Bind ings.NetworkProject._styleSheetSymbol]) |
| 166 return uiSourceCode.contentType().canonicalMimeType(); | 226 return uiSourceCode.contentType().canonicalMimeType(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 186 return project; | 246 return project; |
| 187 | 247 |
| 188 project = new Bindings.ContentProviderBasedProject( | 248 project = new Bindings.ContentProviderBasedProject( |
| 189 this._workspace, projectId, projectType, '', false /* isServiceProject * /); | 249 this._workspace, projectId, projectType, '', false /* isServiceProject * /); |
| 190 project[Bindings.NetworkProject._targetSymbol] = this._target; | 250 project[Bindings.NetworkProject._targetSymbol] = this._target; |
| 191 this._workspaceProjects.set(projectId, project); | 251 this._workspaceProjects.set(projectId, project); |
| 192 return project; | 252 return project; |
| 193 } | 253 } |
| 194 | 254 |
| 195 /** | 255 /** |
| 196 * @param {!Common.ContentProvider} contentProvider | |
| 197 * @param {string} frameId | |
| 198 * @param {boolean} isContentScript | |
| 199 * @param {?number} contentSize | |
| 200 * @return {!Workspace.UISourceCode} | |
| 201 */ | |
| 202 addSourceMapFile(contentProvider, frameId, isContentScript, contentSize) { | |
| 203 var uiSourceCode = this._createFile(contentProvider, frameId, isContentScrip t || false); | |
| 204 var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeM etadata(null, contentSize) : null; | |
| 205 this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); | |
| 206 return uiSourceCode; | |
| 207 } | |
| 208 | |
| 209 /** | |
| 210 * @param {string} url | |
| 211 * @param {string} frameId | |
| 212 * @param {boolean} isContentScript | |
| 213 */ | |
| 214 removeSourceMapFile(url, frameId, isContentScript) { | |
| 215 this._removeFileForURL(url, frameId, isContentScript); | |
| 216 } | |
| 217 | |
| 218 /** | |
| 219 * @param {string} frameId | 256 * @param {string} frameId |
| 220 * @param {string} url | 257 * @param {string} url |
| 221 * @param {boolean} isContentScript | 258 * @param {boolean} isContentScript |
| 222 */ | 259 */ |
| 223 _removeFileForURL(url, frameId, isContentScript) { | 260 _removeFileForURL(url, frameId, isContentScript) { |
| 224 var project = | 261 var project = |
| 225 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); | 262 this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._targ et, frameId, isContentScript)); |
| 226 if (!project) | 263 if (!project) |
| 227 return; | 264 return; |
| 228 project.removeFile(url); | 265 project.removeFile(url); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 /** | 447 /** |
| 411 * @param {!Common.ContentProvider} contentProvider | 448 * @param {!Common.ContentProvider} contentProvider |
| 412 * @param {string} frameId | 449 * @param {string} frameId |
| 413 * @param {boolean} isContentScript | 450 * @param {boolean} isContentScript |
| 414 * @return {!Workspace.UISourceCode} | 451 * @return {!Workspace.UISourceCode} |
| 415 */ | 452 */ |
| 416 _createFile(contentProvider, frameId, isContentScript) { | 453 _createFile(contentProvider, frameId, isContentScript) { |
| 417 var url = contentProvider.contentURL(); | 454 var url = contentProvider.contentURL(); |
| 418 var project = this._workspaceProject(frameId, isContentScript); | 455 var project = this._workspaceProject(frameId, isContentScript); |
| 419 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); | 456 var uiSourceCode = project.createUISourceCode(url, contentProvider.contentTy pe()); |
| 420 uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; | 457 if (frameId) |
| 458 Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); | |
| 421 return uiSourceCode; | 459 return uiSourceCode; |
| 422 } | 460 } |
| 423 | 461 |
| 424 /** | 462 /** |
| 425 * @param {string} frameId | 463 * @param {string} frameId |
| 426 * @param {string} url | 464 * @param {string} url |
| 427 * @return {?Workspace.UISourceCodeMetadata} | 465 * @return {?Workspace.UISourceCodeMetadata} |
| 428 */ | 466 */ |
| 429 _fetchMetadata(frameId, url) { | 467 _fetchMetadata(frameId, url) { |
| 430 if (!this._resourceTreeModel) | 468 if (!this._resourceTreeModel) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 }; | 520 }; |
| 483 | 521 |
| 484 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); | 522 Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject'); |
| 485 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); | 523 Bindings.NetworkProject._resourceSymbol = Symbol('resource'); |
| 486 Bindings.NetworkProject._scriptSymbol = Symbol('script'); | 524 Bindings.NetworkProject._scriptSymbol = Symbol('script'); |
| 487 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); | 525 Bindings.NetworkProject._styleSheetSymbol = Symbol('styleSheet'); |
| 488 Bindings.NetworkProject._targetSymbol = Symbol('target'); | 526 Bindings.NetworkProject._targetSymbol = Symbol('target'); |
| 489 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); | 527 Bindings.NetworkProject._frameIdSymbol = Symbol('frameid'); |
| 490 | 528 |
| 491 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); | 529 Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProjec t._frameAttributionSymbol'); |
| OLD | NEW |