Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1135)

Unified Diff: third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js

Issue 2958403002: [WIP] DevTools: move UISourceCode creation into ResourceScriptMapping
Patch Set: pass everything but breakpointmanager Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 cac03cf1cb3433759881431e237df0d1c9d51464..2268d7a69ccafa3eaec08737349c33240af63270 100644
--- a/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js
+++ b/third_party/WebKit/Source/devtools/front_end/bindings/NetworkProject.js
@@ -28,35 +28,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
- * @implements {SDK.TargetManager.Observer}
* @unrestricted
*/
Bindings.NetworkProjectManager = class extends Common.Object {
- /**
- * @param {!SDK.TargetManager} targetManager
- * @param {!Workspace.Workspace} workspace
- */
- constructor(targetManager, workspace) {
- super();
- this._workspace = workspace;
- targetManager.observeTargets(this);
- }
-
- /**
- * @override
- * @param {!SDK.Target} target
- */
- targetAdded(target) {
- new Bindings.NetworkProject(target, this._workspace);
- }
-
- /**
- * @override
- * @param {!SDK.Target} target
- */
- targetRemoved(target) {
- Bindings.NetworkProject.forTarget(target)._dispose();
- }
};
Bindings.NetworkProjectManager.Events = {
@@ -68,54 +42,6 @@ Bindings.NetworkProjectManager.Events = {
* @unrestricted
*/
Bindings.NetworkProject = class {
- /**
- * @param {!SDK.Target} target
- * @param {!Workspace.Workspace} workspace
- */
- constructor(target, workspace) {
- this._target = target;
- this._workspace = workspace;
- /** @type {!Map<string, !Bindings.ContentProviderBasedProject>} */
- this._workspaceProjects = new Map();
- target[Bindings.NetworkProject._networkProjectSymbol] = this;
-
- this._eventListeners = [];
-
- this._debuggerModel = target.model(SDK.DebuggerModel);
- /** @type {!Set<!SDK.Script>} */
- this._acceptedScripts = new Set();
- if (this._debuggerModel) {
- var runtimeModel = this._debuggerModel.runtimeModel();
- this._eventListeners.push(
- runtimeModel.addEventListener(
- SDK.RuntimeModel.Events.ExecutionContextDestroyed, this._executionContextDestroyed, this),
- this._debuggerModel.addEventListener(
- SDK.DebuggerModel.Events.GlobalObjectCleared, this._globalObjectCleared, this),
- this._debuggerModel.addEventListener(
- SDK.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this),
- this._debuggerModel.addEventListener(
- SDK.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSource, this));
- }
- }
-
- /**
- * @param {!SDK.Target} target
- * @param {string} frameId
- * @param {boolean} isContentScripts
- * @return {string}
- */
- static projectId(target, frameId, isContentScripts) {
- return target.id() + ':' + frameId + ':' + (isContentScripts ? 'contentscripts' : '');
- }
-
- /**
- * @param {!SDK.Target} target
- * @return {!Bindings.NetworkProject}
- */
- static forTarget(target) {
- return target[Bindings.NetworkProject._networkProjectSymbol];
- }
-
/**
* @param {!Workspace.UISourceCode} uiSourceCode
* @param {string} frameId
@@ -205,158 +131,7 @@ Bindings.NetworkProject = class {
var frames = Array.from(attribution.keys()).map(frameId => resourceTreeModel.frameForId(frameId));
return frames.filter(frame => !!frame);
}
-
- /**
- * @param {string} frameId
- * @param {boolean} isContentScripts
- * @return {!Bindings.ContentProviderBasedProject}
- */
- _workspaceProject(frameId, isContentScripts) {
- var projectId = Bindings.NetworkProject.projectId(this._target, frameId, isContentScripts);
- var projectType = isContentScripts ? Workspace.projectTypes.ContentScripts : Workspace.projectTypes.Network;
-
- var project = this._workspaceProjects.get(projectId);
- if (project)
- return project;
-
- project = new Bindings.ContentProviderBasedProject(
- this._workspace, projectId, projectType, '', false /* isServiceProject */);
- project[Bindings.NetworkProject._targetSymbol] = this._target;
- this._workspaceProjects.set(projectId, project);
- return project;
- }
-
- /**
- * @param {string} frameId
- * @param {string} url
- * @param {boolean} isContentScript
- */
- _removeFileForURL(url, frameId, isContentScript) {
- var project =
- this._workspaceProjects.get(Bindings.NetworkProject.projectId(this._target, frameId, isContentScript));
- if (!project)
- return;
- project.removeFile(url);
- }
-
- /**
- * @param {!Workspace.UISourceCode} uiSourceCode
- * @param {!Common.ContentProvider} contentProvider
- * @param {?Workspace.UISourceCodeMetadata} metadata
- * @param {string} mimeType
- */
- _addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata, mimeType) {
- /** @type {!Bindings.ContentProviderBasedProject} */ (uiSourceCode.project())
- .addUISourceCodeWithProvider(uiSourceCode, contentProvider, metadata, mimeType);
- }
-
- /**
- * @param {!SDK.Script} script
- * @return {boolean}
- */
- _acceptsScript(script) {
- if (!script.sourceURL || script.isLiveEdit() || (script.isInlineScript() && !script.hasSourceURL))
- return false;
- // Filter out embedder injected content scripts.
- if (script.isContentScript() && !script.hasSourceURL) {
- var parsedURL = new Common.ParsedURL(script.sourceURL);
- if (!parsedURL.isValid)
- return false;
- }
- return true;
- }
-
- /**
- * @param {!Common.Event} event
- */
- _parsedScriptSource(event) {
- var script = /** @type {!SDK.Script} */ (event.data);
- if (!this._acceptsScript(script))
- return;
- this._acceptedScripts.add(script);
- var originalContentProvider = script.originalContentProvider();
- var frameId = Bindings.frameIdForScript(script);
- script[Bindings.NetworkProject._frameIdSymbol] = frameId;
- var uiSourceCode = this._createFile(originalContentProvider, frameId, script.isContentScript());
- var metadata = Bindings.metadataForURL(this._target, frameId, uiSourceCode.url());
- this._addUISourceCodeWithProvider(uiSourceCode, originalContentProvider, metadata, 'text/javascript');
- }
-
- /**
- * @param {!Common.Event} event
- */
- _executionContextDestroyed(event) {
- var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
- var scripts = this._debuggerModel.scriptsForExecutionContext(executionContext);
- this._removeScripts(scripts);
- }
-
- /**
- * @param {!Array<!SDK.Script>} scripts
- */
- _removeScripts(scripts) {
- for (var script of scripts) {
- if (!this._acceptedScripts.has(script))
- continue;
- this._acceptedScripts.delete(script);
- var frameId = script[Bindings.NetworkProject._frameIdSymbol];
- this._removeFileForURL(script.contentURL(), frameId, script.isContentScript());
- }
- }
-
- /**
- * @param {!Common.Event} event
- */
- _globalObjectCleared(event) {
- this._removeScripts(Array.from(this._acceptedScripts));
- }
-
- /**
- * @param {!Common.ContentProvider} contentProvider
- * @param {string} frameId
- * @param {boolean} isContentScript
- * @return {!Workspace.UISourceCode}
- */
- _createFile(contentProvider, frameId, isContentScript) {
- var url = contentProvider.contentURL();
- var project = this._workspaceProject(frameId, isContentScript);
- var uiSourceCode = project.createUISourceCode(url, contentProvider.contentType());
- if (frameId)
- Bindings.NetworkProject.setInitialFrameAttribution(uiSourceCode, frameId);
- return uiSourceCode;
- }
-
- _dispose() {
- for (var project of this._workspaceProjects.values())
- project.removeProject();
- Common.EventTarget.removeEventListeners(this._eventListeners);
- delete this._target[Bindings.NetworkProject._networkProjectSymbol];
- this._workspaceProjects.clear();
- }
-
- _resetForTest() {
- for (var project of this._workspaceProjects.values())
- project.removeProject();
- this._workspaceProjects.clear();
- }
-
- /**
- * @param {!Workspace.Workspace} workspace
- * @param {string} url
- * @param {!SDK.Script} script
- * @return {?Workspace.UISourceCode}
- */
- static uiSourceCodeForScriptURL(workspace, url, script) {
- var target = script.debuggerModel.target();
- var executionContext = script.executionContext();
- var frameId = executionContext ? executionContext.frameId || '' : '';
- return workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId, false), url) ||
- workspace.uiSourceCode(Bindings.NetworkProject.projectId(target, frameId, true), url);
- }
};
-Bindings.NetworkProject._networkProjectSymbol = Symbol('networkProject');
Bindings.NetworkProject._targetSymbol = Symbol('target');
-Bindings.NetworkProject._frameIdSymbol = Symbol('frameid');
-
Bindings.NetworkProject._frameAttributionSymbol = Symbol('Bindings.NetworkProject._frameAttributionSymbol');

Powered by Google App Engine
This is Rietveld 408576698