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._requestFileSystems();
45 /** @typedef {!{fileSystemName: string, rootURL: string, fileSystemPath: string}} */
46 WebInspector.IsolatedFileSystemManager.FileSystem;
48 WebInspector.IsolatedFileSystemManager.Events = {
49 FileSystemAdded: "FileSystemAdded",
50 FileSystemRemoved: "FileSystemRemoved"
53 WebInspector.IsolatedFileSystemManager.prototype = {
55 * @return {!WebInspector.FileSystemMapping}
59 return this._fileSystemMapping;
62 _requestFileSystems: function()
64 console.assert(!this._loaded);
65 InspectorFrontendHost.requestFileSystems();
68 addFileSystem: function()
70 InspectorFrontendHost.addFileSystem();
74 * @param {string} fileSystemPath
76 removeFileSystem: function(fileSystemPath)
78 InspectorFrontendHost.removeFileSystem(fileSystemPath);
82 * @param {!Array.<!WebInspector.IsolatedFileSystemManager.FileSystem>} fileSystems
84 _fileSystemsLoaded: function(fileSystems)
86 var addedFileSystemPaths = {};
87 for (var i = 0; i < fileSystems.length; ++i) {
88 this._innerAddFileSystem(fileSystems[i]);
89 addedFileSystemPaths[fileSystems[i].fileSystemPath] = true;
91 var fileSystemPaths = this._fileSystemMapping.fileSystemPaths();
92 for (var i = 0; i < fileSystemPaths.length; ++i) {
93 var fileSystemPath = fileSystemPaths[i];
94 if (!addedFileSystemPaths[fileSystemPath])
95 this._fileSystemRemoved(fileSystemPath);
99 this._processPendingFileSystemRequests();
103 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem
105 _innerAddFileSystem: function(fileSystem)
107 var fileSystemPath = fileSystem.fileSystemPath;
108 this._fileSystemMapping.addFileSystem(fileSystemPath);
109 var isolatedFileSystem = new WebInspector.IsolatedFileSystem(this, fileSystemPath, fileSystem.fileSystemName, fileSystem.rootURL);
110 this._fileSystems[fileSystemPath] = isolatedFileSystem;
111 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, isolatedFileSystem);
115 * @return {!Array.<string>}
117 _fileSystemPaths: function()
119 return Object.keys(this._fileSystems);
122 _processPendingFileSystemRequests: function()
124 for (var fileSystemPath in this._pendingFileSystemRequests) {
125 var callbacks = this._pendingFileSystemRequests[fileSystemPath];
126 for (var i = 0; i < callbacks.length; ++i)
127 callbacks[i](this._isolatedFileSystem(fileSystemPath));
129 delete this._pendingFileSystemRequests;
133 * @param {string} errorMessage
134 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem
136 _fileSystemAdded: function(errorMessage, fileSystem)
140 WebInspector.showErrorMessage(errorMessage)
141 else if (fileSystem) {
142 this._innerAddFileSystem(fileSystem);
143 fileSystemPath = fileSystem.fileSystemPath;
148 * @param {string} fileSystemPath
150 _fileSystemRemoved: function(fileSystemPath)
152 this._fileSystemMapping.removeFileSystem(fileSystemPath);
153 var isolatedFileSystem = this._fileSystems[fileSystemPath];
154 delete this._fileSystems[fileSystemPath];
155 if (isolatedFileSystem)
156 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, isolatedFileSystem);
160 * @param {string} fileSystemPath
161 * @return {?DOMFileSystem}
163 _isolatedFileSystem: function(fileSystemPath)
165 var fileSystem = this._fileSystems[fileSystemPath];
168 if (!InspectorFrontendHost.isolatedFileSystem)
170 return InspectorFrontendHost.isolatedFileSystem(fileSystem.name(), fileSystem.rootURL());
174 * @param {string} fileSystemPath
175 * @param {function(?DOMFileSystem)} callback
177 requestDOMFileSystem: function(fileSystemPath, callback)
180 if (!this._pendingFileSystemRequests[fileSystemPath])
181 this._pendingFileSystemRequests[fileSystemPath] = this._pendingFileSystemRequests[fileSystemPath] || [];
182 this._pendingFileSystemRequests[fileSystemPath].push(callback);
185 callback(this._isolatedFileSystem(fileSystemPath));
188 __proto__: WebInspector.Object.prototype
192 * @type {!WebInspector.IsolatedFileSystemManager}
194 WebInspector.isolatedFileSystemManager;
198 * @param {!WebInspector.IsolatedFileSystemManager} IsolatedFileSystemManager
200 WebInspector.IsolatedFileSystemDispatcher = function(IsolatedFileSystemManager)
202 this._IsolatedFileSystemManager = IsolatedFileSystemManager;
205 WebInspector.IsolatedFileSystemDispatcher.prototype = {
207 * @param {!Array.<!WebInspector.IsolatedFileSystemManager.FileSystem>} fileSystems
209 fileSystemsLoaded: function(fileSystems)
211 this._IsolatedFileSystemManager._fileSystemsLoaded(fileSystems);
215 * @param {string} fileSystemPath
217 fileSystemRemoved: function(fileSystemPath)
219 this._IsolatedFileSystemManager._fileSystemRemoved(fileSystemPath);
223 * @param {string} errorMessage
224 * @param {!WebInspector.IsolatedFileSystemManager.FileSystem} fileSystem
226 fileSystemAdded: function(errorMessage, fileSystem)
228 this._IsolatedFileSystemManager._fileSystemAdded(errorMessage, fileSystem);
233 * @type {!WebInspector.IsolatedFileSystemDispatcher}
235 WebInspector.isolatedFileSystemDispatcher;