| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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.IsolatedFileSystem = class { | 34 Workspace.IsolatedFileSystem = class { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.IsolatedFileSystemManager} manager | 36 * @param {!Workspace.IsolatedFileSystemManager} manager |
| 37 * @param {string} path | 37 * @param {string} path |
| 38 * @param {string} embedderPath | 38 * @param {string} embedderPath |
| 39 * @param {!DOMFileSystem} domFileSystem | 39 * @param {!DOMFileSystem} domFileSystem |
| 40 */ | 40 */ |
| 41 constructor(manager, path, embedderPath, domFileSystem) { | 41 constructor(manager, path, embedderPath, domFileSystem) { |
| 42 this._manager = manager; | 42 this._manager = manager; |
| 43 this._path = path; | 43 this._path = path; |
| 44 this._embedderPath = embedderPath; | 44 this._embedderPath = embedderPath; |
| 45 this._domFileSystem = domFileSystem; | 45 this._domFileSystem = domFileSystem; |
| 46 this._excludedFoldersSetting = WebInspector.settings.createLocalSetting('wor
kspaceExcludedFolders', {}); | 46 this._excludedFoldersSetting = Common.settings.createLocalSetting('workspace
ExcludedFolders', {}); |
| 47 /** @type {!Set<string>} */ | 47 /** @type {!Set<string>} */ |
| 48 this._excludedFolders = new Set(this._excludedFoldersSetting.get()[path] ||
[]); | 48 this._excludedFolders = new Set(this._excludedFoldersSetting.get()[path] ||
[]); |
| 49 /** @type {!Set<string>} */ | 49 /** @type {!Set<string>} */ |
| 50 this._nonConfigurableExcludedFolders = new Set(); | 50 this._nonConfigurableExcludedFolders = new Set(); |
| 51 | 51 |
| 52 /** @type {!Set<string>} */ | 52 /** @type {!Set<string>} */ |
| 53 this._filePaths = new Set(); | 53 this._filePaths = new Set(); |
| 54 /** @type {!Set<string>} */ | 54 /** @type {!Set<string>} */ |
| 55 this._gitFolders = new Set(); | 55 this._gitFolders = new Set(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @param {!WebInspector.IsolatedFileSystemManager} manager | 59 * @param {!Workspace.IsolatedFileSystemManager} manager |
| 60 * @param {string} path | 60 * @param {string} path |
| 61 * @param {string} embedderPath | 61 * @param {string} embedderPath |
| 62 * @param {string} name | 62 * @param {string} name |
| 63 * @param {string} rootURL | 63 * @param {string} rootURL |
| 64 * @return {!Promise<?WebInspector.IsolatedFileSystem>} | 64 * @return {!Promise<?Workspace.IsolatedFileSystem>} |
| 65 */ | 65 */ |
| 66 static create(manager, path, embedderPath, name, rootURL) { | 66 static create(manager, path, embedderPath, name, rootURL) { |
| 67 var domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL); | 67 var domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL); |
| 68 if (!domFileSystem) | 68 if (!domFileSystem) |
| 69 return Promise.resolve(/** @type {?WebInspector.IsolatedFileSystem} */ (nu
ll)); | 69 return Promise.resolve(/** @type {?Workspace.IsolatedFileSystem} */ (null)
); |
| 70 | 70 |
| 71 var fileSystem = new WebInspector.IsolatedFileSystem(manager, path, embedder
Path, domFileSystem); | 71 var fileSystem = new Workspace.IsolatedFileSystem(manager, path, embedderPat
h, domFileSystem); |
| 72 var fileContentPromise = fileSystem.requestFileContentPromise('.devtools'); | 72 var fileContentPromise = fileSystem.requestFileContentPromise('.devtools'); |
| 73 return fileContentPromise.then(onConfigAvailable) | 73 return fileContentPromise.then(onConfigAvailable) |
| 74 .then(() => fileSystem) | 74 .then(() => fileSystem) |
| 75 .catchException(/** @type {?WebInspector.IsolatedFileSystem} */ (null)); | 75 .catchException(/** @type {?Workspace.IsolatedFileSystem} */ (null)); |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * @param {?string} projectText | 78 * @param {?string} projectText |
| 79 * @return {!Promise} | 79 * @return {!Promise} |
| 80 */ | 80 */ |
| 81 function onConfigAvailable(projectText) { | 81 function onConfigAvailable(projectText) { |
| 82 if (projectText) { | 82 if (projectText) { |
| 83 try { | 83 try { |
| 84 var projectObject = JSON.parse(projectText); | 84 var projectObject = JSON.parse(projectText); |
| 85 fileSystem._initializeProject( | 85 fileSystem._initializeProject( |
| 86 typeof projectObject === 'object' ? /** @type {!Object} */ (projec
tObject) : null); | 86 typeof projectObject === 'object' ? /** @type {!Object} */ (projec
tObject) : null); |
| 87 } catch (e) { | 87 } catch (e) { |
| 88 WebInspector.console.error('Invalid project file: ' + projectText); | 88 Common.console.error('Invalid project file: ' + projectText); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 return fileSystem._initializeFilePaths(); | 91 return fileSystem._initializeFilePaths(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * @param {!DOMError} error | 96 * @param {!DOMError} error |
| 97 * @return {string} | 97 * @return {string} |
| 98 */ | 98 */ |
| 99 static errorMessage(error) { | 99 static errorMessage(error) { |
| 100 return WebInspector.UIString('File system error: %s', error.message); | 100 return Common.UIString('File system error: %s', error.message); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @param {string} path | 104 * @param {string} path |
| 105 * @return {!Promise<?{modificationTime: !Date, size: number}>} | 105 * @return {!Promise<?{modificationTime: !Date, size: number}>} |
| 106 */ | 106 */ |
| 107 getMetadata(path) { | 107 getMetadata(path) { |
| 108 var fulfill; | 108 var fulfill; |
| 109 var promise = new Promise(f => fulfill = f); | 109 var promise = new Promise(f => fulfill = f); |
| 110 this._domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandler); | 110 this._domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandler); |
| 111 return promise; | 111 return promise; |
| 112 | 112 |
| 113 /** | 113 /** |
| 114 * @param {!FileEntry} entry | 114 * @param {!FileEntry} entry |
| 115 */ | 115 */ |
| 116 function fileEntryLoaded(entry) { | 116 function fileEntryLoaded(entry) { |
| 117 entry.getMetadata(fulfill, errorHandler); | 117 entry.getMetadata(fulfill, errorHandler); |
| 118 } | 118 } |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * @param {!FileError} error | 121 * @param {!FileError} error |
| 122 */ | 122 */ |
| 123 function errorHandler(error) { | 123 function errorHandler(error) { |
| 124 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 124 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 125 console.error(errorMessage + ' when getting file metadata \'' + path); | 125 console.error(errorMessage + ' when getting file metadata \'' + path); |
| 126 fulfill(null); | 126 fulfill(null); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * @return {!Array<string>} | 131 * @return {!Array<string>} |
| 132 */ | 132 */ |
| 133 filePaths() { | 133 filePaths() { |
| 134 return this._filePaths.valuesArray(); | 134 return this._filePaths.valuesArray(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 _initializeFilePaths() { | 184 _initializeFilePaths() { |
| 185 var fulfill; | 185 var fulfill; |
| 186 var promise = new Promise(x => fulfill = x); | 186 var promise = new Promise(x => fulfill = x); |
| 187 var pendingRequests = 1; | 187 var pendingRequests = 1; |
| 188 var boundInnerCallback = innerCallback.bind(this); | 188 var boundInnerCallback = innerCallback.bind(this); |
| 189 this._requestEntries('', boundInnerCallback); | 189 this._requestEntries('', boundInnerCallback); |
| 190 return promise; | 190 return promise; |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * @param {!Array.<!FileEntry>} entries | 193 * @param {!Array.<!FileEntry>} entries |
| 194 * @this {WebInspector.IsolatedFileSystem} | 194 * @this {Workspace.IsolatedFileSystem} |
| 195 */ | 195 */ |
| 196 function innerCallback(entries) { | 196 function innerCallback(entries) { |
| 197 for (var i = 0; i < entries.length; ++i) { | 197 for (var i = 0; i < entries.length; ++i) { |
| 198 var entry = entries[i]; | 198 var entry = entries[i]; |
| 199 if (!entry.isDirectory) { | 199 if (!entry.isDirectory) { |
| 200 if (this._isFileExcluded(entry.fullPath)) | 200 if (this._isFileExcluded(entry.fullPath)) |
| 201 continue; | 201 continue; |
| 202 this._filePaths.add(entry.fullPath.substr(1)); | 202 this._filePaths.add(entry.fullPath.substr(1)); |
| 203 } else { | 203 } else { |
| 204 if (entry.fullPath.endsWith('/.git')) { | 204 if (entry.fullPath.endsWith('/.git')) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 225 createFile(path, name, callback) { | 225 createFile(path, name, callback) { |
| 226 var newFileIndex = 1; | 226 var newFileIndex = 1; |
| 227 if (!name) | 227 if (!name) |
| 228 name = 'NewFile'; | 228 name = 'NewFile'; |
| 229 var nameCandidate; | 229 var nameCandidate; |
| 230 | 230 |
| 231 this._domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(this),
errorHandler.bind(this)); | 231 this._domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(this),
errorHandler.bind(this)); |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * @param {!DirectoryEntry} dirEntry | 234 * @param {!DirectoryEntry} dirEntry |
| 235 * @this {WebInspector.IsolatedFileSystem} | 235 * @this {Workspace.IsolatedFileSystem} |
| 236 */ | 236 */ |
| 237 function dirEntryLoaded(dirEntry) { | 237 function dirEntryLoaded(dirEntry) { |
| 238 var nameCandidate = name; | 238 var nameCandidate = name; |
| 239 if (newFileIndex > 1) | 239 if (newFileIndex > 1) |
| 240 nameCandidate += newFileIndex; | 240 nameCandidate += newFileIndex; |
| 241 ++newFileIndex; | 241 ++newFileIndex; |
| 242 dirEntry.getFile(nameCandidate, {create: true, exclusive: true}, fileCreat
ed, fileCreationError.bind(this)); | 242 dirEntry.getFile(nameCandidate, {create: true, exclusive: true}, fileCreat
ed, fileCreationError.bind(this)); |
| 243 | 243 |
| 244 function fileCreated(entry) { | 244 function fileCreated(entry) { |
| 245 callback(entry.fullPath.substr(1)); | 245 callback(entry.fullPath.substr(1)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * @this {WebInspector.IsolatedFileSystem} | 249 * @this {Workspace.IsolatedFileSystem} |
| 250 */ | 250 */ |
| 251 function fileCreationError(error) { | 251 function fileCreationError(error) { |
| 252 if (error.name === 'InvalidModificationError') { | 252 if (error.name === 'InvalidModificationError') { |
| 253 dirEntryLoaded.call(this, dirEntry); | 253 dirEntryLoaded.call(this, dirEntry); |
| 254 return; | 254 return; |
| 255 } | 255 } |
| 256 | 256 |
| 257 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 257 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 258 console.error( | 258 console.error( |
| 259 errorMessage + ' when testing if file exists \'' + (this._path + '/'
+ path + '/' + nameCandidate) + '\''); | 259 errorMessage + ' when testing if file exists \'' + (this._path + '/'
+ path + '/' + nameCandidate) + '\''); |
| 260 callback(null); | 260 callback(null); |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 264 /** | 264 /** |
| 265 * @this {WebInspector.IsolatedFileSystem} | 265 * @this {Workspace.IsolatedFileSystem} |
| 266 */ | 266 */ |
| 267 function errorHandler(error) { | 267 function errorHandler(error) { |
| 268 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 268 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 269 var filePath = this._path + '/' + path; | 269 var filePath = this._path + '/' + path; |
| 270 if (nameCandidate) | 270 if (nameCandidate) |
| 271 filePath += '/' + nameCandidate; | 271 filePath += '/' + nameCandidate; |
| 272 console.error(errorMessage + ' when getting content for file \'' + (filePa
th) + '\''); | 272 console.error(errorMessage + ' when getting content for file \'' + (filePa
th) + '\''); |
| 273 callback(null); | 273 callback(null); |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 | 276 |
| 277 /** | 277 /** |
| 278 * @param {string} path | 278 * @param {string} path |
| 279 */ | 279 */ |
| 280 deleteFile(path) { | 280 deleteFile(path) { |
| 281 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); | 281 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); |
| 282 | 282 |
| 283 /** | 283 /** |
| 284 * @param {!FileEntry} fileEntry | 284 * @param {!FileEntry} fileEntry |
| 285 * @this {WebInspector.IsolatedFileSystem} | 285 * @this {Workspace.IsolatedFileSystem} |
| 286 */ | 286 */ |
| 287 function fileEntryLoaded(fileEntry) { | 287 function fileEntryLoaded(fileEntry) { |
| 288 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); | 288 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 function fileEntryRemoved() { | 291 function fileEntryRemoved() { |
| 292 } | 292 } |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * @param {!FileError} error | 295 * @param {!FileError} error |
| 296 * @this {WebInspector.IsolatedFileSystem} | 296 * @this {Workspace.IsolatedFileSystem} |
| 297 * @suppress {checkTypes} | 297 * @suppress {checkTypes} |
| 298 * TODO(jsbell): Update externs replacing FileError with DOMException. https
://crbug.com/496901 | 298 * TODO(jsbell): Update externs replacing FileError with DOMException. https
://crbug.com/496901 |
| 299 */ | 299 */ |
| 300 function errorHandler(error) { | 300 function errorHandler(error) { |
| 301 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 301 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 302 console.error(errorMessage + ' when deleting file \'' + (this._path + '/'
+ path) + '\''); | 302 console.error(errorMessage + ' when deleting file \'' + (this._path + '/'
+ path) + '\''); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 /** | 306 /** |
| 307 * @param {string} path | 307 * @param {string} path |
| 308 * @return {!Promise<?string>} | 308 * @return {!Promise<?string>} |
| 309 */ | 309 */ |
| 310 requestFileContentPromise(path) { | 310 requestFileContentPromise(path) { |
| 311 var fulfill; | 311 var fulfill; |
| 312 var promise = new Promise(x => fulfill = x); | 312 var promise = new Promise(x => fulfill = x); |
| 313 this.requestFileContent(path, fulfill); | 313 this.requestFileContent(path, fulfill); |
| 314 return promise; | 314 return promise; |
| 315 } | 315 } |
| 316 | 316 |
| 317 /** | 317 /** |
| 318 * @param {string} path | 318 * @param {string} path |
| 319 * @param {function(?string)} callback | 319 * @param {function(?string)} callback |
| 320 */ | 320 */ |
| 321 requestFileContent(path, callback) { | 321 requestFileContent(path, callback) { |
| 322 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); | 322 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); |
| 323 | 323 |
| 324 /** | 324 /** |
| 325 * @param {!FileEntry} entry | 325 * @param {!FileEntry} entry |
| 326 * @this {WebInspector.IsolatedFileSystem} | 326 * @this {Workspace.IsolatedFileSystem} |
| 327 */ | 327 */ |
| 328 function fileEntryLoaded(entry) { | 328 function fileEntryLoaded(entry) { |
| 329 entry.file(fileLoaded, errorHandler.bind(this)); | 329 entry.file(fileLoaded, errorHandler.bind(this)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 /** | 332 /** |
| 333 * @param {!Blob} file | 333 * @param {!Blob} file |
| 334 */ | 334 */ |
| 335 function fileLoaded(file) { | 335 function fileLoaded(file) { |
| 336 var reader = new FileReader(); | 336 var reader = new FileReader(); |
| 337 reader.onloadend = readerLoadEnd; | 337 reader.onloadend = readerLoadEnd; |
| 338 if (WebInspector.IsolatedFileSystem.ImageExtensions.has(WebInspector.Parse
dURL.extractExtension(path))) | 338 if (Workspace.IsolatedFileSystem.ImageExtensions.has(Common.ParsedURL.extr
actExtension(path))) |
| 339 reader.readAsDataURL(file); | 339 reader.readAsDataURL(file); |
| 340 else | 340 else |
| 341 reader.readAsText(file); | 341 reader.readAsText(file); |
| 342 } | 342 } |
| 343 | 343 |
| 344 /** | 344 /** |
| 345 * @this {!FileReader} | 345 * @this {!FileReader} |
| 346 */ | 346 */ |
| 347 function readerLoadEnd() { | 347 function readerLoadEnd() { |
| 348 /** @type {?string} */ | 348 /** @type {?string} */ |
| 349 var string = null; | 349 var string = null; |
| 350 try { | 350 try { |
| 351 string = /** @type {string} */ (this.result); | 351 string = /** @type {string} */ (this.result); |
| 352 } catch (e) { | 352 } catch (e) { |
| 353 console.error('Can\'t read file: ' + path + ': ' + e); | 353 console.error('Can\'t read file: ' + path + ': ' + e); |
| 354 } | 354 } |
| 355 callback(string); | 355 callback(string); |
| 356 } | 356 } |
| 357 | 357 |
| 358 /** | 358 /** |
| 359 * @this {WebInspector.IsolatedFileSystem} | 359 * @this {Workspace.IsolatedFileSystem} |
| 360 */ | 360 */ |
| 361 function errorHandler(error) { | 361 function errorHandler(error) { |
| 362 if (error.name === 'NotFoundError') { | 362 if (error.name === 'NotFoundError') { |
| 363 callback(null); | 363 callback(null); |
| 364 return; | 364 return; |
| 365 } | 365 } |
| 366 | 366 |
| 367 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 367 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 368 console.error(errorMessage + ' when getting content for file \'' + (this._
path + '/' + path) + '\''); | 368 console.error(errorMessage + ' when getting content for file \'' + (this._
path + '/' + path) + '\''); |
| 369 callback(null); | 369 callback(null); |
| 370 } | 370 } |
| 371 } | 371 } |
| 372 | 372 |
| 373 /** | 373 /** |
| 374 * @param {string} path | 374 * @param {string} path |
| 375 * @param {string} content | 375 * @param {string} content |
| 376 * @param {function()} callback | 376 * @param {function()} callback |
| 377 */ | 377 */ |
| 378 setFileContent(path, content, callback) { | 378 setFileContent(path, content, callback) { |
| 379 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.FileSav
edInWorkspace); | 379 Host.userMetrics.actionTaken(Host.UserMetrics.Action.FileSavedInWorkspace); |
| 380 this._domFileSystem.root.getFile(path, {create: true}, fileEntryLoaded.bind(
this), errorHandler.bind(this)); | 380 this._domFileSystem.root.getFile(path, {create: true}, fileEntryLoaded.bind(
this), errorHandler.bind(this)); |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * @param {!FileEntry} entry | 383 * @param {!FileEntry} entry |
| 384 * @this {WebInspector.IsolatedFileSystem} | 384 * @this {Workspace.IsolatedFileSystem} |
| 385 */ | 385 */ |
| 386 function fileEntryLoaded(entry) { | 386 function fileEntryLoaded(entry) { |
| 387 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); | 387 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); |
| 388 } | 388 } |
| 389 | 389 |
| 390 /** | 390 /** |
| 391 * @param {!FileWriter} fileWriter | 391 * @param {!FileWriter} fileWriter |
| 392 * @this {WebInspector.IsolatedFileSystem} | 392 * @this {Workspace.IsolatedFileSystem} |
| 393 */ | 393 */ |
| 394 function fileWriterCreated(fileWriter) { | 394 function fileWriterCreated(fileWriter) { |
| 395 fileWriter.onerror = errorHandler.bind(this); | 395 fileWriter.onerror = errorHandler.bind(this); |
| 396 fileWriter.onwriteend = fileWritten; | 396 fileWriter.onwriteend = fileWritten; |
| 397 var blob = new Blob([content], {type: 'text/plain'}); | 397 var blob = new Blob([content], {type: 'text/plain'}); |
| 398 fileWriter.write(blob); | 398 fileWriter.write(blob); |
| 399 | 399 |
| 400 function fileWritten() { | 400 function fileWritten() { |
| 401 fileWriter.onwriteend = callback; | 401 fileWriter.onwriteend = callback; |
| 402 fileWriter.truncate(blob.size); | 402 fileWriter.truncate(blob.size); |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 /** | 406 /** |
| 407 * @this {WebInspector.IsolatedFileSystem} | 407 * @this {Workspace.IsolatedFileSystem} |
| 408 */ | 408 */ |
| 409 function errorHandler(error) { | 409 function errorHandler(error) { |
| 410 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 410 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 411 console.error(errorMessage + ' when setting content for file \'' + (this._
path + '/' + path) + '\''); | 411 console.error(errorMessage + ' when setting content for file \'' + (this._
path + '/' + path) + '\''); |
| 412 callback(); | 412 callback(); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 /** | 416 /** |
| 417 * @param {string} path | 417 * @param {string} path |
| 418 * @param {string} newName | 418 * @param {string} newName |
| 419 * @param {function(boolean, string=)} callback | 419 * @param {function(boolean, string=)} callback |
| 420 */ | 420 */ |
| 421 renameFile(path, newName, callback) { | 421 renameFile(path, newName, callback) { |
| 422 newName = newName ? newName.trim() : newName; | 422 newName = newName ? newName.trim() : newName; |
| 423 if (!newName || newName.indexOf('/') !== -1) { | 423 if (!newName || newName.indexOf('/') !== -1) { |
| 424 callback(false); | 424 callback(false); |
| 425 return; | 425 return; |
| 426 } | 426 } |
| 427 var fileEntry; | 427 var fileEntry; |
| 428 var dirEntry; | 428 var dirEntry; |
| 429 | 429 |
| 430 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); | 430 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), err
orHandler.bind(this)); |
| 431 | 431 |
| 432 /** | 432 /** |
| 433 * @param {!FileEntry} entry | 433 * @param {!FileEntry} entry |
| 434 * @this {WebInspector.IsolatedFileSystem} | 434 * @this {Workspace.IsolatedFileSystem} |
| 435 */ | 435 */ |
| 436 function fileEntryLoaded(entry) { | 436 function fileEntryLoaded(entry) { |
| 437 if (entry.name === newName) { | 437 if (entry.name === newName) { |
| 438 callback(false); | 438 callback(false); |
| 439 return; | 439 return; |
| 440 } | 440 } |
| 441 | 441 |
| 442 fileEntry = entry; | 442 fileEntry = entry; |
| 443 fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); | 443 fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); |
| 444 } | 444 } |
| 445 | 445 |
| 446 /** | 446 /** |
| 447 * @param {!Entry} entry | 447 * @param {!Entry} entry |
| 448 * @this {WebInspector.IsolatedFileSystem} | 448 * @this {Workspace.IsolatedFileSystem} |
| 449 */ | 449 */ |
| 450 function dirEntryLoaded(entry) { | 450 function dirEntryLoaded(entry) { |
| 451 dirEntry = entry; | 451 dirEntry = entry; |
| 452 dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorH
andler.bind(this)); | 452 dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorH
andler.bind(this)); |
| 453 } | 453 } |
| 454 | 454 |
| 455 /** | 455 /** |
| 456 * @param {!FileEntry} entry | 456 * @param {!FileEntry} entry |
| 457 */ | 457 */ |
| 458 function newFileEntryLoaded(entry) { | 458 function newFileEntryLoaded(entry) { |
| 459 callback(false); | 459 callback(false); |
| 460 } | 460 } |
| 461 | 461 |
| 462 /** | 462 /** |
| 463 * @this {WebInspector.IsolatedFileSystem} | 463 * @this {Workspace.IsolatedFileSystem} |
| 464 */ | 464 */ |
| 465 function newFileEntryLoadErrorHandler(error) { | 465 function newFileEntryLoadErrorHandler(error) { |
| 466 if (error.name !== 'NotFoundError') { | 466 if (error.name !== 'NotFoundError') { |
| 467 callback(false); | 467 callback(false); |
| 468 return; | 468 return; |
| 469 } | 469 } |
| 470 fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); | 470 fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); |
| 471 } | 471 } |
| 472 | 472 |
| 473 /** | 473 /** |
| 474 * @param {!FileEntry} entry | 474 * @param {!FileEntry} entry |
| 475 */ | 475 */ |
| 476 function fileRenamed(entry) { | 476 function fileRenamed(entry) { |
| 477 callback(true, entry.name); | 477 callback(true, entry.name); |
| 478 } | 478 } |
| 479 | 479 |
| 480 /** | 480 /** |
| 481 * @this {WebInspector.IsolatedFileSystem} | 481 * @this {Workspace.IsolatedFileSystem} |
| 482 */ | 482 */ |
| 483 function errorHandler(error) { | 483 function errorHandler(error) { |
| 484 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 484 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 485 console.error(errorMessage + ' when renaming file \'' + (this._path + '/'
+ path) + '\' to \'' + newName + '\''); | 485 console.error(errorMessage + ' when renaming file \'' + (this._path + '/'
+ path) + '\' to \'' + newName + '\''); |
| 486 callback(false); | 486 callback(false); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 /** | 490 /** |
| 491 * @param {!DirectoryEntry} dirEntry | 491 * @param {!DirectoryEntry} dirEntry |
| 492 * @param {function(!Array.<!FileEntry>)} callback | 492 * @param {function(!Array.<!FileEntry>)} callback |
| 493 */ | 493 */ |
| 494 _readDirectory(dirEntry, callback) { | 494 _readDirectory(dirEntry, callback) { |
| 495 var dirReader = dirEntry.createReader(); | 495 var dirReader = dirEntry.createReader(); |
| 496 var entries = []; | 496 var entries = []; |
| 497 | 497 |
| 498 function innerCallback(results) { | 498 function innerCallback(results) { |
| 499 if (!results.length) { | 499 if (!results.length) { |
| 500 callback(entries.sort()); | 500 callback(entries.sort()); |
| 501 } else { | 501 } else { |
| 502 entries = entries.concat(toArray(results)); | 502 entries = entries.concat(toArray(results)); |
| 503 dirReader.readEntries(innerCallback, errorHandler); | 503 dirReader.readEntries(innerCallback, errorHandler); |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 function toArray(list) { | 507 function toArray(list) { |
| 508 return Array.prototype.slice.call(list || [], 0); | 508 return Array.prototype.slice.call(list || [], 0); |
| 509 } | 509 } |
| 510 | 510 |
| 511 dirReader.readEntries(innerCallback, errorHandler); | 511 dirReader.readEntries(innerCallback, errorHandler); |
| 512 | 512 |
| 513 function errorHandler(error) { | 513 function errorHandler(error) { |
| 514 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 514 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 515 console.error(errorMessage + ' when reading directory \'' + dirEntry.fullP
ath + '\''); | 515 console.error(errorMessage + ' when reading directory \'' + dirEntry.fullP
ath + '\''); |
| 516 callback([]); | 516 callback([]); |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 | 519 |
| 520 /** | 520 /** |
| 521 * @param {string} path | 521 * @param {string} path |
| 522 * @param {function(!Array.<!FileEntry>)} callback | 522 * @param {function(!Array.<!FileEntry>)} callback |
| 523 */ | 523 */ |
| 524 _requestEntries(path, callback) { | 524 _requestEntries(path, callback) { |
| 525 this._domFileSystem.root.getDirectory(path, null, innerCallback.bind(this),
errorHandler); | 525 this._domFileSystem.root.getDirectory(path, null, innerCallback.bind(this),
errorHandler); |
| 526 | 526 |
| 527 /** | 527 /** |
| 528 * @param {!DirectoryEntry} dirEntry | 528 * @param {!DirectoryEntry} dirEntry |
| 529 * @this {WebInspector.IsolatedFileSystem} | 529 * @this {Workspace.IsolatedFileSystem} |
| 530 */ | 530 */ |
| 531 function innerCallback(dirEntry) { | 531 function innerCallback(dirEntry) { |
| 532 this._readDirectory(dirEntry, callback); | 532 this._readDirectory(dirEntry, callback); |
| 533 } | 533 } |
| 534 | 534 |
| 535 function errorHandler(error) { | 535 function errorHandler(error) { |
| 536 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); | 536 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); |
| 537 console.error(errorMessage + ' when requesting entry \'' + path + '\''); | 537 console.error(errorMessage + ' when requesting entry \'' + path + '\''); |
| 538 callback([]); | 538 callback([]); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 | 541 |
| 542 _saveExcludedFolders() { | 542 _saveExcludedFolders() { |
| 543 var settingValue = this._excludedFoldersSetting.get(); | 543 var settingValue = this._excludedFoldersSetting.get(); |
| 544 settingValue[this._path] = this._excludedFolders.valuesArray(); | 544 settingValue[this._path] = this._excludedFolders.valuesArray(); |
| 545 this._excludedFoldersSetting.set(settingValue); | 545 this._excludedFoldersSetting.set(settingValue); |
| 546 } | 546 } |
| 547 | 547 |
| 548 /** | 548 /** |
| 549 * @param {string} path | 549 * @param {string} path |
| 550 */ | 550 */ |
| 551 addExcludedFolder(path) { | 551 addExcludedFolder(path) { |
| 552 this._excludedFolders.add(path); | 552 this._excludedFolders.add(path); |
| 553 this._saveExcludedFolders(); | 553 this._saveExcludedFolders(); |
| 554 this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManage
r.Events.ExcludedFolderAdded, path); | 554 this._manager.dispatchEventToListeners(Workspace.IsolatedFileSystemManager.E
vents.ExcludedFolderAdded, path); |
| 555 } | 555 } |
| 556 | 556 |
| 557 /** | 557 /** |
| 558 * @param {string} path | 558 * @param {string} path |
| 559 */ | 559 */ |
| 560 removeExcludedFolder(path) { | 560 removeExcludedFolder(path) { |
| 561 this._excludedFolders.delete(path); | 561 this._excludedFolders.delete(path); |
| 562 this._saveExcludedFolders(); | 562 this._saveExcludedFolders(); |
| 563 this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManage
r.Events.ExcludedFolderRemoved, path); | 563 this._manager.dispatchEventToListeners(Workspace.IsolatedFileSystemManager.E
vents.ExcludedFolderRemoved, path); |
| 564 } | 564 } |
| 565 | 565 |
| 566 fileSystemRemoved() { | 566 fileSystemRemoved() { |
| 567 var settingValue = this._excludedFoldersSetting.get(); | 567 var settingValue = this._excludedFoldersSetting.get(); |
| 568 delete settingValue[this._path]; | 568 delete settingValue[this._path]; |
| 569 this._excludedFoldersSetting.set(settingValue); | 569 this._excludedFoldersSetting.set(settingValue); |
| 570 } | 570 } |
| 571 | 571 |
| 572 /** | 572 /** |
| 573 * @param {string} folderPath | 573 * @param {string} folderPath |
| (...skipping 15 matching lines...) Expand all Loading... |
| 589 | 589 |
| 590 /** | 590 /** |
| 591 * @return {!Set<string>} | 591 * @return {!Set<string>} |
| 592 */ | 592 */ |
| 593 nonConfigurableExcludedFolders() { | 593 nonConfigurableExcludedFolders() { |
| 594 return this._nonConfigurableExcludedFolders; | 594 return this._nonConfigurableExcludedFolders; |
| 595 } | 595 } |
| 596 | 596 |
| 597 /** | 597 /** |
| 598 * @param {string} query | 598 * @param {string} query |
| 599 * @param {!WebInspector.Progress} progress | 599 * @param {!Common.Progress} progress |
| 600 * @param {function(!Array.<string>)} callback | 600 * @param {function(!Array.<string>)} callback |
| 601 */ | 601 */ |
| 602 searchInPath(query, progress, callback) { | 602 searchInPath(query, progress, callback) { |
| 603 var requestId = this._manager.registerCallback(innerCallback); | 603 var requestId = this._manager.registerCallback(innerCallback); |
| 604 InspectorFrontendHost.searchInPath(requestId, this._embedderPath, query); | 604 InspectorFrontendHost.searchInPath(requestId, this._embedderPath, query); |
| 605 | 605 |
| 606 /** | 606 /** |
| 607 * @param {!Array.<string>} files | 607 * @param {!Array.<string>} files |
| 608 */ | 608 */ |
| 609 function innerCallback(files) { | 609 function innerCallback(files) { |
| 610 files = files.map(embedderPath => WebInspector.ParsedURL.platformPathToURL
(embedderPath)); | 610 files = files.map(embedderPath => Common.ParsedURL.platformPathToURL(embed
derPath)); |
| 611 progress.worked(1); | 611 progress.worked(1); |
| 612 callback(files); | 612 callback(files); |
| 613 } | 613 } |
| 614 } | 614 } |
| 615 | 615 |
| 616 /** | 616 /** |
| 617 * @param {!WebInspector.Progress} progress | 617 * @param {!Common.Progress} progress |
| 618 */ | 618 */ |
| 619 indexContent(progress) { | 619 indexContent(progress) { |
| 620 progress.setTotalWork(1); | 620 progress.setTotalWork(1); |
| 621 var requestId = this._manager.registerProgress(progress); | 621 var requestId = this._manager.registerProgress(progress); |
| 622 InspectorFrontendHost.indexPath(requestId, this._embedderPath); | 622 InspectorFrontendHost.indexPath(requestId, this._embedderPath); |
| 623 } | 623 } |
| 624 }; | 624 }; |
| 625 | 625 |
| 626 WebInspector.IsolatedFileSystem.ImageExtensions = | 626 Workspace.IsolatedFileSystem.ImageExtensions = |
| 627 new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', '
bmp']); | 627 new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', '
bmp']); |
| OLD | NEW |