cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dase...@apache.org
Subject cordova-plugin-file git commit: CB-11305 Enable cdvfile: assets fs root for DOM requests
Date Mon, 01 Aug 2016 08:26:22 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 113f8144b -> 21298dce5


CB-11305 Enable cdvfile: assets fs root for DOM requests

Added test for cdvfile applicationDirectory fs root
Updated the docs and added the assets to Android available fs roots list
Allow cdvfile: access for android automatically


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

Branch: refs/heads/master
Commit: 21298dce51568a2662adee8ff4bfc9b8c838d3a7
Parents: 113f814
Author: daserge <v-seshak@microsoft.com>
Authored: Tue Jul 5 15:27:21 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Mon Aug 1 10:57:34 2016 +0300

----------------------------------------------------------------------
 README.md                        |  5 ++--
 plugin.xml                       |  1 +
 src/android/AssetFilesystem.java |  2 +-
 src/android/FileUtils.java       |  2 +-
 tests/tests.js                   | 43 ++++++++++++++++++++++++++++++++++-
 5 files changed, 48 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21298dce/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index b2f1efb..8a50749 100644
--- a/README.md
+++ b/README.md
@@ -164,7 +164,7 @@ the `cordova.file.*` properties map to physical paths on a real device.
 
 | Device Path                                     | `cordova.file.*`            | `AndroidExtraFileSystems`
| r/w? | persistent? | OS clears | private |
 |:------------------------------------------------|:----------------------------|:--------------------------|:----:|:-----------:|:---------:|:-------:|
-| `file:///android_asset/`                        | applicationDirectory        |       
                   | r    |     N/A     |     N/A   |   Yes   |
+| `file:///android_asset/`                        | applicationDirectory        | assets
                   | r    |     N/A     |     N/A   |   Yes   |
 | `/data/data/<app-id>/`                          | applicationStorageDirectory | -
                        | r/w  |     N/A     |     N/A   |   Yes   |
 | &nbsp;&nbsp;&nbsp;`cache`                       | cacheDirectory          
   | cache                     | r/w  |     Yes     |     Yes\* |   Yes   |
 | &nbsp;&nbsp;&nbsp;`files`                       | dataDirectory           
   | files                     | r/w  |     Yes     |     No    |   Yes   |
@@ -532,7 +532,7 @@ Android recognize a <preference> tag in `config.xml` which names
the
 filesystems to be installed. By default, all file-system roots are enabled.
 
     <preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root"
/>
-    <preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,root"
/>
+    <preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root"
/>
 
 ### Android
 
@@ -541,6 +541,7 @@ filesystems to be installed. By default, all file-system roots are enabled.
 * `sdcard`: The global external file storage directory (this is the root of the SD card,
if one is installed). You must have the `android.permission.WRITE_EXTERNAL_STORAGE` permission
to use this.
 * `cache`: The application's internal cache directory
 * `cache-external`: The application's external cache directory
+* `assets`: The application's bundle (read-only)
 * `root`: The entire device filesystem
 
 Android also supports a special filesystem named "documents", which represents a "/Documents/"
subdirectory within the "files" filesystem.

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21298dce/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 629c2e4..98588df 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -129,6 +129,7 @@ to config.xml in order for the application to find previously stored files.
                 <param name="android-package" value="org.apache.cordova.file.FileUtils"/>
                 <param name="onload" value="true" />
             </feature>
+            <allow-navigation href="cdvfile:*" />
         </config-file>
 
         <config-file target="AndroidManifest.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21298dce/src/android/AssetFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/AssetFilesystem.java b/src/android/AssetFilesystem.java
