You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by kn...@apache.org on 2019/03/12 10:02:37 UTC

[cordova-plugin-file] 01/01: support safari private browsing. use json instead of blob

This is an automated email from the ASF dual-hosted git repository.

knaito pushed a commit to branch support_safari_private_browse
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-file.git

commit 061178c7332885e772530bd910a85af78a559333
Author: knaito <kn...@asial.co.jp>
AuthorDate: Tue Mar 12 19:02:05 2019 +0900

    support safari private browsing. use json instead of blob
---
 src/browser/FileProxy.js | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/browser/FileProxy.js b/src/browser/FileProxy.js
index 66ad46b..dd1e82d 100644
--- a/src/browser/FileProxy.js
+++ b/src/browser/FileProxy.js
@@ -685,6 +685,16 @@
 
         MyFile.prototype.constructor = MyFile;
 
+        MyFile.prototype._toJson = function () { // to support safari private browse
+            return {
+                size: this.size,
+                name: this.name,
+                type: this.type,
+                lastModifiedDate: this.lastModifiedDate,
+                storagePath: this.storagePath
+            };
+        };
+
         // When saving an entry, the fullPath should always lead with a slash and never
         // end with one (e.g. a directory). Also, resolve '.' and '..' to an absolute
         // one. This method ensures path is legit!
@@ -847,7 +857,12 @@
 
             tx.onabort = errorCallback || onError;
             tx.oncomplete = function () {
-                successCallback(request.result);
+                var entry = request.result;
+                if (entry && entry.file_json) {
+                    entry.file_ = new MyFile(entry.file_json);
+                    entry.file_json = null;
+                }
+                successCallback(entry);
             };
         };
 
@@ -961,7 +976,21 @@
                 successCallback(entry);
             };
 
-            tx.objectStore(FILE_STORE_).put(entry, storagePath);
+            try {
+                tx.objectStore(FILE_STORE_).put(entry, storagePath);
+            } catch (e) {
+                if (e.name === 'DataCloneError') { // to support safari private browse
+                    if (!retry) {
+                        if (entry.file_ && entry.file_ instanceof MyFile && entry.file_.blob_) {
+                            entry.file_json = entry.file_._toJson();
+                            entry.file_ = null;
+                            idb_.put(entry, storagePath, successCallback, errorCallback, true);
+                            return;
+                        }
+                    }
+                }
+                throw e;
+            }
         };
 
         // Global error handler. Errors bubble from request, to transaction, to db.


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