cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [12/50] git commit: CB-5699 [BlackBerry10] Update resolveLocalFileSystemURI implementation
Date Mon, 10 Feb 2014 23:22:38 GMT
CB-5699 [BlackBerry10] Update resolveLocalFileSystemURI implementation

The native webkitResolveLocalFileSystemURI does not support accessing URIs
outside of the application sandbox.


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/b7882772
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/b7882772
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/b7882772

Branch: refs/heads/master
Commit: b7882772b329c0690e0eaef264a21661c3e2f659
Parents: a76de41
Author: Bryan Higgins <bhiggins@blackberry.com>
Authored: Tue Dec 24 10:59:12 2013 -0500
Committer: Bryan Higgins <bhiggins@blackberry.com>
Committed: Tue Dec 24 11:43:58 2013 -0500

----------------------------------------------------------------------
 src/blackberry10/index.js                     |  2 +-
 www/blackberry10/fileUtils.js                 |  2 +-
 www/blackberry10/resolveLocalFileSystemURI.js | 58 +++++++++++-----------
 3 files changed, 31 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index 914d966..9e4cfd3 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -1,7 +1,7 @@
 module.exports = {
     setSandbox : function (success, fail, args, env) {
         require("lib/webview").setSandbox(JSON.parse(decodeURIComponent(args[0])));
-        new PluginResult(args, env).noResult(false);
+        new PluginResult(args, env).ok();
     },
 
     isSandboxed : function (success, fail, args, env) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/www/blackberry10/fileUtils.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/fileUtils.js b/www/blackberry10/fileUtils.js
index 06e676d..740669c 100644
--- a/www/blackberry10/fileUtils.js
+++ b/www/blackberry10/fileUtils.js
@@ -47,6 +47,6 @@ module.exports = {
     },
 
     isOutsideSandbox: function (path) {
-        return (path.indexOf("accounts/1000/") === 0 || path.indexOf("/accounts/1000/") ===
0);
+        return (path.indexOf("accounts/1000") !== -1);
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/b7882772/www/blackberry10/resolveLocalFileSystemURI.js
----------------------------------------------------------------------
diff --git a/www/blackberry10/resolveLocalFileSystemURI.js b/www/blackberry10/resolveLocalFileSystemURI.js
index 3ede22c..f447a42 100644
--- a/www/blackberry10/resolveLocalFileSystemURI.js
+++ b/www/blackberry10/resolveLocalFileSystemURI.js
@@ -22,36 +22,36 @@
 var fileUtils = require('./BB10Utils'),
     FileError = require('./FileError');
 
-function stripURI(uri) {
-    var rmFsLocal = uri.substring("filesystem:local:///".length);
-    return rmFsLocal.substring(rmFsLocal.indexOf('/') + 1);
-}
-
 module.exports = function (uri, success, fail) {
-    var sandboxState,
-        decodedURI = decodeURI(uri);
 
-    cordova.exec(function (sandboxed) {
-        sandboxState = sandboxed;
-    }, function (e) {
-        console.log("[ERROR]: Could not retrieve sandbox state ", e);
-    }, "org.apache.cordova.file", "isSandboxed");
+    var decodedURI = decodeURI(uri).replace(/filesystem:/, '').replace(/local:\/\//, '').replace(/file:\/\//,
''),
+        failNotFound = function () {
+            fail(FileError.NOT_FOUND_ERR);
+        },
+        resolveURI = function () {
+            window.webkitRequestFileSystem(
+                window.PERSISTENT,
+                //todo: match app quota (this is only used for sandboxed fs)
+                50*1024*1024,
+                function (fs) {
+                    fs.root.getFile(
+                        decodedURI,
+                        { create: false },
+                        function (entry) {
+                            success(fileUtils.createEntry(entry));
+                        },
+                        failNotFound
+                    );
+                },
+                failNotFound
+            );
+        };
 
-    if (fileUtils.isOutsideSandbox(stripURI(decodedURI))) {
-        cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [false]);
-    } else {
-        cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [true]);
-    }
-    window.webkitResolveLocalFileSystemURL(decodedURI, function (entry) {
-        success(fileUtils.createEntry(entry));
-    }, function (e) {
-        window.webkitResolveLocalFileSystemURL(decodedURI + '/', function (entry) {
-            success(fileUtils.createEntry(entry));
-        }, function (e) {
-            if (typeof fail === "function") {
-                fail(e);
-            }
-        });
-    });
-    cordova.exec(null, null, "org.apache.cordova.file", "setSandbox", [sandboxState]);
+    cordova.exec(
+        resolveURI, 
+        failNotFound, 
+        'org.apache.cordova.file', 
+        'setSandbox', 
+        [!fileUtils.isOutsideSandbox(decodedURI)]
+    );
 };


Mime
View raw message