| 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..35e44e96ce718e8312c392fabd0a1f0d454a357d 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,11 @@ Bindings.NetworkProjectManager = class {
|
| }
|
| };
|
|
|
| +Bindings.NetworkProjectManager.Events = {
|
| + FrameAttributionAdded: Symbol('FrameAttributionAdded'),
|
| + FrameAttributionRemoved: Symbol('FrameAttributionRemoved')
|
| +};
|
| +
|
| /**
|
| * @unrestricted
|
| */
|
| @@ -128,11 +134,62 @@ Bindings.NetworkProject = class {
|
|
|
| /**
|
| * @param {!Workspace.UISourceCode} uiSourceCode
|
| - * @return {?Set<string>}
|
| + * @param {string} frameId
|
| + */
|
| + static _resolveFrame(uiSourceCode, frameId) {
|
| + var target = Bindings.NetworkProject.targetForUISourceCode(uiSourceCode);
|
| + var resourceTreeModel = target && target.model(SDK.ResourceTreeModel);
|
| + return resourceTreeModel ? resourceTreeModel.frameForId(frameId) : null;
|
| + }
|
| +
|
| + /**
|
| + * @param {!Workspace.UISourceCode} uiSourceCode
|
| + * @param {string} frameId
|
| + */
|
| + static setInitialFrameAttribution(uiSourceCode, frameId) {
|
| + var frame = Bindings.NetworkProject._resolveFrame(uiSourceCode, frameId);
|
| + if (!frame)
|
| + return;
|
| + var attribution = new Map();
|
| + attribution.set(frameId, {frame: frame, count: 1});
|
| + uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol] = attribution;
|
| + }
|
| +
|
| + /**
|
| + * @param {!Workspace.UISourceCode} uiSourceCode
|
| + * @param {string} frameId
|
| */
|
| - static frameAttribution(uiSourceCode) {
|
| - var frameId = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol];
|
| - return frameId ? new Set([frameId]) : null;
|
| + static addFrameAttribution(uiSourceCode, frameId) {
|
| + var frame = Bindings.NetworkProject._resolveFrame(uiSourceCode, frameId);
|
| + if (!frame)
|
| + return;
|
| + var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol];
|
| + var attributionInfo = frameAttribution.get(frameId) || {frame: frame, count: 0};
|
| + attributionInfo.count += 1;
|
| + frameAttribution.set(frameId, attributionInfo);
|
| + if (attributionInfo.count !== 1)
|
| + return;
|
| +
|
| + var data = {uiSourceCode: uiSourceCode, frame: frame};
|
| + Bindings.networkProjectManager.dispatchEventToListeners(
|
| + Bindings.NetworkProjectManager.Events.FrameAttributionAdded, data);
|
| + }
|
| +
|
| + /**
|
| + * @param {!Workspace.UISourceCode} uiSourceCode
|
| + * @param {string} frameId
|
| + */
|
| + static removeFrameAttribution(uiSourceCode, frameId) {
|
| + var frameAttribution = uiSourceCode[Bindings.NetworkProject._frameAttributionSymbol];
|
| + var attributionInfo = frameAttribution.get(frameId);
|
| + console.assert(attributionInfo, 'Failed to remove frame attribution for url: ' + uiSourceCode.url());
|
| + attributionInfo.count -= 1;
|
| + if (attributionInfo.count > 0)
|
| + return;
|
| + frameAttribution.delete(frameId);
|
| + var data = {uiSourceCode: uiSourceCode, frame: attributionInfo.frame};
|
| + Bindings.networkProjectManager.dispatchEventToListeners(
|
| + Bindings.NetworkProjectManager.Events.FrameAttributionRemoved, data);
|
| }
|
|
|
| /**
|
| @@ -143,6 +200,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 +215,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 +257,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 +459,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;
|
| }
|
|
|
|
|