index 1b6fce7..2266f3e 100644
--- a/src/android/AssetFilesystem.java
+++ b/src/android/AssetFilesystem.java
@@ -273,7 +273,7 @@ public class AssetFilesystem extends Filesystem {
 
     @Override
     String filesystemPathForURL(LocalFilesystemURL url) {
-        return null;
+        return new File(rootUri.getPath(), url.path).toString();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21298dce/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index f77daec..91e40e2 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -122,7 +122,7 @@ public class FileUtils extends CordovaPlugin {
     }
 
     protected String[] getExtraFileSystemsPreference(Activity activity) {
-        String fileSystemsStr = preferences.getString("androidextrafilesystems", "files,files-external,documents,sdcard,cache,cache-external,root");
+        String fileSystemsStr = preferences.getString("androidextrafilesystems", "files,files-external,documents,sdcard,cache,cache-external,assets,root");
         return fileSystemsStr.split(",");
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/21298dce/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index a7de7aa..33688dc 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -3441,6 +3441,46 @@ exports.defineAutoTests = function () {
                 }
             });
         });
+        describe('resolveLocalFileSystemURL on cdvfile://', function () {
+            it("file.spec.147 should be able to resolve cdvfile applicationDirectory fs root",
function(done) {
+                var cdvfileApplicationDirectoryFsRootName;
+                if (cordova.platformId === 'android') {
+                    cdvfileApplicationDirectoryFsRootName = 'assets';
+                } else if (cordova.platformId === 'ios') {
+                    cdvfileApplicationDirectoryFsRootName = 'bundle';
+                } else {
+                    pending();
+                }
+
+                resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName
+ '/', function(applicationDirectoryRoot) {
+                    expect(applicationDirectoryRoot.isFile).toBe(false);
+                    expect(applicationDirectoryRoot.isDirectory).toBe(true);
+                    expect(applicationDirectoryRoot.name).toCanonicallyMatch('');
+                    expect(applicationDirectoryRoot.fullPath).toCanonicallyMatch('/');
+                    expect(applicationDirectoryRoot.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);
+
+                    // Requires HelloCordova www assets, <allow-navigation href="cdvfile:*"
/> in config.xml or
+                    // cdvfile: in CSP and <access origin="cdvfile://*" /> in config.xml
+                    resolveLocalFileSystemURL('cdvfile://localhost/' + cdvfileApplicationDirectoryFsRootName
+ '/www/img/logo.png', function(entry) {
+                        expect(entry.isFile).toBe(true);
+                        expect(entry.isDirectory).toBe(false);
+                        expect(entry.name).toCanonicallyMatch('logo.png');
+                        expect(entry.fullPath).toCanonicallyMatch('/www/img/logo.png');
+                        expect(entry.filesystem.name).toEqual(cdvfileApplicationDirectoryFsRootName);
+
+                        var img = new Image();
+                        img.onerror = function(err) {
+                            expect(err).not.toBeDefined();
+                            done();
+                        };
+                        img.onload = function() {
+                            done();
+                        };
+                        img.src = entry.toInternalURL();
+                    }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile
applicationDirectory'));
+                }, failed.bind(null, done, 'resolveLocalFileSystemURL failed for cdvfile
applicationDirectory'));
+            });
+        });
         //cross-file-system copy and move
         describe('IndexedDB-based impl', function () {
             it("file.spec.131 Nested file or nested directory should be removed when removing
a parent directory", function (done) {
@@ -3576,6 +3616,7 @@ exports.defineAutoTests = function () {
         // Content and Asset URLs
         if (cordova.platformId == 'android') {
             describe('content: URLs', function() {
+                // Warning: Default HelloWorld www directory structure is required for these
tests (www/index.html at least)
                 function testContentCopy(src, done) {
                     var file2 = "entry.copy.file2b",
                     fullPath = joinURL(temp_root.fullPath, file2),
@@ -3786,7 +3827,7 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
     var fsRoots = {
         "ios" : "library,library-nosync,documents,documents-nosync,cache,bundle,root,private",
         "osx" : "library,library-nosync,documents,documents-nosync,cache,bundle,root,private",
-        "android" : "files,files-external,documents,sdcard,cache,cache-external,root",
+        "android" : "files,files-external,documents,sdcard,cache,cache-external,assets,root",
         "amazon-fireos" : "files,files-external,documents,sdcard,cache,cache-external,root",
         "windows": "temporary,persistent"
     };


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message