Cordova code ported from browser implementation.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Fri, 30 Oct 2015 08:13:30 +0000 (09:13 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 2 Nov 2015 14:51:48 +0000 (15:51 +0100)
The 'src/lib' folder provides the cordova implementation for Tizen.
'src/lib/plugins' contains common code of plugins, downloaded from cordova repositories, was not altered.
'src/lib/cordova-5.1.1.js' was adapted from cordova.js file generated for browser.
'src/lib/cordova_plugins.js' contains list of files for plugins (currently only cordova-plugin-file).

Tizen-specific code follows plugin-style implementation of cordova (see 'src/file/cordova_file_api.js').

Change-Id: I6ade657781acd8e9595f5179364ceb940088458e
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
29 files changed:
src/cordova/cordova_api.js
src/device/cordova_device_api.js
src/dialog/cordova_dialog_api.js
src/file/cordova_file_api.js
src/filetransfer/cordova_filetransfer_api.js
src/lib/cordova-5.1.1.js
src/lib/cordova_plugins.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/DirectoryEntry.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/DirectoryReader.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/Entry.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/File.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileEntry.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileError.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileReader.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileSystem.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileUploadOptions.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileUploadResult.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/FileWriter.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/Flags.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/LocalFileSystem.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/Metadata.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/ProgressEvent.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/fileSystemPaths.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/fileSystems-roots.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/fileSystems.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/requestFileSystem.js [new file with mode: 0644]
src/lib/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js [new file with mode: 0644]
src/media/cordova_media_api.js
src/networkinformation/cordova_networkinformation_api.js

index ac0a716..e3c42e3 100755 (executable)
  *    limitations under the License.
  */
 
-var _global = window || global || {};
-var _document = document || {};
-
-function UUIDcreatePart(length) {
-    var uuidpart = "";
-    for (var i=0; i<length; i++) {
-        var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
-        if (uuidchar.length == 1) {
-            uuidchar = "0" + uuidchar;
-        }
-        uuidpart += uuidchar;
-    }
-    return uuidpart;
-}
-
-var utils = {
-   createUUID : function() {
-       return UUIDcreatePart(4) + '-' +
-           UUIDcreatePart(2) + '-' +
-           UUIDcreatePart(2) + '-' +
-           UUIDcreatePart(2) + '-' +
-           UUIDcreatePart(6);
-   }
-}
-
-function Emitter() {
-  var eventTarget = _document.createDocumentFragment();
-
-  function delegate(method) {
-    this[method] = eventTarget[method].bind(eventTarget);
-  }
-
-  [
-    'addEventListener',
-    'dispatchEvent',
-    'removeEventListener'
-  ].forEach(delegate, this);
-}
-
-function createEvent(n, obj, fun) {
-  var e = new Event(n);
-  e.obj = obj;
-  e.fun = fun;
-  return e;
-}
-
-function wrapFunction(obj, fun) {
-  var old = obj[fun];
-  obj[fun] = function() {
-    old.apply(obj, arguments);
-    cordova._broker.dispatchEvent(createEvent(arguments[0], obj, fun));
-  };
-}
-
-wrapFunction(_global, 'addEventListener');
-wrapFunction(_global, 'removeEventListener');
-wrapFunction(_document, 'addEventListener');
-wrapFunction(_document, 'removeEventListener');
-
-var cordova = {
-  version: '5.1.1',
-  _broker: new Emitter()
-};
-
-_global.cordova = cordova;
-_global.utils = utils;
-
 console.log('Loaded cordova API');
index 371bde6..06e5d11 100755 (executable)
@@ -33,17 +33,7 @@ Object.defineProperty(_global, 'device', {
   value: device
 });
 
+console.log('Loaded cordova.device API');
 
-// fire the listener only once
-// TODO: find a better way of launching the listener, allowing more 'deviceready'
-//       listeners to be registered
-var listener = function (event) {
-  if ('addEventListener' === event.fun) {
-    cordova._broker.removeEventListener('deviceready', listener);
-    event.obj.dispatchEvent(new Event('deviceready'));
-  }
+exports = function(require) {
 };
-
-cordova._broker.addEventListener('deviceready', listener);
-
-console.log('Loaded cordova.device API');
index 6491303..37dbadf 100755 (executable)
@@ -339,3 +339,6 @@ Object.defineProperty(_navigator, 'notification', {
 });
 
 console.log('Loaded cordova.dialog API');
+
+exports = function(require) {
+};
index 3f9930e..bd704f6 100755 (executable)
  *    limitations under the License.
  */
 
-var _global = window || global || {};
-
-var Metadata = function(metadata) {
-  if (typeof metadata == "object") {
-    this.modificationTime = new Date(metadata.modificationTime);
-    this.size = metadata.size || 0;
-  } else if (typeof metadata == "undefined") {
-    this.modificationTime = null;
-    this.size = 0;
-  }
+// TODO: remove when added to public cordova repository -> begin
+var plugin_name = 'cordova-plugin-file.tizen.File';
+
+cordova.define(plugin_name, function(require, exports, module) {
+// TODO: remove -> end
+
+var pathsPrefix = {
+  // TODO: add other directories
+  // Read-only directory where the application is installed.
+  applicationDirectory: 'wgt-package/'
+};
+
+exports.requestAllPaths = function(successCallback) {
+  successCallback(pathsPrefix);
 };
 
-_global.Metadata = Metadata;
+require("cordova/exec/proxy").add("File", exports);
 
 console.log('Loaded cordova.file API');
+
+// TODO: remove when added to public cordova repository -> begin
+});
+
+exports = function(require) {
+  // this plugin is not loaded via cordova_plugins.js, we need to manually add
+  // it to module mapper
+  var mm = require('cordova/modulemapper');
+  mm.runs(plugin_name);
+};
+//TODO: remove -> end
index ae5df5a..662d215 100755 (executable)
@@ -321,3 +321,6 @@ _global.FileTransferError = FileTransferError;
 _global.FileUploadOptions = FileUploadOptions;
 
 console.log('Loaded FileTransfer API');
+
+exports = function(require) {
+};
index ea94010..a63ff4e 100644 (file)
 /*
- *
- * 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.
- *
-*/
-
-(function() {
-  // TODO: load only plugins from cordova_plugins.js file
-
-  // load all plugins
-  for (var plugin in tizen.cordova) {
-    if (tizen.cordova.hasOwnProperty(plugin)) {
-      tizen.cordova[plugin];
-    }
-  }
+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.
+*/
+
+// adapted from cordova.js for browser
+
+;(function() {
+var PLATFORM_VERSION_BUILD_LABEL = '5.1.1';
+//file: src/scripts/require.js
+
+/*jshint -W079 */
+/*jshint -W020 */
+
+var require,
+ define;
+
+(function () {
+ var modules = {},
+ // Stack of moduleIds currently being built.
+     requireStack = [],
+ // Map of module ID -> index into requireStack of modules currently being built.
+     inProgressModules = {},
+     SEPARATOR = ".";
+
+
+
+ function build(module) {
+     var factory = module.factory,
+         localRequire = function (id) {
+             var resultantId = id;
+             //Its a relative path, so lop off the last portion and add the id (minus "./")
+             if (id.charAt(0) === ".") {
+                 resultantId = module.id.slice(0, module.id.lastIndexOf(SEPARATOR)) + SEPARATOR + id.slice(2);
+             }
+             return require(resultantId);
+         };
+     module.exports = {};
+     delete module.factory;
+     factory(localRequire, module.exports, module);
+     return module.exports;
+ }
+
+ require = function (id) {
+     if (!modules[id]) {
+         throw "module " + id + " not found";
+     } else if (id in inProgressModules) {
+         var cycle = requireStack.slice(inProgressModules[id]).join('->') + '->' + id;
+         throw "Cycle in require graph: " + cycle;
+     }
+     if (modules[id].factory) {
+         try {
+             inProgressModules[id] = requireStack.length;
+             requireStack.push(id);
+             return build(modules[id]);
+         } finally {
+             delete inProgressModules[id];
+             requireStack.pop();
+         }
+     }
+     return modules[id].exports;
+ };
+
+ define = function (id, factory) {
+     if (modules[id]) {
+         throw "module " + id + " already defined";
+     }
+
+     modules[id] = {
+         id: id,
+         factory: factory
+     };
+ };
+
+ define.remove = function (id) {
+     delete modules[id];
+ };
+
+ define.moduleMap = modules;
+})();
+
+//Export for use in node
+if (typeof module === "object" && typeof require === "function") {
+ module.exports.require = require;
+ module.exports.define = define;
+}
+
+//file: src/cordova.js
+define("cordova", function(require, exports, module) {
+
+if(window.cordova){
+ throw new Error("cordova already defined");
+}
+
+
+var channel = require('cordova/channel');
+var platform = require('cordova/platform');
+
+
+/**
+* Intercept calls to addEventListener + removeEventListener and handle deviceready,
+* resume, and pause events.
+*/
+var m_document_addEventListener = document.addEventListener;
+var m_document_removeEventListener = document.removeEventListener;
+var m_window_addEventListener = window.addEventListener;
+var m_window_removeEventListener = window.removeEventListener;
+
+/**
+* Houses custom event handlers to intercept on document + window event listeners.
+*/
+var documentEventHandlers = {},
+ windowEventHandlers = {};
+
+document.addEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ if (typeof documentEventHandlers[e] != 'undefined') {
+     documentEventHandlers[e].subscribe(handler);
+ } else {
+     m_document_addEventListener.call(document, evt, handler, capture);
+ }
+};
+
+window.addEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ if (typeof windowEventHandlers[e] != 'undefined') {
+     windowEventHandlers[e].subscribe(handler);
+ } else {
+     m_window_addEventListener.call(window, evt, handler, capture);
+ }
+};
+
+document.removeEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ // If unsubscribing from an event that is handled by a plugin
+ if (typeof documentEventHandlers[e] != "undefined") {
+     documentEventHandlers[e].unsubscribe(handler);
+ } else {
+     m_document_removeEventListener.call(document, evt, handler, capture);
+ }
+};
+
+window.removeEventListener = function(evt, handler, capture) {
+ var e = evt.toLowerCase();
+ // If unsubscribing from an event that is handled by a plugin
+ if (typeof windowEventHandlers[e] != "undefined") {
+     windowEventHandlers[e].unsubscribe(handler);
+ } else {
+     m_window_removeEventListener.call(window, evt, handler, capture);
+ }
+};
+
+function createEvent(type, data) {
+ var event = document.createEvent('Events');
+ event.initEvent(type, false, false);
+ if (data) {
+     for (var i in data) {
+         if (data.hasOwnProperty(i)) {
+             event[i] = data[i];
+         }
+     }
+ }
+ return event;
+}
+
+
+var cordova = {
+ define:define,
+ require:require,
+ version:PLATFORM_VERSION_BUILD_LABEL,
+ platformVersion:PLATFORM_VERSION_BUILD_LABEL,
+ platformId:platform.id,
+ /**
+  * Methods to add/remove your own addEventListener hijacking on document + window.
+  */
+ addWindowEventHandler:function(event) {
+     return (windowEventHandlers[event] = channel.create(event));
+ },
+ addStickyDocumentEventHandler:function(event) {
+     return (documentEventHandlers[event] = channel.createSticky(event));
+ },
+ addDocumentEventHandler:function(event) {
+     return (documentEventHandlers[event] = channel.create(event));
+ },
+ removeWindowEventHandler:function(event) {
+     delete windowEventHandlers[event];
+ },
+ removeDocumentEventHandler:function(event) {
+     delete documentEventHandlers[event];
+ },
+ /**
+  * Retrieve original event handlers that were replaced by Cordova
+  *
+  * @return object
+  */
+ getOriginalHandlers: function() {
+     return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
+     'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
+ },
+ /**
+  * Method to fire event from native code
+  * bNoDetach is required for events which cause an exception which needs to be caught in native code
+  */
+ fireDocumentEvent: function(type, data, bNoDetach) {
+     var evt = createEvent(type, data);
+     if (typeof documentEventHandlers[type] != 'undefined') {
+         if( bNoDetach ) {
+             documentEventHandlers[type].fire(evt);
+         }
+         else {
+             setTimeout(function() {
+                 // Fire deviceready on listeners that were registered before cordova.js was loaded.
+                 if (type == 'deviceready') {
+                     document.dispatchEvent(evt);
+                 }
+                 documentEventHandlers[type].fire(evt);
+             }, 0);
+         }
+     } else {
+         document.dispatchEvent(evt);
+     }
+ },
+ fireWindowEvent: function(type, data) {
+     var evt = createEvent(type,data);
+     if (typeof windowEventHandlers[type] != 'undefined') {
+         setTimeout(function() {
+             windowEventHandlers[type].fire(evt);
+         }, 0);
+     } else {
+         window.dispatchEvent(evt);
+     }
+ },
+
+ /**
+  * Plugin callback mechanism.
+  */
+ // Randomize the starting callbackId to avoid collisions after refreshing or navigating.
+ // This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
+ callbackId: Math.floor(Math.random() * 2000000000),
+ callbacks:  {},
+ callbackStatus: {
+     NO_RESULT: 0,
+     OK: 1,
+     CLASS_NOT_FOUND_EXCEPTION: 2,
+     ILLEGAL_ACCESS_EXCEPTION: 3,
+     INSTANTIATION_EXCEPTION: 4,
+     MALFORMED_URL_EXCEPTION: 5,
+     IO_EXCEPTION: 6,
+     INVALID_ACTION: 7,
+     JSON_EXCEPTION: 8,
+     ERROR: 9
+ },
+
+ /**
+  * Called by native code when returning successful result from an action.
+  */
+ callbackSuccess: function(callbackId, args) {
+     cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
+ },
+
+ /**
+  * Called by native code when returning error result from an action.
+  */
+ callbackError: function(callbackId, args) {
+     // TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
+     // Derive success from status.
+     cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
+ },
+
+ /**
+  * Called by native code when returning the result from an action.
+  */
+ callbackFromNative: function(callbackId, isSuccess, status, args, keepCallback) {
+     try {
+         var callback = cordova.callbacks[callbackId];
+         if (callback) {
+             if (isSuccess && status == cordova.callbackStatus.OK) {
+                 callback.success && callback.success.apply(null, args);
+             } else if (!isSuccess) {
+                 callback.fail && callback.fail.apply(null, args);
+             }
+             /*
+             else
+                 Note, this case is intentionally not caught.
+                 this can happen if isSuccess is true, but callbackStatus is NO_RESULT
+                 which is used to remove a callback from the list without calling the callbacks
+                 typically keepCallback is false in this case
+             */
+             // Clear callback if not expecting any more results
+             if (!keepCallback) {
+                 delete cordova.callbacks[callbackId];
+             }
+         }
+     }
+     catch (err) {
+         var msg = "Error in " + (isSuccess ? "Success" : "Error") + " callbackId: " + callbackId + " : " + err;
+         console && console.log && console.log(msg);
+         cordova.fireWindowEvent("cordovacallbackerror", { 'message': msg });
+         throw err;
+     }
+ },
+ addConstructor: function(func) {
+     channel.onCordovaReady.subscribe(function() {
+         try {
+             func();
+         } catch(e) {
+             console.log("Failed to run constructor: " + e);
+         }
+     });
+ }
+};
+
+
+module.exports = cordova;
+
+});
+
+//file: src/common/argscheck.js
+define("cordova/argscheck", function(require, exports, module) {
+
+var utils = require('cordova/utils');
+
+var moduleExports = module.exports;
+
+var typeMap = {
+ 'A': 'Array',
+ 'D': 'Date',
+ 'N': 'Number',
+ 'S': 'String',
+ 'F': 'Function',
+ 'O': 'Object'
+};
+
+function extractParamName(callee, argIndex) {
+ return (/.*?\((.*?)\)/).exec(callee)[1].split(', ')[argIndex];
+}
+
+function checkArgs(spec, functionName, args, opt_callee) {
+ if (!moduleExports.enableChecks) {
+     return;
+ }
+ var errMsg = null;
+ var typeName;
+ for (var i = 0; i < spec.length; ++i) {
+     var c = spec.charAt(i),
+         cUpper = c.toUpperCase(),
+         arg = args[i];
+     // Asterix means allow anything.
+     if (c == '*') {
+         continue;
+     }
+     typeName = utils.typeName(arg);
+     if ((arg === null || arg === undefined) && c == cUpper) {
+         continue;
+     }
+     if (typeName != typeMap[cUpper]) {
+         errMsg = 'Expected ' + typeMap[cUpper];
+         break;
+     }
+ }
+ if (errMsg) {
+     errMsg += ', but got ' + typeName + '.';
+     errMsg = 'Wrong type for parameter "' + extractParamName(opt_callee || args.callee, i) + '" of ' + functionName + ': ' + errMsg;
+     // Don't log when running unit tests.
+     if (typeof jasmine == 'undefined') {
+         console.error(errMsg);
+     }
+     throw TypeError(errMsg);
+ }
+}
+
+function getValue(value, defaultValue) {
+ return value === undefined ? defaultValue : value;
+}
+
+moduleExports.checkArgs = checkArgs;
+moduleExports.getValue = getValue;
+moduleExports.enableChecks = true;
+
+
+});
+
+//file: src/common/base64.js
+define("cordova/base64", function(require, exports, module) {
+
+var base64 = exports;
+
+base64.fromArrayBuffer = function(arrayBuffer) {
+ var array = new Uint8Array(arrayBuffer);
+ return uint8ToBase64(array);
+};
+
+base64.toArrayBuffer = function(str) {
+ var decodedStr = typeof atob != 'undefined' ? atob(str) : new Buffer(str,'base64').toString('binary');
+ var arrayBuffer = new ArrayBuffer(decodedStr.length);
+ var array = new Uint8Array(arrayBuffer);
+ for (var i=0, len=decodedStr.length; i < len; i++) {
+     array[i] = decodedStr.charCodeAt(i);
+ }
+ return arrayBuffer;
+};
+
+//------------------------------------------------------------------------------
+
+/* This code is based on the performance tests at http://jsperf.com/b64tests
+* This 12-bit-at-a-time algorithm was the best performing version on all
+* platforms tested.
+*/
+
+var b64_6bit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+var b64_12bit;
+
+var b64_12bitTable = function() {
+ b64_12bit = [];
+ for (var i=0; i<64; i++) {
+     for (var j=0; j<64; j++) {
+         b64_12bit[i*64+j] = b64_6bit[i] + b64_6bit[j];
+     }
+ }
+ b64_12bitTable = function() { return b64_12bit; };
+ return b64_12bit;
+};
+
+function uint8ToBase64(rawData) {
+ var numBytes = rawData.byteLength;
+ var output="";
+ var segment;
+ var table = b64_12bitTable();
+ for (var i=0;i<numBytes-2;i+=3) {
+     segment = (rawData[i] << 16) + (rawData[i+1] << 8) + rawData[i+2];
+     output += table[segment >> 12];
+     output += table[segment & 0xfff];
+ }
+ if (numBytes - i == 2) {
+     segment = (rawData[i] << 16) + (rawData[i+1] << 8);
+     output += table[segment >> 12];
+     output += b64_6bit[(segment & 0xfff) >> 6];
+     output += '=';
+ } else if (numBytes - i == 1) {
+     segment = (rawData[i] << 16);
+     output += table[segment >> 12];
+     output += '==';
+ }
+ return output;
+}
+
+});
+
+//file: src/common/builder.js
+define("cordova/builder", function(require, exports, module) {
+
+var utils = require('cordova/utils');
+
+function each(objects, func, context) {
+ for (var prop in objects) {
+     if (objects.hasOwnProperty(prop)) {
+         func.apply(context, [objects[prop], prop]);
+     }
+ }
+}
+
+function clobber(obj, key, value) {
+ exports.replaceHookForTesting(obj, key);
+ var needsProperty = false;
+ try {
+     obj[key] = value;
+ } catch (e) {
+     needsProperty = true;
+ }
+ // Getters can only be overridden by getters.
+ if (needsProperty || obj[key] !== value) {
+     utils.defineGetter(obj, key, function() {
+         return value;
+     });
+ }
+}
+
+function assignOrWrapInDeprecateGetter(obj, key, value, message) {
+ if (message) {
+     utils.defineGetter(obj, key, function() {
+         console.log(message);
+         delete obj[key];
+         clobber(obj, key, value);
+         return value;
+     });
+ } else {
+     clobber(obj, key, value);
+ }
+}
+
+function include(parent, objects, clobber, merge) {
+ each(objects, function (obj, key) {
+     try {
+         var result = obj.path ? require(obj.path) : {};
+
+         if (clobber) {
+             // Clobber if it doesn't exist.
+             if (typeof parent[key] === 'undefined') {
+                 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
+             } else if (typeof obj.path !== 'undefined') {
+                 // If merging, merge properties onto parent, otherwise, clobber.
+                 if (merge) {
+                     recursiveMerge(parent[key], result);
+                 } else {
+                     assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
+                 }
+             }
+             result = parent[key];
+         } else {
+             // Overwrite if not currently defined.
+             if (typeof parent[key] == 'undefined') {
+                 assignOrWrapInDeprecateGetter(parent, key, result, obj.deprecated);
+             } else {
+                 // Set result to what already exists, so we can build children into it if they exist.
+                 result = parent[key];
+             }
+         }
+
+         if (obj.children) {
+             include(result, obj.children, clobber, merge);
+         }
+     } catch(e) {
+         utils.alert('Exception building Cordova JS globals: ' + e + ' for key "' + key + '"');
+     }
+ });
+}
+
+/**
+* Merge properties from one object onto another recursively.  Properties from
+* the src object will overwrite existing target property.
+*
+* @param target Object to merge properties into.
+* @param src Object to merge properties from.
+*/
+function recursiveMerge(target, src) {
+ for (var prop in src) {
+     if (src.hasOwnProperty(prop)) {
+         if (target.prototype && target.prototype.constructor === target) {
+             // If the target object is a constructor override off prototype.
+             clobber(target.prototype, prop, src[prop]);
+         } else {
+             if (typeof src[prop] === 'object' && typeof target[prop] === 'object') {
+                 recursiveMerge(target[prop], src[prop]);
+             } else {
+                 clobber(target, prop, src[prop]);
+             }
+         }
+     }
+ }
+}
+
+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() {};
+
+});
+
+//file: src/common/channel.js
+define("cordova/channel", function(require, exports, module) {
+
+var utils = require('cordova/utils'),
+ nextGuid = 1;
+
+/**
+* Custom pub-sub "channel" that can have functions subscribed to it
+* This object is used to define and control firing of events for
+* cordova initialization, as well as for custom events thereafter.
+*
+* The order of events during page load and Cordova startup is as follows:
+*
+* onDOMContentLoaded*         Internal event that is received when the web page is loaded and parsed.
+* onNativeReady*              Internal event that indicates the Cordova native side is ready.
+* onCordovaReady*             Internal event fired when all Cordova JavaScript objects have been created.
+* onDeviceReady*              User event fired to indicate that Cordova is ready
+* onResume                    User event fired to indicate a start/resume lifecycle event
+* onPause                     User event fired to indicate a pause lifecycle event
+*
+* The events marked with an * are sticky. Once they have fired, they will stay in the fired state.
+* All listeners that subscribe after the event is fired will be executed right away.
+*
+* The only Cordova events that user code should register for are:
+*      deviceready           Cordova native code is initialized and Cordova APIs can be called from JavaScript
+*      pause                 App has moved to background
+*      resume                App has returned to foreground
+*
+* Listeners can be registered as:
+*      document.addEventListener("deviceready", myDeviceReadyListener, false);
+*      document.addEventListener("resume", myResumeListener, false);
+*      document.addEventListener("pause", myPauseListener, false);
+*
+* The DOM lifecycle events should be used for saving and restoring state
+*      window.onload
+*      window.onunload
+*
+*/
+
+/**
+* Channel
+* @constructor
+* @param type  String the channel name
+*/
+var Channel = function(type, sticky) {
+ this.type = type;
+ // Map of guid -> function.
+ this.handlers = {};
+ // 0 = Non-sticky, 1 = Sticky non-fired, 2 = Sticky fired.
+ this.state = sticky ? 1 : 0;
+ // Used in sticky mode to remember args passed to fire().
+ this.fireArgs = null;
+ // Used by onHasSubscribersChange to know if there are any listeners.
+ this.numHandlers = 0;
+ // Function that is called when the first listener is subscribed, or when
+ // the last listener is unsubscribed.
+ this.onHasSubscribersChange = null;
+},
+ channel = {
+     /**
+      * Calls the provided function only after all of the channels specified
+      * have been fired. All channels must be sticky channels.
+      */
+     join: function(h, c) {
+         var len = c.length,
+             i = len,
+             f = function() {
+                 if (!(--i)) h();
+             };
+         for (var j=0; j<len; j++) {
+             if (c[j].state === 0) {
+                 throw Error('Can only use join with sticky channels.');
+             }
+             c[j].subscribe(f);
+         }
+         if (!len) h();
+     },
+     create: function(type) {
+         return channel[type] = new Channel(type, false);
+     },
+     createSticky: function(type) {
+         return channel[type] = new Channel(type, true);
+     },
+
+     /**
+      * cordova Channels that must fire before "deviceready" is fired.
+      */
+     deviceReadyChannelsArray: [],
+     deviceReadyChannelsMap: {},
+
+     /**
+      * Indicate that a feature needs to be initialized before it is ready to be used.
+      * This holds up Cordova's "deviceready" event until the feature has been initialized
+      * and Cordova.initComplete(feature) is called.
+      *
+      * @param feature {String}     The unique feature name
+      */
+     waitForInitialization: function(feature) {
+         if (feature) {
+             var c = channel[feature] || this.createSticky(feature);
+             this.deviceReadyChannelsMap[feature] = c;
+             this.deviceReadyChannelsArray.push(c);
+         }
+     },
+
+     /**
+      * Indicate that initialization code has completed and the feature is ready to be used.
+      *
+      * @param feature {String}     The unique feature name
+      */
+     initializationComplete: function(feature) {
+         var c = this.deviceReadyChannelsMap[feature];
+         if (c) {
+             c.fire();
+         }
+     }
+ };
+
+function forceFunction(f) {
+ if (typeof f != 'function') throw "Function required as first argument!";
+}
+
+/**
+* Subscribes the given function to the channel. Any time that
+* Channel.fire is called so too will the function.
+* Optionally specify an execution context for the function
+* and a guid that can be used to stop subscribing to the channel.
+* Returns the guid.
+*/
+Channel.prototype.subscribe = function(f, c) {
+ // need a function to call
+ forceFunction(f);
+ if (this.state == 2) {
+     f.apply(c || this, this.fireArgs);
+     return;
+ }
+
+ var func = f,
+     guid = f.observer_guid;
+ if (typeof c == "object") { func = utils.close(c, f); }
+
+ if (!guid) {
+     // first time any channel has seen this subscriber
+     guid = '' + nextGuid++;
+ }
+ func.observer_guid = guid;
+ f.observer_guid = guid;
+
+ // Don't add the same handler more than once.
+ if (!this.handlers[guid]) {
+     this.handlers[guid] = func;
+     this.numHandlers++;
+     if (this.numHandlers == 1) {
+         this.onHasSubscribersChange && this.onHasSubscribersChange();
+     }
+ }
+};
+
+/**
+* Unsubscribes the function with the given guid from the channel.
+*/
+Channel.prototype.unsubscribe = function(f) {
+ // need a function to unsubscribe
+ forceFunction(f);
+
+ var guid = f.observer_guid,
+     handler = this.handlers[guid];
+ if (handler) {
+     delete this.handlers[guid];
+     this.numHandlers--;
+     if (this.numHandlers === 0) {
+         this.onHasSubscribersChange && this.onHasSubscribersChange();
+     }
+ }
+};
+
+/**
+* Calls all functions subscribed to this channel.
+*/
+Channel.prototype.fire = function(e) {
+ var fail = false,
+     fireArgs = Array.prototype.slice.call(arguments);
+ // Apply stickiness.
+ if (this.state == 1) {
+     this.state = 2;
+     this.fireArgs = fireArgs;
+ }
+ if (this.numHandlers) {
+     // Copy the values first so that it is safe to modify it from within
+     // callbacks.
+     var toCall = [];
+     for (var item in this.handlers) {
+         toCall.push(this.handlers[item]);
+     }
+     for (var i = 0; i < toCall.length; ++i) {
+         toCall[i].apply(this, fireArgs);
+     }
+     if (this.state == 2 && this.numHandlers) {
+         this.numHandlers = 0;
+         this.handlers = {};
+         this.onHasSubscribersChange && this.onHasSubscribersChange();
+     }
+ }
+};
+
+
+//defining them here so they are ready super fast!
+//DOM event that is received when the web page is loaded and parsed.
+channel.createSticky('onDOMContentLoaded');
+
+//Event to indicate the Cordova native side is ready.
+channel.createSticky('onNativeReady');
+
+//Event to indicate that all Cordova JavaScript objects have been created
+//and it's time to run plugin constructors.
+channel.createSticky('onCordovaReady');
+
+//Event to indicate that all automatically loaded JS plugins are loaded and ready.
+//FIXME remove this
+channel.createSticky('onPluginsReady');
+
+//Event to indicate that Cordova is ready
+channel.createSticky('onDeviceReady');
+
+//Event to indicate a resume lifecycle event
+channel.create('onResume');
+
+//Event to indicate a pause lifecycle event
+channel.create('onPause');
+
+//Channels that must fire before "deviceready" is fired.
+channel.waitForInitialization('onCordovaReady');
+channel.waitForInitialization('onDOMContentLoaded');
+
+module.exports = channel;
+
+});
+
+define("cordova/exec", function(require, exports, module) {
+
+var cordova = require('cordova');
+var execProxy = require('cordova/exec/proxy');
+
+module.exports = function(success, fail, service, action, args) {
+
+ var proxy = execProxy.get(service, action);
+
+ if (proxy) {
+     var callbackId = service + cordova.callbackId++;
+
+     if (typeof success == "function" || typeof fail == "function") {
+         cordova.callbacks[callbackId] = {success:success, fail:fail};
+     }
+
+     try {
+         proxy(success, fail, args);
+     }
+     catch(e) {
+         // TODO throw maybe?
+         var msg = "Exception calling :: " + service + " :: " + action  + " ::exception=" + e;
+         console.log(msg);
+     }
+ }
+ else {
+     fail && fail("Missing Command Error");
+ }
+};
+
+});
+
+//file: src/common/exec/proxy.js
+define("cordova/exec/proxy", function(require, exports, module) {
+
+
+//internal map of proxy function
+var CommandProxyMap = {};
+
+module.exports = {
+
+ // example: cordova.commandProxy.add("Accelerometer",{getCurrentAcceleration: function(successCallback, errorCallback, options) {...},...);
+ add:function(id,proxyObj) {
+     console.log("adding proxy for " + id);
+     CommandProxyMap[id] = proxyObj;
+     return proxyObj;
+ },
+
+ // cordova.commandProxy.remove("Accelerometer");
+ remove:function(id) {
+     var proxy = CommandProxyMap[id];
+     delete CommandProxyMap[id];
+     CommandProxyMap[id] = null;
+     return proxy;
+ },
+
+ get:function(service,action) {
+     return ( CommandProxyMap[service] ? CommandProxyMap[service][action] : null );
+ }
+};
+});
+
+//file: src/common/init.js
+define("cordova/init", function(require, exports, module) {
+
+var channel = require('cordova/channel');
+var cordova = require('cordova');
+var modulemapper = require('cordova/modulemapper');
+var platform = require('cordova/platform');
+var pluginloader = require('cordova/pluginloader');
+var utils = require('cordova/utils');
+
+var platformInitChannelsArray = [channel.onNativeReady, channel.onPluginsReady];
+
+function logUnfiredChannels(arr) {
+ for (var i = 0; i < arr.length; ++i) {
+     if (arr[i].state != 2) {
+         console.log('Channel not fired: ' + arr[i].type);
+     }
+ }
+}
+
+window.setTimeout(function() {
+ if (channel.onDeviceReady.state != 2) {
+     console.log('deviceready has not fired after 5 seconds.');
+     logUnfiredChannels(platformInitChannelsArray);
+     logUnfiredChannels(channel.deviceReadyChannelsArray);
+ }
+}, 5000);
+
+//Replace navigator before any modules are required(), to ensure it happens as soon as possible.
+//We replace it so that properties that can't be clobbered can instead be overridden.
+function replaceNavigator(origNavigator) {
+ var CordovaNavigator = function() {};
+ CordovaNavigator.prototype = origNavigator;
+ var newNavigator = new CordovaNavigator();
+ // This work-around really only applies to new APIs that are newer than Function.bind.
+ // Without it, APIs such as getGamepads() break.
+ if (CordovaNavigator.bind) {
+     for (var key in origNavigator) {
+         if (typeof origNavigator[key] == 'function') {
+             newNavigator[key] = origNavigator[key].bind(origNavigator);
+         }
+         else {
+             (function(k) {
+                 utils.defineGetterSetter(newNavigator,key,function() {
+                     return origNavigator[k];
+                 });
+             })(key);
+         }
+     }
+ }
+ return newNavigator;
+}
+
+if (window.navigator) {
+ window.navigator = replaceNavigator(window.navigator);
+}
+
+if (!window.console) {
+ window.console = {
+     log: function(){}
+ };
+}
+if (!window.console.warn) {
+ window.console.warn = function(msg) {
+     this.log("warn: " + msg);
+ };
+}
+
+//Register pause, resume and deviceready channels as events on document.
+channel.onPause = cordova.addDocumentEventHandler('pause');
+channel.onResume = cordova.addDocumentEventHandler('resume');
+channel.onActivated = cordova.addDocumentEventHandler('activated');
+channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
+
+//Listen for DOMContentLoaded and notify our channel subscribers.
+if (document.readyState == 'complete' || document.readyState == 'interactive') {
+ channel.onDOMContentLoaded.fire();
+} else {
+ document.addEventListener('DOMContentLoaded', function() {
+     channel.onDOMContentLoaded.fire();
+ }, false);
+}
+
+//_nativeReady is global variable that the native side can set
+//to signify that the native code is ready. It is a global since
+//it may be called before any cordova JS is ready.
+if (window._nativeReady) {
+ channel.onNativeReady.fire();
+}
+
+modulemapper.clobbers('cordova', 'cordova');
+modulemapper.clobbers('cordova/exec', 'cordova.exec');
+modulemapper.clobbers('cordova/exec', 'Cordova.exec');
+
+//Call the platform-specific initialization.
+platform.bootstrap && platform.bootstrap();
+
+//Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
+//The delay allows the attached modules to be defined before the plugin loader looks for them.
+setTimeout(function() {
+ pluginloader.load(function() {
+     channel.onPluginsReady.fire();
+ });
+}, 0);
+
+/**
+* Create all cordova objects once native side is ready.
+*/
+channel.join(function() {
+ modulemapper.mapModules(window);
+
+ platform.initialize && platform.initialize();
+
+ // Fire event to notify that all objects are created
+ channel.onCordovaReady.fire();
+
+ // Fire onDeviceReady event once page has fully loaded, all
+ // constructors have run and cordova info has been received from native
+ // side.
+ channel.join(function() {
+     require('cordova').fireDocumentEvent('deviceready');
+ }, channel.deviceReadyChannelsArray);
+
+}, platformInitChannelsArray);
+
+
+});
+
+//file: src/common/init_b.js
+define("cordova/init_b", function(require, exports, module) {
+
+var channel = require('cordova/channel');
+var cordova = require('cordova');
+var modulemapper = require('cordova/modulemapper');
+var platform = require('cordova/platform');
+var utils = require('cordova/utils');
+
+var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];
+
+//setting exec
+cordova.exec = require('cordova/exec');
+
+function logUnfiredChannels(arr) {
+ for (var i = 0; i < arr.length; ++i) {
+     if (arr[i].state != 2) {
+         console.log('Channel not fired: ' + arr[i].type);
+     }
+ }
+}
+
+window.setTimeout(function() {
+ if (channel.onDeviceReady.state != 2) {
+     console.log('deviceready has not fired after 5 seconds.');
+     logUnfiredChannels(platformInitChannelsArray);
+     logUnfiredChannels(channel.deviceReadyChannelsArray);
+ }
+}, 5000);
+
+//Replace navigator before any modules are required(), to ensure it happens as soon as possible.
+//We replace it so that properties that can't be clobbered can instead be overridden.
+function replaceNavigator(origNavigator) {
+ var CordovaNavigator = function() {};
+ CordovaNavigator.prototype = origNavigator;
+ var newNavigator = new CordovaNavigator();
+ // This work-around really only applies to new APIs that are newer than Function.bind.
+ // Without it, APIs such as getGamepads() break.
+ if (CordovaNavigator.bind) {
+     for (var key in origNavigator) {
+         if (typeof origNavigator[key] == 'function') {
+             newNavigator[key] = origNavigator[key].bind(origNavigator);
+         }
+         else {
+             (function(k) {
+                 utils.defineGetterSetter(newNavigator,key,function() {
+                     return origNavigator[k];
+                 });
+             })(key);
+         }
+     }
+ }
+ return newNavigator;
+}
+if (window.navigator) {
+ window.navigator = replaceNavigator(window.navigator);
+}
+
+if (!window.console) {
+ window.console = {
+     log: function(){}
+ };
+}
+if (!window.console.warn) {
+ window.console.warn = function(msg) {
+     this.log("warn: " + msg);
+ };
+}
+
+//Register pause, resume and deviceready channels as events on document.
+channel.onPause = cordova.addDocumentEventHandler('pause');
+channel.onResume = cordova.addDocumentEventHandler('resume');
+channel.onActivated = cordova.addDocumentEventHandler('activated');
+channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
+
+//Listen for DOMContentLoaded and notify our channel subscribers.
+if (document.readyState == 'complete' || document.readyState == 'interactive') {
+ channel.onDOMContentLoaded.fire();
+} else {
+ document.addEventListener('DOMContentLoaded', function() {
+     channel.onDOMContentLoaded.fire();
+ }, false);
+}
+
+//_nativeReady is global variable that the native side can set
+//to signify that the native code is ready. It is a global since
+//it may be called before any cordova JS is ready.
+if (window._nativeReady) {
+ channel.onNativeReady.fire();
+}
+
+//Call the platform-specific initialization.
+platform.bootstrap && platform.bootstrap();
+
+/**
+* Create all cordova objects once native side is ready.
+*/
+channel.join(function() {
+ modulemapper.mapModules(window);
+
+ platform.initialize && platform.initialize();
+
+ // Fire event to notify that all objects are created
+ channel.onCordovaReady.fire();
+
+ // Fire onDeviceReady event once page has fully loaded, all
+ // constructors have run and cordova info has been received from native
+ // side.
+ channel.join(function() {
+     require('cordova').fireDocumentEvent('deviceready');
+ }, channel.deviceReadyChannelsArray);
+
+}, platformInitChannelsArray);
+
+});
+
+//file: src/common/modulemapper.js
+define("cordova/modulemapper", function(require, exports, module) {
+
+var builder = require('cordova/builder'),
+ moduleMap = define.moduleMap,
+ symbolList,
+ deprecationMap;
+
+exports.reset = function() {
+ symbolList = [];
+ deprecationMap = {};
+};
+
+function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
+ if (!(moduleName in moduleMap)) {
+     throw new Error('Module ' + moduleName + ' does not exist.');
+ }
+ symbolList.push(strategy, moduleName, symbolPath);
+ if (opt_deprecationMessage) {
+     deprecationMap[symbolPath] = opt_deprecationMessage;
+ }
+}
+
+//Note: Android 2.3 does have Function.bind().
+exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.runs = function(moduleName) {
+ addEntry('r', moduleName, null);
+};
+
+function prepareNamespace(symbolPath, context) {
+ if (!symbolPath) {
+     return context;
+ }
+ var parts = symbolPath.split('.');
+ var cur = context;
+ for (var i = 0, part; part = parts[i]; ++i) {
+     cur = cur[part] = cur[part] || {};
+ }
+ return cur;
+}
+
+exports.mapModules = function(context) {
+ var origSymbols = {};
+ context.CDV_origSymbols = origSymbols;
+ for (var i = 0, len = symbolList.length; i < len; i += 3) {
+     var strategy = symbolList[i];
+     var moduleName = symbolList[i + 1];
+     var module = require(moduleName);
+     // <runs/>
+     if (strategy == 'r') {
+         continue;
+     }
+     var symbolPath = symbolList[i + 2];
+     var lastDot = symbolPath.lastIndexOf('.');
+     var namespace = symbolPath.substr(0, lastDot);
+     var lastName = symbolPath.substr(lastDot + 1);
+
+     var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
+     var parentObj = prepareNamespace(namespace, context);
+     var target = parentObj[lastName];
+
+     if (strategy == 'm' && target) {
+         builder.recursiveMerge(target, module);
+     } else if ((strategy == 'd' && !target) || (strategy != 'd')) {
+         if (!(symbolPath in origSymbols)) {
+             origSymbols[symbolPath] = target;
+         }
+         builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
+     }
+ }
+};
+
+exports.getOriginalSymbol = function(context, symbolPath) {
+ var origSymbols = context.CDV_origSymbols;
+ if (origSymbols && (symbolPath in origSymbols)) {
+     return origSymbols[symbolPath];
+ }
+ var parts = symbolPath.split('.');
+ var obj = context;
+ for (var i = 0; i < parts.length; ++i) {
+     obj = obj && obj[parts[i]];
+ }
+ return obj;
+};
+
+exports.reset();
+
+
+});
+
+//file: src/common/modulemapper_b.js
+define("cordova/modulemapper_b", function(require, exports, module) {
+
+var builder = require('cordova/builder'),
+ symbolList = [],
+ deprecationMap;
+
+exports.reset = function() {
+ symbolList = [];
+ deprecationMap = {};
+};
+
+function addEntry(strategy, moduleName, symbolPath, opt_deprecationMessage) {
+ symbolList.push(strategy, moduleName, symbolPath);
+ if (opt_deprecationMessage) {
+     deprecationMap[symbolPath] = opt_deprecationMessage;
+ }
+}
+
+//Note: Android 2.3 does have Function.bind().
+exports.clobbers = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('c', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.merges = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('m', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.defaults = function(moduleName, symbolPath, opt_deprecationMessage) {
+ addEntry('d', moduleName, symbolPath, opt_deprecationMessage);
+};
+
+exports.runs = function(moduleName) {
+ addEntry('r', moduleName, null);
+};
+
+function prepareNamespace(symbolPath, context) {
+ if (!symbolPath) {
+     return context;
+ }
+ var parts = symbolPath.split('.');
+ var cur = context;
+ for (var i = 0, part; part = parts[i]; ++i) {
+     cur = cur[part] = cur[part] || {};
+ }
+ return cur;
+}
+
+exports.mapModules = function(context) {
+ var origSymbols = {};
+ context.CDV_origSymbols = origSymbols;
+ for (var i = 0, len = symbolList.length; i < len; i += 3) {
+     var strategy = symbolList[i];
+     var moduleName = symbolList[i + 1];
+     var module = require(moduleName);
+     // <runs/>
+     if (strategy == 'r') {
+         continue;
+     }
+     var symbolPath = symbolList[i + 2];
+     var lastDot = symbolPath.lastIndexOf('.');
+     var namespace = symbolPath.substr(0, lastDot);
+     var lastName = symbolPath.substr(lastDot + 1);
+
+     var deprecationMsg = symbolPath in deprecationMap ? 'Access made to deprecated symbol: ' + symbolPath + '. ' + deprecationMsg : null;
+     var parentObj = prepareNamespace(namespace, context);
+     var target = parentObj[lastName];
+
+     if (strategy == 'm' && target) {
+         builder.recursiveMerge(target, module);
+     } else if ((strategy == 'd' && !target) || (strategy != 'd')) {
+         if (!(symbolPath in origSymbols)) {
+             origSymbols[symbolPath] = target;
+         }
+         builder.assignOrWrapInDeprecateGetter(parentObj, lastName, module, deprecationMsg);
+     }
+ }
+};
+
+exports.getOriginalSymbol = function(context, symbolPath) {
+ var origSymbols = context.CDV_origSymbols;
+ if (origSymbols && (symbolPath in origSymbols)) {
+     return origSymbols[symbolPath];
+ }
+ var parts = symbolPath.split('.');
+ var obj = context;
+ for (var i = 0; i < parts.length; ++i) {
+     obj = obj && obj[parts[i]];
+ }
+ return obj;
+};
+
+exports.reset();
+
+
+});
+
+// Tizen platform
+define("cordova/platform", function(require, exports, module) {
+
+module.exports = {
+ id: 'tizen',
+ cordovaVersion: '5.1.1',
+
+ bootstrap: function() {
+
+     var modulemapper = require('cordova/modulemapper');
+     var channel = require('cordova/channel');
+
+     modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy');
+
+     // load all Tizen plugins
+     for (var plugin in tizen.cordova) {
+       if (tizen.cordova.hasOwnProperty(plugin)) {
+         tizen.cordova[plugin](require);
+       }
+     }
+
+     channel.onNativeReady.fire();
+
+     // FIXME is this the right place to clobber pause/resume? I am guessing not
+     // FIXME pause/resume should be deprecated IN CORDOVA for pagevisiblity api
+     document.addEventListener('webkitvisibilitychange', function() {
+         if (document.webkitHidden) {
+             channel.onPause.fire();
+         }
+         else {
+             channel.onResume.fire();
+         }
+     }, false);
+
+ // End of bootstrap
+ }
+};
+
+});
+
+//file: src/common/pluginloader.js
+define("cordova/pluginloader", function(require, exports, module) {
+
+/*
+ NOTE: this file is NOT used when we use the browserify workflow
+*/
+
+var modulemapper = require('cordova/modulemapper');
+var urlutil = require('cordova/urlutil');
+
+//Helper function to inject a <script> tag.
+//Exported for testing.
+exports.injectScript = function(url, onload, onerror) {
+ var script = document.createElement("script");
+ // onload fires even when script fails loads with an error.
+ script.onload = onload;
+ // onerror fires for malformed URLs.
+ script.onerror = onerror;
+ script.src = url;
+ document.head.appendChild(script);
+};
+
+function injectIfNecessary(id, url, onload, onerror) {
+ onerror = onerror || onload;
+ if (id in define.moduleMap) {
+     onload();
+ } else {
+     exports.injectScript(url, function() {
+         if (id in define.moduleMap) {
+             onload();
+         } else {
+             onerror();
+         }
+     }, onerror);
+ }
+}
+
+function onScriptLoadingComplete(moduleList, finishPluginLoading) {
+ // Loop through all the plugins and then through their clobbers and merges.
+ for (var i = 0, module; module = moduleList[i]; i++) {
+     if (module.clobbers && module.clobbers.length) {
+         for (var j = 0; j < module.clobbers.length; j++) {
+             modulemapper.clobbers(module.id, module.clobbers[j]);
+         }
+     }
+
+     if (module.merges && module.merges.length) {
+         for (var k = 0; k < module.merges.length; k++) {
+             modulemapper.merges(module.id, module.merges[k]);
+         }
+     }
+
+     // Finally, if runs is truthy we want to simply require() the module.
+     if (module.runs) {
+         modulemapper.runs(module.id);
+     }
+ }
+
+ finishPluginLoading();
+}
+
+//Handler for the cordova_plugins.js content.
+//See plugman's plugin_loader.js for the details of this object.
+//This function is only called if the really is a plugins array that isn't empty.
+//Otherwise the onerror response handler will just call finishPluginLoading().
+function handlePluginsObject(path, moduleList, finishPluginLoading) {
+ // Now inject the scripts.
+ var scriptCounter = moduleList.length;
+
+ if (!scriptCounter) {
+     finishPluginLoading();
+     return;
+ }
+ function scriptLoadedCallback() {
+     if (!--scriptCounter) {
+         onScriptLoadingComplete(moduleList, finishPluginLoading);
+     }
+ }
+
+ for (var i = 0; i < moduleList.length; i++) {
+     injectIfNecessary(moduleList[i].id, path + moduleList[i].file, scriptLoadedCallback);
+ }
+}
+
+function findCordovaPath() {
+ var path = null;
+ var scripts = document.getElementsByTagName('script');
+ var term = '/cordova.js';
+ for (var n = scripts.length-1; n>-1; n--) {
+     var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
+     if (src.indexOf(term) == (src.length - term.length)) {
+         path = src.substring(0, src.length - term.length) + '/';
+         break;
+     }
+ }
+ return path;
+}
+
+//Tries to load all plugins' js-modules.
+//This is an async process, but onDeviceReady is blocked on onPluginsReady.
+//onPluginsReady is fired when there are no plugins to load, or they are all done.
+exports.load = function(callback) {
+ var pathPrefix = findCordovaPath();
+ if (pathPrefix === null) {
+     console.log('Could not find cordova.js script tag. Plugin loading may fail.');
+     pathPrefix = '';
+ }
+ injectIfNecessary('cordova/plugin_list', pathPrefix + 'cordova_plugins.js', function() {
+     var moduleList = require("cordova/plugin_list");
+     handlePluginsObject(pathPrefix, moduleList, callback);
+ }, callback);
+};
+
+
+});
+
+//file: src/common/urlutil.js
+define("cordova/urlutil", function(require, exports, module) {
+
+
+/**
+* For already absolute URLs, returns what is passed in.
+* For relative URLs, converts them to absolute ones.
+*/
+exports.makeAbsolute = function makeAbsolute(url) {
+ var anchorEl = document.createElement('a');
+ anchorEl.href = url;
+ return anchorEl.href;
+};
+
+
+});
+
+//file: src/common/utils.js
+define("cordova/utils", function(require, exports, module) {
+
+var utils = exports;
+
+/**
+* Defines a property getter / setter for obj[key].
+*/
+utils.defineGetterSetter = function(obj, key, getFunc, opt_setFunc) {
+ if (Object.defineProperty) {
+     var desc = {
+         get: getFunc,
+         configurable: true
+     };
+     if (opt_setFunc) {
+         desc.set = opt_setFunc;
+     }
+     Object.defineProperty(obj, key, desc);
+ } else {
+     obj.__defineGetter__(key, getFunc);
+     if (opt_setFunc) {
+         obj.__defineSetter__(key, opt_setFunc);
+     }
+ }
+};
+
+/**
+* Defines a property getter for obj[key].
+*/
+utils.defineGetter = utils.defineGetterSetter;
+
+utils.arrayIndexOf = function(a, item) {
+ if (a.indexOf) {
+     return a.indexOf(item);
+ }
+ var len = a.length;
+ for (var i = 0; i < len; ++i) {
+     if (a[i] == item) {
+         return i;
+     }
+ }
+ return -1;
+};
+
+/**
+* Returns whether the item was found in the array.
+*/
+utils.arrayRemove = function(a, item) {
+ var index = utils.arrayIndexOf(a, item);
+ if (index != -1) {
+     a.splice(index, 1);
+ }
+ return index != -1;
+};
+
+utils.typeName = function(val) {
+ return Object.prototype.toString.call(val).slice(8, -1);
+};
+
+/**
+* Returns an indication of whether the argument is an array or not
+*/
+utils.isArray = Array.isArray ||
+             function(a) {return utils.typeName(a) == 'Array';};
+
+/**
+* Returns an indication of whether the argument is a Date or not
+*/
+utils.isDate = function(d) {
+ return (d instanceof Date);
+};
+
+/**
+* Does a deep clone of the object.
+*/
+utils.clone = function(obj) {
+ if(!obj || typeof obj == 'function' || utils.isDate(obj) || typeof obj != 'object') {
+     return obj;
+ }
+
+ var retVal, i;
+
+ if(utils.isArray(obj)){
+     retVal = [];
+     for(i = 0; i < obj.length; ++i){
+         retVal.push(utils.clone(obj[i]));
+     }
+     return retVal;
+ }
+
+ retVal = {};
+ for(i in obj){
+     if(!(i in retVal) || retVal[i] != obj[i]) {
+         retVal[i] = utils.clone(obj[i]);
+     }
+ }
+ return retVal;
+};
+
+/**
+* Returns a wrapped version of the function
+*/
+utils.close = function(context, func, params) {
+ return function() {
+     var args = params || arguments;
+     return func.apply(context, args);
+ };
+};
+
+//------------------------------------------------------------------------------
+function UUIDcreatePart(length) {
+ var uuidpart = "";
+ for (var i=0; i<length; i++) {
+     var uuidchar = parseInt((Math.random() * 256), 10).toString(16);
+     if (uuidchar.length == 1) {
+         uuidchar = "0" + uuidchar;
+     }
+     uuidpart += uuidchar;
+ }
+ return uuidpart;
+}
+
+/**
+* Create a UUID
+*/
+utils.createUUID = function() {
+ return UUIDcreatePart(4) + '-' +
+     UUIDcreatePart(2) + '-' +
+     UUIDcreatePart(2) + '-' +
+     UUIDcreatePart(2) + '-' +
+     UUIDcreatePart(6);
+};
+
+
+/**
+* Extends a child object from a parent object using classical inheritance
+* pattern.
+*/
+utils.extend = (function() {
+ // proxy used to establish prototype chain
+ var F = function() {};
+ // extend Child from Parent
+ return function(Child, Parent) {
+
+     F.prototype = Parent.prototype;
+     Child.prototype = new F();
+     Child.__super__ = Parent.prototype;
+     Child.prototype.constructor = Child;
+ };
+}());
+
+/**
+* Alerts a message in any available way: alert or console.log.
+*/
+utils.alert = function(msg) {
+ if (window.alert) {
+     window.alert(msg);
+ } else if (console && console.log) {
+     console.log(msg);
+ }
+};
+
+
+
+
+
+});
+
+window.cordova = require('cordova');
+//file: src/scripts/bootstrap.js
+
+require('cordova/init');
+
 })();
\ No newline at end of file
diff --git a/src/lib/cordova_plugins.js b/src/lib/cordova_plugins.js
new file mode 100644 (file)
index 0000000..239fb9b
--- /dev/null
@@ -0,0 +1,148 @@
+cordova.define('cordova/plugin_list', function(require, exports, module) {
+module.exports = [
+    {
+        "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js",
+        "id": "cordova-plugin-file.DirectoryEntry",
+        "clobbers": [
+            "window.DirectoryEntry"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/DirectoryReader.js",
+        "id": "cordova-plugin-file.DirectoryReader",
+        "clobbers": [
+            "window.DirectoryReader"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/Entry.js",
+        "id": "cordova-plugin-file.Entry",
+        "clobbers": [
+            "window.Entry"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/File.js",
+        "id": "cordova-plugin-file.File",
+        "clobbers": [
+            "window.File"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileEntry.js",
+        "id": "cordova-plugin-file.FileEntry",
+        "clobbers": [
+            "window.FileEntry"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileError.js",
+        "id": "cordova-plugin-file.FileError",
+        "clobbers": [
+            "window.FileError"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileReader.js",
+        "id": "cordova-plugin-file.FileReader",
+        "clobbers": [
+            "window.FileReader"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileSystem.js",
+        "id": "cordova-plugin-file.FileSystem",
+        "clobbers": [
+            "window.FileSystem"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js",
+        "id": "cordova-plugin-file.FileUploadOptions",
+        "clobbers": [
+            "window.FileUploadOptions"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileUploadResult.js",
+        "id": "cordova-plugin-file.FileUploadResult",
+        "clobbers": [
+            "window.FileUploadResult"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/FileWriter.js",
+        "id": "cordova-plugin-file.FileWriter",
+        "clobbers": [
+            "window.FileWriter"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/Flags.js",
+        "id": "cordova-plugin-file.Flags",
+        "clobbers": [
+            "window.Flags"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js",
+        "id": "cordova-plugin-file.LocalFileSystem",
+        "clobbers": [
+            "window.LocalFileSystem"
+        ],
+        "merges": [
+            "window"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/Metadata.js",
+        "id": "cordova-plugin-file.Metadata",
+        "clobbers": [
+            "window.Metadata"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/ProgressEvent.js",
+        "id": "cordova-plugin-file.ProgressEvent",
+        "clobbers": [
+            "window.ProgressEvent"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/fileSystems.js",
+        "id": "cordova-plugin-file.fileSystems"
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/fileSystems-roots.js",
+        "id": "cordova-plugin-file.fileSystems-roots"
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/requestFileSystem.js",
+        "id": "cordova-plugin-file.requestFileSystem",
+        "clobbers": [
+            "window.requestFileSystem"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js",
+        "id": "cordova-plugin-file.resolveLocalFileSystemURI",
+        "merges": [
+            "window"
+        ]
+    },
+    {
+        "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js",
+        "id": "cordova-plugin-file.fileSystemPaths",
+        "merges": [
+            "cordova"
+        ],
+        "runs": true
+    }
+];
+module.exports.metadata =
+// TOP OF METADATA
+{
+    "cordova-plugin-file": "3.0.0",
+}
+// BOTTOM OF METADATA
+});
\ No newline at end of file
diff --git a/src/lib/plugins/cordova-plugin-file/www/DirectoryEntry.js b/src/lib/plugins/cordova-plugin-file/www/DirectoryEntry.js
new file mode 100644 (file)
index 0000000..464d339
--- /dev/null
@@ -0,0 +1,119 @@
+cordova.define("cordova-plugin-file.DirectoryEntry", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var argscheck = require('cordova/argscheck'),
+    utils = require('cordova/utils'),
+    exec = require('cordova/exec'),
+    Entry = require('./Entry'),
+    FileError = require('./FileError'),
+    DirectoryReader = require('./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)
+ * {FileSystem} filesystem on which the directory resides (readonly)
+ */
+var DirectoryEntry = function(name, fullPath, fileSystem, nativeURL) {
+
+    // add trailing slash if it is missing
+    if ((fullPath) && !/\/$/.test(fullPath)) {
+        fullPath += "/";
+    }
+    // add trailing slash if it is missing
+    if (nativeURL && !/\/$/.test(nativeURL)) {
+        nativeURL += "/";
+    }
+    DirectoryEntry.__super__.constructor.call(this, false, true, name, fullPath, fileSystem, nativeURL);
+};
+
+utils.extend(DirectoryEntry, Entry);
+
+/**
+ * Creates a new DirectoryReader to read entries from this directory
+ */
+DirectoryEntry.prototype.createReader = function() {
+    return new DirectoryReader(this.toInternalURL());
+};
+
+/**
+ * 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) {
+    argscheck.checkArgs('sOFF', 'DirectoryEntry.getDirectory', arguments);
+    var fs = this.filesystem;
+    var win = successCallback && function(result) {
+        var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
+        successCallback(entry);
+    };
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getDirectory", [this.toInternalURL(), path, options]);
+};
+
+/**
+ * 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) {
+    argscheck.checkArgs('FF', 'DirectoryEntry.removeRecursively', arguments);
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(successCallback, fail, "File", "removeRecursively", [this.toInternalURL()]);
+};
+
+/**
+ * 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) {
+    argscheck.checkArgs('sOFF', 'DirectoryEntry.getFile', arguments);
+    var fs = this.filesystem;
+    var win = successCallback && function(result) {
+        var FileEntry = require('./FileEntry');
+        var entry = new FileEntry(result.name, result.fullPath, fs, result.nativeURL);
+        successCallback(entry);
+    };
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getFile", [this.toInternalURL(), path, options]);
+};
+
+module.exports = DirectoryEntry;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/DirectoryReader.js b/src/lib/plugins/cordova-plugin-file/www/DirectoryReader.js
new file mode 100644 (file)
index 0000000..921b486
--- /dev/null
@@ -0,0 +1,75 @@
+cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var exec = require('cordova/exec'),
+    FileError = require('./FileError') ;
+
+/**
+ * An interface that lists the files and directories in a directory.
+ */
+function DirectoryReader(localURL) {
+    this.localURL = localURL || null;
+    this.hasReadEntries = false;
+}
+
+/**
+ * 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) {
+    // If we've already read and passed on this directory's entries, return an empty list.
+    if (this.hasReadEntries) {
+        successCallback([]);
+        return;
+    }
+    var reader = this;
+    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('./DirectoryEntry'))();
+            }
+            else if (result[i].isFile) {
+                entry = new (require('./FileEntry'))();
+            }
+            entry.isDirectory = result[i].isDirectory;
+            entry.isFile = result[i].isFile;
+            entry.name = result[i].name;
+            entry.fullPath = result[i].fullPath;
+            entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
+            entry.nativeURL = result[i].nativeURL;
+            retVal.push(entry);
+        }
+        reader.hasReadEntries = true;
+        successCallback(retVal);
+    };
+    var fail = typeof errorCallback !== 'function' ? null : function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "readEntries", [this.localURL]);
+};
+
+module.exports = DirectoryReader;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/Entry.js b/src/lib/plugins/cordova-plugin-file/www/Entry.js
new file mode 100644 (file)
index 0000000..5563149
--- /dev/null
@@ -0,0 +1,262 @@
+cordova.define("cordova-plugin-file.Entry", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var argscheck = require('cordova/argscheck'),
+    exec = require('cordova/exec'),
+    FileError = require('./FileError'),
+    Metadata = require('./Metadata');
+
+/**
+ * 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)
+ * @param fileSystem
+ *            {FileSystem} the filesystem on which this entry resides
+ *            (readonly)
+ * @param nativeURL
+ *            {DOMString} an alternate URL which can be used by native
+ *            webview controls, for example media players.
+ *            (optional, readonly)
+ */
+function Entry(isFile, isDirectory, name, fullPath, fileSystem, nativeURL) {
+    this.isFile = !!isFile;
+    this.isDirectory = !!isDirectory;
+    this.name = name || '';
+    this.fullPath = fullPath || '';
+    this.filesystem = fileSystem || null;
+    this.nativeURL = nativeURL || 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(entryMetadata) {
+        var metadata = new Metadata({
+            size: entryMetadata.size,
+            modificationTime: entryMetadata.lastModifiedDate
+        });
+        successCallback(metadata);
+    };
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(success, fail, "File", "getFileMetadata", [this.toInternalURL()]);
+};
+
+/**
+ * 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.toInternalURL(), metadataObject]);
+};
+
+/**
+ * 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));
+    };
+    var filesystem = this.filesystem,
+        srcURL = this.toInternalURL(),
+        // entry name
+        name = newName || this.name,
+        success = function(entry) {
+            if (entry) {
+                if (successCallback) {
+                    // create appropriate Entry object
+                    var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
+                    var fs = newFSName ? new FileSystem(newFSName, { name: "", fullPath: "/" }) : new FileSystem(parent.filesystem.name, { name: "", fullPath: "/" });
+                    var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
+                    successCallback(result);
+                }
+            }
+            else {
+                // no Entry object returned
+                fail && fail(FileError.NOT_FOUND_ERR);
+            }
+        };
+
+    // copy
+    exec(success, fail, "File", "moveTo", [srcURL, parent.toInternalURL(), name]);
+};
+
+/**
+ * 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));
+    };
+    var filesystem = this.filesystem,
+        srcURL = this.toInternalURL(),
+        // entry name
+        name = newName || this.name,
+        // success callback
+        success = function(entry) {
+            if (entry) {
+                if (successCallback) {
+                    // create appropriate Entry object
+                    var newFSName = entry.filesystemName || (entry.filesystem && entry.filesystem.name);
+                    var fs = newFSName ? new FileSystem(newFSName, { name: "", fullPath: "/" }) : new FileSystem(parent.filesystem.name, { name: "", fullPath: "/" });
+                    var result = (entry.isDirectory) ? new (require('./DirectoryEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL) : new (require('cordova-plugin-file.FileEntry'))(entry.name, entry.fullPath, fs, entry.nativeURL);
+                    successCallback(result);
+                }
+            }
+            else {
+                // no Entry object returned
+                fail && fail(FileError.NOT_FOUND_ERR);
+            }
+        };
+
+    // copy
+    exec(success, fail, "File", "copyTo", [srcURL, parent.toInternalURL(), name]);
+};
+
+/**
+ * Return a URL that can be passed across the bridge to identify this entry.
+ */
+Entry.prototype.toInternalURL = function() {
+    if (this.filesystem && this.filesystem.__format__) {
+      return this.filesystem.__format__(this.fullPath, this.nativeURL);
+    }
+};
+
+/**
+ * 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() {
+    console.log("DEPRECATED: Update your code to use 'toURL'");
+    return this.toURL();
+};
+
+/**
+ * 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'");
+    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.toInternalURL()]);
+};
+
+/**
+ * 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 fs = this.filesystem;
+    var win = successCallback && function(result) {
+        var DirectoryEntry = require('./DirectoryEntry');
+        var entry = new DirectoryEntry(result.name, result.fullPath, fs, result.nativeURL);
+        successCallback(entry);
+    };
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getParent", [this.toInternalURL()]);
+};
+
+module.exports = Entry;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/File.js b/src/lib/plugins/cordova-plugin-file/www/File.js
new file mode 100644 (file)
index 0000000..47c267b
--- /dev/null
@@ -0,0 +1,81 @@
+cordova.define("cordova-plugin-file.File", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Constructor.
+ * name {DOMString} name of the file, without path information
+ * fullPath {DOMString} the full path of the file, including the name
+ * type {DOMString} mime type
+ * lastModifiedDate {Date} last modified date
+ * size {Number} size of the file in bytes
+ */
+
+var File = function(name, localURL, type, lastModifiedDate, size){
+    this.name = name || '';
+    this.localURL = localURL || null;
+    this.type = type || null;
+    this.lastModified = lastModifiedDate || null;
+    // For backwards compatibility, store the timestamp in lastModifiedDate as well
+    this.lastModifiedDate = lastModifiedDate || null;
+    this.size = size || 0;
+
+    // These store the absolute start and end for slicing the file.
+    this.start = 0;
+    this.end = this.size;
+};
+
+/**
+ * Returns a "slice" of the file. Since Cordova Files don't contain the actual
+ * content, this really returns a File with adjusted start and end.
+ * Slices of slices are supported.
+ * start {Number} The index at which to start the slice (inclusive).
+ * end {Number} The index at which to end the slice (exclusive).
+ */
+File.prototype.slice = function(start, end) {
+    var size = this.end - this.start;
+    var newStart = 0;
+    var newEnd = size;
+    if (arguments.length) {
+        if (start < 0) {
+            newStart = Math.max(size + start, 0);
+        } else {
+            newStart = Math.min(size, start);
+        }
+    }
+
+    if (arguments.length >= 2) {
+        if (end < 0) {
+            newEnd = Math.max(size + end, 0);
+        } else {
+            newEnd = Math.min(end, size);
+        }
+    }
+
+    var newFile = new File(this.name, this.localURL, this.type, this.lastModified, this.size);
+    newFile.start = this.start + newStart;
+    newFile.end = this.start + newEnd;
+    return newFile;
+};
+
+
+module.exports = File;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileEntry.js b/src/lib/plugins/cordova-plugin-file/www/FileEntry.js
new file mode 100644 (file)
index 0000000..981ae7b
--- /dev/null
@@ -0,0 +1,83 @@
+cordova.define("cordova-plugin-file.FileEntry", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var utils = require('cordova/utils'),
+    exec = require('cordova/exec'),
+    Entry = require('./Entry'),
+    FileWriter = require('./FileWriter'),
+    File = require('./File'),
+    FileError = require('./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, fileSystem, nativeURL) {
+     FileEntry.__super__.constructor.apply(this, [true, false, name, fullPath, fileSystem, nativeURL]);
+};
+
+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.localURL === null || writer.localURL === "") {
+            errorCallback && errorCallback(new FileError(FileError.INVALID_STATE_ERR));
+        } else {
+            successCallback && successCallback(writer);
+        }
+    }, 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 localURL = this.toInternalURL();
+    var win = successCallback && function(f) {
+        var file = new File(f.name, localURL, f.type, f.lastModifiedDate, f.size);
+        successCallback(file);
+    };
+    var fail = errorCallback && function(code) {
+        errorCallback(new FileError(code));
+    };
+    exec(win, fail, "File", "getFileMetadata", [localURL]);
+};
+
+
+module.exports = FileEntry;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileError.js b/src/lib/plugins/cordova-plugin-file/www/FileError.js
new file mode 100644 (file)
index 0000000..403f73b
--- /dev/null
@@ -0,0 +1,48 @@
+cordova.define("cordova-plugin-file.FileError", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * FileError
+ */
+function FileError(error) {
+  this.code = error || null;
+}
+
+// File error codes
+// Found in DOMException
+FileError.NOT_FOUND_ERR = 1;
+FileError.SECURITY_ERR = 2;
+FileError.ABORT_ERR = 3;
+
+// Added by File API specification
+FileError.NOT_READABLE_ERR = 4;
+FileError.ENCODING_ERR = 5;
+FileError.NO_MODIFICATION_ALLOWED_ERR = 6;
+FileError.INVALID_STATE_ERR = 7;
+FileError.SYNTAX_ERR = 8;
+FileError.INVALID_MODIFICATION_ERR = 9;
+FileError.QUOTA_EXCEEDED_ERR = 10;
+FileError.TYPE_MISMATCH_ERR = 11;
+FileError.PATH_EXISTS_ERR = 12;
+
+module.exports = FileError;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileReader.js b/src/lib/plugins/cordova-plugin-file/www/FileReader.js
new file mode 100644 (file)
index 0000000..6955e9f
--- /dev/null
@@ -0,0 +1,392 @@
+cordova.define("cordova-plugin-file.FileReader", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var exec = require('cordova/exec'),
+    modulemapper = require('cordova/modulemapper'),
+    utils = require('cordova/utils'),
+    File = require('./File'),
+    FileError = require('./FileError'),
+    ProgressEvent = require('./ProgressEvent'),
+    origFileReader = modulemapper.getOriginalSymbol(window, 'FileReader');
+
+/**
+ * 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._localURL = '';
+    this._realReader = origFileReader ? new origFileReader() : {};
+};
+
+// States
+FileReader.EMPTY = 0;
+FileReader.LOADING = 1;
+FileReader.DONE = 2;
+
+utils.defineGetter(FileReader.prototype, 'readyState', function() {
+    return this._localURL ? this._readyState : this._realReader.readyState;
+});
+
+utils.defineGetter(FileReader.prototype, 'error', function() {
+    return this._localURL ? this._error: this._realReader.error;
+});
+
+utils.defineGetter(FileReader.prototype, 'result', function() {
+    return this._localURL ? this._result: this._realReader.result;
+});
+
+function defineEvent(eventName) {
+    utils.defineGetterSetter(FileReader.prototype, eventName, function() {
+        return this._realReader[eventName] || null;
+    }, function(value) {
+        this._realReader[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.localURL == 'string') {
+        reader._localURL = file.localURL;
+    } else {
+        reader._localURL = '';
+        return true;
+    }
+
+    reader.onloadstart && reader.onloadstart(new ProgressEvent("loadstart", {target:reader}));
+}
+
+/**
+ * Abort reading file.
+ */
+FileReader.prototype.abort = function() {
+    if (origFileReader && !this._localURL) {
+        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}));
+    }
+};
+
+/**
+ * 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);
+    }
+
+    // Default encoding is UTF-8
+    var enc = encoding ? encoding : "UTF-8";
+    var me = this;
+    var execArgs = [this._localURL, enc, file.start, file.end];
+
+    // 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;
+
+            // 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._localURL, file.start, file.end];
+
+    // 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);
+    }
+
+    var me = this;
+    var execArgs = [this._localURL, file.start, file.end];
+
+    // 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;
+
+            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", "readAsBinaryString", execArgs);
+};
+
+/**
+ * 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);
+    }
+
+    var me = this;
+    var execArgs = [this._localURL, file.start, file.end];
+
+    // 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;
+
+            if (r instanceof Array) {
+                r = new Uint8Array(r).buffer;
+            }
+            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", "readAsArrayBuffer", execArgs);
+};
+
+module.exports = FileReader;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileSystem.js b/src/lib/plugins/cordova-plugin-file/www/FileSystem.js
new file mode 100644 (file)
index 0000000..26639b1
--- /dev/null
@@ -0,0 +1,50 @@
+cordova.define("cordova-plugin-file.FileSystem", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var DirectoryEntry = require('./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) {
+    this.name = name;
+    if (root) {
+        this.root = new DirectoryEntry(root.name, root.fullPath, this, root.nativeURL);
+    } else {
+        this.root = new DirectoryEntry(this.name, '/', this);
+    }
+};
+
+FileSystem.prototype.__format__ = function(fullPath, nativeUrl) {
+    return fullPath;
+};
+
+FileSystem.prototype.toJSON = function() {
+    return "<FileSystem: " + this.name + ">";
+};
+
+module.exports = FileSystem;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileUploadOptions.js b/src/lib/plugins/cordova-plugin-file/www/FileUploadOptions.js
new file mode 100644 (file)
index 0000000..9928359
--- /dev/null
@@ -0,0 +1,43 @@
+cordova.define("cordova-plugin-file.FileUploadOptions", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Options to customize the HTTP request used to upload files.
+ * @constructor
+ * @param fileKey {String}   Name of file request parameter.
+ * @param fileName {String}  Filename to be used by the server. Defaults to image.jpg.
+ * @param mimeType {String}  Mimetype of the uploaded file. Defaults to image/jpeg.
+ * @param params {Object}    Object with key: value params to send to the server.
+ * @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, 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;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileUploadResult.js b/src/lib/plugins/cordova-plugin-file/www/FileUploadResult.js
new file mode 100644 (file)
index 0000000..3110814
--- /dev/null
@@ -0,0 +1,31 @@
+cordova.define("cordova-plugin-file.FileUploadResult", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * FileUploadResult
+ * @constructor
+ */
+module.exports = function FileUploadResult(size, code, content) {
+       this.bytesSent = size;
+       this.responseCode = code;
+       this.response = content;
+ };
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/FileWriter.js b/src/lib/plugins/cordova-plugin-file/www/FileWriter.js
new file mode 100644 (file)
index 0000000..8e3f509
--- /dev/null
@@ -0,0 +1,304 @@
+cordova.define("cordova-plugin-file.FileWriter", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var exec = require('cordova/exec'),
+    FileError = require('./FileError'),
+    ProgressEvent = require('./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.localURL = file.localURL || file;
+        this.length = file.size || 0;
+    }
+    // default is to write at the beginning of the file
+    this.position = 0;
+
+    this.readyState = 0; // EMPTY
+
+    this.result = null;
+
+    // Error
+    this.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).
+};
+
+// States
+FileWriter.INIT = 0;
+FileWriter.WRITING = 1;
+FileWriter.DONE = 2;
+
+/**
+ * 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);
+    }
+
+    // set error
+    this.error = new FileError(FileError.ABORT_ERR);
+
+    this.readyState = FileWriter.DONE;
+
+    // If abort callback
+    if (typeof this.onabort === "function") {
+        this.onabort(new ProgressEvent("abort", {"target":this}));
+    }
+
+    // If write end callback
+    if (typeof this.onwriteend === "function") {
+        this.onwriteend(new ProgressEvent("writeend", {"target":this}));
+    }
+};
+
+/**
+ * Writes data to the file
+ *
+ * @param data text or blob to be written
+ */
+FileWriter.prototype.write = function(data) {
+
+    var that=this;
+    var supportsBinary = (typeof window.Blob !== 'undefined' && typeof window.ArrayBuffer !== 'undefined');
+    var isProxySupportBlobNatively = (cordova.platformId === "windows8" || cordova.platformId === "windows");
+    var isBinary;
+
+    // Check to see if the incoming data is a blob
+    if (data instanceof File || (!isProxySupportBlobNatively && supportsBinary && data instanceof Blob)) {
+        var fileReader = new FileReader();
+        fileReader.onload = function() {
+            // Call this method again, with the arraybuffer as argument
+            FileWriter.prototype.write.call(that, this.result);
+        };
+        if (supportsBinary) {
+            fileReader.readAsArrayBuffer(data);
+        } else {
+            fileReader.readAsText(data);
+        }
+        return;
+    }
+
+    // Mark data type for safer transport over the binary bridge
+    isBinary = supportsBinary && (data instanceof ArrayBuffer);
+    if (isBinary && cordova.platformId === "windowsphone") {
+        // create a plain array, using the keys from the Uint8Array view so that we can serialize it
+        data = Array.apply(null, new Uint8Array(data));
+    }
+    
+    // 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}));
+            }
+
+            // If onwriteend callback
+            if (typeof me.onwriteend === "function") {
+                me.onwriteend(new ProgressEvent("writeend", {"target":me}));
+            }
+        }, "File", "write", [this.localURL, data, this.position, isBinary]);
+};
+
+/**
+ * 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;
+    }
+};
+
+/**
+ * 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.localURL, size]);
+};
+
+module.exports = FileWriter;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/Flags.js b/src/lib/plugins/cordova-plugin-file/www/Flags.js
new file mode 100644 (file)
index 0000000..dfac709
--- /dev/null
@@ -0,0 +1,38 @@
+cordova.define("cordova-plugin-file.Flags", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Supplies arguments to methods that lookup or create files and directories.
+ *
+ * @param create
+ *            {boolean} file or directory if it doesn't exist
+ * @param exclusive
+ *            {boolean} used with create; if true the command will fail if
+ *            target path exists
+ */
+function Flags(create, exclusive) {
+    this.create = create || false;
+    this.exclusive = exclusive || false;
+}
+
+module.exports = Flags;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/LocalFileSystem.js b/src/lib/plugins/cordova-plugin-file/www/LocalFileSystem.js
new file mode 100644 (file)
index 0000000..e424c10
--- /dev/null
@@ -0,0 +1,25 @@
+cordova.define("cordova-plugin-file.LocalFileSystem", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+exports.TEMPORARY = 0;
+exports.PERSISTENT = 1;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/Metadata.js b/src/lib/plugins/cordova-plugin-file/www/Metadata.js
new file mode 100644 (file)
index 0000000..efa4b3e
--- /dev/null
@@ -0,0 +1,42 @@
+cordova.define("cordova-plugin-file.Metadata", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+/**
+ * Information about the state of the file or directory
+ *
+ * {Date} modificationTime (readonly)
+ */
+var Metadata = function(metadata) {
+    if (typeof metadata == "object") {
+        this.modificationTime = new Date(metadata.modificationTime);
+        this.size = metadata.size || 0;
+    } else if (typeof metadata == "undefined") {
+        this.modificationTime = null;
+        this.size = 0;
+    } else {
+        /* Backwards compatiblity with platforms that only return a timestamp */
+        this.modificationTime = new Date(metadata);
+    }
+};
+
+module.exports = Metadata;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/ProgressEvent.js b/src/lib/plugins/cordova-plugin-file/www/ProgressEvent.js
new file mode 100644 (file)
index 0000000..0086f02
--- /dev/null
@@ -0,0 +1,69 @@
+cordova.define("cordova-plugin-file.ProgressEvent", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+// If ProgressEvent exists in global context, use it already, otherwise use our own polyfill
+// Feature test: See if we can instantiate a native ProgressEvent;
+// if so, use that approach,
+// otherwise fill-in with our own implementation.
+//
+// NOTE: right now we always fill in with our own. Down the road would be nice if we can use whatever is native in the webview.
+var ProgressEvent = (function() {
+    /*
+    var createEvent = function(data) {
+        var event = document.createEvent('Events');
+        event.initEvent('ProgressEvent', false, false);
+        if (data) {
+            for (var i in data) {
+                if (data.hasOwnProperty(i)) {
+                    event[i] = data[i];
+                }
+            }
+            if (data.target) {
+                // TODO: cannot call <some_custom_object>.dispatchEvent
+                // need to first figure out how to implement EventTarget
+            }
+        }
+        return event;
+    };
+    try {
+        var ev = createEvent({type:"abort",target:document});
+        return function ProgressEvent(type, data) {
+            data.type = type;
+            return createEvent(data);
+        };
+    } catch(e){
+    */
+        return function ProgressEvent(type, dict) {
+            this.type = type;
+            this.bubbles = false;
+            this.cancelBubble = false;
+            this.cancelable = false;
+            this.lengthComputable = false;
+            this.loaded = dict && dict.loaded ? dict.loaded : 0;
+            this.total = dict && dict.total ? dict.total : 0;
+            this.target = dict && dict.target ? dict.target : null;
+        };
+    //}
+})();
+
+module.exports = ProgressEvent;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/fileSystemPaths.js b/src/lib/plugins/cordova-plugin-file/www/fileSystemPaths.js
new file mode 100644 (file)
index 0000000..6e19528
--- /dev/null
@@ -0,0 +1,65 @@
+cordova.define("cordova-plugin-file.fileSystemPaths", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+var exec = require('cordova/exec');
+var channel = require('cordova/channel');
+
+exports.file = {
+    // Read-only directory where the application is installed.
+    applicationDirectory: null,
+    // Root of app's private writable storage
+    applicationStorageDirectory: null,
+    // Where to put app-specific data files.
+    dataDirectory: null,
+    // Cached files that should survive app restarts.
+    // Apps should not rely on the OS to delete files in here.
+    cacheDirectory: null,
+    // Android: the application space on external storage.
+    externalApplicationStorageDirectory: null,
+    // Android: Where to put app-specific data files on external storage.
+    externalDataDirectory: null,
+    // Android: the application cache on external storage.
+    externalCacheDirectory: null,
+    // Android: the external storage (SD card) root.
+    externalRootDirectory: null,
+    // iOS: Temp directory that the OS can clear at will.
+    tempDirectory: null,
+    // iOS: Holds app-specific files that should be synced (e.g. to iCloud).
+    syncedDataDirectory: null,
+    // iOS: Files private to the app, but that are meaningful to other applciations (e.g. Office files)
+    documentsDirectory: null,
+    // BlackBerry10: Files globally available to all apps
+    sharedDirectory: null
+};
+
+channel.waitForInitialization('onFileSystemPathsReady');
+channel.onCordovaReady.subscribe(function() {
+    function after(paths) {
+        for (var k in paths) {
+            exports.file[k] = paths[k];
+        }
+        channel.initializationComplete('onFileSystemPathsReady');
+    }
+    exec(after, null, 'File', 'requestAllPaths', []);
+});
+
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/fileSystems-roots.js b/src/lib/plugins/cordova-plugin-file/www/fileSystems-roots.js
new file mode 100644 (file)
index 0000000..187d111
--- /dev/null
@@ -0,0 +1,45 @@
+cordova.define("cordova-plugin-file.fileSystems-roots", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+// Map of fsName -> FileSystem.
+var fsMap = null;
+var FileSystem = require('./FileSystem');
+var exec = require('cordova/exec');
+
+// Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
+require('./fileSystems').getFs = function(name, callback) {
+    if (fsMap) {
+        callback(fsMap[name]);
+    } else {
+        exec(success, null, "File", "requestAllFileSystems", []);
+        function success(response) {
+            fsMap = {};
+            for (var i = 0; i < response.length; ++i) {
+                var fsRoot = response[i];
+                var fs = new FileSystem(fsRoot.filesystemName, fsRoot);
+                fsMap[fs.name] = fs;
+            }
+            callback(fsMap[name]);
+        }
+    }
+};
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/fileSystems.js b/src/lib/plugins/cordova-plugin-file/www/fileSystems.js
new file mode 100644 (file)
index 0000000..2b8084b
--- /dev/null
@@ -0,0 +1,27 @@
+cordova.define("cordova-plugin-file.fileSystems", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+// Overridden by Android, BlackBerry 10 and iOS to populate fsMap.
+module.exports.getFs = function(name, callback) {
+    callback(null);
+};
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/requestFileSystem.js b/src/lib/plugins/cordova-plugin-file/www/requestFileSystem.js
new file mode 100644 (file)
index 0000000..6626acc
--- /dev/null
@@ -0,0 +1,78 @@
+cordova.define("cordova-plugin-file.requestFileSystem", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+//For browser platform: not all browsers use this file.
+function checkBrowser() {
+    if (cordova.platformId === "browser" && navigator.userAgent.search(/Chrome/) > 0) {
+        var requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
+        module.exports = requestFileSystem;
+        return;
+    }
+}
+checkBrowser();
+
+var argscheck = require('cordova/argscheck'),
+    FileError = require('./FileError'),
+    FileSystem = require('./FileSystem'),
+    exec = require('cordova/exec');
+var fileSystems = require('./fileSystems');
+
+/**
+ * Request a file system in which to store application data.
+ * @param type  local file system type
+ * @param size  indicates how much storage space, in bytes, the application expects to need
+ * @param successCallback  invoked with a FileSystem object
+ * @param errorCallback  invoked if error occurs retrieving file system
+ */
+var requestFileSystem = function(type, size, successCallback, errorCallback) {
+    argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
+    var fail = function(code) {
+        errorCallback && errorCallback(new FileError(code));
+    };
+
+    if (type < 0) {
+        fail(FileError.SYNTAX_ERR);
+    } else {
+        // if successful, return a FileSystem object
+        var success = function(file_system) {
+            if (file_system) {
+                if (successCallback) {
+                    fileSystems.getFs(file_system.name, function(fs) {
+                        // This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
+                        if (!fs) {
+                            fs = new FileSystem(file_system.name, file_system.root);
+                        }
+                        successCallback(fs);
+                    });
+                }
+            }
+            else {
+                // no FileSystem object returned
+                fail(FileError.NOT_FOUND_ERR);
+            }
+        };
+        exec(success, fail, "File", "requestFileSystem", [type, size]);
+    }
+};
+
+module.exports = requestFileSystem;
+
+});
diff --git a/src/lib/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js b/src/lib/plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js
new file mode 100644 (file)
index 0000000..791a005
--- /dev/null
@@ -0,0 +1,89 @@
+cordova.define("cordova-plugin-file.resolveLocalFileSystemURI", function(require, exports, module) { /*
+ *
+ * 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.
+ *
+*/
+
+//For browser platform: not all browsers use overrided `resolveLocalFileSystemURL`.
+function checkBrowser() {
+    if (cordova.platformId === "browser" && navigator.userAgent.search(/Chrome/) > 0) {
+        var requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
+        module.exports = requestFileSystem;
+        return;
+    }
+}
+checkBrowser();
+
+var argscheck = require('cordova/argscheck'),
+    DirectoryEntry = require('./DirectoryEntry'),
+    FileEntry = require('./FileEntry'),
+    FileError = require('./FileError'),
+    exec = require('cordova/exec');
+var fileSystems = require('./fileSystems');
+
+/**
+ * Look up file system Entry referred to by local URI.
+ * @param {DOMString} uri  URI referring to a local file or directory
+ * @param successCallback  invoked with Entry object corresponding to URI
+ * @param errorCallback    invoked if error occurs retrieving file system entry
+ */
+module.exports.resolveLocalFileSystemURL = function(uri, successCallback, errorCallback) {
+    argscheck.checkArgs('sFF', 'resolveLocalFileSystemURI', arguments);
+    // error callback
+    var fail = function(error) {
+        errorCallback && errorCallback(new FileError(error));
+    };
+    // sanity check for 'not:valid:filename' or '/not:valid:filename'
+    // file.spec.12 window.resolveLocalFileSystemURI should error (ENCODING_ERR) when resolving invalid URI with leading /.
+    if(!uri || uri.split(":").length > 2) {
+        setTimeout( function() {
+            fail(FileError.ENCODING_ERR);
+        },0);
+        return;
+    }
+    // if successful, return either a file or directory entry
+    var success = function(entry) {
+        if (entry) {
+            if (successCallback) {
+                // create appropriate Entry object
+                var fsName = entry.filesystemName || (entry.filesystem && entry.filesystem.name) || (entry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary');
+                fileSystems.getFs(fsName, function(fs) {
+                    // This should happen only on platforms that haven't implemented requestAllFileSystems (windows)
+                    if (!fs) {
+                        fs = new FileSystem(fsName, {name:"", fullPath:"/"});
+                    }
+                    var result = (entry.isDirectory) ? new DirectoryEntry(entry.name, entry.fullPath, fs, entry.nativeURL) : new FileEntry(entry.name, entry.fullPath, fs, entry.nativeURL);
+                    successCallback(result);
+                });
+            }
+        }
+        else {
+            // no Entry object returned
+            fail(FileError.NOT_FOUND_ERR);
+        }
+    };
+
+    exec(success, fail, "File", "resolveLocalFileSystemURI", [uri]);
+};
+
+module.exports.resolveLocalFileSystemURI = function() {
+    console.log("resolveLocalFileSystemURI is deprecated. Please call resolveLocalFileSystemURL instead.");
+    module.exports.resolveLocalFileSystemURL.apply(this, arguments);
+};
+
+});
index c0d7704..f538820 100755 (executable)
@@ -217,10 +217,7 @@ Media.prototype.stopRecord = function(){};
 
 _global.Media = Media;
 
-cordova._broker.addEventListener('deviceready', function (event) {
-  if ('addEventListener' === event.fun) {
-    event.obj.dispatchEvent(new Event('deviceready'));
-  }
-});
-
 console.log('Loaded cordova.device API');
+
+exports = function(require) {
+};
index 4504096..660d226 100644 (file)
@@ -95,3 +95,6 @@ _global.navigator.connection = connection;
 _global.navigator.network = network;
 
 console.log('Loaded cordova.networkinformation API');
+
+exports = function(require) {
+};