cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [4/8] git commit: CB-6393: Change behaviour of toURL and toNativeURL
Date Fri, 04 Apr 2014 17:11:55 GMT
CB-6393: Change behaviour of toURL and toNativeURL

Change Entry.toURL to return webview-usable URLs where possible.
Soft-deprecate Entry.toNativeURL
Introduce Entry.toInternalURL, for internal use for bridge-formatting Entry objects


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

Branch: refs/heads/dev
Commit: 37bedcb0543bfc4f37517af32120b6ab9743315a
Parents: 2305896
Author: Ian Clelland <iclelland@chromium.org>
Authored: Tue Apr 1 12:07:42 2014 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Fri Apr 4 09:28:06 2014 -0400

----------------------------------------------------------------------
 plugin.xml            |  3 ---
 www/DirectoryEntry.js |  8 ++++----
 www/Entry.js          | 47 ++++++++++++++++++++++++++++++----------------
 www/FileEntry.js      |  2 +-
 www/ios/Entry.js      | 35 ----------------------------------
 5 files changed, 36 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/37bedcb0/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index b1f2729..61fad18 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -177,9 +177,6 @@ xmlns:android="http://schemas.android.com/apk/res/android"
         <source-file src="src/ios/CDVAssetLibraryFilesystem.m" />
 
         <!-- ios specific file apis -->
-        <js-module src="www/ios/Entry.js" name="iosEntry">
-            <merges target="window.Entry" />
-        </js-module>
         <js-module src="www/ios/FileSystem.js" name="iosFileSystem">
             <merges target="window.FileSystem" />
         </js-module>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/37bedcb0/www/DirectoryEntry.js
----------------------------------------------------------------------
diff --git a/www/DirectoryEntry.js b/www/DirectoryEntry.js
index 417c97e..8b98283 100644
--- a/www/DirectoryEntry.js
+++ b/www/DirectoryEntry.js
@@ -45,7 +45,7 @@ utils.extend(DirectoryEntry, Entry);
  * Creates a new DirectoryReader to read entries from this directory
  */
 DirectoryEntry.prototype.createReader = function() {
-    return new DirectoryReader(this.toURL());
+    return new DirectoryReader(this.toInternalURL());
 };
 
 /**
@@ -66,7 +66,7 @@ DirectoryEntry.prototype.getDirectory = function(path, options, successCallback,
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(win, fail, "File", "getDirectory", [this.filesystem.__format__(this.fullPath), path,
options]);
+    exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]);
 };
 
 /**
@@ -80,7 +80,7 @@ DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCall
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(successCallback, fail, "File", "removeRecursively", [this.filesystem.__format__(this.fullPath)]);
+    exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]);
 };
 
 /**
@@ -102,7 +102,7 @@ DirectoryEntry.prototype.getFile = function(path, options, successCallback,
erro
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(win, fail, "File", "getFile", [this.filesystem.__format__(this.fullPath), path,
options]);
+    exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]);
 };
 
 module.exports = DirectoryEntry;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/37bedcb0/www/Entry.js
----------------------------------------------------------------------
diff --git a/www/Entry.js b/www/Entry.js
index b025334..d143d32 100644
--- a/www/Entry.js
+++ b/www/Entry.js
@@ -71,7 +71,7 @@ Entry.prototype.getMetadata = function(successCallback, errorCallback) {
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(success, fail, "File", "getMetadata", [this.filesystem.__format__(this.fullPath)]);
+    exec(success, fail, "File", "getMetadata", [this.toInternalURL()]);
 };
 
 /**
@@ -86,7 +86,7 @@ Entry.prototype.getMetadata = function(successCallback, errorCallback) {
  */
 Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) {
     argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments);
-    exec(successCallback, errorCallback, "File", "setMetadata", [this.filesystem.__format__(this.fullPath),
metadataObject]);
+    exec(successCallback, errorCallback, "File", "setMetadata", [this.toInternalURL(), metadataObject]);
 };
 
 /**
@@ -106,7 +106,7 @@ Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallbac
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    var srcURL = this.filesystem.__format__(this.fullPath),
+    var srcURL = this.toInternalURL(),
         // entry name
         name = newName || this.name,
         success = function(entry) {
@@ -125,7 +125,7 @@ Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallbac
         };
 
     // copy
-    exec(success, fail, "File", "moveTo", [srcURL, parent.filesystem.__format__(parent.fullPath),
name]);
+    exec(success, fail, "File", "moveTo", [srcURL, parent.toInternalURL(), name]);
 };
 
 /**
@@ -145,7 +145,7 @@ Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallbac
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    var srcURL = this.filesystem.__format__(this.fullPath),
+    var srcURL = this.toInternalURL(),
         // entry name
         name = newName || this.name,
         // success callback
@@ -165,26 +165,42 @@ Entry.prototype.copyTo = function(parent, newName, successCallback,
errorCallbac
         };
 
     // copy
-    exec(success, fail, "File", "copyTo", [srcURL, parent.filesystem.__format__(parent.fullPath),
name]);
+    exec(success, fail, "File", "copyTo", [srcURL, parent.toInternalURL(), name]);
 };
 
 /**
- * Return a URL that can be used to identify this entry.
+ * Return a URL that can be passed across the bridge to identify this entry.
  */
