Skip to content

Commit

Permalink
[DevTools] Introduce Project.isServiceProject method.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
dgozman authored and Commit bot committed Dec 5, 2016
1 parent 2eee2aa commit 9f64da2
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 31 deletions.
2 changes: 1 addition & 1 deletion front_end/Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@
* @param {!Workspace.UISourceCode} uiSourceCode
*/
function filterOutService(uiSourceCode) {
return !uiSourceCode.isFromServiceProject();
return !uiSourceCode.project().isServiceProject();
}

var uiSourceCodes = Workspace.workspace.uiSourceCodes();
Expand Down
4 changes: 2 additions & 2 deletions front_end/bindings/CompilerScriptMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 11 additions & 1 deletion front_end/bindings/ContentProviderBasedProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, !Common.ContentProvider>} */
this._contentProviders = {};
this._isServiceProject = isServiceProject;
workspace.addProject(this);
}

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion front_end/bindings/DefaultScriptMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, !Workspace.UISourceCode>} */
this._uiSourceCodeForScriptId = new Map();
/** @type {!Map.<!Workspace.UISourceCode, string>} */
Expand Down
3 changes: 2 additions & 1 deletion front_end/bindings/NetworkProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions front_end/bindings/ResourceScriptMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions front_end/persistence/FileSystemWorkspaceBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion front_end/snippets/ScriptSnippetModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion front_end/sources/NavigatorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Sources.NavigatorView = class extends UI.VBox {
* @return {boolean}
*/
accept(uiSourceCode) {
return !uiSourceCode.isFromServiceProject();
return !uiSourceCode.project().isServiceProject();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion front_end/sources/OpenResourceDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Sources.OpenResourceDialog = class extends Sources.FilteredUISourceCodeListDeleg
* @return {boolean}
*/
filterProject(project) {
return !Workspace.Project.isServiceProject(project);
return !project.isServiceProject();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion front_end/sources/ScriptFormatterEditorAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<!SDK.Script, !Workspace.UISourceCode>} */
this._uiSourceCodes = new Map();
Expand Down
2 changes: 1 addition & 1 deletion front_end/sources/SourcesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion front_end/sources/SourcesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion front_end/sources/UISourceCodeFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 0 additions & 7 deletions front_end/workspace/UISourceCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
14 changes: 5 additions & 9 deletions front_end/workspace/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -90,6 +81,11 @@ Workspace.Project.prototype = {
*/
type() {},

/**
* @return {boolean}
*/
isServiceProject() {},

/**
* @return {string}
*/
Expand Down

0 comments on commit 9f64da2

Please sign in to comment.