2
* Copyright (C) 2012 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are
8
* * Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* * Redistributions in binary form must reproduce the above
11
* copyright notice, this list of conditions and the following disclaimer
12
* in the documentation and/or other materials provided with the
14
* * Neither the name of Google Inc. nor the names of its
15
* contributors may be used to endorse or promote products derived from
16
* this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
WebInspector.WorkspaceController = function(workspace)
36
this._workspace = workspace;
37
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
38
WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
41
WebInspector.WorkspaceController.prototype = {
42
_mainFrameNavigated: function()
44
WebInspector.Revision.filterOutStaleRevisions();
45
this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset, this._workspace.project());
46
this._workspace.project().reset();
47
this._workspace.reset();
48
this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectDidReset, this._workspace.project());
51
_frameAdded: function(event)
53
var frame = /** @type {WebInspector.ResourceTreeFrame} */ (event.data);
54
if (frame.isMainFrame())
55
WebInspector.Revision.filterOutStaleRevisions();
61
* @param {string} path
62
* @param {WebInspector.ResourceType} contentType
63
* @param {boolean} isEditable
64
* @param {boolean=} isContentScript
65
* @param {boolean=} isSnippet
67
WebInspector.FileDescriptor = function(path, contentType, isEditable, isContentScript, isSnippet)
70
this.contentType = contentType;
71
this.isEditable = isEditable;
72
this.isContentScript = isContentScript || false;
73
this.isSnippet = isSnippet || false;
79
WebInspector.WorkspaceProvider = function() { }
81
WebInspector.WorkspaceProvider.Events = {
82
FileAdded: "FileAdded",
83
FileRemoved: "FileRemoved"
86
WebInspector.WorkspaceProvider.prototype = {
88
* @param {string} path
89
* @param {function(?string,boolean,string)} callback
91
requestFileContent: function(path, callback) { },
94
* @param {string} query
95
* @param {boolean} caseSensitive
96
* @param {boolean} isRegex
97
* @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
99
searchInFileContent: function(path, query, caseSensitive, isRegex, callback) { },
102
* @param {string} eventType
103
* @param {function(WebInspector.Event)} listener
104
* @param {Object=} thisObject
106
addEventListener: function(eventType, listener, thisObject) { },
109
* @param {string} eventType
110
* @param {function(WebInspector.Event)} listener
111
* @param {Object=} thisObject
113
removeEventListener: function(eventType, listener, thisObject) { }
117
* @type {?WebInspector.WorkspaceController}
119
WebInspector.workspaceController = null;
122
* @param {WebInspector.Workspace} workspace
123
* @param {WebInspector.WorkspaceProvider} workspaceProvider
126
WebInspector.Project = function(workspace, workspaceProvider)
128
this._uiSourceCodes = [];
129
this._workspace = workspace;
130
this._workspaceProvider = workspaceProvider;
131
this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileAdded, this._fileAdded, this);
132
this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileRemoved, this._fileRemoved, this);
135
WebInspector.Project.prototype = {
138
this._workspaceProvider.reset();
139
this._uiSourceCodes = [];
142
_fileAdded: function(event)
144
var fileDescriptor = /** @type {WebInspector.FileDescriptor} */ (event.data);
145
var uiSourceCode = this.uiSourceCodeForURL(fileDescriptor.path);
150
uiSourceCode = new WebInspector.UISourceCode(this._workspace, fileDescriptor.path, fileDescriptor.contentType, fileDescriptor.isEditable);
151
uiSourceCode.isContentScript = fileDescriptor.isContentScript;
152
uiSourceCode.isSnippet = fileDescriptor.isSnippet;
153
this._uiSourceCodes.push(uiSourceCode);
154
this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
157
_fileRemoved: function(event)
159
var path = /** @type {string} */ (event.data);
160
var uiSourceCode = this.uiSourceCodeForURL(path);
163
this._uiSourceCodes.splice(this._uiSourceCodes.indexOf(uiSourceCode), 1);
164
this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, uiSourceCode);
168
* @param {string} url
169
* @return {?WebInspector.UISourceCode}
171
uiSourceCodeForURL: function(url)
173
for (var i = 0; i < this._uiSourceCodes.length; ++i) {
174
if (this._uiSourceCodes[i].url === url)
175
return this._uiSourceCodes[i];
181
* @return {Array.<WebInspector.UISourceCode>}
183
uiSourceCodes: function()
185
return this._uiSourceCodes;
189
* @param {string} path
190
* @param {function(?string,boolean,string)} callback
192
requestFileContent: function(path, callback)
194
this._workspaceProvider.requestFileContent(path, callback);
198
* @param {string} query
199
* @param {boolean} caseSensitive
200
* @param {boolean} isRegex
201
* @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
203
searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
205
this._workspaceProvider.searchInFileContent(path, query, caseSensitive, isRegex, callback);
211
* @implements {WebInspector.UISourceCodeProvider}
212
* @extends {WebInspector.Object}
214
WebInspector.Workspace = function()
216
/** @type {Object.<string, WebInspector.ContentProvider>} */
217
this._temporaryContentProviders = new Map();
220
WebInspector.Workspace.Events = {
221
UISourceCodeContentCommitted: "UISourceCodeContentCommitted",
222
ProjectWillReset: "ProjectWillReset",
223
ProjectDidReset: "ProjectDidReset"
226
WebInspector.Workspace.prototype = {
228
* @param {string} url
229
* @return {?WebInspector.UISourceCode}
231
uiSourceCodeForURL: function(url)
233
return this._project.uiSourceCodeForURL(url);
237
* @param {string} projectName
238
* @param {WebInspector.WorkspaceProvider} workspaceProvider
240
addProject: function(projectName, workspaceProvider)
242
// FIXME: support multiple projects identified by project name.
243
this._project = new WebInspector.Project(this, workspaceProvider);
247
* @return {WebInspector.Project}
251
return this._project;
255
* @return {Array.<WebInspector.UISourceCode>}
257
uiSourceCodes: function()
259
return this._project.uiSourceCodes();
263
* @param {string} path
264
* @param {WebInspector.ContentProvider} contentProvider
265
* @param {boolean} isEditable
266
* @param {boolean=} isContentScript
267
* @param {boolean=} isSnippet
269
addTemporaryUISourceCode: function(path, contentProvider, isEditable, isContentScript, isSnippet)
271
var uiSourceCode = new WebInspector.UISourceCode(this, path, contentProvider.contentType(), isEditable);
272
this._temporaryContentProviders.put(uiSourceCode, contentProvider);
273
uiSourceCode.isContentScript = isContentScript;
274
uiSourceCode.isSnippet = isSnippet;
275
uiSourceCode.isTemporary = true;
276
this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeAdded, uiSourceCode);
281
* @param {WebInspector.UISourceCode} uiSourceCode
283
removeTemporaryUISourceCode: function(uiSourceCode)
285
this._temporaryContentProviders.remove(uiSourceCode.url);
286
this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, uiSourceCode);
290
* @param {WebInspector.UISourceCode} uiSourceCode
291
* @param {function(?string,boolean,string)} callback
293
requestFileContent: function(uiSourceCode, callback)
295
if (this._temporaryContentProviders.get(uiSourceCode)) {
296
this._temporaryContentProviders.get(uiSourceCode).requestContent(callback);
299
this._project.requestFileContent(uiSourceCode.url, callback);
303
* @param {WebInspector.UISourceCode} uiSourceCode
304
* @param {string} query
305
* @param {boolean} caseSensitive
306
* @param {boolean} isRegex
307
* @param {function(Array.<WebInspector.ContentProvider.SearchMatch>)} callback
309
searchInFileContent: function(uiSourceCode, query, caseSensitive, isRegex, callback)
311
if (this._temporaryContentProviders.get(uiSourceCode)) {
312
this._temporaryContentProviders.get(uiSourceCode).searchInContent(query, caseSensitive, isRegex, callback);
315
this._project.searchInFileContent(uiSourceCode.url, query, caseSensitive, isRegex, callback);
320
this._temporaryContentProviders = new Map();
323
__proto__: WebInspector.Object.prototype
327
* @type {?WebInspector.Workspace}
329
WebInspector.workspace = null;