Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js b/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js |
| index 4c288b061890f851cb9fb31f0ed52449e5611ea2..e44d4561bfe65875c047dc5a7e4c3abb0cc8a75c 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js |
| @@ -31,12 +31,13 @@ |
| * @implements {SDK.TargetManager.Observer} |
| * @unrestricted |
| */ |
| -Bindings.NetworkProjectManager = class { |
| +Bindings.NetworkProjectManager = class extends Common.Object { |
| /** |
| * @param {!SDK.TargetManager} targetManager |
| * @param {!Workspace.Workspace} workspace |
| */ |
| constructor(targetManager, workspace) { |
| + super(); |
| this._workspace = workspace; |
| targetManager.observeTargets(this); |
| } |
| @@ -58,6 +59,10 @@ Bindings.NetworkProjectManager = class { |
| } |
| }; |
| +Bindings.NetworkProjectManager.Events = { |
| + FrameAttributionChanged: Symbol('FrameAttributionChanged') |
|
dgozman
2017/05/11 23:55:16
Make it two events.
lushnikov
2017/05/12 01:18:00
Done.
|
| +}; |
| + |
| /** |
| * @unrestricted |
| */ |
| @@ -128,11 +133,58 @@ Bindings.NetworkProject = class { |
| /** |
| * @param {!Workspace.UISourceCode} uiSourceCode |
| - * @return {?Set<string>} |
| + * @param {string} frameId |
| */ |
| - static frameAttribution(uiSourceCode) { |
| - var frameId = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; |
| - return frameId ? new Set([frameId]) : null; |
| + 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
|
| + var attribution = new Map(); |
| + attribution.set(frameId, 1); |
| + uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = attribution; |
| + } |
| + |
| + /** |
| + * @param {!Workspace.UISourceCode} uiSourceCode |
| + * @param {string} frameId |
| + */ |
| + static addFrameAttribution(uiSourceCode, frameId) { |
| + var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; |
| + var count = frameAttribution.get(frameId) || 0; |
| + frameAttribution.set(frameId, count + 1); |
| + if (count !== 0) |
| + return; |
| + |
| + var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| + var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
| + var frame = resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null; |
| + if (!frame) |
| + return; |
| + |
| + var data = {uiSourceCode: uiSourceCode, added: frame, removed: null}; |
| + Bindings.networkProjectManager.dispatchEventToListeners( |
| + Bindings.NetworkProjectManager.Events.FrameAttributionChanged, data); |
| + } |
| + |
| + /** |
| + * @param {!Workspace.UISourceCode} uiSourceCode |
| + * @param {string} frameId |
| + */ |
| + static removeFrameAttribution(uiSourceCode, frameId) { |
| + var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; |
| + var count = frameAttribution.get(frameId); |
| + console.assert( |
| + 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.
|
| + frameAttribution.set(frameId, count - 1); |
| + if (count !== 1) |
| + return; |
| + frameAttribution.delete(frameId); |
| + var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| + var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
| + var frame = resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null; |
| + 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.
|
| + return; |
| + |
| + var data = {uiSourceCode: uiSourceCode, added: null, removed: frame}; |
| + Bindings.networkProjectManager.dispatchEventToListeners( |
| + Bindings.NetworkProjectManager.Events.FrameAttributionChanged, data); |
| } |
| /** |
| @@ -143,6 +195,14 @@ Bindings.NetworkProject = class { |
| return uiSourceCode.project()[Bindings.NetworkProject._targetSymbol] || null; |
| } |
| + /** |
| + * @param {!Workspace.Project} project |
| + * @param {!SDK.Target} target |
| + */ |
| + static setTargetForProject(project, target) { |
| + project[Bindings.NetworkProject._targetSymbol] = target; |
| + } |
| + |
| /** |
| * @param {!Workspace.UISourceCode} uiSourceCode |
| * @return {!Array<!SDK.ResourceTreeFrame>} |
| @@ -150,10 +210,10 @@ Bindings.NetworkProject = class { |
| static framesForUISourceCode(uiSourceCode) { |
| var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode); |
| var resourceTreeModel = target && target.model(SDK.ResourceTreeModel); |
| - var frameIds = Bindings.NetworkProject.frameAttribution(uiSourceCode); |
| - if (!resourceTreeModel || !frameIds) |
| + var attribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol]; |
| + if (!resourceTreeModel || !attribution) |
| return []; |
| - var frames = Array.from(frameIds).map(frameId => resourceTreeModel.frameForId(frameId)); |
| + var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel.frameForId(frameId)); |
| return frames.filter(frame => !!frame); |
| } |
| @@ -192,29 +252,6 @@ Bindings.NetworkProject = class { |
| return project; |
| } |
| - /** |
| - * @param {!Common.ContentProvider} contentProvider |
| - * @param {string} frameId |
| - * @param {boolean} isContentScript |
| - * @param {?number} contentSize |
| - * @return {!Workspace.UISourceCode} |
| - */ |
| - addSourceMapFile(contentProvider, frameId, isContentScript, contentSize) { |
| - var uiSourceCode = this._createFile(contentProvider, frameId, isContentScript || false); |
| - var metadata = typeof contentSize === 'number' ? new Workspace.UISourceCodeMetadata(null, contentSize) : null; |
| - this._addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata); |
| - 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 |
| @@ -417,7 +454,8 @@ Bindings.NetworkProject = class { |
| var url = contentProvider.contentURL(); |
| var project = this._workspaceProject(frameId, isContentScript); |
| var uiSourceCode = project.createUISourceCode(url, contentProvider.contentType()); |
| - uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = frameId; |
| + if (frameId) |
| + Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId); |
| return uiSourceCode; |
| } |