123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
-
-
- (function () {
-
-
-
- if (!require('./isChrome')()) {
- return;
- }
-
- var channel = require('cordova/channel');
- var FileError = require('./FileError');
- var PERSISTENT_FS_QUOTA = 5 * 1024 * 1024;
- var filePluginIsReadyEvent = new Event('filePluginIsReady');
-
- var entryFunctionsCreated = false;
- var quotaWasRequested = false;
- var eventWasThrown = false;
-
- if (!window.requestFileSystem) {
- window.requestFileSystem = function (type, size, win, fail) {
- if (fail) {
- fail('Not supported');
- }
- };
- } else {
- window.requestFileSystem(window.TEMPORARY, 1, createFileEntryFunctions, function () {});
- }
-
- if (!window.resolveLocalFileSystemURL) {
- window.resolveLocalFileSystemURL = function (url, win, fail) {
- if (fail) {
- fail('Not supported');
- }
- };
- }
-
-
-
-
- var nativeResolveLocalFileSystemURL = window.resolveLocalFileSystemURL || window.webkitResolveLocalFileSystemURL;
- window.resolveLocalFileSystemURL = function (url, win, fail) {
-
-
- if (url.trim().substr(0, 7) === 'cdvfile') {
-
-
- if (url.indexOf('cdvfile://localhost') !== -1) {
-
- var indexPersistent = url.indexOf('persistent');
- var indexTemporary = url.indexOf('temporary');
-
-
-
- var prefix = 'filesystem:file:///';
- if (location.protocol !== 'file:') {
- prefix = 'filesystem:' + location.origin + '/';
- }
-
- var result;
- if (indexPersistent !== -1) {
-
-
- result = prefix + 'persistent' + url.substr(indexPersistent + 10);
- nativeResolveLocalFileSystemURL(result, win, fail);
- return;
- }
-
- if (indexTemporary !== -1) {
-
-
- result = prefix + 'temporary' + url.substr(indexTemporary + 9);
- nativeResolveLocalFileSystemURL(result, win, fail);
- return;
- }
- }
-
-
- if (fail) {
- fail(new FileError(FileError.ENCODING_ERR));
- }
- } else {
- nativeResolveLocalFileSystemURL(url, win, fail);
- }
- };
-
- function createFileEntryFunctions (fs) {
- fs.root.getFile('todelete_658674_833_4_cdv', {create: true}, function (fileEntry) {
- var fileEntryType = Object.getPrototypeOf(fileEntry);
- var entryType = Object.getPrototypeOf(fileEntryType);
-
-
- var origToURL = entryType.toURL;
- entryType.toURL = function () {
- var origURL = origToURL.call(this);
- if (this.isDirectory && origURL.substr(-1) !== '/') {
- return origURL + '/';
- }
- return origURL;
- };
-
- entryType.toNativeURL = function () {
- console.warn("DEPRECATED: Update your code to use 'toURL'");
- return this.toURL();
- };
-
- entryType.toInternalURL = function () {
- if (this.toURL().indexOf('persistent') > -1) {
- return 'cdvfile://localhost/persistent' + this.fullPath;
- }
-
- if (this.toURL().indexOf('temporary') > -1) {
- return 'cdvfile://localhost/temporary' + this.fullPath;
- }
- };
-
- entryType.setMetadata = function (win, fail /*, metadata */) {
- if (fail) {
- fail('Not supported');
- }
- };
-
- fileEntry.createWriter(function (writer) {
- var originalWrite = writer.write;
- var writerProto = Object.getPrototypeOf(writer);
- writerProto.write = function (blob) {
- if (blob instanceof Blob) {
- originalWrite.apply(this, [blob]);
- } else {
- var realBlob = new Blob([blob]);
- originalWrite.apply(this, [realBlob]);
- }
- };
-
- fileEntry.remove(function () { entryFunctionsCreated = true; }, function () { });
- });
- });
- }
-
- window.initPersistentFileSystem = function (size, win, fail) {
- if (navigator.webkitPersistentStorage) {
- navigator.webkitPersistentStorage.requestQuota(size, win, fail);
- return;
- }
-
- fail('This browser does not support this function');
- };
-
- window.isFilePluginReadyRaised = function () { return eventWasThrown; };
-
- window.initPersistentFileSystem(PERSISTENT_FS_QUOTA, function () {
- console.log('Persistent fs quota granted');
- quotaWasRequested = true;
- }, function (e) {
- console.log('Error occured while trying to request Persistent fs quota: ' + JSON.stringify(e));
- });
-
- channel.onCordovaReady.subscribe(function () {
- function dispatchEventIfReady () {
- if (entryFunctionsCreated && quotaWasRequested) {
- window.dispatchEvent(filePluginIsReadyEvent);
- eventWasThrown = true;
- } else {
- setTimeout(dispatchEventIfReady, 100);
- }
- }
-
- dispatchEventIfReady();
- }, false);
- })();
|