CB-6013 [BlackBerry10] wrap webkit prefixed called in requestAnimationFrame
Due to a bug in BB10's webkit implementation, requestAnimationFrame is required to make multiple calls to requestFileSystem in the same callback chain. Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/e6345198 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/e6345198 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/e6345198 Branch: refs/heads/master Commit: e634519852bca8f46b8d24c02648722f2a284c05 Parents: cf97ac0 Author: Bryan Higgins <[email protected]> Authored: Thu Feb 20 13:21:47 2014 -0500 Committer: Bryan Higgins <[email protected]> Committed: Fri Feb 21 13:34:23 2014 -0500 ---------------------------------------------------------------------- www/blackberry10/DirectoryEntry.js | 91 ++++++++++------------ www/blackberry10/Entry.js | 6 +- www/blackberry10/FileReader.js | 2 +- www/blackberry10/FileWriter.js | 2 +- www/blackberry10/requestFileSystem.js | 27 ++++--- www/blackberry10/resolveLocalFileSystemURI.js | 38 +++++---- 6 files changed, 80 insertions(+), 86 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/DirectoryEntry.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/DirectoryEntry.js b/www/blackberry10/DirectoryEntry.js index f84395d..051a043 100644 --- a/www/blackberry10/DirectoryEntry.js +++ b/www/blackberry10/DirectoryEntry.js @@ -31,20 +31,13 @@ var argscheck = require('cordova/argscheck'), utils.extend(DirectoryEntry, Entry); -function err(sandboxState, errorCallback) { - return function (e) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]); - errorCallback(e); - } -}; - DirectoryEntry.prototype.createReader = function () { return new DirectoryReader(this.fullPath); }; DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) { - var sandboxState, - currentPath = this.nativeEntry.fullPath, + var currentPath = this.nativeEntry.fullPath, + that = this, fullPath; if (path.indexOf("/") === 0) { @@ -53,30 +46,28 @@ DirectoryEntry.prototype.getDirectory = function (path, options, successCallback fullPath = currentPath + "/" + path; } - cordova.exec(function (sandboxed) { - sandboxState = sandboxed; - }, function (e) { - console.log("[ERROR]: Could not retrieve sandbox state ", e); - }, "org.apache.cordova.file", "isSandboxed"); - argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments); if (fileUtils.isOutsideSandbox(fullPath)) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [false]); - window.webkitRequestFileSystem(window.PERSISTENT, this.filesystem._size, function (fs) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]); - fs.root.getDirectory(fullPath, options, function (entry) { - successCallback(fileUtils.createEntry(entry)); - }, err(sandboxState, errorCallback)); - }, err(sandboxState, errorCallback)); + cordova.exec(function () { + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem(window.PERSISTENT, that.filesystem._size, function (fs) { + fs.root.getDirectory(fullPath, options, function (entry) { + successCallback(fileUtils.createEntry(entry)); + }, errorCallback); + }, errorCallback); + }); + }, errorCallback, "org.apache.cordova.file", "setSandbox", [false]); } else { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [true]); - window.webkitRequestFileSystem(fileUtils.getFileSystemName(this.filesystem) === "persistent" ? window.PERSISTENT : window.TEMPORARY, this.filesystem._size, function (fs) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]); - fs.root.getDirectory(fullPath, options, function (entry) { - successCallback(fileUtils.createEntry(entry)); - }, err(sandboxState, errorCallback)); - }, err(sandboxState, errorCallback)); + cordova.exec(function () { + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem(fileUtils.getFileSystemName(that.filesystem) === "persistent" ? window.PERSISTENT : window.TEMPORARY, that.filesystem._size, function (fs) { + fs.root.getDirectory(fullPath, options, function (entry) { + successCallback(fileUtils.createEntry(entry)); + }, errorCallback); + }, errorCallback); + }); + }, errorCallback, "org.apache.cordova.file", "setSandbox", [true]); } }; @@ -86,8 +77,8 @@ DirectoryEntry.prototype.removeRecursively = function (successCallback, errorCal }; DirectoryEntry.prototype.getFile = function (path, options, successCallback, errorCallback) { - var sandboxState, - currentPath = this.nativeEntry.fullPath, + var currentPath = this.nativeEntry.fullPath, + that = this, fullPath; if (path.indexOf("/") === 0) { @@ -96,30 +87,28 @@ DirectoryEntry.prototype.getFile = function (path, options, successCallback, err fullPath = currentPath + "/" + path; } - cordova.exec(function (sandboxed) { - sandboxState = sandboxed; - }, function (e) { - console.log("[ERROR]: Could not retrieve sandbox state ", e); - }, "org.apache.cordova.file", "isSandboxed"); - argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments); if (fileUtils.isOutsideSandbox(fullPath)) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [false]); - window.webkitRequestFileSystem(window.PERSISTENT, this.filesystem._size, function (fs) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]); - fs.root.getFile(fullPath, options, function (entry) { - successCallback(fileUtils.createEntry(entry)); - }, err(sandboxState, errorCallback)); - }, err(sandboxState, errorCallback)); + cordova.exec(function () { + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem(window.PERSISTENT, that.filesystem._size, function (fs) { + fs.root.getFile(fullPath, options, function (entry) { + successCallback(fileUtils.createEntry(entry)); + }, errorCallback); + }, errorCallback); + }); + }, errorCallback, "org.apache.cordova.file", "setSandbox", [false]); } else { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [true]); - window.webkitRequestFileSystem(fileUtils.getFileSystemName(this.filesystem) === "persistent" ? window.PERSISTENT: window.TEMPORARY, this.filesystem._size, function (fs) { - cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]); - fs.root.getFile(fullPath, options, function (entry) { - successCallback(fileUtils.createEntry(entry)); - }, err(sandboxState, errorCallback)); - }, err(sandboxState, errorCallback)); + cordova.exec(function () { + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem(fileUtils.getFileSystemName(that.filesystem) === "persistent" ? window.PERSISTENT: window.TEMPORARY, that.filesystem._size, function (fs) { + fs.root.getFile(fullPath, options, function (entry) { + successCallback(fileUtils.createEntry(entry)); + }, errorCallback); + }, errorCallback); + }); + }, errorCallback, "org.apache.cordova.file", "setSandbox", [true]); } }; http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/Entry.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/Entry.js b/www/blackberry10/Entry.js index d432bfd..be5c1e3 100644 --- a/www/blackberry10/Entry.js +++ b/www/blackberry10/Entry.js @@ -92,11 +92,7 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac }; Entry.prototype.toURL = function() { - var nativeURI = this.nativeEntry.toURL(); - if (nativeURI.charAt(nativeURI.length - 1) === '/') { - return nativeURI.slice(0, -1); - } - return nativeURI; + return this.nativeEntry.fullPath; }; Entry.prototype.toURI = function(mimeType) { http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/FileReader.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/FileReader.js b/www/blackberry10/FileReader.js index 6e3a10c..a3943ba 100644 --- a/www/blackberry10/FileReader.js +++ b/www/blackberry10/FileReader.js @@ -60,7 +60,7 @@ FileReader.prototype.abort = function() { function read(method, context, file, encoding) { if (file.fullPath) { - resolveLocalFileSystemURI("filesystem:local:///persistent/" + file.fullPath, function (entry) { + resolveLocalFileSystemURI(file.fullPath, function (entry) { entry.nativeEntry.file(function (nativeFile) { context.nativeReader[method].call(context.nativeReader, nativeFile, encoding); }, context.onerror); http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/FileWriter.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/FileWriter.js b/www/blackberry10/FileWriter.js index 8992943..d50efc5 100644 --- a/www/blackberry10/FileWriter.js +++ b/www/blackberry10/FileWriter.js @@ -29,7 +29,7 @@ function FileWriter (file) { this.file = file; this.events = {}; this.pending = []; - resolveLocalFileSystemURI("filesystem:local:///persistent/" + file.fullPath, function (entry) { + resolveLocalFileSystemURI(file.fullPath, function (entry) { entry.nativeEntry.createWriter(function (writer) { var i, event; http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/requestFileSystem.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/requestFileSystem.js b/www/blackberry10/requestFileSystem.js index e3e2d1e..a68f819 100644 --- a/www/blackberry10/requestFileSystem.js +++ b/www/blackberry10/requestFileSystem.js @@ -35,16 +35,21 @@ module.exports = function (type, size, success, fail) { fail(new FileError(FileError.SYNTAX_ERR)); } } else { - window.webkitRequestFileSystem(type, size, function (fs) { - cordovaFsRoot = fileUtils.createEntry(fs.root); - cordovaFs = new FileSystem(fileUtils.getFileSystemName(fs), cordovaFsRoot); - cordovaFsRoot.filesystem = cordovaFs; - cordovaFs._size = size; - success(cordovaFs); - }, function (error) { - if (typeof fail === "function") { - fail(new FileError(error)); - } - }); + cordova.exec(function () { + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem(type, size, function (fs) { + cordovaFsRoot = fileUtils.createEntry(fs.root); + cordovaFs = new FileSystem(fileUtils.getFileSystemName(fs), cordovaFsRoot); + cordovaFsRoot.filesystem = cordovaFs; + cordovaFs._size = size; + success(cordovaFs); + }, function (error) { + if (typeof fail === "function") { + fail(new FileError(error)); + } + }); + }); + }, fail, "org.apache.cordova.file", "setSandbox", [true]); + } }; http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/e6345198/www/blackberry10/resolveLocalFileSystemURI.js ---------------------------------------------------------------------- diff --git a/www/blackberry10/resolveLocalFileSystemURI.js b/www/blackberry10/resolveLocalFileSystemURI.js index a3f62f7..95c9d21 100644 --- a/www/blackberry10/resolveLocalFileSystemURI.js +++ b/www/blackberry10/resolveLocalFileSystemURI.js @@ -26,25 +26,29 @@ module.exports = function (uri, success, fail) { var decodedURI = decodeURI(uri).replace(/filesystem:/, '').replace(/file:\/\//, ''), failNotFound = function () { - fail(FileError.NOT_FOUND_ERR); + if (fail) { + fail(FileError.NOT_FOUND_ERR); + } }, resolveURI = function () { - window.webkitRequestFileSystem( - window.PERSISTENT, - 50*1024*1024, - function (fs) { - var op = decodedURI.slice(-1) === '/' ? 'getDirectory' : 'getFile'; - fs.root[op]( - decodedURI, - { create: false }, - function (entry) { - success(fileUtils.createEntry(entry)); - }, - failNotFound - ); - }, - failNotFound - ); + window.requestAnimationFrame(function () { + window.webkitRequestFileSystem( + window.PERSISTENT, + 50*1024*1024, + function (fs) { + var op = decodedURI.slice(-1) === '/' ? 'getDirectory' : 'getFile'; + fs.root[op]( + decodedURI, + { create: false }, + function (entry) { + success(fileUtils.createEntry(entry)); + }, + failNotFound + ); + }, + failNotFound + ); + }); }; if (decodedURI.substring(0, 8) === 'local://') {
