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.
33 * @extends {WebInspector.Object}
35 WebInspector.IsolatedFileSystemManager = function()
37 /** @type {!Object.<string, !WebInspector.IsolatedFileSystem>} */
38 this._fileSystems = {};
39 /** @type {!Object.<string, !Array.<function(?DOMFileSystem)>>} */
40 this._pendingFileSystemRequests = {};
41 this._fileSystemMapping = new WebInspector.FileSystemMapping();
42 this._excludedFolderManager = new WebInspector.ExcludedFolderManager();
43 this._requestFileSystems();
45 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FileSystemsLoaded, this._onFileSystemsLoaded, this);
46 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FileSystemRemoved, this._onFileSystemRemoved, this);
47 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FileSystemAdded, this._onFileSystemAdded, this);
50 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string}} */
51 WebInspector.IsolatedFileSystemManager.FileSystem;
53 WebInspector.IsolatedFileSystemManager.Events = {
54 FileSystemAdded: "FileSystemAdded",
55 FileSystemRemoved: "FileSystemRemoved"
58 WebInspector.IsolatedFileSystemManager.prototype = {
60 * @return {!WebInspector.FileSystemMapping}
64 return this._fileSystemMapping;
68 * @return {!WebInspector.ExcludedFolderManager}
70 excludedFolderManager: function()
72 return this._excludedFolderManager;
75 _requestFileSystems: function()
77 console.assert(!this._loaded);
78 InspectorFrontendHost.requestFileSystems();
81 addFileSystem: function()
83 InspectorFrontendHost.addFileSystem();
87 * @param {string} fileSystemPath
89 removeFileSystem: function(fileSystemPath)
91 InspectorFrontendHost.removeFileSystem(fileSystemPath);
95 * @param {!WebInspector.Event} event
97 _onFileSystemsLoaded: function(event)
99 var fileSystems = /** @type {!Array.<!WebInspector.IsolatedFileSystemManager.FileSystem>} */ (event.data);
100 var addedFileSystemPaths = {};
101 for (var i = 0; i < fileSystems.length; ++i) {
102 this._innerAddFileSystem(fileSystems[i]);
103 addedFileSystemPaths[fileSystems[i].fileSystemPath] = true;
105 var fileSystemPaths = this._fileSystemMapping.fileSystemPaths();
106 for (var i = 0; i < fileSystemPaths.length; ++i) {
107 var fileSystemPath = fileSystemPaths[i];
108 if (!addedFileSystemPaths[fileSystemPath])
109 this._fileSystemRemoved(fileSystemPath);
113 this._processPendingFileSystemRequests();
117 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem
119 _innerAddFileSystem: function(fileSystem)
121 var fileSystemPath = fileSystem.fileSystemPath;
122 this._fileSystemMapping.addFileSystem(fileSystemPath);
123 var isolatedFileSystem = new WebInspector.IsolatedFileSystem(this, fileSystemPath, fileSystem.fileSystemName, fileSystem.rootURL);
124 this._fileSystems[fileSystemPath] = isolatedFileSystem;
125 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, isolatedFileSystem);
128 _processPendingFileSystemRequests: function()
130 for (var fileSystemPath in this._pendingFileSystemRequests) {
131 var callbacks = this._pendingFileSystemRequests[fileSystemPath];
132 for (var i = 0; i < callbacks.length; ++i)
133 callbacks[i](this._isolatedFileSystem(fileSystemPath));
135 delete this._pendingFileSystemRequests;
139 * @param {!WebInspector.Event} event
141 _onFileSystemAdded: function(event)
143 var errorMessage = /** @type {string} */ (event.data["errorMessage"]);
144 var fileSystem = /** @type {?WebInspector.IsolatedFileSystemManager.FileSystem} */ (event.data["fileSystem"]);
146 WebInspector.console.error(errorMessage, true);
148 this._innerAddFileSystem(fileSystem);
152 * @param {!WebInspector.Event} event
154 _onFileSystemRemoved: function(event)
156 this._fileSystemRemoved(/** @type {string} */ (event.data));
160 * @param {string} fileSystemPath
162 _fileSystemRemoved: function(fileSystemPath)
164 this._fileSystemMapping.removeFileSystem(fileSystemPath);
165 this._excludedFolderManager.removeFileSystem(fileSystemPath);
166 var isolatedFileSystem = this._fileSystems[fileSystemPath];
167 delete this._fileSystems[fileSystemPath];
168 if (isolatedFileSystem)
169 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, isolatedFileSystem);
173 * @param {string} fileSystemPath
174 * @return {?DOMFileSystem}
176 _isolatedFileSystem: function(fileSystemPath)
178 var fileSystem = this._fileSystems[fileSystemPath];
181 if (!InspectorFrontendHost.isolatedFileSystem)
183 return InspectorFrontendHost.isolatedFileSystem(fileSystem.name(), fileSystem.rootURL());
187 * @param {string} fileSystemPath
188 * @param {function(?DOMFileSystem)} callback
190 requestDOMFileSystem: function(fileSystemPath, callback)
193 if (!this._pendingFileSystemRequests[fileSystemPath])
194 this._pendingFileSystemRequests[fileSystemPath] = this._pendingFileSystemRequests[fileSystemPath] || [];
195 this._pendingFileSystemRequests[fileSystemPath].push(callback);
198 callback(this._isolatedFileSystem(fileSystemPath));
201 __proto__: WebInspector.Object.prototype
205 * @type {!WebInspector.IsolatedFileSystemManager}
207 WebInspector.isolatedFileSystemManager;