You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/14 06:15:28 UTC
[21/50] [abbrv] Update cordova.js
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/4255d17b/blackberry10/javascript/cordova.blackberry10.js
----------------------------------------------------------------------
diff --git a/blackberry10/javascript/cordova.blackberry10.js b/blackberry10/javascript/cordova.blackberry10.js
index 45f9aff..b94f2c9 100644
--- a/blackberry10/javascript/cordova.blackberry10.js
+++ b/blackberry10/javascript/cordova.blackberry10.js
@@ -1,8 +1,8 @@
// Platform: blackberry10
-// commit c8e2a018e93036393bcf5e0edd855187e5c587c5
+// commit 57999a27c82207cdb0c73f6395d14d18fb1b4170
-// File generated at :: Thu Apr 11 2013 16:14:07 GMT-0400 (EDT)
+// File generated at :: Wed Apr 17 2013 11:51:51 GMT-0400 (EDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -273,7 +273,7 @@ var cordova = {
*/
callbackSuccess: function(callbackId, args) {
try {
- cordova.callbackFromNative(callbackId, true, args.status, args.message, args.keepCallback);
+ cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
} catch (e) {
console.log("Error in error callback: " + callbackId + " = "+e);
}
@@ -286,7 +286,7 @@ var cordova = {
// TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
// Derive success from status.
try {
- cordova.callbackFromNative(callbackId, false, args.status, args.message, args.keepCallback);
+ cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
} catch (e) {
console.log("Error in error callback: " + callbackId + " = "+e);
}
@@ -295,13 +295,13 @@ var cordova = {
/**
* Called by native code when returning the result from an action.
*/
- callbackFromNative: function(callbackId, success, status, message, keepCallback) {
+ callbackFromNative: function(callbackId, success, status, args, keepCallback) {
var callback = cordova.callbacks[callbackId];
if (callback) {
if (success && status == cordova.callbackStatus.OK) {
- callback.success && callback.success(message);
+ callback.success && callback.success.apply(null, args);
} else if (!success) {
- callback.fail && callback.fail(message);
+ callback.fail && callback.fail.apply(null, args);
}
// Clear callback if not expecting any more results
@@ -410,6 +410,7 @@ function each(objects, func, context) {
}
function clobber(obj, key, value) {
+ exports.replaceHookForTesting(obj, key);
obj[key] = value;
// Getters can only be overridden by getters.
if (obj[key] !== value) {
@@ -493,19 +494,18 @@ function recursiveMerge(target, src) {
}
}
-module.exports = {
- buildIntoButDoNotClobber: function(objects, target) {
- include(target, objects, false, false);
- },
- buildIntoAndClobber: function(objects, target) {
- include(target, objects, true, false);
- },
- buildIntoAndMerge: function(objects, target) {
- include(target, objects, true, true);
- },
- recursiveMerge: recursiveMerge,
- assignOrWrapInDeprecateGetter: assignOrWrapInDeprecateGetter
+exports.buildIntoButDoNotClobber = function(objects, target) {
+ include(target, objects, false, false);
};
+exports.buildIntoAndClobber = function(objects, target) {
+ include(target, objects, true, false);
+};
+exports.buildIntoAndMerge = function(objects, target) {
+ include(target, objects, true, true);
+};
+exports.recursiveMerge = recursiveMerge;
+exports.assignOrWrapInDeprecateGetter = assignOrWrapInDeprecateGetter;
+exports.replaceHookForTesting = function() {};
});
@@ -735,6 +735,9 @@ channel.createSticky('onCordovaInfoReady');
// Event to indicate that the connection property has been set.
channel.createSticky('onCordovaConnectionReady');
+// Event to indicate that all automatically loaded JS plugins are loaded and ready.
+channel.createSticky('onPluginsReady');
+
// Event to indicate that Cordova is ready
channel.createSticky('onDeviceReady');
@@ -785,176 +788,6 @@ module.exports = {
};
});
-// file: lib/common/common.js
-define("cordova/common", function(require, exports, module) {
-
-module.exports = {
- defaults: {
- cordova: {
- path: 'cordova',
- children: {
- exec: {
- path: 'cordova/exec'
- },
- logger: {
- path: 'cordova/plugin/logger'
- }
- }
- },
- Cordova: {
- children: {
- exec: {
- path: 'cordova/exec'
- }
- }
- },
- open : {
- path: 'cordova/plugin/InAppBrowser'
- },
- navigator: {
- children: {
- notification: {
- path: 'cordova/plugin/notification'
- },
- accelerometer: {
- path: 'cordova/plugin/accelerometer'
- },
- battery: {
- path: 'cordova/plugin/battery'
- },
- camera:{
- path: 'cordova/plugin/Camera'
- },
- compass:{
- path: 'cordova/plugin/compass'
- },
- contacts: {
- path: 'cordova/plugin/contacts'
- },
- device:{
- children:{
- capture: {
- path: 'cordova/plugin/capture'
- }
- }
- },
- geolocation: {
- path: 'cordova/plugin/geolocation'
- },
- globalization: {
- path: 'cordova/plugin/globalization'
- },
- network: {
- children: {
- connection: {
- path: 'cordova/plugin/network',
- deprecated: 'navigator.network.connection is deprecated. Use navigator.connection instead.'
- }
- }
- },
- splashscreen: {
- path: 'cordova/plugin/splashscreen'
- }
- }
- },
- Acceleration: {
- path: 'cordova/plugin/Acceleration'
- },
- Camera:{
- path: 'cordova/plugin/CameraConstants'
- },
- CameraPopoverOptions: {
- path: 'cordova/plugin/CameraPopoverOptions'
- },
- CaptureError: {
- path: 'cordova/plugin/CaptureError'
- },
- CaptureAudioOptions:{
- path: 'cordova/plugin/CaptureAudioOptions'
- },
- CaptureImageOptions: {
- path: 'cordova/plugin/CaptureImageOptions'
- },
- CaptureVideoOptions: {
- path: 'cordova/plugin/CaptureVideoOptions'
- },
- CompassHeading:{
- path: 'cordova/plugin/CompassHeading'
- },
- CompassError:{
- path: 'cordova/plugin/CompassError'
- },
- ConfigurationData: {
- path: 'cordova/plugin/ConfigurationData'
- },
- Connection: {
- path: 'cordova/plugin/Connection'
- },
- Contact: {
- path: 'cordova/plugin/Contact'
- },
- ContactAddress: {
- path: 'cordova/plugin/ContactAddress'
- },
- ContactError: {
- path: 'cordova/plugin/ContactError'
- },
- ContactField: {
- path: 'cordova/plugin/ContactField'
- },
- ContactFindOptions: {
- path: 'cordova/plugin/ContactFindOptions'
- },
- ContactName: {
- path: 'cordova/plugin/ContactName'
- },
- ContactOrganization: {
- path: 'cordova/plugin/ContactOrganization'
- },
- Coordinates: {
- path: 'cordova/plugin/Coordinates'
- },
- device: {
- path: 'cordova/plugin/device'
- },
- GlobalizationError: {
- path: 'cordova/plugin/GlobalizationError'
- },
- Media: {
- path: 'cordova/plugin/Media'
- },
- MediaError: {
- path: 'cordova/plugin/MediaError'
- },
- MediaFile: {
- path: 'cordova/plugin/MediaFile'
- },
- MediaFileData:{
- path: 'cordova/plugin/MediaFileData'
- },
- Position: {
- path: 'cordova/plugin/Position'
- },
- PositionError: {
- path: 'cordova/plugin/PositionError'
- },
- ProgressEvent: {
- path: 'cordova/plugin/ProgressEvent'
- }
- },
- clobbers: {
- navigator: {
- children: {
- connection: {
- path: 'cordova/plugin/network'
- }
- }
- }
- }
-};
-
-});
-
// file: lib/blackberry10/exec.js
define("cordova/exec", function(require, exports, module) {
@@ -1032,9 +865,9 @@ function prepareNamespace(symbolPath, context) {
var parts = symbolPath.split('.');
var cur = context;
for (var i = 0, part; part = parts[i]; ++i) {
- cur[part] = cur[part] || {};
+ cur = cur[part] = cur[part] || {};
}
- return cur[parts[i-1]];
+ return cur;
}
exports.mapModules = function(context) {
@@ -1056,7 +889,7 @@ exports.mapModules = function(context) {
if (strategy == 'm' && target) {
builder.recursiveMerge(target, module);
} else if ((strategy == 'd' && !target) || (strategy != 'd')) {
- if (target) {
+ if (!(symbolPath in origSymbols)) {
origSymbols[symbolPath] = target;
}
builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
@@ -1133,7 +966,8 @@ define("cordova/plugin/Camera", function(require, exports, module) {
var argscheck = require('cordova/argscheck'),
exec = require('cordova/exec'),
- Camera = require('cordova/plugin/CameraConstants');
+ Camera = require('cordova/plugin/CameraConstants'),
+ CameraPopoverHandle = require('cordova/plugin/CameraPopoverHandle');
var cameraExport = {};
@@ -1168,11 +1002,13 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
var correctOrientation = !!options.correctOrientation;
var saveToPhotoAlbum = !!options.saveToPhotoAlbum;
var popoverOptions = getValue(options.popoverOptions, null);
+ var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK);
var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,
- mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions];
+ mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection];
exec(successCallback, errorCallback, "Camera", "takePicture", args);
+ return new CameraPopoverHandle();
};
cameraExport.cleanup = function(successCallback, errorCallback) {
@@ -1212,11 +1048,33 @@ module.exports = {
ARROW_LEFT : 4,
ARROW_RIGHT : 8,
ARROW_ANY : 15
+ },
+ Direction:{
+ BACK: 0,
+ FRONT: 1
}
};
});
+// file: lib/common/plugin/CameraPopoverHandle.js
+define("cordova/plugin/CameraPopoverHandle", function(require, exports, module) {
+
+var exec = require('cordova/exec');
+
+/**
+ * A handle to an image picker popover.
+ */
+var CameraPopoverHandle = function() {
+ this.setPosition = function(popoverOptions) {
+ console.log('CameraPopoverHandle.setPosition is only supported on iOS.');
+ };
+};
+
+module.exports = CameraPopoverHandle;
+
+});
+
// file: lib/common/plugin/CameraPopoverOptions.js
define("cordova/plugin/CameraPopoverOptions", function(require, exports, module) {
@@ -1342,9 +1200,9 @@ module.exports = CompassError;
define("cordova/plugin/CompassHeading", function(require, exports, module) {
var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
- this.magneticHeading = magneticHeading || null;
- this.trueHeading = trueHeading || null;
- this.headingAccuracy = headingAccuracy || null;
+ this.magneticHeading = magneticHeading;
+ this.trueHeading = trueHeading;
+ this.headingAccuracy = headingAccuracy;
this.timestamp = timestamp || new Date().getTime();
};
@@ -1762,167 +1620,88 @@ module.exports = Coordinates;
});
-// file: lib/common/plugin/DirectoryEntry.js
+// file: lib/blackberry10/plugin/DirectoryEntry.js
define("cordova/plugin/DirectoryEntry", function(require, exports, module) {
var argscheck = require('cordova/argscheck'),
utils = require('cordova/utils'),
- exec = require('cordova/exec'),
Entry = require('cordova/plugin/Entry'),
FileError = require('cordova/plugin/FileError'),
- DirectoryReader = require('cordova/plugin/DirectoryReader');
-
-/**
- * An interface representing a directory on the file system.
- *
- * {boolean} isFile always false (readonly)
- * {boolean} isDirectory always true (readonly)
- * {DOMString} name of the directory, excluding the path leading to it (readonly)
- * {DOMString} fullPath the absolute full path to the directory (readonly)
- * TODO: implement this!!! {FileSystem} filesystem on which the directory resides (readonly)
- */
-var DirectoryEntry = function(name, fullPath) {
- DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath);
-};
+ DirectoryReader = require('cordova/plugin/DirectoryReader'),
+ fileUtils = require('cordova/plugin/blackberry10/fileUtils'),
+ DirectoryEntry = function (name, fullPath) {
+ DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath);
+ };
utils.extend(DirectoryEntry, Entry);
-/**
- * Creates a new DirectoryReader to read entries from this directory
- */
-DirectoryEntry.prototype.createReader = function() {
+DirectoryEntry.prototype.createReader = function () {
return new DirectoryReader(this.fullPath);
};
-/**
- * Creates or looks up a directory
- *
- * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a directory
- * @param {Flags} options to create or exclusively create the directory
- * @param {Function} successCallback is called with the new entry
- * @param {Function} errorCallback is called with a FileError
- */
-DirectoryEntry.prototype.getDirectory = function(path, options, successCallback, errorCallback) {
+DirectoryEntry.prototype.getDirectory = function (path, options, successCallback, errorCallback) {
argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments);
- var win = successCallback && function(result) {
- var entry = new DirectoryEntry(result.name, result.fullPath);
- successCallback(entry);
- };
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- exec(win, fail, "File", "getDirectory", [this.fullPath, path, options]);
+ this.nativeEntry.getDirectory(path, options, function (entry) {
+ successCallback(fileUtils.createEntry(entry));
+ }, errorCallback);
};
-/**
- * Deletes a directory and all of it's contents
- *
- * @param {Function} successCallback is called with no parameters
- * @param {Function} errorCallback is called with a FileError
- */
-DirectoryEntry.prototype.removeRecursively = function(successCallback, errorCallback) {
+DirectoryEntry.prototype.removeRecursively = function (successCallback, errorCallback) {
argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments);
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- exec(successCallback, fail, "File", "removeRecursively", [this.fullPath]);
+ this.nativeEntry.removeRecursively(successCallback, errorCallback);
};
-/**
- * Creates or looks up a file
- *
- * @param {DOMString} path either a relative or absolute path from this directory in which to look up or create a file
- * @param {Flags} options to create or exclusively create the file
- * @param {Function} successCallback is called with the new entry
- * @param {Function} errorCallback is called with a FileError
- */
-DirectoryEntry.prototype.getFile = function(path, options, successCallback, errorCallback) {
+DirectoryEntry.prototype.getFile = function (path, options, successCallback, errorCallback) {
argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments);
- var win = successCallback && function(result) {
- var FileEntry = require('cordova/plugin/FileEntry');
- var entry = new FileEntry(result.name, result.fullPath);
- successCallback(entry);
- };
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- exec(win, fail, "File", "getFile", [this.fullPath, path, options]);
+ this.nativeEntry.getFile(path, options, function (entry) {
+ successCallback(fileUtils.createEntry(entry));
+ }, errorCallback);
};
module.exports = DirectoryEntry;
});
-// file: lib/common/plugin/DirectoryReader.js
+// file: lib/blackberry10/plugin/DirectoryReader.js
define("cordova/plugin/DirectoryReader", function(require, exports, module) {
-var exec = require('cordova/exec'),
- FileError = require('cordova/plugin/FileError') ;
+var FileError = require('cordova/plugin/FileError'),
+ fileUtils = require('cordova/plugin/blackberry10/fileUtils');
-/**
- * An interface that lists the files and directories in a directory.
- */
function DirectoryReader(path) {
- this.path = path || null;
+ this.path = path;
}
-/**
- * Returns a list of entries from a directory.
- *
- * @param {Function} successCallback is called with a list of entries
- * @param {Function} errorCallback is called with a FileError
- */
DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
var win = typeof successCallback !== 'function' ? null : function(result) {
- var retVal = [];
- for (var i=0; i<result.length; i++) {
- var entry = null;
- if (result[i].isDirectory) {
- entry = new (require('cordova/plugin/DirectoryEntry'))();
- }
- else if (result[i].isFile) {
- entry = new (require('cordova/plugin/FileEntry'))();
+ var retVal = [];
+ for (var i=0; i<result.length; i++) {
+ retVal.push(fileUtils.createEntry(result[i]));
}
- entry.isDirectory = result[i].isDirectory;
- entry.isFile = result[i].isFile;
- entry.name = result[i].name;
- entry.fullPath = result[i].fullPath;
- retVal.push(entry);
- }
- successCallback(retVal);
- };
- var fail = typeof errorCallback !== 'function' ? null : function(code) {
- errorCallback(new FileError(code));
- };
- exec(win, fail, "File", "readEntries", [this.path]);
+ successCallback(retVal);
+ },
+ fail = typeof errorCallback !== 'function' ? null : function(code) {
+ errorCallback(new FileError(code));
+ };
+ fileUtils.getEntryForURI(this.path, function (entry) {
+ entry.nativeEntry.createReader().readEntries(win, fail);
+ }, function () {
+ fail(FileError.NOT_FOUND_ERR);
+ });
};
module.exports = DirectoryReader;
});
-// file: lib/common/plugin/Entry.js
+// file: lib/blackberry10/plugin/Entry.js
define("cordova/plugin/Entry", function(require, exports, module) {
var argscheck = require('cordova/argscheck'),
- exec = require('cordova/exec'),
FileError = require('cordova/plugin/FileError'),
- Metadata = require('cordova/plugin/Metadata');
+ Metadata = require('cordova/plugin/Metadata'),
+ fileUtils = require('cordova/plugin/blackberry10/fileUtils');
-/**
- * Represents a file or directory on the local file system.
- *
- * @param isFile
- * {boolean} true if Entry is a file (readonly)
- * @param isDirectory
- * {boolean} true if Entry is a directory (readonly)
- * @param name
- * {DOMString} name of the file or directory, excluding the path
- * leading to it (readonly)
- * @param fullPath
- * {DOMString} the absolute full path to the file or directory
- * (readonly)
- */
function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
this.isFile = !!isFile;
this.isDirectory = !!isDirectory;
@@ -1931,175 +1710,87 @@ function Entry(isFile, isDirectory, name, fullPath, fileSystem) {
this.filesystem = fileSystem || null;
}
-/**
- * Look up the metadata of the entry.
- *
- * @param successCallback
- * {Function} is called with a Metadata object
- * @param errorCallback
- * {Function} is called with a FileError
- */
Entry.prototype.getMetadata = function(successCallback, errorCallback) {
argscheck.checkArgs('FF', 'Entry.getMetadata', arguments);
- var success = successCallback && function(lastModified) {
+ var success = function(lastModified) {
var metadata = new Metadata(lastModified);
- successCallback(metadata);
- };
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
+ if (typeof successCallback === 'function') {
+ successCallback(metadata);
+ }
};
-
- exec(success, fail, "File", "getMetadata", [this.fullPath]);
+ this.nativeEntry.getMetadata(success, errorCallback);
};
-/**
- * Set the metadata of the entry.
- *
- * @param successCallback
- * {Function} is called with a Metadata object
- * @param errorCallback
- * {Function} is called with a FileError
- * @param metadataObject
- * {Object} keys and values to set
- */
Entry.prototype.setMetadata = function(successCallback, errorCallback, metadataObject) {
argscheck.checkArgs('FFO', 'Entry.setMetadata', arguments);
- exec(successCallback, errorCallback, "File", "setMetadata", [this.fullPath, metadataObject]);
+ errorCallback("Not supported by platform");
};
-/**
- * Move a file or directory to a new location.
- *
- * @param parent
- * {DirectoryEntry} the directory to which to move this entry
- * @param newName
- * {DOMString} new name of the entry, defaults to the current name
- * @param successCallback
- * {Function} called with the new DirectoryEntry object
- * @param errorCallback
- * {Function} called with a FileError
- */
Entry.prototype.moveTo = function(parent, newName, successCallback, errorCallback) {
argscheck.checkArgs('oSFF', 'Entry.moveTo', arguments);
var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- // source path
- var srcPath = this.fullPath,
- // entry name
+ errorCallback(new FileError(code));
+ },
+ srcPath = this.fullPath,
name = newName || this.name,
success = function(entry) {
if (entry) {
- if (successCallback) {
- // create appropriate Entry object
- var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
- successCallback(result);
+ if (successCallback === 'function') {
+ successCallback(fileUtils.createEntry(entry));
}
}
else {
- // no Entry object returned
- fail && fail(FileError.NOT_FOUND_ERR);
+ if (typeof fail === 'function') {
+ fail(FileError.NOT_FOUND_ERR);
+ }
}
};
-
- // copy
- exec(success, fail, "File", "moveTo", [srcPath, parent.fullPath, name]);
+ this.nativeEntry.moveTo(parent.nativeEntry, newName, success, errorCallback);
};
-/**
- * Copy a directory to a different location.
- *
- * @param parent
- * {DirectoryEntry} the directory to which to copy the entry
- * @param newName
- * {DOMString} new name of the entry, defaults to the current name
- * @param successCallback
- * {Function} called with the new Entry object
- * @param errorCallback
- * {Function} called with a FileError
- */
+
Entry.prototype.copyTo = function(parent, newName, successCallback, errorCallback) {
argscheck.checkArgs('oSFF', 'Entry.copyTo', arguments);
var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
-
- // source path
- var srcPath = this.fullPath,
- // entry name
+ errorCallback(new FileError(code));
+ },
+ srcPath = this.fullPath,
name = newName || this.name,
- // success callback
success = function(entry) {
if (entry) {
- if (successCallback) {
- // create appropriate Entry object
- var result = (entry.isDirectory) ? new (require('cordova/plugin/DirectoryEntry'))(entry.name, entry.fullPath) : new (require('cordova/plugin/FileEntry'))(entry.name, entry.fullPath);
- successCallback(result);
+ if (typeof successCallback === 'function') {
+ successCallback(fileUtils.createEntry(entry));
}
}
else {
- // no Entry object returned
- fail && fail(FileError.NOT_FOUND_ERR);
+ if (typeof fail === 'function') {
+ fail(FileError.NOT_FOUND_ERR);
+ }
}
};
-
- // copy
- exec(success, fail, "File", "copyTo", [srcPath, parent.fullPath, name]);
+ this.nativeEntry.copyTo(parent.nativeEntry, newName, success, errorCallback);
};
-/**
- * Return a URL that can be used to identify this entry.
- */
Entry.prototype.toURL = function() {
- // fullPath attribute contains the full URL
return this.fullPath;
};
-/**
- * Returns a URI that can be used to identify this entry.
- *
- * @param {DOMString} mimeType for a FileEntry, the mime type to be used to interpret the file, when loaded through this URI.
- * @return uri
- */
Entry.prototype.toURI = function(mimeType) {
console.log("DEPRECATED: Update your code to use 'toURL'");
- // fullPath attribute contains the full URI
return this.toURL();
};
-/**
- * Remove a file or directory. It is an error to attempt to delete a
- * directory that is not empty. It is an error to attempt to delete a
- * root directory of a file system.
- *
- * @param successCallback {Function} called with no parameters
- * @param errorCallback {Function} called with a FileError
- */
Entry.prototype.remove = function(successCallback, errorCallback) {
argscheck.checkArgs('FF', 'Entry.remove', arguments);
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- exec(successCallback, fail, "File", "remove", [this.fullPath]);
+ this.nativeEntry.remove(successCallback, errorCallback);
};
-/**
- * Look up the parent DirectoryEntry of this entry.
- *
- * @param successCallback {Function} called with the parent DirectoryEntry object
- * @param errorCallback {Function} called with a FileError
- */
Entry.prototype.getParent = function(successCallback, errorCallback) {
argscheck.checkArgs('FF', 'Entry.getParent', arguments);
var win = successCallback && function(result) {
- var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
- var entry = new DirectoryEntry(result.name, result.fullPath);
- successCallback(entry);
- };
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
+ successCallback(fileUtils.createEntry(result));
};
- exec(win, fail, "File", "getParent", [this.fullPath]);
+ this.nativeEntry.getParent(win, errorCallback);
};
module.exports = Entry;
@@ -2168,67 +1859,34 @@ module.exports = File;
});
-// file: lib/common/plugin/FileEntry.js
+// file: lib/blackberry10/plugin/FileEntry.js
define("cordova/plugin/FileEntry", function(require, exports, module) {
var utils = require('cordova/utils'),
- exec = require('cordova/exec'),
Entry = require('cordova/plugin/Entry'),
FileWriter = require('cordova/plugin/FileWriter'),
File = require('cordova/plugin/File'),
- FileError = require('cordova/plugin/FileError');
-
-/**
- * An interface representing a file on the file system.
- *
- * {boolean} isFile always true (readonly)
- * {boolean} isDirectory always false (readonly)
- * {DOMString} name of the file, excluding the path leading to it (readonly)
- * {DOMString} fullPath the absolute full path to the file (readonly)
- * {FileSystem} filesystem on which the file resides (readonly)
- */
-var FileEntry = function(name, fullPath) {
- FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath]);
-};
+ FileError = require('cordova/plugin/FileError'),
+ FileEntry = function (name, fullPath) {
+ FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath]);
+ };
utils.extend(FileEntry, Entry);
-/**
- * Creates a new FileWriter associated with the file that this FileEntry represents.
- *
- * @param {Function} successCallback is called with the new FileWriter
- * @param {Function} errorCallback is called with a FileError
- */
FileEntry.prototype.createWriter = function(successCallback, errorCallback) {
- this.file(function(filePointer) {
- var writer = new FileWriter(filePointer);
-
- if (writer.fileName === null || writer.fileName === "") {
- errorCallback && errorCallback(new FileError(FileError.INVALID_STATE_ERR));
- } else {
- successCallback && successCallback(writer);
- }
+ this.file(function (file) {
+ successCallback(new FileWriter(file));
}, errorCallback);
};
-/**
- * Returns a File that represents the current state of the file that this FileEntry represents.
- *
- * @param {Function} successCallback is called with the new File object
- * @param {Function} errorCallback is called with a FileError
- */
FileEntry.prototype.file = function(successCallback, errorCallback) {
- var win = successCallback && function(f) {
- var file = new File(f.name, f.fullPath, f.type, f.lastModifiedDate, f.size);
- successCallback(file);
- };
- var fail = errorCallback && function(code) {
- errorCallback(new FileError(code));
- };
- exec(win, fail, "File", "getFileMetadata", [this.fullPath]);
+ var fullPath = this.fullPath,
+ success = function (file) {
+ successCallback(new File(file.name, fullPath, file.type, file.lastModifiedDate, file.size));
+ };
+ this.nativeEntry.file(success, errorCallback);
};
-
module.exports = FileEntry;
});
@@ -2264,317 +1922,99 @@ module.exports = FileError;
});
-// file: lib/common/plugin/FileReader.js
+// file: lib/blackberry10/plugin/FileReader.js
define("cordova/plugin/FileReader", function(require, exports, module) {
-var exec = require('cordova/exec'),
- modulemapper = require('cordova/modulemapper'),
- utils = require('cordova/utils'),
- File = require('cordova/plugin/File'),
- FileError = require('cordova/plugin/FileError'),
- ProgressEvent = require('cordova/plugin/ProgressEvent'),
- origFileReader = modulemapper.getOriginalSymbol(this, 'FileReader');
+var origFileReader = window.FileReader,
+ fileUtils = require('cordova/plugin/blackberry10/fileUtils'),
+ utils = require('cordova/utils');
-/**
- * This class reads the mobile device file system.
- *
- * For Android:
- * The root directory is the root of the file system.
- * To read from the SD card, the file name is "sdcard/my_file.txt"
- * @constructor
- */
var FileReader = function() {
- this._readyState = 0;
- this._error = null;
- this._result = null;
- this._fileName = '';
- this._realReader = origFileReader ? new origFileReader() : {};
+ this.nativeReader = new origFileReader();
};
-// States
-FileReader.EMPTY = 0;
-FileReader.LOADING = 1;
-FileReader.DONE = 2;
-
utils.defineGetter(FileReader.prototype, 'readyState', function() {
- return this._fileName ? this._readyState : this._realReader.readyState;
+ return this.nativeReader.readyState;
});
utils.defineGetter(FileReader.prototype, 'error', function() {
- return this._fileName ? this._error: this._realReader.error;
+ return this.nativeReader.error;
});
utils.defineGetter(FileReader.prototype, 'result', function() {
- return this._fileName ? this._result: this._realReader.result;
+ return this.nativeReader.result;
});
function defineEvent(eventName) {
utils.defineGetterSetter(FileReader.prototype, eventName, function() {
- return this._realReader[eventName] || null;
+ return this.nativeReader[eventName] || null;
}, function(value) {
- this._realReader[eventName] = value;
+ this.nativeReader[eventName] = value;
});
}
-defineEvent('onloadstart'); // When the read starts.
-defineEvent('onprogress'); // While reading (and decoding) file or fileBlob data, and reporting partial file data (progress.loaded/progress.total)
-defineEvent('onload'); // When the read has successfully completed.
-defineEvent('onerror'); // When the read has failed (see errors).
-defineEvent('onloadend'); // When the request has completed (either in success or failure).
-defineEvent('onabort'); // When the read has been aborted. For instance, by invoking the abort() method.
-
-function initRead(reader, file) {
- // Already loading something
- if (reader.readyState == FileReader.LOADING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- reader._result = null;
- reader._error = null;
- reader._readyState = FileReader.LOADING;
- if (typeof file == 'string') {
- // Deprecated in Cordova 2.4.
- console.warning('Using a string argument with FileReader.readAs functions is deprecated.');
- reader._fileName = file;
- } else if (typeof file.fullPath == 'string') {
- reader._fileName = file.fullPath;
- } else {
- reader._fileName = '';
- return true;
- }
-
- reader.onloadstart && reader.onloadstart(new ProgressEvent("loadstart", {target:reader}));
-}
+defineEvent('onabort');
+defineEvent('onerror');
+defineEvent('onload');
+defineEvent('onloadend');
+defineEvent('onloadstart');
+defineEvent('onprogress');
-/**
- * Abort reading file.
- */
FileReader.prototype.abort = function() {
- if (origFileReader && !this._fileName) {
- return this._realReader.abort();
- }
- this._result = null;
-
- if (this._readyState == FileReader.DONE || this._readyState == FileReader.EMPTY) {
- return;
- }
-
- this._readyState = FileReader.DONE;
-
- // If abort callback
- if (typeof this.onabort === 'function') {
- this.onabort(new ProgressEvent('abort', {target:this}));
- }
- // If load end callback
- if (typeof this.onloadend === 'function') {
- this.onloadend(new ProgressEvent('loadend', {target:this}));
- }
+ return this.nativeReader.abort();
};
-/**
- * Read text file.
- *
- * @param file {File} File object containing file properties
- * @param encoding [Optional] (see http://www.iana.org/assignments/character-sets)
- */
FileReader.prototype.readAsText = function(file, encoding) {
- if (initRead(this, file)) {
- return this._realReader.readAsText(file, encoding);
- }
+ var that = this;
+ fileUtils.getEntryForURI(file.fullPath, function (entry) {
+ entry.nativeEntry.file(function (nativeFile) {
+ that.nativeReader.readAsText(nativeFile, encoding);
+ }, that.onerror);
+ }, that.onerror);
+};
- // Default encoding is UTF-8
- var enc = encoding ? encoding : "UTF-8";
- var me = this;
- var execArgs = [this._fileName, enc];
+FileReader.prototype.readAsDataURL = function(file) {
+ var that = this;
+ fileUtils.getEntryForURI(file.fullPath, function (entry) {
+ entry.nativeEntry.file(function (nativeFile) {
+ that.nativeReader.readAsDataURL(nativeFile);
+ }, that.onerror);
+ }, that.onerror);
+};
- // Maybe add slice parameters.
- if (file.end < file.size) {
- execArgs.push(file.start, file.end);
- } else if (file.start > 0) {
- execArgs.push(file.start);
- }
+FileReader.prototype.readAsBinaryString = function(file) {
+ var that = this;
+ fileUtils.getEntryForURI(file.fullPath, function (entry) {
+ entry.nativeEntry.file(function (nativeFile) {
+ that.nativeReader.readAsBinaryString(nativeFile);
+ }, that.onerror);
+ }, that.onerror);
+};
- // Read file
- exec(
- // Success callback
- function(r) {
- // If DONE (cancelled), then don't do anything
- if (me._readyState === FileReader.DONE) {
- return;
- }
+FileReader.prototype.readAsArrayBuffer = function(file) {
+ var that = this;
+ fileUtils.getEntryForURI(file.fullPath, function (entry) {
+ entry.nativeEntry.file(function (nativeFile) {
+ that.nativeReader.readAsArrayBuffer(nativeFile);
+ }, that.onerror);
+ }, that.onerror);
+};
- // Save result
- me._result = r;
+window.FileReader = FileReader;
+module.exports = FileReader;
- // If onload callback
- if (typeof me.onload === "function") {
- me.onload(new ProgressEvent("load", {target:me}));
- }
+});
- // DONE state
- me._readyState = FileReader.DONE;
+// file: lib/blackberry10/plugin/FileSystem.js
+define("cordova/plugin/FileSystem", function(require, exports, module) {
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- },
- // Error callback
- function(e) {
- // If DONE (cancelled), then don't do anything
- if (me._readyState === FileReader.DONE) {
- return;
- }
-
- // DONE state
- me._readyState = FileReader.DONE;
-
- // null result
- me._result = null;
-
- // Save error
- me._error = new FileError(e);
-
- // If onerror callback
- if (typeof me.onerror === "function") {
- me.onerror(new ProgressEvent("error", {target:me}));
- }
-
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- }, "File", "readAsText", execArgs);
-};
-
-
-/**
- * Read file and return data as a base64 encoded data url.
- * A data url is of the form:
- * data:[<mediatype>][;base64],<data>
- *
- * @param file {File} File object containing file properties
- */
-FileReader.prototype.readAsDataURL = function(file) {
- if (initRead(this, file)) {
- return this._realReader.readAsDataURL(file);
- }
-
- var me = this;
- var execArgs = [this._fileName];
-
- // Maybe add slice parameters.
- if (file.end < file.size) {
- execArgs.push(file.start, file.end);
- } else if (file.start > 0) {
- execArgs.push(file.start);
- }
-
- // Read file
- exec(
- // Success callback
- function(r) {
- // If DONE (cancelled), then don't do anything
- if (me._readyState === FileReader.DONE) {
- return;
- }
-
- // DONE state
- me._readyState = FileReader.DONE;
-
- // Save result
- me._result = r;
-
- // If onload callback
- if (typeof me.onload === "function") {
- me.onload(new ProgressEvent("load", {target:me}));
- }
-
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- },
- // Error callback
- function(e) {
- // If DONE (cancelled), then don't do anything
- if (me._readyState === FileReader.DONE) {
- return;
- }
-
- // DONE state
- me._readyState = FileReader.DONE;
-
- me._result = null;
-
- // Save error
- me._error = new FileError(e);
-
- // If onerror callback
- if (typeof me.onerror === "function") {
- me.onerror(new ProgressEvent("error", {target:me}));
- }
-
- // If onloadend callback
- if (typeof me.onloadend === "function") {
- me.onloadend(new ProgressEvent("loadend", {target:me}));
- }
- }, "File", "readAsDataURL", execArgs);
-};
-
-/**
- * Read file and return data as a binary data.
- *
- * @param file {File} File object containing file properties
- */
-FileReader.prototype.readAsBinaryString = function(file) {
- if (initRead(this, file)) {
- return this._realReader.readAsBinaryString(file);
- }
- // TODO - Can't return binary data to browser.
- console.log('method "readAsBinaryString" is not supported at this time.');
- this.abort();
-};
-
-/**
- * Read file and return data as a binary data.
- *
- * @param file {File} File object containing file properties
- */
-FileReader.prototype.readAsArrayBuffer = function(file) {
- if (initRead(this, file)) {
- return this._realReader.readAsArrayBuffer(file);
- }
- // TODO - Can't return binary data to browser.
- console.log('This method is not supported at this time.');
- this.abort();
-};
-
-module.exports = FileReader;
-
-});
-
-// file: lib/common/plugin/FileSystem.js
-define("cordova/plugin/FileSystem", function(require, exports, module) {
-
-var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
-
-/**
- * An interface representing a file system
- *
- * @constructor
- * {DOMString} name the unique name of the file system (readonly)
- * {DirectoryEntry} root directory of the file system (readonly)
- */
-var FileSystem = function(name, root) {
+module.exports = function(name, root) {
this.name = name || null;
if (root) {
- this.root = new DirectoryEntry(root.name, root.fullPath);
+ this.root = root;
}
};
-module.exports = FileSystem;
-
});
// file: lib/common/plugin/FileTransfer.js
@@ -2593,6 +2033,38 @@ function newProgressEvent(result) {
return pe;
}
+function getBasicAuthHeader(urlString) {
+ var header = null;
+
+ if (window.btoa) {
+ // parse the url using the Location object
+ var url = document.createElement('a');
+ url.href = urlString;
+
+ var credentials = null;
+ var protocol = url.protocol + "//";
+ var origin = protocol + url.host;
+
+ // check whether there are the username:password credentials in the url
+ if (url.href.indexOf(origin) !== 0) { // credentials found
+ var atIndex = url.href.indexOf("@");
+ credentials = url.href.substring(protocol.length, atIndex);
+ }
+
+ if (credentials) {
+ var authHeader = "Authorization";
+ var authHeaderValue = "Basic " + window.btoa(credentials);
+
+ header = {
+ name : authHeader,
+ value : authHeaderValue
+ };
+ }
+ }
+
+ return header;
+}
+
var idCounter = 0;
/**
@@ -2623,11 +2095,25 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
var params = null;
var chunkedMode = true;
var headers = null;
+ var httpMethod = null;
+ var basicAuthHeader = getBasicAuthHeader(server);
+ if (basicAuthHeader) {
+ options = options || {};
+ options.headers = options.headers || {};
+ options.headers[basicAuthHeader.name] = basicAuthHeader.value;
+ }
+
if (options) {
fileKey = options.fileKey;
fileName = options.fileName;
mimeType = options.mimeType;
headers = options.headers;
+ httpMethod = options.httpMethod || "POST";
+ if (httpMethod.toUpperCase() == "PUT"){
+ httpMethod = "PUT";
+ } else {
+ httpMethod = "POST";
+ }
if (options.chunkedMode !== null || typeof options.chunkedMode != "undefined") {
chunkedMode = options.chunkedMode;
}
@@ -2640,7 +2126,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
}
var fail = errorCallback && function(e) {
- var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
+ var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body);
errorCallback(error);
};
@@ -2654,7 +2140,7 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
successCallback && successCallback(result);
}
};
- exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id]);
+ exec(win, fail, 'FileTransfer', 'upload', [filePath, server, fileKey, fileName, mimeType, params, trustAllHosts, chunkedMode, headers, this._id, httpMethod]);
};
/**
@@ -2664,10 +2150,24 @@ FileTransfer.prototype.upload = function(filePath, server, successCallback, erro
* @param successCallback (Function} Callback to be invoked when upload has completed
* @param errorCallback {Function} Callback to be invoked upon error
* @param trustAllHosts {Boolean} Optional trust all hosts (e.g. for self-signed certs), defaults to false
+ * @param options {FileDownloadOptions} Optional parameters such as headers
*/
-FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts) {
+FileTransfer.prototype.download = function(source, target, successCallback, errorCallback, trustAllHosts, options) {
argscheck.checkArgs('ssFF*', 'FileTransfer.download', arguments);
var self = this;
+
+ var basicAuthHeader = getBasicAuthHeader(source);
+ if (basicAuthHeader) {
+ options = options || {};
+ options.headers = options.headers || {};
+ options.headers[basicAuthHeader.name] = basicAuthHeader.value;
+ }
+
+ var headers = null;
+ if (options) {
+ headers = options.headers || null;
+ }
+
var win = function(result) {
if (typeof result.lengthComputable != "undefined") {
if (self.onprogress) {
@@ -2690,20 +2190,19 @@ FileTransfer.prototype.download = function(source, target, successCallback, erro
};
var fail = errorCallback && function(e) {
- var error = new FileTransferError(e.code, e.source, e.target, e.http_status);
+ var error = new FileTransferError(e.code, e.source, e.target, e.http_status, e.body);
errorCallback(error);
};
- exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id]);
+ exec(win, fail, 'FileTransfer', 'download', [source, target, trustAllHosts, this._id, headers]);
};
/**
- * Aborts the ongoing file transfer on this object
- * @param successCallback {Function} Callback to be invoked upon success
- * @param errorCallback {Function} Callback to be invoked upon error
+ * Aborts the ongoing file transfer on this object. The original error
+ * callback for the file transfer will be called if necessary.
*/
-FileTransfer.prototype.abort = function(successCallback, errorCallback) {
- exec(successCallback, errorCallback, 'FileTransfer', 'abort', [this._id]);
+FileTransfer.prototype.abort = function() {
+ exec(null, null, 'FileTransfer', 'abort', [this._id]);
};
module.exports = FileTransfer;
@@ -2717,11 +2216,12 @@ define("cordova/plugin/FileTransferError", function(require, exports, module) {
* FileTransferError
* @constructor
*/
-var FileTransferError = function(code, source, target, status) {
+var FileTransferError = function(code, source, target, status, body) {
this.code = code || null;
this.source = source || null;
this.target = target || null;
this.http_status = status || null;
+ this.body = body || null;
};
FileTransferError.FILE_NOT_FOUND_ERR = 1;
@@ -2746,12 +2246,13 @@ define("cordova/plugin/FileUploadOptions", function(require, exports, module) {
* @param headers {Object} Keys are header names, values are header values. Multiple
* headers of the same name are not supported.
*/
-var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers) {
+var FileUploadOptions = function(fileKey, fileName, mimeType, params, headers, httpMethod) {
this.fileKey = fileKey || null;
this.fileName = fileName || null;
this.mimeType = mimeType || null;
this.params = params || null;
this.headers = headers || null;
+ this.httpMethod = httpMethod || null;
};
module.exports = FileUploadOptions;
@@ -2775,259 +2276,105 @@ module.exports = FileUploadResult;
});
-// file: lib/common/plugin/FileWriter.js
+// file: lib/blackberry10/plugin/FileWriter.js
define("cordova/plugin/FileWriter", function(require, exports, module) {
-var exec = require('cordova/exec'),
- FileError = require('cordova/plugin/FileError'),
- ProgressEvent = require('cordova/plugin/ProgressEvent');
-
-/**
- * This class writes to the mobile device file system.
- *
- * For Android:
- * The root directory is the root of the file system.
- * To write to the SD card, the file name is "sdcard/my_file.txt"
- *
- * @constructor
- * @param file {File} File object containing file properties
- * @param append if true write to the end of the file, otherwise overwrite the file
- */
-var FileWriter = function(file) {
- this.fileName = "";
- this.length = 0;
- if (file) {
- this.fileName = file.fullPath || file;
- this.length = file.size || 0;
- }
- // default is to write at the beginning of the file
- this.position = 0;
-
- this.readyState = 0; // EMPTY
+var FileError = require('cordova/plugin/FileError'),
+ ProgressEvent = require('cordova/plugin/ProgressEvent'),
+ fileUtils = require('cordova/plugin/blackberry10/fileUtils'),
+ utils = require('cordova/utils');
- this.result = null;
+function FileWriter (file) {
+ var that = this;
+ this.file = file;
+ this.events = {};
+ this.pending = [];
+ fileUtils.getEntryForURI(file.fullPath, function (entry) {
+ entry.nativeEntry.createWriter(function (writer) {
+ var i,
+ event;
+ that.nativeWriter = writer;
+ for (event in that.events) {
+ if (that.events.hasOwnProperty(event)) {
+ that.nativeWriter[event] = that.events[event];
+ }
+ }
+ for (i = 0; i < that.pending.length; i++) {
+ that.pending[i]();
+ }
+ });
+ });
+ this.events = {};
+ this.pending = [];
+}
- // Error
- this.error = null;
+utils.defineGetter(FileWriter.prototype, 'error', function() {
+ return this.nativeWriter ? this.nativeWriter.error : null;
+});
- // Event handlers
- this.onwritestart = null; // When writing starts
- this.onprogress = null; // While writing the file, and reporting partial file data
- this.onwrite = null; // When the write has successfully completed.
- this.onwriteend = null; // When the request has completed (either in success or failure).
- this.onabort = null; // When the write has been aborted. For instance, by invoking the abort() method.
- this.onerror = null; // When the write has failed (see errors).
-};
+utils.defineGetter(FileWriter.prototype, 'fileName', function() {
+ return this.nativeWriter ? this.nativeWriter.fileName : this.file.name;
+});
-// States
-FileWriter.INIT = 0;
-FileWriter.WRITING = 1;
-FileWriter.DONE = 2;
+utils.defineGetter(FileWriter.prototype, 'length', function() {
+ return this.nativeWriter ? this.nativeWriter.length : this.file.size;
+});
-/**
- * Abort writing file.
- */
-FileWriter.prototype.abort = function() {
- // check for invalid state
- if (this.readyState === FileWriter.DONE || this.readyState === FileWriter.INIT) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
+utils.defineGetter(FileWriter.prototype, 'position', function() {
+ return this.nativeWriter ? this.nativeWriter.position : 0;
+});
- // set error
- this.error = new FileError(FileError.ABORT_ERR);
+utils.defineGetter(FileWriter.prototype, 'readyState', function() {
+ return this.nativeWriter ? this.nativeWriter.readyState : 0;
+});
- this.readyState = FileWriter.DONE;
+function defineEvent(eventName) {
+ utils.defineGetterSetter(FileWriter.prototype, eventName, function() {
+ return this.nativeWriter ? this.nativeWriter[eventName] || null : this.events[eventName] || null;
+ }, function(value) {
+ if (this.nativeWriter) {
+ this.nativeWriter[eventName] = value;
+ }
+ else {
+ this.events[eventName] = value;
+ }
+ });
+}
- // If abort callback
- if (typeof this.onabort === "function") {
- this.onabort(new ProgressEvent("abort", {"target":this}));
- }
+defineEvent('onabort');
+defineEvent('onerror');
+defineEvent('onprogress');
+defineEvent('onwrite');
+defineEvent('onwriteend');
+defineEvent('onwritestart');
- // If write end callback
- if (typeof this.onwriteend === "function") {
- this.onwriteend(new ProgressEvent("writeend", {"target":this}));
- }
+FileWriter.prototype.abort = function() {
+ this.nativeWriter.abort();
};
-/**
- * Writes data to the file
- *
- * @param text to be written
- */
FileWriter.prototype.write = function(text) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // WRITING state
- this.readyState = FileWriter.WRITING;
-
- var me = this;
-
- // If onwritestart callback
- if (typeof me.onwritestart === "function") {
- me.onwritestart(new ProgressEvent("writestart", {"target":me}));
- }
-
- // Write file
- exec(
- // Success callback
- function(r) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // position always increases by bytes written because file would be extended
- me.position += r;
- // The length of the file is now where we are done writing.
-
- me.length = me.position;
-
- // DONE state
- me.readyState = FileWriter.DONE;
-
- // If onwrite callback
- if (typeof me.onwrite === "function") {
- me.onwrite(new ProgressEvent("write", {"target":me}));
- }
-
- // If onwriteend callback
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
- },
- // Error callback
- function(e) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // DONE state
- me.readyState = FileWriter.DONE;
-
- // Save error
- me.error = new FileError(e);
-
- // If onerror callback
- if (typeof me.onerror === "function") {
- me.onerror(new ProgressEvent("error", {"target":me}));
- }
+ var that = this,
+ op = function () {
+ that.nativeWriter.write(new Blob([text]));
+ };
+ this.nativeWriter ? op() : this.pending.push(op);
- // If onwriteend callback
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
- }, "File", "write", [this.fileName, text, this.position]);
};
-/**
- * Moves the file pointer to the location specified.
- *
- * If the offset is a negative number the position of the file
- * pointer is rewound. If the offset is greater than the file
- * size the position is set to the end of the file.
- *
- * @param offset is the location to move the file pointer to.
- */
FileWriter.prototype.seek = function(offset) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- if (!offset && offset !== 0) {
- return;
- }
-
- // See back from end of file.
- if (offset < 0) {
- this.position = Math.max(offset + this.length, 0);
- }
- // Offset is bigger than file size so set position
- // to the end of the file.
- else if (offset > this.length) {
- this.position = this.length;
- }
- // Offset is between 0 and file size so set the position
- // to start writing.
- else {
- this.position = offset;
- }
+ var that = this,
+ op = function () {
+ that.nativeWriter.seek(offset);
+ };
+ this.nativeWriter ? op() : this.pending.push(op);
};
-/**
- * Truncates the file to the size specified.
- *
- * @param size to chop the file at.
- */
FileWriter.prototype.truncate = function(size) {
- // Throw an exception if we are already writing a file
- if (this.readyState === FileWriter.WRITING) {
- throw new FileError(FileError.INVALID_STATE_ERR);
- }
-
- // WRITING state
- this.readyState = FileWriter.WRITING;
-
- var me = this;
-
- // If onwritestart callback
- if (typeof me.onwritestart === "function") {
- me.onwritestart(new ProgressEvent("writestart", {"target":this}));
- }
-
- // Write file
- exec(
- // Success callback
- function(r) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // DONE state
- me.readyState = FileWriter.DONE;
-
- // Update the length of the file
- me.length = r;
- me.position = Math.min(me.position, r);
-
- // If onwrite callback
- if (typeof me.onwrite === "function") {
- me.onwrite(new ProgressEvent("write", {"target":me}));
- }
-
- // If onwriteend callback
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
- },
- // Error callback
- function(e) {
- // If DONE (cancelled), then don't do anything
- if (me.readyState === FileWriter.DONE) {
- return;
- }
-
- // DONE state
- me.readyState = FileWriter.DONE;
-
- // Save error
- me.error = new FileError(e);
-
- // If onerror callback
- if (typeof me.onerror === "function") {
- me.onerror(new ProgressEvent("error", {"target":me}));
- }
-
- // If onwriteend callback
- if (typeof me.onwriteend === "function") {
- me.onwriteend(new ProgressEvent("writeend", {"target":me}));
- }
- }, "File", "truncate", [this.fileName, size]);
+ var that = this,
+ op = function () {
+ that.nativeWriter.truncate(size);
+ };
+ this.nativeWriter ? op() : this.pending.push(op);
};
module.exports = FileWriter;
@@ -3086,11 +2433,13 @@ define("cordova/plugin/InAppBrowser", function(require, exports, module) {
var exec = require('cordova/exec');
var channel = require('cordova/channel');
+var modulemapper = require('cordova/modulemapper');
function InAppBrowser() {
this.channels = {
'loadstart': channel.create('loadstart'),
'loadstop' : channel.create('loadstop'),
+ 'loaderror' : channel.create('loaderror'),
'exit' : channel.create('exit')
};
}
@@ -3113,6 +2462,26 @@ InAppBrowser.prototype = {
if (eventname in this.channels) {
this.channels[eventname].unsubscribe(f);
}
+ },
+
+ executeScript: function(injectDetails, cb) {
+ if (injectDetails.code) {
+ exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]);
+ } else if (injectDetails.file) {
+ exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]);
+ } else {
+ throw new Error('executeScript requires exactly one of code or file to be specified');
+ }
+ },
+
+ insertCSS: function(injectDetails, cb) {
+ if (injectDetails.code) {
+ exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]);
+ } else if (injectDetails.file) {
+ exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]);
+ } else {
+ throw new Error('insertCSS requires exactly one of code or file to be specified');
+ }
}
};
@@ -3121,12 +2490,17 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) {
var cb = function(eventname) {
iab._eventHandler(eventname);
};
- exec(cb, null, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
+
+ // Don't catch calls that write to existing frames (e.g. named iframes).
+ if (window.frames && window.frames[strWindowName]) {
+ var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
+ return origOpenFunc.apply(window, arguments);
+ }
+
+ exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
return iab;
};
-//Export the original open so it can be used if needed
-module.exports._orig = window.open;
});
@@ -3697,6 +3071,17 @@ module.exports = accelerometer;
});
+// file: lib/common/plugin/accelerometer/symbols.js
+define("cordova/plugin/accelerometer/symbols", function(require, exports, module) {
+
+
+var modulemapper = require('cordova/modulemapper');
+
+modulemapper.defaults('cordova/plugin/Acceleration', 'Acceleration');
+modulemapper.defaults('cordova/plugin/accelerometer', 'navigator.accelerometer');
+
+});
+
// file: lib/common/plugin/battery.js
define("cordova/plugin/battery", function(require, exports, module) {
@@ -3781,18 +3166,29 @@ module.exports = battery;
});
+// file: lib/common/plugin/battery/symbols.js
+define("cordova/plugin/battery/symbols", function(require, exports, module) {
+
+
+var modulemapper = require('cordova/modulemapper');
+
+modulemapper.defaults('cordova/plugin/battery', 'navigator.battery');
+
+});
+
// file: lib/blackberry10/plugin/blackberry10/InAppBrowser.js
define("cordova/plugin/blackberry10/InAppBrowser", function(require, exports, module) {
var cordova = require('cordova'),
- core = require('cordova/plugin/InAppBrowser'),
+ modulemapper = require('cordova/modulemapper'),
+ origOpen = modulemapper.getOriginalSymbol(window, 'open'),
browser = {
close: function () { } //dummy so we don't have to check for undefined
};
var navigate = {
"_blank": function (url, whitelisted) {
- return core._orig.apply(null, [url, "_blank"]);
+ return origOpen(url, "_blank");
},
"_self": function (url, whitelisted) {
@@ -3801,7 +3197,7 @@ var navigate = {
return window;
}
else {
- return core._orig.apply(null, [url, "_blank"]);
+ return origOpen(url, "_blank");
}
},
@@ -4205,441 +3601,220 @@ module.exports = {
});
-// file: lib/blackberry10/plugin/blackberry10/file.js
-define("cordova/plugin/blackberry10/file", function(require, exports, module) {
+// file: lib/blackberry10/plugin/blackberry10/fileTransfer.js
+define("cordova/plugin/blackberry10/fileTransfer", function(require, exports, module) {
-/*global WebKitBlobBuilder:false */
+/*global Blob:false */
var cordova = require('cordova'),
- FileError = require('cordova/plugin/FileError'),
- DirectoryEntry = require('cordova/plugin/DirectoryEntry'),
- FileEntry = require('cordova/plugin/FileEntry'),
- File = require('cordova/plugin/File'),
- FileSystem = require('cordova/plugin/FileSystem'),
- FileReader = require('cordova/plugin/FileReader'),
- nativeRequestFileSystem = window.webkitRequestFileSystem,
+ ProgressEvent = require('cordova/plugin/ProgressEvent'),
nativeResolveLocalFileSystemURI = function(uri, success, fail) {
if (uri.substring(0,11) !== "filesystem:") {
uri = "filesystem:" + uri;
}
window.webkitResolveLocalFileSystemURL(uri, success, fail);
},
- NativeFileReader = window.FileReader;
-
-window.FileReader = FileReader;
-window.File = File;
+ xhr;
-function getFileSystemName(nativeFs) {
- return (nativeFs.name.indexOf("Persistent") != -1) ? "persistent" : "temporary";
+function getParentPath(filePath) {
+ var pos = filePath.lastIndexOf('/');
+ return filePath.substring(0, pos + 1);
}
-function makeEntry(entry) {
- if (entry.isDirectory) {
- return new DirectoryEntry(entry.name, decodeURI(entry.toURL()).substring(11));
- }
- else {
- return new FileEntry(entry.name, decodeURI(entry.toURL()).substring(11));
- }
+function getFileName(filePath) {
+ var pos = filePath.lastIndexOf('/');
+ return filePath.substring(pos + 1);
}
-module.exports = {
- /* requestFileSystem */
- requestFileSystem: function(args, successCallback, errorCallback) {
- var type = args[0],
- size = args[1];
-
- nativeRequestFileSystem(type, size, function(nativeFs) {
- successCallback(new FileSystem(getFileSystemName(nativeFs), makeEntry(nativeFs.root)));
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* resolveLocalFileSystemURI */
- resolveLocalFileSystemURI: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- var code = error.code;
- switch (code) {
- case 5:
- code = FileError.NOT_FOUND_ERR;
- break;
-
- case 2:
- code = FileError.ENCODING_ERR;
- break;
- }
- errorCallback(code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* DirectoryReader */
- readEntries: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(dirEntry) {
- var reader = dirEntry.createReader();
- reader.readEntries(function(entries) {
- var retVal = [];
- for (var i = 0; i < entries.length; i++) {
- retVal.push(makeEntry(entries[i]));
- }
- successCallback(retVal);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* Entry */
- getMetadata: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- entry.getMetadata(function(metaData) {
- successCallback(metaData.modificationTime);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- moveTo: function(args, successCallback, errorCallback) {
- var srcUri = args[0],
- parentUri = args[1],
- name = args[2];
-
- nativeResolveLocalFileSystemURI(srcUri, function(source) {
- nativeResolveLocalFileSystemURI(parentUri, function(parent) {
- source.moveTo(parent, name, function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- copyTo: function(args, successCallback, errorCallback) {
- var srcUri = args[0],
- parentUri = args[1],
- name = args[2];
-
- nativeResolveLocalFileSystemURI(srcUri, function(source) {
- nativeResolveLocalFileSystemURI(parentUri, function(parent) {
- source.copyTo(parent, name, function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- remove: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- if (entry.fullPath === "/") {
- errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
- } else {
- entry.remove(
- function (success) {
- if (successCallback) {
- successCallback(success);
- }
- },
- function(error) {
- if (errorCallback) {
- errorCallback(error.code);
- }
- }
- );
- }
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- getParent: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- entry.getParent(function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* FileEntry */
- getFileMetadata: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- entry.file(function(file) {
- var retVal = new File(file.name, decodeURI(entry.toURL()), file.type, file.lastModifiedDate, file.size);
- successCallback(retVal);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* DirectoryEntry */
- getDirectory: function(args, successCallback, errorCallback) {
- var uri = args[0],
- path = args[1],
- options = args[2];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- entry.getDirectory(path, options, function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- if (error.code === FileError.INVALID_MODIFICATION_ERR) {
- if (options.create) {
- errorCallback(FileError.PATH_EXISTS_ERR);
- } else {
- errorCallback(FileError.ENCODING_ERR);
- }
- } else {
- errorCallback(error.code);
- }
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- removeRecursively: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- if (entry.fullPath === "/") {
- errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR);
- } else {
- entry.removeRecursively(
- function (success) {
- if (successCallback) {
- successCallback(success);
- }
- },
- function(error) {
- errorCallback(error.code);
- }
- );
- }
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- getFile: function(args, successCallback, errorCallback) {
- var uri = args[0],
- path = args[1],
- options = args[2];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- entry.getFile(path, options, function(entry) {
- successCallback(makeEntry(entry));
- }, function(error) {
- if (error.code === FileError.INVALID_MODIFICATION_ERR) {
- if (options.create) {
- errorCallback(FileError.PATH_EXISTS_ERR);
- } else {
- errorCallback(FileError.NOT_FOUND_ERR);
- }
- } else {
- errorCallback(error.code);
- }
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
-
- /* FileReader */
- readAsText: function(args, successCallback, errorCallback) {
- var uri = args[0],
- encoding = args[1];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- var onLoadEnd = function(evt) {
- if (!evt.target.error) {
- successCallback(evt.target.result);
- }
- },
- onError = function(evt) {
- errorCallback(evt.target.error.code);
- };
+function cleanUpPath(filePath) {
+ var pos = filePath.lastIndexOf('/');
+ return filePath.substring(0, pos) + filePath.substring(pos + 1, filePath.length);
+}
- var reader = new NativeFileReader();
+function checkURL(url) {
+ return url.indexOf(' ') === -1 ? true : false;
+}
- reader.onloadend = onLoadEnd;
- reader.onerror = onError;
- entry.file(function(file) {
- reader.readAsText(file, encoding);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
+module.exports = {
+ abort: function () {
return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
},
- readAsDataURL: function(args, successCallback, errorCallback) {
- var uri = args[0];
-
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- var onLoadEnd = function(evt) {
- if (!evt.target.error) {
- successCallback(evt.target.result);
- }
- },
- onError = function(evt) {
- errorCallback(evt.target.error.code);
- };
+ upload: function(args, win, fail) {
+ var filePath = args[0],
+ server = args[1],
+ fileKey = args[2],
+ fileName = args[3],
+ mimeType = args[4],
+ params = args[5],
+ /*trustAllHosts = args[6],*/
+ chunkedMode = args[7],
+ headers = args[8];
- var reader = new NativeFileReader();
+ if (!checkURL(server)) {
+ fail(new window.FileTransferError(window.FileTransferError.INVALID_URL_ERR));
+ }
- reader.onloadend = onLoadEnd;
- reader.onerror = onError;
+ nativeResolveLocalFileSystemURI(filePath, function(entry) {
entry.file(function(file) {
- reader.readAsDataURL(file);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
- },
+ function uploadFile(blobFile) {
+ var fd = new FormData();
- /* FileWriter */
- write: function(args, successCallback, errorCallback) {
- var uri = args[0],
- text = args[1],
- position = args[2];
+ fd.append(fileKey, blobFile, fileName);
+ for (var prop in params) {
+ if(params.hasOwnProperty(prop)) {
+ fd.append(prop, params[prop]);
+ }
+ }
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- var onWriteEnd = function(evt) {
- if(!evt.target.error) {
- successCallback(evt.target.position - position);
- } else {
- errorCallback(evt.target.error.code);
+ xhr = new XMLHttpRequest();
+ xhr.open("POST", server);
+ xhr.onload = function(evt) {
+ if (xhr.status == 200) {
+ var result = new window.FileUploadResult();
+ result.bytesSent = file.size;
+ result.responseCode = xhr.status;
+ result.response = xhr.response;
+ win(result);
+ } else if (xhr.status == 404) {
+ fail(new window.FileTransferError(window.FileTransferError.INVALID_URL_ERR, server, filePath, xhr.status));
+ } else {
+ fail(new window.FileTransferError(window.FileTransferError.CONNECTION_ERR, server, filePath, xhr.status));
+ }
+ };
+ xhr.ontimeout = function(evt) {
+ fail(new window.FileTransferError(window.FileTransferError.CONNECTION_ERR, server, filePath, xhr.status));
+ };
+ xhr.onerror = function () {
+ fail(new window.FileTransferError(window.FileTransferError.CONNECTION_ERR, server, filePath, this.status));
+ };
+ xhr.onprogress = function (evt) {
+ win(evt);
+ };
+
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ xhr.setRequestHeader(header, headers[header]);
+ }
}
- },
- onError = function(evt) {
- errorCallback(evt.target.error.code);
- };
- entry.createWriter(function(writer) {
- writer.onwriteend = onWriteEnd;
- writer.onerror = onError;
+ xhr.send(fd);
+ }
- writer.seek(position);
- writer.write(new Blob([text], {type: "text/plain"}));
+ var bytesPerChunk;
+ if (chunkedMode === true) {
+ bytesPerChunk = 1024 * 1024; // 1MB chunk sizes.
+ } else {
+ bytesPerChunk = file.size;
+ }
+ var start = 0;
+ var end = bytesPerChunk;
+ while (start < file.size) {
+ var chunk = file.slice(start, end, mimeType);
+ uploadFile(chunk);
+ start = end;
+ end = start + bytesPerChunk;
+ }
}, function(error) {
- errorCallback(error.code);
+ fail(new window.FileTransferError(window.FileTransferError.FILE_NOT_FOUND_ERR));
});
}, function(error) {
- errorCallback(error.code);
+ fail(new window.FileTransferError(window.FileTransferError.FILE_NOT_FOUND_ERR));
});
+
return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
},
- truncate: function(args, successCallback, errorCallback) {
- var uri = args[0],
- size = args[1];
+ download: function (args, win, fail) {
+ var source = args[0],
+ target = cleanUpPath(args[1]),
+ fileWriter;
+
+ if (!checkURL(source)) {
+ fail(new window.FileTransferError(window.FileTransferError.INVALID_URL_ERR));
+ }
- nativeResolveLocalFileSystemURI(uri, function(entry) {
- var onWriteEnd = function(evt) {
- if(!evt.target.error) {
- successCallback(evt.target.length);
+ xhr = new XMLHttpRequest();
+
+ function writeFile(entry) {
+ entry.createWriter(function (writer) {
+ fileWriter = writer;
+ fileWriter.onwriteend = function (evt) {
+ if (!evt.target.error) {
+ win(new window.FileEntry(entry.name, entry.toURL()));
} else {
- errorCallback(evt.target.error.code);
+ fail(evt.target.error);
}
- },
- onError = function(evt) {
- errorCallback(evt.target.error.code);
- };
+ };
+ fileWriter.onerror = function (evt) {
+ fail(evt.target.error);
+ };
+ fileWriter.write(new Blob([xhr.response]));
+ }, function (error) {
+ fail(error);
+ });
+ }
- entry.createWriter(function(writer) {
- writer.onwriteend = onWriteEnd;
- writer.onerror = onError;
+ xhr.onerror = function (e) {
+ fail(new window.FileTransferError(window.FileTransferError.CONNECTION_ERR, source, target, xhr.status));
+ };
- writer.truncate(size);
- }, function(error) {
- errorCallback(error.code);
- });
- }, function(error) {
- errorCallback(error.code);
- });
+ xhr.onload = function () {
+ if (xhr.readyState === xhr.DONE) {
+ if (xhr.status === 200 && xhr.response) {
+ nativeResolveLocalFileSystemURI(getParentPath(target), function (dir) {
+ dir.getFile(getFileName(target), {create: true}, writeFile, function (error) {
+ fail(new window.FileTransferError(window.FileTransferError.FILE_NOT_FOUND_ERR));
+ });
+ }, function (error) {
+ fail(new window.FileTransferError(window.FileTransferError.FILE_NOT_FOUND_ERR));
+ });
+ } else if (xhr.status === 404) {
+ fail(new window.FileTransferError(window.FileTransferError.INVALID_URL_ERR, source, target, xhr.status));
+ } else {
+ fail(new window.FileTransferError(window.FileTransferError.CONNECTION_ERR, source, target, xhr.status));
+ }
+ }
+ };
+ xhr.onprogress = function (evt) {
+ win(evt);
+ };
+
+ xhr.responseType = "blob";
+ xhr.open("GET", source, true);
+ xhr.send();
return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
}
};
});
-// file: lib/blackberry10/plugin/blackberry10/fileTransfer.js
-define("cordova/plugin/blackberry10/fileTransfer", function(require, exports, module) {
+// file: lib/blackberry10/plugin/blackberry10/fileUtils.js
+define("cordova/plugin/blackberry10/fileUtils", function(require, exports, module) {
-var cordova = require('cordova');
+function convertPath(url) {
+ return decodeURI(url).substring(11).replace(/\/$/, '');
+}
module.exports = {
- download: function (args, win, fail) {
- var source = args[0],
- target = args[1];
- blackberry.io.filetransfer.download(source, target, win, fail);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
+ createEntry: function (entry) {
+ var cordovaEntry;
+ if (entry.isFile) {
+ cordovaEntry = new window.FileEntry(entry.name, convertPath(entry.toURL()));
+ } else {
+ cordovaEntry = new window.DirectoryEntry(entry.name, convertPath(entry.toURL()));
+ }
+ cordovaEntry.nativeEntry = entry;
+ return cordovaEntry;
},
- upload: function (args, win, fail) {
- var path = args[0],
- server = args[1],
- options = {
- fileKey: args[2],
- fileName: args[3],
- mimeType: args[4],
- params: args[5],
- chunkedMode: args[6]
- };
+ getEntryForURI: function (uri, success, fail) {
+ //TODO: account for local vs file system
+ window.resolveLocalFileSystemURI(uri, success, fail);
+ },
- blackberry.io.filetransfer.upload(path, server, win, fail, options);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "async"};
+ getFileSystemName: function (fs) {
+ return (fs.name.indexOf('Persistent') != -1) ? 'persistent' : 'temporary';
}
};
@@ -4877,9 +4052,6 @@ module.exports = {
});
},
clobbers: {
- requestFileSystem: {
- path: "cordova/plugin/blackberry10/requestFileSystem"
- },
navigator: {
children: {
notification: {
@@ -4890,6 +4062,9 @@ module.exports = {
}
}
}
+ },
+ File: {
+ path: 'cordova/plugin/File'
}
},
merges: {
@@ -4947,7 +4122,7 @@ module.exports = {
}
}
if (count === 0) {
- callback();
+ callback();
}
},
@@ -4974,30 +4149,6 @@ module.exports = {
};
request.send(null);
}
-}
-
-});
-
-// file: lib/blackberry10/plugin/blackberry10/requestFileSystem.js
-define("cordova/plugin/blackberry10/requestFileSystem", function(require, exports, module) {
-
-function getFileSystemName(fs) {
- return (fs.name.indexOf("Persistent") != -1) ? "persistent" : "temporary";
-}
-
-function makeEntry(entry) {
- if (entry.isDirectory) {
- return new DirectoryEntry(entry.name, decodeURI(entry.toURL()).substring(11));
- }
- else {
- return new FileEntry(entry.name, decodeURI(entry.toURL()).substring(11));
- }
-}
-
-module.exports = function (type, size, success, fail) {
- window.webkitRequestFileSystem(type, size, function (fs) {
- success((new FileSystem
<TRUNCATED>