| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 WebInspector.FileSystemMapping = class extends WebInspector.Object { | 34 Workspace.FileSystemMapping = class extends Common.Object { |
| 35 constructor() { | 35 constructor() { |
| 36 super(); | 36 super(); |
| 37 this._fileSystemMappingSetting = WebInspector.settings.createLocalSetting('f
ileSystemMapping', {}); | 37 this._fileSystemMappingSetting = Common.settings.createLocalSetting('fileSys
temMapping', {}); |
| 38 /** @type {!Object.<string, !Array.<!WebInspector.FileSystemMapping.Entry>>}
*/ | 38 /** @type {!Object.<string, !Array.<!Workspace.FileSystemMapping.Entry>>} */ |
| 39 this._fileSystemMappings = {}; | 39 this._fileSystemMappings = {}; |
| 40 this._loadFromSettings(); | 40 this._loadFromSettings(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 _loadFromSettings() { | 43 _loadFromSettings() { |
| 44 var savedMapping = this._fileSystemMappingSetting.get(); | 44 var savedMapping = this._fileSystemMappingSetting.get(); |
| 45 this._fileSystemMappings = {}; | 45 this._fileSystemMappings = {}; |
| 46 for (var fileSystemPath in savedMapping) { | 46 for (var fileSystemPath in savedMapping) { |
| 47 var savedFileSystemMappings = savedMapping[fileSystemPath]; | 47 var savedFileSystemMappings = savedMapping[fileSystemPath]; |
| 48 fileSystemPath = WebInspector.ParsedURL.platformPathToURL(fileSystemPath); | 48 fileSystemPath = Common.ParsedURL.platformPathToURL(fileSystemPath); |
| 49 this._fileSystemMappings[fileSystemPath] = []; | 49 this._fileSystemMappings[fileSystemPath] = []; |
| 50 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; | 50 var fileSystemMappings = this._fileSystemMappings[fileSystemPath]; |
| 51 | 51 |
| 52 for (var i = 0; i < savedFileSystemMappings.length; ++i) { | 52 for (var i = 0; i < savedFileSystemMappings.length; ++i) { |
| 53 var savedEntry = savedFileSystemMappings[i]; | 53 var savedEntry = savedFileSystemMappings[i]; |
| 54 var entry = | 54 var entry = |
| 55 new WebInspector.FileSystemMapping.Entry(fileSystemPath, savedEntry.
urlPrefix, savedEntry.pathPrefix, true); | 55 new Workspace.FileSystemMapping.Entry(fileSystemPath, savedEntry.url
Prefix, savedEntry.pathPrefix, true); |
| 56 fileSystemMappings.push(entry); | 56 fileSystemMappings.push(entry); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 | 59 |
| 60 this._rebuildIndexes(); | 60 this._rebuildIndexes(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 _saveToSettings() { | 63 _saveToSettings() { |
| 64 var setting = {}; | 64 var setting = {}; |
| 65 for (var fileSystemPath in this._fileSystemMappings) { | 65 for (var fileSystemPath in this._fileSystemMappings) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, false); | 139 this._innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, false); |
| 140 } | 140 } |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * @param {string} fileSystemPath | 143 * @param {string} fileSystemPath |
| 144 * @param {string} urlPrefix | 144 * @param {string} urlPrefix |
| 145 * @param {string} pathPrefix | 145 * @param {string} pathPrefix |
| 146 * @param {boolean} configurable | 146 * @param {boolean} configurable |
| 147 */ | 147 */ |
| 148 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, configurable) { | 148 _innerAddFileMapping(fileSystemPath, urlPrefix, pathPrefix, configurable) { |
| 149 var entry = new WebInspector.FileSystemMapping.Entry(fileSystemPath, urlPref
ix, pathPrefix, configurable); | 149 var entry = new Workspace.FileSystemMapping.Entry(fileSystemPath, urlPrefix,
pathPrefix, configurable); |
| 150 this._fileSystemMappings[fileSystemPath].push(entry); | 150 this._fileSystemMappings[fileSystemPath].push(entry); |
| 151 this._rebuildIndexes(); | 151 this._rebuildIndexes(); |
| 152 this.dispatchEventToListeners(WebInspector.FileSystemMapping.Events.FileMapp
ingAdded, entry); | 152 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping
Added, entry); |
| 153 } | 153 } |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * @param {string} fileSystemPath | 156 * @param {string} fileSystemPath |
| 157 * @param {string} urlPrefix | 157 * @param {string} urlPrefix |
| 158 * @param {string} pathPrefix | 158 * @param {string} pathPrefix |
| 159 */ | 159 */ |
| 160 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) { | 160 removeFileMapping(fileSystemPath, urlPrefix, pathPrefix) { |
| 161 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path
Prefix); | 161 var entry = this._configurableMappingEntryForPathPrefix(fileSystemPath, path
Prefix); |
| 162 if (!entry) | 162 if (!entry) |
| 163 return; | 163 return; |
| 164 this._fileSystemMappings[fileSystemPath].remove(entry); | 164 this._fileSystemMappings[fileSystemPath].remove(entry); |
| 165 this._rebuildIndexes(); | 165 this._rebuildIndexes(); |
| 166 this._saveToSettings(); | 166 this._saveToSettings(); |
| 167 this.dispatchEventToListeners(WebInspector.FileSystemMapping.Events.FileMapp
ingRemoved, entry); | 167 this.dispatchEventToListeners(Workspace.FileSystemMapping.Events.FileMapping
Removed, entry); |
| 168 } | 168 } |
| 169 | 169 |
| 170 /** | 170 /** |
| 171 * @param {string} url | 171 * @param {string} url |
| 172 * @return {?WebInspector.FileSystemMapping.Entry} | 172 * @return {?Workspace.FileSystemMapping.Entry} |
| 173 */ | 173 */ |
| 174 _mappingEntryForURL(url) { | 174 _mappingEntryForURL(url) { |
| 175 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) { | 175 for (var i = this._urlPrefixes.length - 1; i >= 0; --i) { |
| 176 var urlPrefix = this._urlPrefixes[i]; | 176 var urlPrefix = this._urlPrefixes[i]; |
| 177 if (url.startsWith(urlPrefix)) | 177 if (url.startsWith(urlPrefix)) |
| 178 return this._mappingForURLPrefix[urlPrefix]; | 178 return this._mappingForURLPrefix[urlPrefix]; |
| 179 } | 179 } |
| 180 return null; | 180 return null; |
| 181 } | 181 } |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * @param {string} fileSystemPath | 184 * @param {string} fileSystemPath |
| 185 * @param {string} filePath | 185 * @param {string} filePath |
| 186 * @return {?WebInspector.FileSystemMapping.Entry} | 186 * @return {?Workspace.FileSystemMapping.Entry} |
| 187 */ | 187 */ |
| 188 _mappingEntryForPath(fileSystemPath, filePath) { | 188 _mappingEntryForPath(fileSystemPath, filePath) { |
| 189 var entries = this._fileSystemMappings[fileSystemPath]; | 189 var entries = this._fileSystemMappings[fileSystemPath]; |
| 190 if (!entries) | 190 if (!entries) |
| 191 return null; | 191 return null; |
| 192 | 192 |
| 193 var entry = null; | 193 var entry = null; |
| 194 for (var i = 0; i < entries.length; ++i) { | 194 for (var i = 0; i < entries.length; ++i) { |
| 195 var pathPrefix = entries[i].pathPrefix; | 195 var pathPrefix = entries[i].pathPrefix; |
| 196 if (entry && entry.configurable && !entries[i].configurable) | 196 if (entry && entry.configurable && !entries[i].configurable) |
| 197 continue; | 197 continue; |
| 198 // We are looking for the longest pathPrefix match. | 198 // We are looking for the longest pathPrefix match. |
| 199 if (entry && entry.pathPrefix.length > pathPrefix.length) | 199 if (entry && entry.pathPrefix.length > pathPrefix.length) |
| 200 continue; | 200 continue; |
| 201 if (filePath.startsWith(pathPrefix)) | 201 if (filePath.startsWith(pathPrefix)) |
| 202 entry = entries[i]; | 202 entry = entries[i]; |
| 203 } | 203 } |
| 204 return entry; | 204 return entry; |
| 205 } | 205 } |
| 206 | 206 |
| 207 /** | 207 /** |
| 208 * @param {string} fileSystemPath | 208 * @param {string} fileSystemPath |
| 209 * @param {string} pathPrefix | 209 * @param {string} pathPrefix |
| 210 * @return {?WebInspector.FileSystemMapping.Entry} | 210 * @return {?Workspace.FileSystemMapping.Entry} |
| 211 */ | 211 */ |
| 212 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) { | 212 _configurableMappingEntryForPathPrefix(fileSystemPath, pathPrefix) { |
| 213 var entries = this._fileSystemMappings[fileSystemPath]; | 213 var entries = this._fileSystemMappings[fileSystemPath]; |
| 214 for (var i = 0; i < entries.length; ++i) { | 214 for (var i = 0; i < entries.length; ++i) { |
| 215 if (entries[i].configurable && pathPrefix === entries[i].pathPrefix) | 215 if (entries[i].configurable && pathPrefix === entries[i].pathPrefix) |
| 216 return entries[i]; | 216 return entries[i]; |
| 217 } | 217 } |
| 218 return null; | 218 return null; |
| 219 } | 219 } |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * @param {string} fileSystemPath | 222 * @param {string} fileSystemPath |
| 223 * @return {!Array.<!WebInspector.FileSystemMapping.Entry>} | 223 * @return {!Array.<!Workspace.FileSystemMapping.Entry>} |
| 224 */ | 224 */ |
| 225 mappingEntries(fileSystemPath) { | 225 mappingEntries(fileSystemPath) { |
| 226 return this._fileSystemMappings[fileSystemPath].slice(); | 226 return this._fileSystemMappings[fileSystemPath].slice(); |
| 227 } | 227 } |
| 228 | 228 |
| 229 /** | 229 /** |
| 230 * @param {string} url | 230 * @param {string} url |
| 231 * @return {boolean} | 231 * @return {boolean} |
| 232 */ | 232 */ |
| 233 hasMappingForNetworkURL(url) { | 233 hasMappingForNetworkURL(url) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 else | 296 else |
| 297 this.addFileMapping(fileSystemPath, urlPrefix + pathPrefix, '/'); | 297 this.addFileMapping(fileSystemPath, urlPrefix + pathPrefix, '/'); |
| 298 } | 298 } |
| 299 | 299 |
| 300 resetForTesting() { | 300 resetForTesting() { |
| 301 this._fileSystemMappings = {}; | 301 this._fileSystemMappings = {}; |
| 302 } | 302 } |
| 303 }; | 303 }; |
| 304 | 304 |
| 305 /** @enum {symbol} */ | 305 /** @enum {symbol} */ |
| 306 WebInspector.FileSystemMapping.Events = { | 306 Workspace.FileSystemMapping.Events = { |
| 307 FileMappingAdded: Symbol('FileMappingAdded'), | 307 FileMappingAdded: Symbol('FileMappingAdded'), |
| 308 FileMappingRemoved: Symbol('FileMappingRemoved') | 308 FileMappingRemoved: Symbol('FileMappingRemoved') |
| 309 }; | 309 }; |
| 310 | 310 |
| 311 /** | 311 /** |
| 312 * @unrestricted | 312 * @unrestricted |
| 313 */ | 313 */ |
| 314 WebInspector.FileSystemMapping.Entry = class { | 314 Workspace.FileSystemMapping.Entry = class { |
| 315 /** | 315 /** |
| 316 * @param {string} fileSystemPath | 316 * @param {string} fileSystemPath |
| 317 * @param {string} urlPrefix | 317 * @param {string} urlPrefix |
| 318 * @param {string} pathPrefix | 318 * @param {string} pathPrefix |
| 319 * @param {boolean} configurable | 319 * @param {boolean} configurable |
| 320 */ | 320 */ |
| 321 constructor(fileSystemPath, urlPrefix, pathPrefix, configurable) { | 321 constructor(fileSystemPath, urlPrefix, pathPrefix, configurable) { |
| 322 this.fileSystemPath = fileSystemPath; | 322 this.fileSystemPath = fileSystemPath; |
| 323 this.urlPrefix = urlPrefix; | 323 this.urlPrefix = urlPrefix; |
| 324 this.pathPrefix = pathPrefix; | 324 this.pathPrefix = pathPrefix; |
| 325 this.configurable = configurable; | 325 this.configurable = configurable; |
| 326 } | 326 } |
| 327 }; | 327 }; |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * @type {!WebInspector.FileSystemMapping} | 330 * @type {!Workspace.FileSystemMapping} |
| 331 */ | 331 */ |
| 332 WebInspector.fileSystemMapping; | 332 Workspace.fileSystemMapping; |
| OLD | NEW |