| 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 21 matching lines...) Expand all Loading... |
| 32 * @constructor | 32 * @constructor |
| 33 * @param {!WebInspector.IsolatedFileSystemManager} manager | 33 * @param {!WebInspector.IsolatedFileSystemManager} manager |
| 34 * @param {string} path | 34 * @param {string} path |
| 35 * @param {string} name | 35 * @param {string} name |
| 36 * @param {string} rootURL | 36 * @param {string} rootURL |
| 37 */ | 37 */ |
| 38 WebInspector.IsolatedFileSystem = function(manager, path, name, rootURL) | 38 WebInspector.IsolatedFileSystem = function(manager, path, name, rootURL) |
| 39 { | 39 { |
| 40 this._manager = manager; | 40 this._manager = manager; |
| 41 this._path = path; | 41 this._path = path; |
| 42 this._name = name; | 42 this._domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL
); |
| 43 this._rootURL = rootURL; | |
| 44 } | 43 } |
| 45 | 44 |
| 46 /** | 45 /** |
| 47 * @param {!FileError} error | 46 * @param {!FileError} error |
| 48 * @return {string} | 47 * @return {string} |
| 49 */ | 48 */ |
| 50 WebInspector.IsolatedFileSystem.errorMessage = function(error) | 49 WebInspector.IsolatedFileSystem.errorMessage = function(error) |
| 51 { | 50 { |
| 52 return WebInspector.UIString("File system error: %s", error.message); | 51 return WebInspector.UIString("File system error: %s", error.message); |
| 53 } | 52 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 77 */ | 76 */ |
| 78 normalizedPath: function() | 77 normalizedPath: function() |
| 79 { | 78 { |
| 80 if (this._normalizedPath) | 79 if (this._normalizedPath) |
| 81 return this._normalizedPath; | 80 return this._normalizedPath; |
| 82 this._normalizedPath = WebInspector.IsolatedFileSystem.normalizePath(thi
s._path); | 81 this._normalizedPath = WebInspector.IsolatedFileSystem.normalizePath(thi
s._path); |
| 83 return this._normalizedPath; | 82 return this._normalizedPath; |
| 84 }, | 83 }, |
| 85 | 84 |
| 86 /** | 85 /** |
| 87 * @return {string} | |
| 88 */ | |
| 89 name: function() | |
| 90 { | |
| 91 return this._name; | |
| 92 }, | |
| 93 | |
| 94 /** | |
| 95 * @return {string} | |
| 96 */ | |
| 97 rootURL: function() | |
| 98 { | |
| 99 return this._rootURL; | |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * @param {function(?DOMFileSystem)} callback | |
| 104 */ | |
| 105 _requestFileSystem: function(callback) | |
| 106 { | |
| 107 this._manager.requestDOMFileSystem(this._path, callback); | |
| 108 }, | |
| 109 | |
| 110 /** | |
| 111 * @param {string} path | 86 * @param {string} path |
| 112 * @param {function(string)} fileCallback | 87 * @param {function(string)} fileCallback |
| 113 * @param {function()=} finishedCallback | 88 * @param {function()=} finishedCallback |
| 114 */ | 89 */ |
| 115 requestFilesRecursive: function(path, fileCallback, finishedCallback) | 90 requestFilesRecursive: function(path, fileCallback, finishedCallback) |
| 116 { | 91 { |
| 117 var domFileSystem; | 92 var pendingRequests = 1; |
| 118 var pendingRequests = 0; | 93 this._requestEntries(path, innerCallback.bind(this)); |
| 119 this._requestFileSystem(fileSystemLoaded.bind(this)); | |
| 120 /** | |
| 121 * @param {?DOMFileSystem} fs | |
| 122 * @this {WebInspector.IsolatedFileSystem} | |
| 123 */ | |
| 124 function fileSystemLoaded(fs) | |
| 125 { | |
| 126 domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 127 console.assert(domFileSystem); | |
| 128 ++pendingRequests; | |
| 129 this._requestEntries(domFileSystem, path, innerCallback.bind(this)); | |
| 130 } | |
| 131 | 94 |
| 132 /** | 95 /** |
| 133 * @param {!Array.<!FileEntry>} entries | 96 * @param {!Array.<!FileEntry>} entries |
| 134 * @this {WebInspector.IsolatedFileSystem} | 97 * @this {WebInspector.IsolatedFileSystem} |
| 135 */ | 98 */ |
| 136 function innerCallback(entries) | 99 function innerCallback(entries) |
| 137 { | 100 { |
| 138 for (var i = 0; i < entries.length; ++i) { | 101 for (var i = 0; i < entries.length; ++i) { |
| 139 var entry = entries[i]; | 102 var entry = entries[i]; |
| 140 if (!entry.isDirectory) { | 103 if (!entry.isDirectory) { |
| 141 if (this._manager.excludedFolderManager().isFileExcluded(thi
s._path, entry.fullPath)) | 104 if (this._manager.excludedFolderManager().isFileExcluded(thi
s._path, entry.fullPath)) |
| 142 continue; | 105 continue; |
| 143 fileCallback(entry.fullPath.substr(1)); | 106 fileCallback(entry.fullPath.substr(1)); |
| 144 } | 107 } |
| 145 else { | 108 else { |
| 146 if (this._manager.excludedFolderManager().isFileExcluded(thi
s._path, entry.fullPath + "/")) | 109 if (this._manager.excludedFolderManager().isFileExcluded(thi
s._path, entry.fullPath + "/")) |
| 147 continue; | 110 continue; |
| 148 ++pendingRequests; | 111 ++pendingRequests; |
| 149 this._requestEntries(domFileSystem, entry.fullPath, innerCal
lback.bind(this)); | 112 this._requestEntries(entry.fullPath, innerCallback.bind(this
)); |
| 150 } | 113 } |
| 151 } | 114 } |
| 152 if (finishedCallback && (--pendingRequests === 0)) | 115 if (finishedCallback && (--pendingRequests === 0)) |
| 153 finishedCallback(); | 116 finishedCallback(); |
| 154 } | 117 } |
| 155 }, | 118 }, |
| 156 | 119 |
| 157 /** | 120 /** |
| 158 * @param {string} path | 121 * @param {string} path |
| 159 * @param {?string} name | 122 * @param {?string} name |
| 160 * @param {function(?string)} callback | 123 * @param {function(?string)} callback |
| 161 */ | 124 */ |
| 162 createFile: function(path, name, callback) | 125 createFile: function(path, name, callback) |
| 163 { | 126 { |
| 164 this._requestFileSystem(fileSystemLoaded.bind(this)); | |
| 165 var newFileIndex = 1; | 127 var newFileIndex = 1; |
| 166 if (!name) | 128 if (!name) |
| 167 name = "NewFile"; | 129 name = "NewFile"; |
| 168 var nameCandidate; | 130 var nameCandidate; |
| 169 | 131 |
| 170 /** | 132 this._domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(th
is), errorHandler.bind(this)); |
| 171 * @param {?DOMFileSystem} fs | |
| 172 * @this {WebInspector.IsolatedFileSystem} | |
| 173 */ | |
| 174 function fileSystemLoaded(fs) | |
| 175 { | |
| 176 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 177 console.assert(domFileSystem); | |
| 178 domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(this
), errorHandler.bind(this)); | |
| 179 } | |
| 180 | 133 |
| 181 /** | 134 /** |
| 182 * @param {!DirectoryEntry} dirEntry | 135 * @param {!DirectoryEntry} dirEntry |
| 183 * @this {WebInspector.IsolatedFileSystem} | 136 * @this {WebInspector.IsolatedFileSystem} |
| 184 */ | 137 */ |
| 185 function dirEntryLoaded(dirEntry) | 138 function dirEntryLoaded(dirEntry) |
| 186 { | 139 { |
| 187 var nameCandidate = name; | 140 var nameCandidate = name; |
| 188 if (newFileIndex > 1) | 141 if (newFileIndex > 1) |
| 189 nameCandidate += newFileIndex; | 142 nameCandidate += newFileIndex; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 console.error(errorMessage + " when getting content for file '" + (f
ilePath) + "'"); | 176 console.error(errorMessage + " when getting content for file '" + (f
ilePath) + "'"); |
| 224 callback(null); | 177 callback(null); |
| 225 } | 178 } |
| 226 }, | 179 }, |
| 227 | 180 |
| 228 /** | 181 /** |
| 229 * @param {string} path | 182 * @param {string} path |
| 230 */ | 183 */ |
| 231 deleteFile: function(path) | 184 deleteFile: function(path) |
| 232 { | 185 { |
| 233 this._requestFileSystem(fileSystemLoaded.bind(this)); | 186 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this),
errorHandler.bind(this)); |
| 234 | |
| 235 /** | |
| 236 * @param {?DOMFileSystem} fs | |
| 237 * @this {WebInspector.IsolatedFileSystem} | |
| 238 */ | |
| 239 function fileSystemLoaded(fs) | |
| 240 { | |
| 241 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 242 console.assert(domFileSystem); | |
| 243 domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), e
rrorHandler.bind(this)); | |
| 244 } | |
| 245 | 187 |
| 246 /** | 188 /** |
| 247 * @param {!FileEntry} fileEntry | 189 * @param {!FileEntry} fileEntry |
| 248 * @this {WebInspector.IsolatedFileSystem} | 190 * @this {WebInspector.IsolatedFileSystem} |
| 249 */ | 191 */ |
| 250 function fileEntryLoaded(fileEntry) | 192 function fileEntryLoaded(fileEntry) |
| 251 { | 193 { |
| 252 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); | 194 fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); |
| 253 } | 195 } |
| 254 | 196 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 266 console.error(errorMessage + " when deleting file '" + (this._path +
"/" + path) + "'"); | 208 console.error(errorMessage + " when deleting file '" + (this._path +
"/" + path) + "'"); |
| 267 } | 209 } |
| 268 }, | 210 }, |
| 269 | 211 |
| 270 /** | 212 /** |
| 271 * @param {string} path | 213 * @param {string} path |
| 272 * @param {function(?Date, ?number)} callback | 214 * @param {function(?Date, ?number)} callback |
| 273 */ | 215 */ |
| 274 requestMetadata: function(path, callback) | 216 requestMetadata: function(path, callback) |
| 275 { | 217 { |
| 276 this._requestFileSystem(fileSystemLoaded); | 218 this._domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandl
er); |
| 277 | |
| 278 /** | |
| 279 * @param {?DOMFileSystem} fs | |
| 280 */ | |
| 281 function fileSystemLoaded(fs) | |
| 282 { | |
| 283 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 284 console.assert(domFileSystem); | |
| 285 domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandler
); | |
| 286 } | |
| 287 | 219 |
| 288 /** | 220 /** |
| 289 * @param {!FileEntry} entry | 221 * @param {!FileEntry} entry |
| 290 */ | 222 */ |
| 291 function fileEntryLoaded(entry) | 223 function fileEntryLoaded(entry) |
| 292 { | 224 { |
| 293 entry.getMetadata(successHandler, errorHandler); | 225 entry.getMetadata(successHandler, errorHandler); |
| 294 } | 226 } |
| 295 | 227 |
| 296 /** | 228 /** |
| (...skipping 12 matching lines...) Expand all Loading... |
| 309 callback(null, null); | 241 callback(null, null); |
| 310 } | 242 } |
| 311 }, | 243 }, |
| 312 | 244 |
| 313 /** | 245 /** |
| 314 * @param {string} path | 246 * @param {string} path |
| 315 * @param {function(?string)} callback | 247 * @param {function(?string)} callback |
| 316 */ | 248 */ |
| 317 requestFileContent: function(path, callback) | 249 requestFileContent: function(path, callback) |
| 318 { | 250 { |
| 319 this._requestFileSystem(fileSystemLoaded.bind(this)); | 251 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this),
errorHandler.bind(this)); |
| 320 | |
| 321 /** | |
| 322 * @param {?DOMFileSystem} fs | |
| 323 * @this {WebInspector.IsolatedFileSystem} | |
| 324 */ | |
| 325 function fileSystemLoaded(fs) | |
| 326 { | |
| 327 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 328 console.assert(domFileSystem); | |
| 329 domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), e
rrorHandler.bind(this)); | |
| 330 } | |
| 331 | 252 |
| 332 /** | 253 /** |
| 333 * @param {!FileEntry} entry | 254 * @param {!FileEntry} entry |
| 334 * @this {WebInspector.IsolatedFileSystem} | 255 * @this {WebInspector.IsolatedFileSystem} |
| 335 */ | 256 */ |
| 336 function fileEntryLoaded(entry) | 257 function fileEntryLoaded(entry) |
| 337 { | 258 { |
| 338 entry.file(fileLoaded, errorHandler.bind(this)); | 259 entry.file(fileLoaded, errorHandler.bind(this)); |
| 339 } | 260 } |
| 340 | 261 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 300 } |
| 380 }, | 301 }, |
| 381 | 302 |
| 382 /** | 303 /** |
| 383 * @param {string} path | 304 * @param {string} path |
| 384 * @param {string} content | 305 * @param {string} content |
| 385 * @param {function()} callback | 306 * @param {function()} callback |
| 386 */ | 307 */ |
| 387 setFileContent: function(path, content, callback) | 308 setFileContent: function(path, content, callback) |
| 388 { | 309 { |
| 389 this._requestFileSystem(fileSystemLoaded.bind(this)); | |
| 390 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Fil
eSavedInWorkspace); | 310 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Fil
eSavedInWorkspace); |
| 391 | 311 this._domFileSystem.root.getFile(path, { create: true }, fileEntryLoaded
.bind(this), errorHandler.bind(this)); |
| 392 /** | |
| 393 * @param {?DOMFileSystem} fs | |
| 394 * @this {WebInspector.IsolatedFileSystem} | |
| 395 */ | |
| 396 function fileSystemLoaded(fs) | |
| 397 { | |
| 398 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 399 console.assert(domFileSystem); | |
| 400 domFileSystem.root.getFile(path, { create: true }, fileEntryLoaded.b
ind(this), errorHandler.bind(this)); | |
| 401 } | |
| 402 | 312 |
| 403 /** | 313 /** |
| 404 * @param {!FileEntry} entry | 314 * @param {!FileEntry} entry |
| 405 * @this {WebInspector.IsolatedFileSystem} | 315 * @this {WebInspector.IsolatedFileSystem} |
| 406 */ | 316 */ |
| 407 function fileEntryLoaded(entry) | 317 function fileEntryLoaded(entry) |
| 408 { | 318 { |
| 409 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(t
his)); | 319 entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(t
his)); |
| 410 } | 320 } |
| 411 | 321 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 */ | 355 */ |
| 446 renameFile: function(path, newName, callback) | 356 renameFile: function(path, newName, callback) |
| 447 { | 357 { |
| 448 newName = newName ? newName.trim() : newName; | 358 newName = newName ? newName.trim() : newName; |
| 449 if (!newName || newName.indexOf("/") !== -1) { | 359 if (!newName || newName.indexOf("/") !== -1) { |
| 450 callback(false); | 360 callback(false); |
| 451 return; | 361 return; |
| 452 } | 362 } |
| 453 var fileEntry; | 363 var fileEntry; |
| 454 var dirEntry; | 364 var dirEntry; |
| 455 this._requestFileSystem(fileSystemLoaded.bind(this)); | |
| 456 | 365 |
| 457 /** | 366 this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this),
errorHandler.bind(this)); |
| 458 * @param {?DOMFileSystem} fs | |
| 459 * @this {WebInspector.IsolatedFileSystem} | |
| 460 */ | |
| 461 function fileSystemLoaded(fs) | |
| 462 { | |
| 463 var domFileSystem = /** @type {!DOMFileSystem} */ (fs); | |
| 464 console.assert(domFileSystem); | |
| 465 domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), e
rrorHandler.bind(this)); | |
| 466 } | |
| 467 | 367 |
| 468 /** | 368 /** |
| 469 * @param {!FileEntry} entry | 369 * @param {!FileEntry} entry |
| 470 * @this {WebInspector.IsolatedFileSystem} | 370 * @this {WebInspector.IsolatedFileSystem} |
| 471 */ | 371 */ |
| 472 function fileEntryLoaded(entry) | 372 function fileEntryLoaded(entry) |
| 473 { | 373 { |
| 474 if (entry.name === newName) { | 374 if (entry.name === newName) { |
| 475 callback(false); | 375 callback(false); |
| 476 return; | 376 return; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 | 457 |
| 558 function errorHandler(error) | 458 function errorHandler(error) |
| 559 { | 459 { |
| 560 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(erro
r); | 460 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(erro
r); |
| 561 console.error(errorMessage + " when reading directory '" + dirEntry.
fullPath + "'"); | 461 console.error(errorMessage + " when reading directory '" + dirEntry.
fullPath + "'"); |
| 562 callback([]); | 462 callback([]); |
| 563 } | 463 } |
| 564 }, | 464 }, |
| 565 | 465 |
| 566 /** | 466 /** |
| 567 * @param {!DOMFileSystem} domFileSystem | |
| 568 * @param {string} path | 467 * @param {string} path |
| 569 * @param {function(!Array.<!FileEntry>)} callback | 468 * @param {function(!Array.<!FileEntry>)} callback |
| 570 */ | 469 */ |
| 571 _requestEntries: function(domFileSystem, path, callback) | 470 _requestEntries: function(path, callback) |
| 572 { | 471 { |
| 573 domFileSystem.root.getDirectory(path, null, innerCallback.bind(this), er
rorHandler); | 472 this._domFileSystem.root.getDirectory(path, null, innerCallback.bind(thi
s), errorHandler); |
| 574 | 473 |
| 575 /** | 474 /** |
| 576 * @param {!DirectoryEntry} dirEntry | 475 * @param {!DirectoryEntry} dirEntry |
| 577 * @this {WebInspector.IsolatedFileSystem} | 476 * @this {WebInspector.IsolatedFileSystem} |
| 578 */ | 477 */ |
| 579 function innerCallback(dirEntry) | 478 function innerCallback(dirEntry) |
| 580 { | 479 { |
| 581 this._readDirectory(dirEntry, callback); | 480 this._readDirectory(dirEntry, callback); |
| 582 } | 481 } |
| 583 | 482 |
| 584 function errorHandler(error) | 483 function errorHandler(error) |
| 585 { | 484 { |
| 586 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(erro
r); | 485 var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(erro
r); |
| 587 console.error(errorMessage + " when requesting entry '" + path + "'"
); | 486 console.error(errorMessage + " when requesting entry '" + path + "'"
); |
| 588 callback([]); | 487 callback([]); |
| 589 } | 488 } |
| 590 } | 489 } |
| 591 } | 490 } |
| OLD | NEW |