| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 Workspace.FileSystemMapping = class extends Common.Object { | 34 Workspace.FileSystemMapping = class extends Common.Object { |
| 35 constructor() { | 35 /** |
| 36 * @param {!Workspace.IsolatedFileSystemManager} fileSystemManager |
| 37 */ |
| 38 constructor(fileSystemManager) { |
| 36 super(); | 39 super(); |
| 37 this._fileSystemMappingSetting = Common.settings.createLocalSetting('fileSys
temMapping', {}); | 40 this._fileSystemMappingSetting = Common.settings.createLocalSetting('fileSys
temMapping', {}); |
| 38 /** @type {!Object.<string, !Array.<!Workspace.FileSystemMapping.Entry>>} */ | 41 /** @type {!Object.<string, !Array.<!Workspace.FileSystemMapping.Entry>>} */ |
| 39 this._fileSystemMappings = {}; | 42 this._fileSystemMappings = {}; |
| 40 this._loadFromSettings(); | 43 this._loadFromSettings(); |
| 44 |
| 45 this._eventListeners = [ |
| 46 fileSystemManager.addEventListener( |
| 47 Workspace.IsolatedFileSystemManager.Events.FileSystemAdded, this._file
SystemAdded, this), |
| 48 fileSystemManager.addEventListener( |
| 49 Workspace.IsolatedFileSystemManager.Events.FileSystemRemoved, this._fi
leSystemRemoved, this), |
| 50 ]; |
| 51 fileSystemManager.waitForFileSystems().then(this._fileSystemsLoaded.bind(thi
s)); |
| 52 } |
| 53 |
| 54 /** |
| 55 * @param {!Array<!Workspace.IsolatedFileSystem>} fileSystems |
| 56 */ |
| 57 _fileSystemsLoaded(fileSystems) { |
| 58 for (var fileSystem of fileSystems) |
| 59 this._addMappingsForFilesystem(fileSystem); |
| 60 } |
| 61 |
| 62 /** |
| 63 * @param {!Common.Event} event |
| 64 */ |
| 65 _fileSystemAdded(event) { |
| 66 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); |
| 67 this._addMappingsForFilesystem(fileSystem); |
| 68 } |
| 69 |
| 70 /** |
| 71 * @param {!Workspace.IsolatedFileSystem} fileSystem |
| 72 */ |
| 73 _addMappingsForFilesystem(fileSystem) { |
| 74 this.addFileSystem(fileSystem.path()); |
| 75 |
| 76 var mappings = fileSystem.projectProperty('mappings'); |
| 77 for (var i = 0; Array.isArray(mappings) && i < mappings.length; ++i) { |
| 78 var mapping = mappings[i]; |
| 79 if (!mapping || typeof mapping !== 'object') |
| 80 continue; |
| 81 var folder = mapping['folder']; |
| 82 var url = mapping['url']; |
| 83 if (typeof folder !== 'string' || typeof url !== 'string') |
| 84 continue; |
| 85 this.addNonConfigurableFileMapping(fileSystem.path(), url, folder); |
| 86 } |
| 87 } |
| 88 |
| 89 /** |
| 90 * @param {!Common.Event} event |
| 91 */ |
| 92 _fileSystemRemoved(event) { |
| 93 var fileSystem = /** @type {!Workspace.IsolatedFileSystem} */ (event.data); |
| 94 this.removeFileSystem(fileSystem.path()); |
| 41 } | 95 } |
| 42 | 96 |
| 43 _loadFromSettings() { | 97 _loadFromSettings() { |
| 44 var savedMapping = this._fileSystemMappingSetting.get(); | 98 var savedMapping = this._fileSystemMappingSetting.get(); |
| 45 this._fileSystemMappings = {}; | 99 this._fileSystemMappings = {}; |
| 46 for (var fileSystemPath in savedMapping) { | 100 for (var fileSystemPath in savedMapping) { |
| 47 var savedFileSystemMappings = savedMapping[fileSystemPath]; | 101 var savedFileSystemMappings = savedMapping[fileSystemPath]; |
| 48 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); | 102 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); |
| 49 this._fileSystemMappings[fileSystemPath] = []; | 103 this._fileSystemMappings[fileSystemPath] = []; |
| 50 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; | 104 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 var urlPrefix = url.substr(0, url.length - commonPathSuffixLength); | 347 var urlPrefix = url.substr(0, url.length - commonPathSuffixLength); |
| 294 if (to >= from) | 348 if (to >= from) |
| 295 this.addFileMapping(fileSystemPath, urlPrefix, pathPrefix); | 349 this.addFileMapping(fileSystemPath, urlPrefix, pathPrefix); |
| 296 else | 350 else |
| 297 this.addFileMapping(fileSystemPath, urlPrefix + pathPrefix, '/'); | 351 this.addFileMapping(fileSystemPath, urlPrefix + pathPrefix, '/'); |
| 298 } | 352 } |
| 299 | 353 |
| 300 resetForTesting() { | 354 resetForTesting() { |
| 301 this._fileSystemMappings = {}; | 355 this._fileSystemMappings = {}; |
| 302 } | 356 } |
| 357 |
| 358 dispose() { |
| 359 Common.EventTarget.removeEventListeners(this._eventListeners); |
| 360 } |
| 303 }; | 361 }; |
| 304 | 362 |
| 305 /** @enum {symbol} */ | 363 /** @enum {symbol} */ |
| 306 Workspace.FileSystemMapping.Events = { | 364 Workspace.FileSystemMapping.Events = { |
| 307 FileMappingAdded: Symbol('FileMappingAdded'), | 365 FileMappingAdded: Symbol('FileMappingAdded'), |
| 308 FileMappingRemoved: Symbol('FileMappingRemoved') | 366 FileMappingRemoved: Symbol('FileMappingRemoved') |
| 309 }; | 367 }; |
| 310 | 368 |
| 311 /** | 369 /** |
| 312 * @unrestricted | 370 * @unrestricted |
| (...skipping 10 matching lines...) Expand all Loading... |
| 323 this.urlPrefix = urlPrefix; | 381 this.urlPrefix = urlPrefix; |
| 324 this.pathPrefix = pathPrefix; | 382 this.pathPrefix = pathPrefix; |
| 325 this.configurable = configurable; | 383 this.configurable = configurable; |
| 326 } | 384 } |
| 327 }; | 385 }; |
| 328 | 386 |
| 329 /** | 387 /** |
| 330 * @type {!Workspace.FileSystemMapping} | 388 * @type {!Workspace.FileSystemMapping} |
| 331 */ | 389 */ |
| 332 Workspace.fileSystemMapping; | 390 Workspace.fileSystemMapping; |
| OLD | NEW |