Index: third_party/WebKit/Source/devtools/front_end/workspace/IsolatedFileSystem.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/workspace/IsolatedFileSystem.js b/third_party/WebKit/Source/devtools/front_end/workspace/IsolatedFileSystem.js |
index 86d4c8e38bbef0cf8a3122c8cd391cf0fe94ae5f..21a1a3374253c0c4983a83f9c0f149ee3788d4be 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/workspace/IsolatedFileSystem.js |
+++ b/third_party/WebKit/Source/devtools/front_end/workspace/IsolatedFileSystem.js |
@@ -27,21 +27,22 @@ |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
- |
/** |
- * @constructor |
- * @param {!WebInspector.IsolatedFileSystemManager} manager |
- * @param {string} path |
- * @param {string} embedderPath |
- * @param {!DOMFileSystem} domFileSystem |
+ * @unrestricted |
*/ |
-WebInspector.IsolatedFileSystem = function(manager, path, embedderPath, domFileSystem) |
-{ |
+WebInspector.IsolatedFileSystem = class { |
+ /** |
+ * @param {!WebInspector.IsolatedFileSystemManager} manager |
+ * @param {string} path |
+ * @param {string} embedderPath |
+ * @param {!DOMFileSystem} domFileSystem |
+ */ |
+ constructor(manager, path, embedderPath, domFileSystem) { |
this._manager = manager; |
this._path = path; |
this._embedderPath = embedderPath; |
this._domFileSystem = domFileSystem; |
- this._excludedFoldersSetting = WebInspector.settings.createLocalSetting("workspaceExcludedFolders", {}); |
+ this._excludedFoldersSetting = WebInspector.settings.createLocalSetting('workspaceExcludedFolders', {}); |
/** @type {!Set<string>} */ |
this._excludedFolders = new Set(this._excludedFoldersSetting.get()[path] || []); |
/** @type {!Set<string>} */ |
@@ -51,632 +52,577 @@ WebInspector.IsolatedFileSystem = function(manager, path, embedderPath, domFileS |
this._filePaths = new Set(); |
/** @type {!Set<string>} */ |
this._gitFolders = new Set(); |
-}; |
- |
-WebInspector.IsolatedFileSystem.ImageExtensions = new Set(["jpeg", "jpg", "svg", "gif", "webp", "png", "ico", "tiff", "tif", "bmp"]); |
- |
-/** |
- * @constructor |
- * @param {!WebInspector.IsolatedFileSystemManager} manager |
- * @param {string} path |
- * @param {string} embedderPath |
- * @param {string} name |
- * @param {string} rootURL |
- * @return {!Promise<?WebInspector.IsolatedFileSystem>} |
- */ |
-WebInspector.IsolatedFileSystem.create = function(manager, path, embedderPath, name, rootURL) |
-{ |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.IsolatedFileSystemManager} manager |
+ * @param {string} path |
+ * @param {string} embedderPath |
+ * @param {string} name |
+ * @param {string} rootURL |
+ * @return {!Promise<?WebInspector.IsolatedFileSystem>} |
+ */ |
+ static create(manager, path, embedderPath, name, rootURL) { |
var domFileSystem = InspectorFrontendHost.isolatedFileSystem(name, rootURL); |
if (!domFileSystem) |
- return Promise.resolve(/** @type {?WebInspector.IsolatedFileSystem} */(null)); |
+ return Promise.resolve(/** @type {?WebInspector.IsolatedFileSystem} */ (null)); |
var fileSystem = new WebInspector.IsolatedFileSystem(manager, path, embedderPath, domFileSystem); |
- var fileContentPromise = fileSystem.requestFileContentPromise(".devtools"); |
+ var fileContentPromise = fileSystem.requestFileContentPromise('.devtools'); |
return fileContentPromise.then(onConfigAvailable) |
.then(() => fileSystem) |
- .catchException(/** @type {?WebInspector.IsolatedFileSystem} */(null)); |
+ .catchException(/** @type {?WebInspector.IsolatedFileSystem} */ (null)); |
/** |
* @param {?string} projectText |
* @return {!Promise} |
*/ |
- function onConfigAvailable(projectText) |
- { |
- if (projectText) { |
- try { |
- var projectObject = JSON.parse(projectText); |
- fileSystem._initializeProject(typeof projectObject === "object" ? /** @type {!Object} */ (projectObject) : null); |
- } catch (e) { |
- WebInspector.console.error("Invalid project file: " + projectText); |
- } |
+ function onConfigAvailable(projectText) { |
+ if (projectText) { |
+ try { |
+ var projectObject = JSON.parse(projectText); |
+ fileSystem._initializeProject( |
+ typeof projectObject === 'object' ? /** @type {!Object} */ (projectObject) : null); |
+ } catch (e) { |
+ WebInspector.console.error('Invalid project file: ' + projectText); |
} |
- return fileSystem._initializeFilePaths(); |
+ } |
+ return fileSystem._initializeFilePaths(); |
} |
-}; |
+ } |
+ |
+ /** |
+ * @param {!DOMError} error |
+ * @return {string} |
+ */ |
+ static errorMessage(error) { |
+ return WebInspector.UIString('File system error: %s', error.message); |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ * @return {!Promise<?{modificationTime: !Date, size: number}>} |
+ */ |
+ getMetadata(path) { |
+ var fulfill; |
+ var promise = new Promise(f => fulfill = f); |
+ this._domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandler); |
+ return promise; |
-/** |
- * @param {!DOMError} error |
- * @return {string} |
- */ |
-WebInspector.IsolatedFileSystem.errorMessage = function(error) |
-{ |
- return WebInspector.UIString("File system error: %s", error.message); |
-}; |
- |
-WebInspector.IsolatedFileSystem.prototype = { |
/** |
- * @param {string} path |
- * @return {!Promise<?{modificationTime: !Date, size: number}>} |
+ * @param {!FileEntry} entry |
*/ |
- getMetadata: function(path) |
- { |
- var fulfill; |
- var promise = new Promise(f => fulfill = f); |
- this._domFileSystem.root.getFile(path, null, fileEntryLoaded, errorHandler); |
- return promise; |
- |
- /** |
- * @param {!FileEntry} entry |
- */ |
- function fileEntryLoaded(entry) |
- { |
- entry.getMetadata(fulfill, errorHandler); |
- } |
- |
- /** |
- * @param {!FileError} error |
- */ |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when getting file metadata '" + path); |
- fulfill(null); |
- } |
- }, |
+ function fileEntryLoaded(entry) { |
+ entry.getMetadata(fulfill, errorHandler); |
+ } |
/** |
- * @return {!Array<string>} |
+ * @param {!FileError} error |
*/ |
- filePaths: function() |
- { |
- return this._filePaths.valuesArray(); |
- }, |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when getting file metadata \'' + path); |
+ fulfill(null); |
+ } |
+ } |
+ |
+ /** |
+ * @return {!Array<string>} |
+ */ |
+ filePaths() { |
+ return this._filePaths.valuesArray(); |
+ } |
+ |
+ /** |
+ * @return {!Array<string>} |
+ */ |
+ gitFolders() { |
+ return this._gitFolders.valuesArray(); |
+ } |
+ |
+ /** |
+ * @return {string} |
+ */ |
+ path() { |
+ return this._path; |
+ } |
+ |
+ /** |
+ * @return {string} |
+ */ |
+ embedderPath() { |
+ return this._embedderPath; |
+ } |
+ |
+ /** |
+ * @param {?Object} projectObject |
+ */ |
+ _initializeProject(projectObject) { |
+ this._projectObject = projectObject; |
+ |
+ var projectExcludes = this.projectProperty('excludes'); |
+ if (Array.isArray(projectExcludes)) { |
+ for (var folder of /** @type {!Array<*>} */ (projectExcludes)) { |
+ if (typeof folder === 'string') |
+ this._nonConfigurableExcludedFolders.add(folder); |
+ } |
+ } |
+ } |
+ |
+ /** |
+ * @param {string} key |
+ * @return {*} |
+ */ |
+ projectProperty(key) { |
+ return this._projectObject ? this._projectObject[key] : null; |
+ } |
+ |
+ /** |
+ * @return {!Promise} |
+ */ |
+ _initializeFilePaths() { |
+ var fulfill; |
+ var promise = new Promise(x => fulfill = x); |
+ var pendingRequests = 1; |
+ var boundInnerCallback = innerCallback.bind(this); |
+ this._requestEntries('', boundInnerCallback); |
+ return promise; |
/** |
- * @return {!Array<string>} |
+ * @param {!Array.<!FileEntry>} entries |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- gitFolders: function() |
- { |
- return this._gitFolders.valuesArray(); |
- }, |
+ function innerCallback(entries) { |
+ for (var i = 0; i < entries.length; ++i) { |
+ var entry = entries[i]; |
+ if (!entry.isDirectory) { |
+ if (this._isFileExcluded(entry.fullPath)) |
+ continue; |
+ this._filePaths.add(entry.fullPath.substr(1)); |
+ } else { |
+ if (entry.fullPath.endsWith('/.git')) { |
+ var lastSlash = entry.fullPath.lastIndexOf('/'); |
+ var parentFolder = entry.fullPath.substring(1, lastSlash); |
+ this._gitFolders.add(parentFolder); |
+ } |
+ if (this._isFileExcluded(entry.fullPath + '/')) |
+ continue; |
+ ++pendingRequests; |
+ this._requestEntries(entry.fullPath, boundInnerCallback); |
+ } |
+ } |
+ if ((--pendingRequests === 0)) |
+ fulfill(); |
+ } |
+ } |
- /** |
- * @return {string} |
- */ |
- path: function() |
- { |
- return this._path; |
- }, |
+ /** |
+ * @param {string} path |
+ * @param {?string} name |
+ * @param {function(?string)} callback |
+ */ |
+ createFile(path, name, callback) { |
+ var newFileIndex = 1; |
+ if (!name) |
+ name = 'NewFile'; |
+ var nameCandidate; |
- /** |
- * @return {string} |
- */ |
- embedderPath: function() |
- { |
- return this._embedderPath; |
- }, |
+ this._domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(this), errorHandler.bind(this)); |
/** |
- * @param {?Object} projectObject |
+ * @param {!DirectoryEntry} dirEntry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- _initializeProject: function(projectObject) |
- { |
- this._projectObject = projectObject; |
- |
- var projectExcludes = this.projectProperty("excludes"); |
- if (Array.isArray(projectExcludes)) { |
- for (var folder of /** @type {!Array<*>} */ (projectExcludes)) { |
- if (typeof folder === "string") |
- this._nonConfigurableExcludedFolders.add(folder); |
- } |
+ function dirEntryLoaded(dirEntry) { |
+ var nameCandidate = name; |
+ if (newFileIndex > 1) |
+ nameCandidate += newFileIndex; |
+ ++newFileIndex; |
+ dirEntry.getFile(nameCandidate, {create: true, exclusive: true}, fileCreated, fileCreationError.bind(this)); |
+ |
+ function fileCreated(entry) { |
+ callback(entry.fullPath.substr(1)); |
+ } |
+ |
+ /** |
+ * @this {WebInspector.IsolatedFileSystem} |
+ */ |
+ function fileCreationError(error) { |
+ if (error.name === 'InvalidModificationError') { |
+ dirEntryLoaded.call(this, dirEntry); |
+ return; |
} |
- }, |
- /** |
- * @param {string} key |
- * @return {*} |
- */ |
- projectProperty: function(key) |
- { |
- return this._projectObject ? this._projectObject[key] : null; |
- }, |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error( |
+ errorMessage + ' when testing if file exists \'' + (this._path + '/' + path + '/' + nameCandidate) + '\''); |
+ callback(null); |
+ } |
+ } |
/** |
- * @return {!Promise} |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- _initializeFilePaths: function() |
- { |
- var fulfill; |
- var promise = new Promise(x => fulfill = x); |
- var pendingRequests = 1; |
- var boundInnerCallback = innerCallback.bind(this); |
- this._requestEntries("", boundInnerCallback); |
- return promise; |
- |
- /** |
- * @param {!Array.<!FileEntry>} entries |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function innerCallback(entries) |
- { |
- for (var i = 0; i < entries.length; ++i) { |
- var entry = entries[i]; |
- if (!entry.isDirectory) { |
- if (this._isFileExcluded(entry.fullPath)) |
- continue; |
- this._filePaths.add(entry.fullPath.substr(1)); |
- } else { |
- if (entry.fullPath.endsWith("/.git")) { |
- var lastSlash = entry.fullPath.lastIndexOf("/"); |
- var parentFolder = entry.fullPath.substring(1, lastSlash); |
- this._gitFolders.add(parentFolder); |
- } |
- if (this._isFileExcluded(entry.fullPath + "/")) |
- continue; |
- ++pendingRequests; |
- this._requestEntries(entry.fullPath, boundInnerCallback); |
- } |
- } |
- if ((--pendingRequests === 0)) |
- fulfill(); |
- } |
- }, |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ var filePath = this._path + '/' + path; |
+ if (nameCandidate) |
+ filePath += '/' + nameCandidate; |
+ console.error(errorMessage + ' when getting content for file \'' + (filePath) + '\''); |
+ callback(null); |
+ } |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ */ |
+ deleteFile(path) { |
+ this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
/** |
- * @param {string} path |
- * @param {?string} name |
- * @param {function(?string)} callback |
+ * @param {!FileEntry} fileEntry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- createFile: function(path, name, callback) |
- { |
- var newFileIndex = 1; |
- if (!name) |
- name = "NewFile"; |
- var nameCandidate; |
- |
- this._domFileSystem.root.getDirectory(path, null, dirEntryLoaded.bind(this), errorHandler.bind(this)); |
- |
- /** |
- * @param {!DirectoryEntry} dirEntry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function dirEntryLoaded(dirEntry) |
- { |
- var nameCandidate = name; |
- if (newFileIndex > 1) |
- nameCandidate += newFileIndex; |
- ++newFileIndex; |
- dirEntry.getFile(nameCandidate, { create: true, exclusive: true }, fileCreated, fileCreationError.bind(this)); |
- |
- function fileCreated(entry) |
- { |
- callback(entry.fullPath.substr(1)); |
- } |
- |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileCreationError(error) |
- { |
- if (error.name === "InvalidModificationError") { |
- dirEntryLoaded.call(this, dirEntry); |
- return; |
- } |
- |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when testing if file exists '" + (this._path + "/" + path + "/" + nameCandidate) + "'"); |
- callback(null); |
- } |
- } |
+ function fileEntryLoaded(fileEntry) { |
+ fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); |
+ } |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- var filePath = this._path + "/" + path; |
- if (nameCandidate) |
- filePath += "/" + nameCandidate; |
- console.error(errorMessage + " when getting content for file '" + (filePath) + "'"); |
- callback(null); |
- } |
- }, |
+ function fileEntryRemoved() { |
+ } |
/** |
- * @param {string} path |
+ * @param {!FileError} error |
+ * @this {WebInspector.IsolatedFileSystem} |
+ * @suppress {checkTypes} |
+ * TODO(jsbell): Update externs replacing FileError with DOMException. https://crbug.com/496901 |
*/ |
- deleteFile: function(path) |
- { |
- this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
- |
- /** |
- * @param {!FileEntry} fileEntry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileEntryLoaded(fileEntry) |
- { |
- fileEntry.remove(fileEntryRemoved, errorHandler.bind(this)); |
- } |
- |
- function fileEntryRemoved() |
- { |
- } |
- |
- /** |
- * @param {!FileError} error |
- * @this {WebInspector.IsolatedFileSystem} |
- * @suppress {checkTypes} |
- * TODO(jsbell): Update externs replacing FileError with DOMException. https://crbug.com/496901 |
- */ |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when deleting file '" + (this._path + "/" + path) + "'"); |
- } |
- }, |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when deleting file \'' + (this._path + '/' + path) + '\''); |
+ } |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ * @return {!Promise<?string>} |
+ */ |
+ requestFileContentPromise(path) { |
+ var fulfill; |
+ var promise = new Promise(x => fulfill = x); |
+ this.requestFileContent(path, fulfill); |
+ return promise; |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ * @param {function(?string)} callback |
+ */ |
+ requestFileContent(path, callback) { |
+ this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
/** |
- * @param {string} path |
- * @return {!Promise<?string>} |
+ * @param {!FileEntry} entry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- requestFileContentPromise: function(path) |
- { |
- var fulfill; |
- var promise = new Promise(x => fulfill = x); |
- this.requestFileContent(path, fulfill); |
- return promise; |
- }, |
+ function fileEntryLoaded(entry) { |
+ entry.file(fileLoaded, errorHandler.bind(this)); |
+ } |
/** |
- * @param {string} path |
- * @param {function(?string)} callback |
+ * @param {!Blob} file |
*/ |
- requestFileContent: function(path, callback) |
- { |
- this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
- |
- /** |
- * @param {!FileEntry} entry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileEntryLoaded(entry) |
- { |
- entry.file(fileLoaded, errorHandler.bind(this)); |
- } |
- |
- /** |
- * @param {!Blob} file |
- */ |
- function fileLoaded(file) |
- { |
- var reader = new FileReader(); |
- reader.onloadend = readerLoadEnd; |
- if (WebInspector.IsolatedFileSystem.ImageExtensions.has(WebInspector.ParsedURL.extractExtension(path))) |
- reader.readAsDataURL(file); |
- else |
- reader.readAsText(file); |
- } |
- |
- /** |
- * @this {!FileReader} |
- */ |
- function readerLoadEnd() |
- { |
- /** @type {?string} */ |
- var string = null; |
- try { |
- string = /** @type {string} */ (this.result); |
- } catch (e) { |
- console.error("Can't read file: " + path + ": " + e); |
- } |
- callback(string); |
- } |
- |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function errorHandler(error) |
- { |
- if (error.name === "NotFoundError") { |
- callback(null); |
- return; |
- } |
- |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when getting content for file '" + (this._path + "/" + path) + "'"); |
- callback(null); |
- } |
- }, |
+ function fileLoaded(file) { |
+ var reader = new FileReader(); |
+ reader.onloadend = readerLoadEnd; |
+ if (WebInspector.IsolatedFileSystem.ImageExtensions.has(WebInspector.ParsedURL.extractExtension(path))) |
+ reader.readAsDataURL(file); |
+ else |
+ reader.readAsText(file); |
+ } |
/** |
- * @param {string} path |
- * @param {string} content |
- * @param {function()} callback |
+ * @this {!FileReader} |
*/ |
- setFileContent: function(path, content, callback) |
- { |
- WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.FileSavedInWorkspace); |
- this._domFileSystem.root.getFile(path, { create: true }, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
- |
- /** |
- * @param {!FileEntry} entry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileEntryLoaded(entry) |
- { |
- entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); |
- } |
- |
- /** |
- * @param {!FileWriter} fileWriter |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileWriterCreated(fileWriter) |
- { |
- fileWriter.onerror = errorHandler.bind(this); |
- fileWriter.onwriteend = fileWritten; |
- var blob = new Blob([content], { type: "text/plain" }); |
- fileWriter.write(blob); |
- |
- function fileWritten() |
- { |
- fileWriter.onwriteend = callback; |
- fileWriter.truncate(blob.size); |
- } |
- } |
- |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when setting content for file '" + (this._path + "/" + path) + "'"); |
- callback(); |
- } |
- }, |
+ function readerLoadEnd() { |
+ /** @type {?string} */ |
+ var string = null; |
+ try { |
+ string = /** @type {string} */ (this.result); |
+ } catch (e) { |
+ console.error('Can\'t read file: ' + path + ': ' + e); |
+ } |
+ callback(string); |
+ } |
/** |
- * @param {string} path |
- * @param {string} newName |
- * @param {function(boolean, string=)} callback |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- renameFile: function(path, newName, callback) |
- { |
- newName = newName ? newName.trim() : newName; |
- if (!newName || newName.indexOf("/") !== -1) { |
- callback(false); |
- return; |
- } |
- var fileEntry; |
- var dirEntry; |
- |
- this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
- |
- /** |
- * @param {!FileEntry} entry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function fileEntryLoaded(entry) |
- { |
- if (entry.name === newName) { |
- callback(false); |
- return; |
- } |
- |
- fileEntry = entry; |
- fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); |
- } |
- |
- /** |
- * @param {!Entry} entry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function dirEntryLoaded(entry) |
- { |
- dirEntry = entry; |
- dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorHandler.bind(this)); |
- } |
- |
- /** |
- * @param {!FileEntry} entry |
- */ |
- function newFileEntryLoaded(entry) |
- { |
- callback(false); |
- } |
- |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function newFileEntryLoadErrorHandler(error) |
- { |
- if (error.name !== "NotFoundError") { |
- callback(false); |
- return; |
- } |
- fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); |
- } |
- |
- /** |
- * @param {!FileEntry} entry |
- */ |
- function fileRenamed(entry) |
- { |
- callback(true, entry.name); |
- } |
+ function errorHandler(error) { |
+ if (error.name === 'NotFoundError') { |
+ callback(null); |
+ return; |
+ } |
+ |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when getting content for file \'' + (this._path + '/' + path) + '\''); |
+ callback(null); |
+ } |
+ } |
- /** |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when renaming file '" + (this._path + "/" + path) + "' to '" + newName + "'"); |
- callback(false); |
- } |
- }, |
+ /** |
+ * @param {string} path |
+ * @param {string} content |
+ * @param {function()} callback |
+ */ |
+ setFileContent(path, content, callback) { |
+ WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.FileSavedInWorkspace); |
+ this._domFileSystem.root.getFile(path, {create: true}, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
/** |
- * @param {!DirectoryEntry} dirEntry |
- * @param {function(!Array.<!FileEntry>)} callback |
+ * @param {!FileEntry} entry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- _readDirectory: function(dirEntry, callback) |
- { |
- var dirReader = dirEntry.createReader(); |
- var entries = []; |
- |
- function innerCallback(results) |
- { |
- if (!results.length) { |
- callback(entries.sort()); |
- } else { |
- entries = entries.concat(toArray(results)); |
- dirReader.readEntries(innerCallback, errorHandler); |
- } |
- } |
- |
- function toArray(list) |
- { |
- return Array.prototype.slice.call(list || [], 0); |
- } |
- |
- dirReader.readEntries(innerCallback, errorHandler); |
+ function fileEntryLoaded(entry) { |
+ entry.createWriter(fileWriterCreated.bind(this), errorHandler.bind(this)); |
+ } |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when reading directory '" + dirEntry.fullPath + "'"); |
- callback([]); |
- } |
- }, |
+ /** |
+ * @param {!FileWriter} fileWriter |
+ * @this {WebInspector.IsolatedFileSystem} |
+ */ |
+ function fileWriterCreated(fileWriter) { |
+ fileWriter.onerror = errorHandler.bind(this); |
+ fileWriter.onwriteend = fileWritten; |
+ var blob = new Blob([content], {type: 'text/plain'}); |
+ fileWriter.write(blob); |
+ |
+ function fileWritten() { |
+ fileWriter.onwriteend = callback; |
+ fileWriter.truncate(blob.size); |
+ } |
+ } |
/** |
- * @param {string} path |
- * @param {function(!Array.<!FileEntry>)} callback |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- _requestEntries: function(path, callback) |
- { |
- this._domFileSystem.root.getDirectory(path, null, innerCallback.bind(this), errorHandler); |
- |
- /** |
- * @param {!DirectoryEntry} dirEntry |
- * @this {WebInspector.IsolatedFileSystem} |
- */ |
- function innerCallback(dirEntry) |
- { |
- this._readDirectory(dirEntry, callback); |
- } |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when setting content for file \'' + (this._path + '/' + path) + '\''); |
+ callback(); |
+ } |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ * @param {string} newName |
+ * @param {function(boolean, string=)} callback |
+ */ |
+ renameFile(path, newName, callback) { |
+ newName = newName ? newName.trim() : newName; |
+ if (!newName || newName.indexOf('/') !== -1) { |
+ callback(false); |
+ return; |
+ } |
+ var fileEntry; |
+ var dirEntry; |
- function errorHandler(error) |
- { |
- var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
- console.error(errorMessage + " when requesting entry '" + path + "'"); |
- callback([]); |
- } |
- }, |
+ this._domFileSystem.root.getFile(path, null, fileEntryLoaded.bind(this), errorHandler.bind(this)); |
- _saveExcludedFolders: function() |
- { |
- var settingValue = this._excludedFoldersSetting.get(); |
- settingValue[this._path] = this._excludedFolders.valuesArray(); |
- this._excludedFoldersSetting.set(settingValue); |
- }, |
+ /** |
+ * @param {!FileEntry} entry |
+ * @this {WebInspector.IsolatedFileSystem} |
+ */ |
+ function fileEntryLoaded(entry) { |
+ if (entry.name === newName) { |
+ callback(false); |
+ return; |
+ } |
+ |
+ fileEntry = entry; |
+ fileEntry.getParent(dirEntryLoaded.bind(this), errorHandler.bind(this)); |
+ } |
/** |
- * @param {string} path |
+ * @param {!Entry} entry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- addExcludedFolder: function(path) |
- { |
- this._excludedFolders.add(path); |
- this._saveExcludedFolders(); |
- this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderAdded, path); |
- }, |
+ function dirEntryLoaded(entry) { |
+ dirEntry = entry; |
+ dirEntry.getFile(newName, null, newFileEntryLoaded, newFileEntryLoadErrorHandler.bind(this)); |
+ } |
/** |
- * @param {string} path |
+ * @param {!FileEntry} entry |
*/ |
- removeExcludedFolder: function(path) |
- { |
- this._excludedFolders.delete(path); |
- this._saveExcludedFolders(); |
- this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderRemoved, path); |
- }, |
- |
- fileSystemRemoved: function() |
- { |
- var settingValue = this._excludedFoldersSetting.get(); |
- delete settingValue[this._path]; |
- this._excludedFoldersSetting.set(settingValue); |
- }, |
+ function newFileEntryLoaded(entry) { |
+ callback(false); |
+ } |
/** |
- * @param {string} folderPath |
- * @return {boolean} |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- _isFileExcluded: function(folderPath) |
- { |
- if (this._nonConfigurableExcludedFolders.has(folderPath) || this._excludedFolders.has(folderPath)) |
- return true; |
- var regex = this._manager.workspaceFolderExcludePatternSetting().asRegExp(); |
- return !!(regex && regex.test(folderPath)); |
- }, |
+ function newFileEntryLoadErrorHandler(error) { |
+ if (error.name !== 'NotFoundError') { |
+ callback(false); |
+ return; |
+ } |
+ fileEntry.moveTo(dirEntry, newName, fileRenamed, errorHandler.bind(this)); |
+ } |
/** |
- * @return {!Set<string>} |
+ * @param {!FileEntry} entry |
*/ |
- excludedFolders: function() |
- { |
- return this._excludedFolders; |
- }, |
+ function fileRenamed(entry) { |
+ callback(true, entry.name); |
+ } |
/** |
- * @return {!Set<string>} |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- nonConfigurableExcludedFolders: function() |
- { |
- return this._nonConfigurableExcludedFolders; |
- }, |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when renaming file \'' + (this._path + '/' + path) + '\' to \'' + newName + '\''); |
+ callback(false); |
+ } |
+ } |
+ |
+ /** |
+ * @param {!DirectoryEntry} dirEntry |
+ * @param {function(!Array.<!FileEntry>)} callback |
+ */ |
+ _readDirectory(dirEntry, callback) { |
+ var dirReader = dirEntry.createReader(); |
+ var entries = []; |
+ |
+ function innerCallback(results) { |
+ if (!results.length) { |
+ callback(entries.sort()); |
+ } else { |
+ entries = entries.concat(toArray(results)); |
+ dirReader.readEntries(innerCallback, errorHandler); |
+ } |
+ } |
+ |
+ function toArray(list) { |
+ return Array.prototype.slice.call(list || [], 0); |
+ } |
+ |
+ dirReader.readEntries(innerCallback, errorHandler); |
+ |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when reading directory \'' + dirEntry.fullPath + '\''); |
+ callback([]); |
+ } |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ * @param {function(!Array.<!FileEntry>)} callback |
+ */ |
+ _requestEntries(path, callback) { |
+ this._domFileSystem.root.getDirectory(path, null, innerCallback.bind(this), errorHandler); |
/** |
- * @param {string} query |
- * @param {!WebInspector.Progress} progress |
- * @param {function(!Array.<string>)} callback |
+ * @param {!DirectoryEntry} dirEntry |
+ * @this {WebInspector.IsolatedFileSystem} |
*/ |
- searchInPath: function(query, progress, callback) |
- { |
- var requestId = this._manager.registerCallback(innerCallback); |
- InspectorFrontendHost.searchInPath(requestId, this._embedderPath, query); |
- |
- /** |
- * @param {!Array.<string>} files |
- */ |
- function innerCallback(files) |
- { |
- files = files.map(embedderPath => WebInspector.ParsedURL.platformPathToURL(embedderPath)); |
- progress.worked(1); |
- callback(files); |
- } |
- }, |
+ function innerCallback(dirEntry) { |
+ this._readDirectory(dirEntry, callback); |
+ } |
+ |
+ function errorHandler(error) { |
+ var errorMessage = WebInspector.IsolatedFileSystem.errorMessage(error); |
+ console.error(errorMessage + ' when requesting entry \'' + path + '\''); |
+ callback([]); |
+ } |
+ } |
+ |
+ _saveExcludedFolders() { |
+ var settingValue = this._excludedFoldersSetting.get(); |
+ settingValue[this._path] = this._excludedFolders.valuesArray(); |
+ this._excludedFoldersSetting.set(settingValue); |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ */ |
+ addExcludedFolder(path) { |
+ this._excludedFolders.add(path); |
+ this._saveExcludedFolders(); |
+ this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderAdded, path); |
+ } |
+ |
+ /** |
+ * @param {string} path |
+ */ |
+ removeExcludedFolder(path) { |
+ this._excludedFolders.delete(path); |
+ this._saveExcludedFolders(); |
+ this._manager.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.ExcludedFolderRemoved, path); |
+ } |
+ |
+ fileSystemRemoved() { |
+ var settingValue = this._excludedFoldersSetting.get(); |
+ delete settingValue[this._path]; |
+ this._excludedFoldersSetting.set(settingValue); |
+ } |
+ |
+ /** |
+ * @param {string} folderPath |
+ * @return {boolean} |
+ */ |
+ _isFileExcluded(folderPath) { |
+ if (this._nonConfigurableExcludedFolders.has(folderPath) || this._excludedFolders.has(folderPath)) |
+ return true; |
+ var regex = this._manager.workspaceFolderExcludePatternSetting().asRegExp(); |
+ return !!(regex && regex.test(folderPath)); |
+ } |
+ |
+ /** |
+ * @return {!Set<string>} |
+ */ |
+ excludedFolders() { |
+ return this._excludedFolders; |
+ } |
+ |
+ /** |
+ * @return {!Set<string>} |
+ */ |
+ nonConfigurableExcludedFolders() { |
+ return this._nonConfigurableExcludedFolders; |
+ } |
+ |
+ /** |
+ * @param {string} query |
+ * @param {!WebInspector.Progress} progress |
+ * @param {function(!Array.<string>)} callback |
+ */ |
+ searchInPath(query, progress, callback) { |
+ var requestId = this._manager.registerCallback(innerCallback); |
+ InspectorFrontendHost.searchInPath(requestId, this._embedderPath, query); |
/** |
- * @param {!WebInspector.Progress} progress |
+ * @param {!Array.<string>} files |
*/ |
- indexContent: function(progress) |
- { |
- progress.setTotalWork(1); |
- var requestId = this._manager.registerProgress(progress); |
- InspectorFrontendHost.indexPath(requestId, this._embedderPath); |
+ function innerCallback(files) { |
+ files = files.map(embedderPath => WebInspector.ParsedURL.platformPathToURL(embedderPath)); |
+ progress.worked(1); |
+ callback(files); |
} |
+ } |
+ |
+ /** |
+ * @param {!WebInspector.Progress} progress |
+ */ |
+ indexContent(progress) { |
+ progress.setTotalWork(1); |
+ var requestId = this._manager.registerProgress(progress); |
+ InspectorFrontendHost.indexPath(requestId, this._embedderPath); |
+ } |
}; |
+ |
+WebInspector.IsolatedFileSystem.ImageExtensions = |
+ new Set(['jpeg', 'jpg', 'svg', 'gif', 'webp', 'png', 'ico', 'tiff', 'tif', 'bmp']); |
+ |
+ |