-Entry.prototype.toURL = function() {
+Entry.prototype.toInternalURL = function() {
     if (this.filesystem && this.filesystem.__format__) {
       return this.filesystem.__format__(this.fullPath);
     }
-    // fullPath attribute contains the full URL
-    return "file://localhost" + this.fullPath;
 };
 
 /**
- * Return a URL that can be used to as the src attribute of a <video> or
- * <audio> tag, in case it is different from the URL returned by .toURL().
+ * Return a URL that can be used to identify this entry.
+ * Use a URL that can be used to as the src attribute of a <video> or
+ * <audio> tag. If that is not possible, construct a cdvfile:// URL.
+ */
+Entry.prototype.toURL = function() {
+    if (this.nativeURL) {
+      return this.nativeURL;
+    }
+    // fullPath attribute may contain the full URL in the case that
+    // toInternalURL fails.
+    return this.toInternalURL() || "file://localhost" + this.fullPath;
+};
+
+/**
+ * Backwards-compatibility: In v1.0.0 - 1.0.2, .toURL would only return a
+ * cdvfile:// URL, and this method was necessary to obtain URLs usable by the
+ * webview.
+ * See CB-6051, CB-6106, CB-6117, CB-6152, CB-6199, CB-6201, CB-6243, CB-6249,
+ * and CB-6300.
  */
 Entry.prototype.toNativeURL = function() {
-    return this.nativeURL || this.toURL();
+    console.log("DEPRECATED: Update your code to use 'toURL'");
+    return this.toURL();
 };
 
 /**
@@ -195,7 +211,6 @@ Entry.prototype.toNativeURL = function() {
  */
 Entry.prototype.toURI = function(mimeType) {
     console.log("DEPRECATED: Update your code to use 'toURL'");
-    // fullPath attribute contains the full URI
     return this.toURL();
 };
 
@@ -212,7 +227,7 @@ Entry.prototype.remove = function(successCallback, errorCallback) {
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(successCallback, fail, "File", "remove", [this.filesystem.__format__(this.fullPath)]);
+    exec(successCallback, fail, "File", "remove", [this.toInternalURL()]);
 };
 
 /**
@@ -232,7 +247,7 @@ Entry.prototype.getParent = function(successCallback, errorCallback) {
     var fail = errorCallback && function(code) {
         errorCallback(new FileError(code));
     };
-    exec(win, fail, "File", "getParent", [this.filesystem.__format__(this.fullPath)]);
+    exec(win, fail, "File", "getParent", [this.toInternalURL()]);
 };
 
 module.exports = Entry;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/37bedcb0/www/FileEntry.js
----------------------------------------------------------------------
diff --git a/www/FileEntry.js b/www/FileEntry.js
index ac11d06..59a9dc3 100644
--- a/www/FileEntry.js
+++ b/www/FileEntry.js
@@ -66,7 +66,7 @@ FileEntry.prototype.createWriter = function(successCallback, errorCallback)
{
  * @param {Function} errorCallback is called with a FileError
  */
 FileEntry.prototype.file = function(successCallback, errorCallback) {
-    var localURL = this.filesystem.__format__(this.fullPath);
+    var localURL = this.toInternalURL();
     var win = successCallback && function(f) {
         var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
         successCallback(file);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/37bedcb0/www/ios/Entry.js
----------------------------------------------------------------------
diff --git a/www/ios/Entry.js b/www/ios/Entry.js
deleted file mode 100644
index b76162d..0000000
--- a/www/ios/Entry.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-module.exports = {
-    toURL:function() {
-        // TODO: refactor path in a cross-platform way so we can eliminate
-        // these kinds of platform-specific hacks.
-        if (this.filesystem && this.filesystem.__format__) {
-          return this.filesystem.__format__(this.fullPath);
-        }
-        return "file://localhost" + this.fullPath;
-    },
-    toURI: function() {
-        console.log("DEPRECATED: Update your code to use 'toURL'");
-        return this.toURL();
-    }
-};


Mime
View raw message