From 9f64da2c8abc047165236689fcf7538ca2134b1a Mon Sep 17 00:00:00 2001 From: dgozman Date: Mon, 5 Dec 2016 12:38:20 -0800 Subject: [PATCH] [DevTools] Introduce Project.isServiceProject method. This one is used instead of checking for specific project type. BUG=none Review-Url: https://codereview.chromium.org/2537223003 Cr-Commit-Position: refs/heads/master@{#436389} --- front_end/Tests.js | 2 +- front_end/bindings/CompilerScriptMapping.js | 4 ++-- front_end/bindings/ContentProviderBasedProject.js | 12 +++++++++++- front_end/bindings/DefaultScriptMapping.js | 3 ++- front_end/bindings/NetworkProject.js | 3 ++- front_end/bindings/ResourceScriptMapping.js | 4 ++-- .../persistence/FileSystemWorkspaceBinding.js | 8 ++++++++ front_end/snippets/ScriptSnippetModel.js | 2 +- front_end/sources/NavigatorView.js | 2 +- front_end/sources/OpenResourceDialog.js | 2 +- front_end/sources/ScriptFormatterEditorAction.js | 3 ++- front_end/sources/SourcesPanel.js | 2 +- front_end/sources/SourcesView.js | 2 +- front_end/sources/UISourceCodeFrame.js | 2 +- front_end/workspace/UISourceCode.js | 7 ------- front_end/workspace/Workspace.js | 14 +++++--------- 16 files changed, 41 insertions(+), 31 deletions(-) diff --git a/front_end/Tests.js b/front_end/Tests.js index 8ec346af5f..74afd92051 100644 --- a/front_end/Tests.js +++ b/front_end/Tests.js @@ -1003,7 +1003,7 @@ * @param {!Workspace.UISourceCode} uiSourceCode */ function filterOutService(uiSourceCode) { - return !uiSourceCode.isFromServiceProject(); + return !uiSourceCode.project().isServiceProject(); } var uiSourceCodes = Workspace.workspace.uiSourceCodes(); diff --git a/front_end/bindings/CompilerScriptMapping.js b/front_end/bindings/CompilerScriptMapping.js index 320eb1cdb6..085c4a467b 100644 --- a/front_end/bindings/CompilerScriptMapping.js +++ b/front_end/bindings/CompilerScriptMapping.js @@ -57,8 +57,8 @@ Bindings.CompilerScriptMapping = class { this._stubUISourceCodes = new Map(); var projectId = Bindings.CompilerScriptMapping.projectIdForTarget(this._target); - this._stubProject = - new Bindings.ContentProviderBasedProject(workspace, projectId, Workspace.projectTypes.Service, ''); + this._stubProject = new Bindings.ContentProviderBasedProject( + workspace, projectId, Workspace.projectTypes.Service, '', true /* isServiceProject */); this._eventListeners = [ workspace.addEventListener( Workspace.Workspace.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this), diff --git a/front_end/bindings/ContentProviderBasedProject.js b/front_end/bindings/ContentProviderBasedProject.js index 4bb95ea70e..3e5a1ea1a1 100644 --- a/front_end/bindings/ContentProviderBasedProject.js +++ b/front_end/bindings/ContentProviderBasedProject.js @@ -38,11 +38,13 @@ Bindings.ContentProviderBasedProject = class extends Workspace.ProjectStore { * @param {string} id * @param {!Workspace.projectTypes} type * @param {string} displayName + * @param {boolean} isServiceProject */ - constructor(workspace, id, type, displayName) { + constructor(workspace, id, type, displayName, isServiceProject) { super(workspace, id, type, displayName); /** @type {!Object.} */ this._contentProviders = {}; + this._isServiceProject = isServiceProject; workspace.addProject(this); } @@ -56,6 +58,14 @@ Bindings.ContentProviderBasedProject = class extends Workspace.ProjectStore { contentProvider.requestContent().then(callback); } + /** + * @override + * @return {boolean} + */ + isServiceProject() { + return this._isServiceProject; + } + /** * @override * @param {!Workspace.UISourceCode} uiSourceCode diff --git a/front_end/bindings/DefaultScriptMapping.js b/front_end/bindings/DefaultScriptMapping.js index 8e8f028758..095aafcebb 100644 --- a/front_end/bindings/DefaultScriptMapping.js +++ b/front_end/bindings/DefaultScriptMapping.js @@ -41,7 +41,8 @@ Bindings.DefaultScriptMapping = class { this._debuggerModel = debuggerModel; this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; var projectId = Bindings.DefaultScriptMapping.projectIdForTarget(debuggerModel.target()); - this._project = new Bindings.ContentProviderBasedProject(workspace, projectId, Workspace.projectTypes.Debugger, ''); + this._project = new Bindings.ContentProviderBasedProject( + workspace, projectId, Workspace.projectTypes.Debugger, '', true /* isServiceProject */); /** @type {!Map.} */ this._uiSourceCodeForScriptId = new Map(); /** @type {!Map.} */ diff --git a/front_end/bindings/NetworkProject.js b/front_end/bindings/NetworkProject.js index fce722668c..e75c0456c1 100644 --- a/front_end/bindings/NetworkProject.js +++ b/front_end/bindings/NetworkProject.js @@ -173,7 +173,8 @@ Bindings.NetworkProject = class extends SDK.SDKObject { if (project) return project; - project = new Bindings.ContentProviderBasedProject(this._workspace, projectId, projectType, ''); + project = new Bindings.ContentProviderBasedProject( + this._workspace, projectId, projectType, '', false /* isServiceProject */); project[Bindings.NetworkProject._targetSymbol] = this.target(); project[Bindings.NetworkProject._frameSymbol] = frame; this._workspaceProjects.set(projectId, project); diff --git a/front_end/bindings/ResourceScriptMapping.js b/front_end/bindings/ResourceScriptMapping.js index ef706d1e8a..29e7dcd0a5 100644 --- a/front_end/bindings/ResourceScriptMapping.js +++ b/front_end/bindings/ResourceScriptMapping.js @@ -154,7 +154,7 @@ Bindings.ResourceScriptMapping = class { */ _uiSourceCodeAdded(event) { var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); - if (uiSourceCode.isFromServiceProject()) + if (uiSourceCode.project().isServiceProject()) return; var scripts = this._scriptsForUISourceCode(uiSourceCode); if (!scripts.length) @@ -168,7 +168,7 @@ Bindings.ResourceScriptMapping = class { */ _uiSourceCodeRemoved(event) { var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data); - if (uiSourceCode.isFromServiceProject() || !this._boundUISourceCodes.has(uiSourceCode)) + if (uiSourceCode.project().isServiceProject() || !this._boundUISourceCodes.has(uiSourceCode)) return; this._unbindUISourceCode(uiSourceCode); diff --git a/front_end/persistence/FileSystemWorkspaceBinding.js b/front_end/persistence/FileSystemWorkspaceBinding.js index a867498f35..8091642beb 100644 --- a/front_end/persistence/FileSystemWorkspaceBinding.js +++ b/front_end/persistence/FileSystemWorkspaceBinding.js @@ -227,6 +227,14 @@ Persistence.FileSystemWorkspaceBinding.FileSystem = class extends Workspace.Proj return uiSourceCode.url().substring(this._fileSystemPath.length); } + /** + * @override + * @return {boolean} + */ + isServiceProject() { + return false; + } + /** * @override * @param {!Workspace.UISourceCode} uiSourceCode diff --git a/front_end/snippets/ScriptSnippetModel.js b/front_end/snippets/ScriptSnippetModel.js index f33e26cae7..0dc5259fff 100644 --- a/front_end/snippets/ScriptSnippetModel.js +++ b/front_end/snippets/ScriptSnippetModel.js @@ -552,7 +552,7 @@ Snippets.SnippetsProject = class extends Bindings.ContentProviderBasedProject { * @param {!Snippets.ScriptSnippetModel} model */ constructor(workspace, model) { - super(workspace, 'snippets:', Workspace.projectTypes.Snippets, ''); + super(workspace, 'snippets:', Workspace.projectTypes.Snippets, '', false /* isServiceProject */); this._model = model; } diff --git a/front_end/sources/NavigatorView.js b/front_end/sources/NavigatorView.js index 2ef3d1cf0a..defaecff99 100644 --- a/front_end/sources/NavigatorView.js +++ b/front_end/sources/NavigatorView.js @@ -236,7 +236,7 @@ Sources.NavigatorView = class extends UI.VBox { * @return {boolean} */ accept(uiSourceCode) { - return !uiSourceCode.isFromServiceProject(); + return !uiSourceCode.project().isServiceProject(); } /** diff --git a/front_end/sources/OpenResourceDialog.js b/front_end/sources/OpenResourceDialog.js index fdc7f3bf7b..f9baca446b 100644 --- a/front_end/sources/OpenResourceDialog.js +++ b/front_end/sources/OpenResourceDialog.js @@ -61,7 +61,7 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListDeleg * @return {boolean} */ filterProject(project) { - return !Workspace.Project.isServiceProject(project); + return !project.isServiceProject(); } /** diff --git a/front_end/sources/ScriptFormatterEditorAction.js b/front_end/sources/ScriptFormatterEditorAction.js index 80d29525dc..1576286602 100644 --- a/front_end/sources/ScriptFormatterEditorAction.js +++ b/front_end/sources/ScriptFormatterEditorAction.js @@ -104,7 +104,8 @@ Sources.ScriptFormatterEditorAction = class { constructor() { this._projectId = 'formatter:'; this._project = new Bindings.ContentProviderBasedProject( - Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter'); + Workspace.workspace, this._projectId, Workspace.projectTypes.Formatter, 'formatter', + true /* isServiceProject */); /** @type {!Map.} */ this._uiSourceCodes = new Map(); diff --git a/front_end/sources/SourcesPanel.js b/front_end/sources/SourcesPanel.js index 8ac011af62..1508ed0382 100644 --- a/front_end/sources/SourcesPanel.js +++ b/front_end/sources/SourcesPanel.js @@ -831,7 +831,7 @@ Sources.SourcesPanel = class extends UI.Panel { return; var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (target); - if (!uiSourceCode.isFromServiceProject() && + if (!uiSourceCode.project().isServiceProject() && !event.target.isSelfOrDescendant(this._navigatorTabbedLocation.widget().element)) { contextMenu.appendItem( Common.UIString.capitalize('Reveal in ^navigator'), this._handleContextMenuReveal.bind(this, uiSourceCode)); diff --git a/front_end/sources/SourcesView.js b/front_end/sources/SourcesView.js index 030602f53d..b6f88160ef 100644 --- a/front_end/sources/SourcesView.js +++ b/front_end/sources/SourcesView.js @@ -253,7 +253,7 @@ Sources.SourcesView = class extends UI.VBox { * @param {!Workspace.UISourceCode} uiSourceCode */ _addUISourceCode(uiSourceCode) { - if (uiSourceCode.isFromServiceProject()) + if (uiSourceCode.project().isServiceProject()) return; this._editorContainer.addUISourceCode(uiSourceCode); } diff --git a/front_end/sources/UISourceCodeFrame.js b/front_end/sources/UISourceCodeFrame.js index 6da0f29cf8..1693e31c5a 100644 --- a/front_end/sources/UISourceCodeFrame.js +++ b/front_end/sources/UISourceCodeFrame.js @@ -156,7 +156,7 @@ Sources.UISourceCodeFrame = class extends SourceFrame.SourceFrame { return true; if (this._uiSourceCode.project().canSetFileContent()) return true; - if (this._uiSourceCode.isFromServiceProject()) + if (this._uiSourceCode.project().isServiceProject()) return false; return this._uiSourceCode.contentType() !== Common.resourceTypes.Document; } diff --git a/front_end/workspace/UISourceCode.js b/front_end/workspace/UISourceCode.js index 176fa8e392..13276a2301 100644 --- a/front_end/workspace/UISourceCode.js +++ b/front_end/workspace/UISourceCode.js @@ -132,13 +132,6 @@ Workspace.UISourceCode = class extends Common.Object { return skipTrim ? name : name.trimEnd(100); } - /** - * @return {boolean} - */ - isFromServiceProject() { - return Workspace.Project.isServiceProject(this._project); - } - /** * @return {boolean} */ diff --git a/front_end/workspace/Workspace.js b/front_end/workspace/Workspace.js index d908fd9d48..35c15398b4 100644 --- a/front_end/workspace/Workspace.js +++ b/front_end/workspace/Workspace.js @@ -65,15 +65,6 @@ Workspace.ProjectSearchConfig.prototype = { */ Workspace.Project = function() {}; -/** - * @param {!Workspace.Project} project - * @return {boolean} - */ -Workspace.Project.isServiceProject = function(project) { - return project.type() === Workspace.projectTypes.Debugger || project.type() === Workspace.projectTypes.Formatter || - project.type() === Workspace.projectTypes.Service; -}; - Workspace.Project.prototype = { /** * @return {!Workspace.Workspace} @@ -90,6 +81,11 @@ Workspace.Project.prototype = { */ type() {}, + /** + * @return {boolean} + */ + isServiceProject() {}, + /** * @return {string} */