| 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 Workspace.IsolatedFileSystem = class { | 34 Persistence.IsolatedFileSystem = class { |
| 35 /** | 35 /** |
| 36 * @param {!Workspace.IsolatedFileSystemManager} manager | 36 * @param {!Persistence.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 = Common.settings.createLocalSetting('workspace
ExcludedFolders', {}); | 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 | 49 |
| 50 /** @type {!Set<string>} */ | 50 /** @type {!Set<string>} */ |
| 51 this._initialFilePaths = new Set(); | 51 this._initialFilePaths = new Set(); |
| 52 /** @type {!Set<string>} */ | 52 /** @type {!Set<string>} */ |
| 53 this._initialGitFolders = new Set(); | 53 this._initialGitFolders = new Set(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {!Workspace.IsolatedFileSystemManager} manager | 57 * @param {!Persistence.IsolatedFileSystemManager} manager |
| 58 * @param {string} path | 58 * @param {string} path |
| 59 * @param {string} embedderPath | 59 * @param {string} embedderPath |
| 60 * @param {string} name | 60 * @param {string} name |
| 61 * @param {string} rootURL | 61 * @param {string} rootURL |
| 62 * @return {!Promise<?Workspace.IsolatedFileSystem>} | 62 * @return {!Promise<?Persistence.IsolatedFileSystem>} |
| 63 */ | 63 */ |
| 64 static create(manager, path, embedderPath, name, rootURL) { | 64 static create(manager, path, embedderPath, name, rootURL) { |
| 65 var domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL); | 65 var domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL); |
| 66 if (!domFileSystem) | 66 if (!domFileSystem) |
| 67 return Promise.resolve(/** @type {?Workspace.IsolatedFileSystem} */ (null)
); | 67 return Promise.resolve(/** @type {?Persistence.IsolatedFileSystem} */ (nul
l)); |
| 68 | 68 |
| 69 var fileSystem = new Workspace.IsolatedFileSystem(manager, path, embedderPat
h, domFileSystem); | 69 var fileSystem = new Persistence.IsolatedFileSystem(manager, path, embedderP
ath, domFileSystem); |
| 70 return fileSystem._initializeFilePaths() | 70 return fileSystem._initializeFilePaths() |
| 71 .then(() => fileSystem) | 71 .then(() => fileSystem) |
| 72 .catchException(/** @type {?Workspace.IsolatedFileSystem} */ (null)); | 72 .catchException(/** @type {?Persistence.IsolatedFileSystem} */ (null)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * @param {!DOMError} error | 76 * @param {!DOMError} error |
| 77 * @return {string} | 77 * @return {string} |
| 78 */ | 78 */ |
| 79 static errorMessage(error) { | 79 static errorMessage(error) { |
| 80 return Common.UIString('File system error: %s', error.message); | 80 return Common.UIString('File system error: %s', error.message); |
| 81 } | 81 } |
| 82 | 82 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 * @param {!FileEntry} entry | 94 * @param {!FileEntry} entry |
| 95 */ | 95 */ |
| 96 function fileEntryLoaded(entry) { | 96 function fileEntryLoaded(entry) { |
| 97 entry.getMetadata(fulfill, errorHandler); | 97 entry.getMetadata(fulfill, errorHandler); |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * @param {!FileError} error | 101 * @param {!FileError} error |
| 102 */ | 102 */ |
| 103 function errorHandler(error) { | 103 function errorHandler(error) { |
| 104 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 104 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 105 console.error(errorMessage + ' when getting file metadata \'' + path); | 105 console.error(errorMessage + ' when getting file metadata \'' + path); |
| 106 fulfill(null); | 106 fulfill(null); |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @return {!Array<string>} | 111 * @return {!Array<string>} |
| 112 */ | 112 */ |
| 113 initialFilePaths() { | 113 initialFilePaths() { |
| 114 return this._initialFilePaths.valuesArray(); | 114 return this._initialFilePaths.valuesArray(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 141 _initializeFilePaths() { | 141 _initializeFilePaths() { |
| 142 var fulfill; | 142 var fulfill; |
| 143 var promise = new Promise(x => fulfill = x); | 143 var promise = new Promise(x => fulfill = x); |
| 144 var pendingRequests = 1; | 144 var pendingRequests = 1; |
| 145 var boundInnerCallback = innerCallback.bind(this); | 145 var boundInnerCallback = innerCallback.bind(this); |
| 146 this._requestEntries('', boundInnerCallback); | 146 this._requestEntries('', boundInnerCallback); |
| 147 return promise; | 147 return promise; |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * @param {!Array.<!FileEntry>} entries | 150 * @param {!Array.<!FileEntry>} entries |
| 151 * @this {Workspace.IsolatedFileSystem} | 151 * @this {Persistence.IsolatedFileSystem} |
| 152 */ | 152 */ |
| 153 function innerCallback(entries) { | 153 function innerCallback(entries) { |
| 154 for (var i = 0; i < entries.length; ++i) { | 154 for (var i = 0; i < entries.length; ++i) { |
| 155 var entry = entries[i]; | 155 var entry = entries[i]; |
| 156 if (!entry.isDirectory) { | 156 if (!entry.isDirectory) { |
| 157 if (this._isFileExcluded(entry.fullPath)) | 157 if (this._isFileExcluded(entry.fullPath)) |
| 158 continue; | 158 continue; |
| 159 this._initialFilePaths.add(entry.fullPath.substr(1)); | 159 this._initialFilePaths.add(entry.fullPath.substr(1)); |
| 160 } else { | 160 } else { |
| 161 if (entry.fullPath.endsWith('/.git')) { | 161 if (entry.fullPath.endsWith('/.git')) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 182 createFile(path, name, callback) { | 182 createFile(path, name, callback) { |
| 183 var newFileIndex = 1; | 183 var newFileIndex = 1; |
| 184 if (!name) | 184 if (!name) |
| 185 name = 'NewFile'; | 185 name = 'NewFile'; |
| 186 var nameCandidate; | 186 var nameCandidate; |
| 187 | 187 |
| 188 this._domFileSystem.root.getDirectory(path, undefined, dirEntryLoaded.bind(t
his), errorHandler.bind(this)); | 188 this._domFileSystem.root.getDirectory(path, undefined, dirEntryLoaded.bind(t
his), errorHandler.bind(this)); |
| 189 | 189 |
| 190 /** | 190 /** |
| 191 * @param {!DirectoryEntry} dirEntry | 191 * @param {!DirectoryEntry} dirEntry |
| 192 * @this {Workspace.IsolatedFileSystem} | 192 * @this {Persistence.IsolatedFileSystem} |
| 193 */ | 193 */ |
| 194 function dirEntryLoaded(dirEntry) { | 194 function dirEntryLoaded(dirEntry) { |
| 195 var nameCandidate = name; | 195 var nameCandidate = name; |
| 196 if (newFileIndex > 1) | 196 if (newFileIndex > 1) |
| 197 nameCandidate += newFileIndex; | 197 nameCandidate += newFileIndex; |
| 198 ++newFileIndex; | 198 ++newFileIndex; |
| 199 dirEntry.getFile(nameCandidate, {create: true, exclusive: true}, fileCreat
ed, fileCreationError.bind(this)); | 199 dirEntry.getFile(nameCandidate, {create: true, exclusive: true}, fileCreat
ed, fileCreationError.bind(this)); |
| 200 | 200 |
| 201 function fileCreated(entry) { | 201 function fileCreated(entry) { |
| 202 callback(entry.fullPath.substr(1)); | 202 callback(entry.fullPath.substr(1)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 /** | 205 /** |
| 206 * @this {Workspace.IsolatedFileSystem} | 206 * @this {Persistence.IsolatedFileSystem} |
| 207 */ | 207 */ |
| 208 function fileCreationError(error) { | 208 function fileCreationError(error) { |
| 209 if (error.name === 'InvalidModificationError') { | 209 if (error.name === 'InvalidModificationError') { |
| 210 dirEntryLoaded.call(this, dirEntry); | 210 dirEntryLoaded.call(this, dirEntry); |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 213 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 214 console.error( | 214 console.error( |
| 215 errorMessage + ' when testing if file exists \'' + (this._path + '/'
+ path + '/' + nameCandidate) + '\''); | 215 errorMessage + ' when testing if file exists \'' + (this._path + '/'
+ path + '/' + nameCandidate) + '\''); |
| 216 callback(null); | 216 callback(null); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 /** | 220 /** |
| 221 * @this {Workspace.IsolatedFileSystem} | 221 * @this {Persistence.IsolatedFileSystem} |
| 222 */ | 222 */ |
| 223 function errorHandler(error) { | 223 function errorHandler(error) { |
| 224 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 224 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 225 var filePath = this._path + '/' + path; | 225 var filePath = this._path + '/' + path; |
| 226 if (nameCandidate) | 226 if (nameCandidate) |
| 227 filePath += '/' + nameCandidate; | 227 filePath += '/' + nameCandidate; |
| 228 console.error(errorMessage + ' when getting content for file \'' + (filePa
th) + '\''); | 228 console.error(errorMessage + ' when getting content for file \'' + (filePa
th) + '\''); |
| 229 callback(null); | 229 callback(null); |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * @param {string} path | 234 * @param {string} path |
| 235 */ | 235 */ |
| 236 deleteFile(path) { | 236 deleteFile(path) { |
| 237 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); | 237 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); |
| 238 | 238 |
| 239 /** | 239 /** |
| 240 * @param {!FileEntry} fileEntry | 240 * @param {!FileEntry} fileEntry |
| 241 * @this {Workspace.IsolatedFileSystem} | 241 * @this {Persistence.IsolatedFileSystem} |
| 242 */ | 242 */ |
| 243 function fileEntryLoaded(fileEntry) { | 243 function fileEntryLoaded(fileEntry) { |
| 244 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); | 244 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 function fileEntryRemoved() { | 247 function fileEntryRemoved() { |
| 248 } | 248 } |
| 249 | 249 |
| 250 /** | 250 /** |
| 251 * @param {!FileError} error | 251 * @param {!FileError} error |
| 252 * @this {Workspace.IsolatedFileSystem} | 252 * @this {Persistence.IsolatedFileSystem} |
| 253 * @suppress {checkTypes} | 253 * @suppress {checkTypes} |
| 254 * TODO(jsbell): Update externs replacing FileError with DOMException. https
://crbug.com/496901 | 254 * TODO(jsbell): Update externs replacing FileError with DOMException. https
://crbug.com/496901 |
| 255 */ | 255 */ |
| 256 function errorHandler(error) { | 256 function errorHandler(error) { |
| 257 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 257 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 258 console.error(errorMessage + ' when deleting file \'' + (this._path + '/'
+ path) + '\''); | 258 console.error(errorMessage + ' when deleting file \'' + (this._path + '/'
+ path) + '\''); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * @param {string} path | 263 * @param {string} path |
| 264 * @return {!Promise<?string>} | 264 * @return {!Promise<?string>} |
| 265 */ | 265 */ |
| 266 requestFileContentPromise(path) { | 266 requestFileContentPromise(path) { |
| 267 var fulfill; | 267 var fulfill; |
| 268 var promise = new Promise(x => fulfill = x); | 268 var promise = new Promise(x => fulfill = x); |
| 269 this.requestFileContent(path, fulfill); | 269 this.requestFileContent(path, fulfill); |
| 270 return promise; | 270 return promise; |
| 271 } | 271 } |
| 272 | 272 |
| 273 /** | 273 /** |
| 274 * @param {string} path | 274 * @param {string} path |
| 275 * @param {function(?string)} callback | 275 * @param {function(?string)} callback |
| 276 */ | 276 */ |
| 277 requestFileContent(path, callback) { | 277 requestFileContent(path, callback) { |
| 278 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); | 278 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); |
| 279 | 279 |
| 280 /** | 280 /** |
| 281 * @param {!FileEntry} entry | 281 * @param {!FileEntry} entry |
| 282 * @this {Workspace.IsolatedFileSystem} | 282 * @this {Persistence.IsolatedFileSystem} |
| 283 */ | 283 */ |
| 284 function fileEntryLoaded(entry) { | 284 function fileEntryLoaded(entry) { |
| 285 entry.file(fileLoaded, errorHandler.bind(this)); | 285 entry.file(fileLoaded, errorHandler.bind(this)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * @param {!Blob} file | 289 * @param {!Blob} file |
| 290 */ | 290 */ |
| 291 function fileLoaded(file) { | 291 function fileLoaded(file) { |
| 292 var reader = new FileReader(); | 292 var reader = new FileReader(); |
| 293 reader.onloadend = readerLoadEnd; | 293 reader.onloadend = readerLoadEnd; |
| 294 if (Workspace.IsolatedFileSystem.ImageExtensions.has(Common.ParsedURL.extr
actExtension(path))) | 294 if (Persistence.IsolatedFileSystem.ImageExtensions.has(Common.ParsedURL.ex
tractExtension(path))) |
| 295 reader.readAsDataURL(file); | 295 reader.readAsDataURL(file); |
| 296 else | 296 else |
| 297 reader.readAsText(file); | 297 reader.readAsText(file); |
| 298 } | 298 } |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * @this {!FileReader} | 301 * @this {!FileReader} |
| 302 */ | 302 */ |
| 303 function readerLoadEnd() { | 303 function readerLoadEnd() { |
| 304 /** @type {?string} */ | 304 /** @type {?string} */ |
| 305 var string = null; | 305 var string = null; |
| 306 try { | 306 try { |
| 307 string = /** @type {string} */ (this.result); | 307 string = /** @type {string} */ (this.result); |
| 308 } catch (e) { | 308 } catch (e) { |
| 309 console.error('Can\'t read file: ' + path + ': ' + e); | 309 console.error('Can\'t read file: ' + path + ': ' + e); |
| 310 } | 310 } |
| 311 callback(string); | 311 callback(string); |
| 312 } | 312 } |
| 313 | 313 |
| 314 /** | 314 /** |
| 315 * @this {Workspace.IsolatedFileSystem} | 315 * @this {Persistence.IsolatedFileSystem} |
| 316 */ | 316 */ |
| 317 function errorHandler(error) { | 317 function errorHandler(error) { |
| 318 if (error.name === 'NotFoundError') { | 318 if (error.name === 'NotFoundError') { |
| 319 callback(null); | 319 callback(null); |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 | 322 |
| 323 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 323 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 324 console.error(errorMessage + ' when getting content for file \'' + (this._
path + '/' + path) + '\''); | 324 console.error(errorMessage + ' when getting content for file \'' + (this._
path + '/' + path) + '\''); |
| 325 callback(null); | 325 callback(null); |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 /** | 329 /** |
| 330 * @param {string} path | 330 * @param {string} path |
| 331 * @param {string} content | 331 * @param {string} content |
| 332 * @param {function()} callback | 332 * @param {function()} callback |
| 333 */ | 333 */ |
| 334 setFileContent(path, content, callback) { | 334 setFileContent(path, content, callback) { |
| 335 Host.userMetrics.actionTaken(Host.UserMetrics.Action.FileSavedInWorkspace); | 335 Host.userMetrics.actionTaken(Host.UserMetrics.Action.FileSavedInWorkspace); |
| 336 this._domFileSystem.root.getFile(path, {create: true}, fileEntryLoaded.bind(
this), errorHandler.bind(this)); | 336 this._domFileSystem.root.getFile(path, {create: true}, fileEntryLoaded.bind(
this), errorHandler.bind(this)); |
| 337 | 337 |
| 338 /** | 338 /** |
| 339 * @param {!FileEntry} entry | 339 * @param {!FileEntry} entry |
| 340 * @this {Workspace.IsolatedFileSystem} | 340 * @this {Persistence.IsolatedFileSystem} |
| 341 */ | 341 */ |
| 342 function fileEntryLoaded(entry) { | 342 function fileEntryLoaded(entry) { |
| 343 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); | 343 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); |
| 344 } | 344 } |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * @param {!FileWriter} fileWriter | 347 * @param {!FileWriter} fileWriter |
| 348 * @this {Workspace.IsolatedFileSystem} | 348 * @this {Persistence.IsolatedFileSystem} |
| 349 */ | 349 */ |
| 350 function fileWriterCreated(fileWriter) { | 350 function fileWriterCreated(fileWriter) { |
| 351 fileWriter.onerror = errorHandler.bind(this); | 351 fileWriter.onerror = errorHandler.bind(this); |
| 352 fileWriter.onwriteend = fileWritten; | 352 fileWriter.onwriteend = fileWritten; |
| 353 var blob = new Blob([content], {type: 'text/plain'}); | 353 var blob = new Blob([content], {type: 'text/plain'}); |
| 354 fileWriter.write(blob); | 354 fileWriter.write(blob); |
| 355 | 355 |
| 356 function fileWritten() { | 356 function fileWritten() { |
| 357 fileWriter.onwriteend = callback; | 357 fileWriter.onwriteend = callback; |
| 358 fileWriter.truncate(blob.size); | 358 fileWriter.truncate(blob.size); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 /** | 362 /** |
| 363 * @this {Workspace.IsolatedFileSystem} | 363 * @this {Persistence.IsolatedFileSystem} |
| 364 */ | 364 */ |
| 365 function errorHandler(error) { | 365 function errorHandler(error) { |
| 366 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 366 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 367 console.error(errorMessage + ' when setting content for file \'' + (this._
path + '/' + path) + '\''); | 367 console.error(errorMessage + ' when setting content for file \'' + (this._
path + '/' + path) + '\''); |
| 368 callback(); | 368 callback(); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 /** | 372 /** |
| 373 * @param {string} path | 373 * @param {string} path |
| 374 * @param {string} newName | 374 * @param {string} newName |
| 375 * @param {function(boolean, string=)} callback | 375 * @param {function(boolean, string=)} callback |
| 376 */ | 376 */ |
| 377 renameFile(path, newName, callback) { | 377 renameFile(path, newName, callback) { |
| 378 newName = newName ? newName.trim() : newName; | 378 newName = newName ? newName.trim() : newName; |
| 379 if (!newName || newName.indexOf('/') !== -1) { | 379 if (!newName || newName.indexOf('/') !== -1) { |
| 380 callback(false); | 380 callback(false); |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 var fileEntry; | 383 var fileEntry; |
| 384 var dirEntry; | 384 var dirEntry; |
| 385 | 385 |
| 386 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); | 386 this._domFileSystem.root.getFile(path, undefined, fileEntryLoaded.bind(this)
, errorHandler.bind(this)); |
| 387 | 387 |
| 388 /** | 388 /** |
| 389 * @param {!FileEntry} entry | 389 * @param {!FileEntry} entry |
| 390 * @this {Workspace.IsolatedFileSystem} | 390 * @this {Persistence.IsolatedFileSystem} |
| 391 */ | 391 */ |
| 392 function fileEntryLoaded(entry) { | 392 function fileEntryLoaded(entry) { |
| 393 if (entry.name === newName) { | 393 if (entry.name === newName) { |
| 394 callback(false); | 394 callback(false); |
| 395 return; | 395 return; |
| 396 } | 396 } |
| 397 | 397 |
| 398 fileEntry = entry; | 398 fileEntry = entry; |
| 399 fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); | 399 fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 /** | 402 /** |
| 403 * @param {!Entry} entry | 403 * @param {!Entry} entry |
| 404 * @this {Workspace.IsolatedFileSystem} | 404 * @this {Persistence.IsolatedFileSystem} |
| 405 */ | 405 */ |
| 406 function dirEntryLoaded(entry) { | 406 function dirEntryLoaded(entry) { |
| 407 dirEntry = entry; | 407 dirEntry = entry; |
| 408 dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorH
andler.bind(this)); | 408 dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorH
andler.bind(this)); |
| 409 } | 409 } |
| 410 | 410 |
| 411 /** | 411 /** |
| 412 * @param {!FileEntry} entry | 412 * @param {!FileEntry} entry |
| 413 */ | 413 */ |
| 414 function newFileEntryLoaded(entry) { | 414 function newFileEntryLoaded(entry) { |
| 415 callback(false); | 415 callback(false); |
| 416 } | 416 } |
| 417 | 417 |
| 418 /** | 418 /** |
| 419 * @this {Workspace.IsolatedFileSystem} | 419 * @this {Persistence.IsolatedFileSystem} |
| 420 */ | 420 */ |
| 421 function newFileEntryLoadErrorHandler(error) { | 421 function newFileEntryLoadErrorHandler(error) { |
| 422 if (error.name !== 'NotFoundError') { | 422 if (error.name !== 'NotFoundError') { |
| 423 callback(false); | 423 callback(false); |
| 424 return; | 424 return; |
| 425 } | 425 } |
| 426 fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); | 426 fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 /** | 429 /** |
| 430 * @param {!FileEntry} entry | 430 * @param {!FileEntry} entry |
| 431 */ | 431 */ |
| 432 function fileRenamed(entry) { | 432 function fileRenamed(entry) { |
| 433 callback(true, entry.name); | 433 callback(true, entry.name); |
| 434 } | 434 } |
| 435 | 435 |
| 436 /** | 436 /** |
| 437 * @this {Workspace.IsolatedFileSystem} | 437 * @this {Persistence.IsolatedFileSystem} |
| 438 */ | 438 */ |
| 439 function errorHandler(error) { | 439 function errorHandler(error) { |
| 440 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 440 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 441 console.error(errorMessage + ' when renaming file \'' + (this._path + '/'
+ path) + '\' to \'' + newName + '\''); | 441 console.error(errorMessage + ' when renaming file \'' + (this._path + '/'
+ path) + '\' to \'' + newName + '\''); |
| 442 callback(false); | 442 callback(false); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 /** | 446 /** |
| 447 * @param {!DirectoryEntry} dirEntry | 447 * @param {!DirectoryEntry} dirEntry |
| 448 * @param {function(!Array.<!FileEntry>)} callback | 448 * @param {function(!Array.<!FileEntry>)} callback |
| 449 */ | 449 */ |
| 450 _readDirectory(dirEntry, callback) { | 450 _readDirectory(dirEntry, callback) { |
| 451 var dirReader = dirEntry.createReader(); | 451 var dirReader = dirEntry.createReader(); |
| 452 var entries = []; | 452 var entries = []; |
| 453 | 453 |
| 454 function innerCallback(results) { | 454 function innerCallback(results) { |
| 455 if (!results.length) { | 455 if (!results.length) { |
| 456 callback(entries.sort()); | 456 callback(entries.sort()); |
| 457 } else { | 457 } else { |
| 458 entries = entries.concat(toArray(results)); | 458 entries = entries.concat(toArray(results)); |
| 459 dirReader.readEntries(innerCallback, errorHandler); | 459 dirReader.readEntries(innerCallback, errorHandler); |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 function toArray(list) { | 463 function toArray(list) { |
| 464 return Array.prototype.slice.call(list || [], 0); | 464 return Array.prototype.slice.call(list || [], 0); |
| 465 } | 465 } |
| 466 | 466 |
| 467 dirReader.readEntries(innerCallback, errorHandler); | 467 dirReader.readEntries(innerCallback, errorHandler); |
| 468 | 468 |
| 469 function errorHandler(error) { | 469 function errorHandler(error) { |
| 470 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 470 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 471 console.error(errorMessage + ' when reading directory \'' + dirEntry.fullP
ath + '\''); | 471 console.error(errorMessage + ' when reading directory \'' + dirEntry.fullP
ath + '\''); |
| 472 callback([]); | 472 callback([]); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 | 475 |
| 476 /** | 476 /** |
| 477 * @param {string} path | 477 * @param {string} path |
| 478 * @param {function(!Array.<!FileEntry>)} callback | 478 * @param {function(!Array.<!FileEntry>)} callback |
| 479 */ | 479 */ |
| 480 _requestEntries(path, callback) { | 480 _requestEntries(path, callback) { |
| 481 this._domFileSystem.root.getDirectory(path, undefined, innerCallback.bind(th
is), errorHandler); | 481 this._domFileSystem.root.getDirectory(path, undefined, innerCallback.bind(th
is), errorHandler); |
| 482 | 482 |
| 483 /** | 483 /** |
| 484 * @param {!DirectoryEntry} dirEntry | 484 * @param {!DirectoryEntry} dirEntry |
| 485 * @this {Workspace.IsolatedFileSystem} | 485 * @this {Persistence.IsolatedFileSystem} |
| 486 */ | 486 */ |
| 487 function innerCallback(dirEntry) { | 487 function innerCallback(dirEntry) { |
| 488 this._readDirectory(dirEntry, callback); | 488 this._readDirectory(dirEntry, callback); |
| 489 } | 489 } |
| 490 | 490 |
| 491 function errorHandler(error) { | 491 function errorHandler(error) { |
| 492 var errorMessage = Workspace.IsolatedFileSystem.errorMessage(error); | 492 var errorMessage = Persistence.IsolatedFileSystem.errorMessage(error); |
| 493 console.error(errorMessage + ' when requesting entry \'' + path + '\''); | 493 console.error(errorMessage + ' when requesting entry \'' + path + '\''); |
| 494 callback([]); | 494 callback([]); |
| 495 } | 495 } |
| 496 } | 496 } |
| 497 | 497 |
| 498 _saveExcludedFolders() { | 498 _saveExcludedFolders() { |
| 499 var settingValue = this._excludedFoldersSetting.get(); | 499 var settingValue = this._excludedFoldersSetting.get(); |
| 500 settingValue[this._path] = this._excludedFolders.valuesArray(); | 500 settingValue[this._path] = this._excludedFolders.valuesArray(); |
| 501 this._excludedFoldersSetting.set(settingValue); | 501 this._excludedFoldersSetting.set(settingValue); |
| 502 } | 502 } |
| 503 | 503 |
| 504 /** | 504 /** |
| 505 * @param {string} path | 505 * @param {string} path |
| 506 */ | 506 */ |
| 507 addExcludedFolder(path) { | 507 addExcludedFolder(path) { |
| 508 this._excludedFolders.add(path); | 508 this._excludedFolders.add(path); |
| 509 this._saveExcludedFolders(); | 509 this._saveExcludedFolders(); |
| 510 this._manager.dispatchEventToListeners(Workspace.IsolatedFileSystemManager.E
vents.ExcludedFolderAdded, path); | 510 this._manager.dispatchEventToListeners(Persistence.IsolatedFileSystemManager
.Events.ExcludedFolderAdded, path); |
| 511 } | 511 } |
| 512 | 512 |
| 513 /** | 513 /** |
| 514 * @param {string} path | 514 * @param {string} path |
| 515 */ | 515 */ |
| 516 removeExcludedFolder(path) { | 516 removeExcludedFolder(path) { |
| 517 this._excludedFolders.delete(path); | 517 this._excludedFolders.delete(path); |
| 518 this._saveExcludedFolders(); | 518 this._saveExcludedFolders(); |
| 519 this._manager.dispatchEventToListeners(Workspace.IsolatedFileSystemManager.E
vents.ExcludedFolderRemoved, path); | 519 this._manager.dispatchEventToListeners(Persistence.IsolatedFileSystemManager
.Events.ExcludedFolderRemoved, path); |
| 520 } | 520 } |
| 521 | 521 |
| 522 fileSystemRemoved() { | 522 fileSystemRemoved() { |
| 523 var settingValue = this._excludedFoldersSetting.get(); | 523 var settingValue = this._excludedFoldersSetting.get(); |
| 524 delete settingValue[this._path]; | 524 delete settingValue[this._path]; |
| 525 this._excludedFoldersSetting.set(settingValue); | 525 this._excludedFoldersSetting.set(settingValue); |
| 526 } | 526 } |
| 527 | 527 |
| 528 /** | 528 /** |
| 529 * @param {string} folderPath | 529 * @param {string} folderPath |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 /** | 565 /** |
| 566 * @param {!Common.Progress} progress | 566 * @param {!Common.Progress} progress |
| 567 */ | 567 */ |
| 568 indexContent(progress) { | 568 indexContent(progress) { |
| 569 progress.setTotalWork(1); | 569 progress.setTotalWork(1); |
| 570 var requestId = this._manager.registerProgress(progress); | 570 var requestId = this._manager.registerProgress(progress); |
| 571 InspectorFrontendHost.indexPath(requestId, this._embedderPath); | 571 InspectorFrontendHost.indexPath(requestId, this._embedderPath); |
| 572 } | 572 } |
| 573 }; | 573 }; |
| 574 | 574 |
| 575 Workspace.IsolatedFileSystem.ImageExtensions = | 575 Persistence.IsolatedFileSystem.ImageExtensions = |
| 576 new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', '
bmp']); | 576 new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', '
bmp']); |
| OLD | NEW |