diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/browser.json b/cordova-lib/spec-cordova/fixtures/platforms/browser/browser.json new file mode 100644 index 000000000..4b9f4c1fb --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/browser.json @@ -0,0 +1,252 @@ +{ + "prepare_queue": { + "installed": [], + "uninstalled": [] + }, + "config_munge": { + "files": { + "config.xml": { + "parents": { + "/*": [ + { + "xml": "", + "count": 1 + } + ] + } + } + } + }, + "installed_plugins": { + "cordova-plugin-compat": { + "PACKAGE_NAME": "com.example.hello" + }, + "cordova-plugin-camera": { + "PACKAGE_NAME": "com.example.hello" + }, + "cordova-plugin-file": { + "PACKAGE_NAME": "com.example.hello" + }, + "cordova-plugin-whitelist": { + "PACKAGE_NAME": "com.example.hello" + } + }, + "dependent_plugins": {}, + "modules": [ + { + "file": "plugins/cordova-plugin-camera/www/CameraConstants.js", + "id": "cordova-plugin-camera.Camera", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "Camera" + ] + }, + { + "file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js", + "id": "cordova-plugin-camera.CameraPopoverOptions", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "CameraPopoverOptions" + ] + }, + { + "file": "plugins/cordova-plugin-camera/www/Camera.js", + "id": "cordova-plugin-camera.camera", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "navigator.camera" + ] + }, + { + "file": "plugins/cordova-plugin-camera/src/browser/CameraProxy.js", + "id": "cordova-plugin-camera.CameraProxy", + "pluginId": "cordova-plugin-camera", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js", + "id": "cordova-plugin-file.DirectoryEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryReader.js", + "id": "cordova-plugin-file.DirectoryReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Entry.js", + "id": "cordova-plugin-file.Entry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Entry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/File.js", + "id": "cordova-plugin-file.File", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.File" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileEntry.js", + "id": "cordova-plugin-file.FileEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileError.js", + "id": "cordova-plugin-file.FileError", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileError" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileReader.js", + "id": "cordova-plugin-file.FileReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileSystem.js", + "id": "cordova-plugin-file.FileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js", + "id": "cordova-plugin-file.FileUploadOptions", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadOptions" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadResult.js", + "id": "cordova-plugin-file.FileUploadResult", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadResult" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileWriter.js", + "id": "cordova-plugin-file.FileWriter", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileWriter" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Flags.js", + "id": "cordova-plugin-file.Flags", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Flags" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js", + "id": "cordova-plugin-file.LocalFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.LocalFileSystem" + ], + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Metadata.js", + "id": "cordova-plugin-file.Metadata", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Metadata" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/ProgressEvent.js", + "id": "cordova-plugin-file.ProgressEvent", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.ProgressEvent" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems.js", + "id": "cordova-plugin-file.fileSystems", + "pluginId": "cordova-plugin-file" + }, + { + "file": "plugins/cordova-plugin-file/www/requestFileSystem.js", + "id": "cordova-plugin-file.requestFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.requestFileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.resolveLocalFileSystemURI", + "pluginId": "cordova-plugin-file", + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/browser/isChrome.js", + "id": "cordova-plugin-file.isChrome", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/browser/Preparing.js", + "id": "cordova-plugin-file.Preparing", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/src/browser/FileProxy.js", + "id": "cordova-plugin-file.browserFileProxy", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js", + "id": "cordova-plugin-file.fileSystemPaths", + "pluginId": "cordova-plugin-file", + "merges": [ + "cordova" + ], + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/browser/FileSystem.js", + "id": "cordova-plugin-file.firefoxFileSystem", + "pluginId": "cordova-plugin-file", + "merges": [ + "window.FileSystem" + ] + } + ], + "plugin_metadata": { + "cordova-plugin-compat": "1.1.0", + "cordova-plugin-camera": "2.3.1", + "cordova-plugin-file": "4.3.1", + "cordova-plugin-whitelist": "1.3.1" + } +} \ No newline at end of file diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/config.xml b/cordova-lib/spec-cordova/fixtures/platforms/browser/config.xml new file mode 100644 index 000000000..4b015fca0 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/config.xml @@ -0,0 +1,21 @@ + + + + + + HelloWorld + + This is the project created from the template: PhoneGap WebVR Boilerplate. + + + Apache Cordova Team + + + + + + + + + + diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/build b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/build similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/build rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/build diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/build.bat b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/build.bat similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/build.bat rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/build.bat diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/clean b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/clean old mode 100644 new mode 100755 similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/clean rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/clean diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/defaults.xml b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/defaults.xml similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/defaults.xml rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/defaults.xml diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/lib/build.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/build.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/lib/build.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/build.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/lib/check_reqs.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/check_reqs.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/lib/check_reqs.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/check_reqs.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/lib/clean.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/clean.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/lib/clean.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/lib/clean.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/run b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/run similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/run rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/run diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/run.bat b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/run.bat similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/run.bat rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/run.bat diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/version b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/version similarity index 97% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/version rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/version index 8acf18f92..8a13bae70 100755 --- a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/version +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/version @@ -20,6 +20,6 @@ */ // Coho updates this line: -var VERSION = "4.2.0-dev"; +var VERSION = "4.1.0"; console.log(VERSION); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/version.bat b/cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/version.bat similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/cordova/version.bat rename to cordova-lib/spec-cordova/fixtures/platforms/browser/cordova/version.bat diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/css/index.css b/cordova-lib/spec-cordova/fixtures/platforms/browser/css/index.css similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/css/index.css rename to cordova-lib/spec-cordova/fixtures/platforms/browser/css/index.css diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/img/logo.png b/cordova-lib/spec-cordova/fixtures/platforms/browser/img/logo.png similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/img/logo.png rename to cordova-lib/spec-cordova/fixtures/platforms/browser/img/logo.png diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/index.html b/cordova-lib/spec-cordova/fixtures/platforms/browser/index.html similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/index.html rename to cordova-lib/spec-cordova/fixtures/platforms/browser/index.html diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/js/index.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/js/index.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/js/index.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/js/index.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/manifest.webapp b/cordova-lib/spec-cordova/fixtures/platforms/browser/manifest.webapp similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/bin/templates/project/www/manifest.webapp rename to cordova-lib/spec-cordova/fixtures/platforms/browser/manifest.webapp diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/package.json b/cordova-lib/spec-cordova/fixtures/platforms/browser/package.json new file mode 100644 index 000000000..63c589ce1 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/package.json @@ -0,0 +1,11 @@ +{ + "name": "testbase1", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC" +} \ No newline at end of file diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/confighelper.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/confighelper.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/confighelper.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/confighelper.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/confighelper.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/confighelper.js new file mode 100644 index 000000000..b6d606e27 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/confighelper.js @@ -0,0 +1,95 @@ +/* + * + * 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 config; + +function Config(xhr) { + function loadPreferences(xhr) { + var parser = new DOMParser(); + var doc = parser.parseFromString(xhr.responseText, "application/xml"); + + var preferences = doc.getElementsByTagName("preference"); + return Array.prototype.slice.call(preferences); + } + + this.xhr = xhr; + this.preferences = loadPreferences(this.xhr); +} + +function readConfig(success, error) { + var xhr; + + if(typeof config != 'undefined') { + success(config); + } + + function fail(msg) { + console.error(msg); + + if(error) { + error(msg); + } + } + + var xhrStatusChangeHandler = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 /* file:// */) { + config = new Config(xhr); + success(config); + } + else { + fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText); + } + } + }; + + if ("ActiveXObject" in window) { + // Needed for XHR-ing via file:// protocol in IE + xhr = new window.ActiveXObject("MSXML2.XMLHTTP"); + xhr.onreadystatechange = xhrStatusChangeHandler; + } else { + xhr = new XMLHttpRequest(); + xhr.addEventListener("load", xhrStatusChangeHandler); + } + + try { + xhr.open("get", "/config.xml", true); + xhr.send(); + } catch(e) { + fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e)); + } +} + +/** + * Reads a preference value from config.xml. + * Returns preference value or undefined if it does not exist. + * @param {String} preferenceName Preference name to read */ +Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) { + var preferenceItem = this.preferences && this.preferences.filter(function(item) { + return item.attributes.name && item.attributes.name.value === preferenceName; + }); + + if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) { + return preferenceItem[0].attributes.value.value; + } +}; + +exports.readConfig = readConfig; diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/exec.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/exec.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/exec.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/exec.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/platform.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/platform.js similarity index 100% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-js-src/platform.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova-js-src/platform.js diff --git a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-lib/cordova.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova.js similarity index 99% rename from cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-lib/cordova.js rename to cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova.js index d2edd37ff..80ad30269 100644 --- a/cordova-lib/spec-cordova/fixtures/platforms/cordova-browser/cordova-lib/cordova.js +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova.js @@ -19,7 +19,7 @@ under the License. */ ;(function() { -var PLATFORM_VERSION_BUILD_LABEL = '4.2.0-dev'; +var PLATFORM_VERSION_BUILD_LABEL = '4.1.0'; // file: src/scripts/require.js /*jshint -W079 */ diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova_plugins.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova_plugins.js new file mode 100644 index 000000000..1aba0863b --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/cordova_plugins.js @@ -0,0 +1,222 @@ +cordova.define('cordova/plugin_list', function(require, exports, module) { +module.exports = [ + { + "file": "plugins/cordova-plugin-camera/www/CameraConstants.js", + "id": "cordova-plugin-camera.Camera", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "Camera" + ] + }, + { + "file": "plugins/cordova-plugin-camera/www/CameraPopoverOptions.js", + "id": "cordova-plugin-camera.CameraPopoverOptions", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "CameraPopoverOptions" + ] + }, + { + "file": "plugins/cordova-plugin-camera/www/Camera.js", + "id": "cordova-plugin-camera.camera", + "pluginId": "cordova-plugin-camera", + "clobbers": [ + "navigator.camera" + ] + }, + { + "file": "plugins/cordova-plugin-camera/src/browser/CameraProxy.js", + "id": "cordova-plugin-camera.CameraProxy", + "pluginId": "cordova-plugin-camera", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryEntry.js", + "id": "cordova-plugin-file.DirectoryEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/DirectoryReader.js", + "id": "cordova-plugin-file.DirectoryReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.DirectoryReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Entry.js", + "id": "cordova-plugin-file.Entry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Entry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/File.js", + "id": "cordova-plugin-file.File", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.File" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileEntry.js", + "id": "cordova-plugin-file.FileEntry", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileEntry" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileError.js", + "id": "cordova-plugin-file.FileError", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileError" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileReader.js", + "id": "cordova-plugin-file.FileReader", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileReader" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileSystem.js", + "id": "cordova-plugin-file.FileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadOptions.js", + "id": "cordova-plugin-file.FileUploadOptions", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadOptions" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileUploadResult.js", + "id": "cordova-plugin-file.FileUploadResult", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileUploadResult" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/FileWriter.js", + "id": "cordova-plugin-file.FileWriter", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.FileWriter" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Flags.js", + "id": "cordova-plugin-file.Flags", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Flags" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/LocalFileSystem.js", + "id": "cordova-plugin-file.LocalFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.LocalFileSystem" + ], + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/Metadata.js", + "id": "cordova-plugin-file.Metadata", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.Metadata" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/ProgressEvent.js", + "id": "cordova-plugin-file.ProgressEvent", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.ProgressEvent" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystems.js", + "id": "cordova-plugin-file.fileSystems", + "pluginId": "cordova-plugin-file" + }, + { + "file": "plugins/cordova-plugin-file/www/requestFileSystem.js", + "id": "cordova-plugin-file.requestFileSystem", + "pluginId": "cordova-plugin-file", + "clobbers": [ + "window.requestFileSystem" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/resolveLocalFileSystemURI.js", + "id": "cordova-plugin-file.resolveLocalFileSystemURI", + "pluginId": "cordova-plugin-file", + "merges": [ + "window" + ] + }, + { + "file": "plugins/cordova-plugin-file/www/browser/isChrome.js", + "id": "cordova-plugin-file.isChrome", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/browser/Preparing.js", + "id": "cordova-plugin-file.Preparing", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/src/browser/FileProxy.js", + "id": "cordova-plugin-file.browserFileProxy", + "pluginId": "cordova-plugin-file", + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/fileSystemPaths.js", + "id": "cordova-plugin-file.fileSystemPaths", + "pluginId": "cordova-plugin-file", + "merges": [ + "cordova" + ], + "runs": true + }, + { + "file": "plugins/cordova-plugin-file/www/browser/FileSystem.js", + "id": "cordova-plugin-file.firefoxFileSystem", + "pluginId": "cordova-plugin-file", + "merges": [ + "window.FileSystem" + ] + } +]; +module.exports.metadata = +// TOP OF METADATA +{ + "cordova-plugin-compat": "1.1.0", + "cordova-plugin-camera": "2.3.1", + "cordova-plugin-file": "4.3.1", + "cordova-plugin-whitelist": "1.3.1" +} +// BOTTOM OF METADATA +}); \ No newline at end of file diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/exec.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/exec.js new file mode 100644 index 000000000..97f736a26 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/exec.js @@ -0,0 +1,114 @@ +/* + * + * 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. + * +*/ + +/*jslint sloppy:true, plusplus:true*/ +/*global require, module, console */ + +var cordova = require('cordova'); +var execProxy = require('cordova/exec/proxy'); + +/** + * Execute a cordova command. It is up to the native side whether this action + * is synchronous or asynchronous. The native side can return: + * Synchronous: PluginResult object as a JSON string + * Asynchronous: Empty string "" + * If async, the native side will cordova.callbackSuccess or cordova.callbackError, + * depending upon the result of the action. + * + * @param {Function} success The success callback + * @param {Function} fail The fail callback + * @param {String} service The name of the service to use + * @param {String} action Action to be run in cordova + * @param {String[]} [args] Zero or more arguments to pass to the method + */ +module.exports = function (success, fail, service, action, args) { + + var proxy = execProxy.get(service, action); + + args = args || []; + + if (proxy) { + + var callbackId = service + cordova.callbackId++; + + if (typeof success === "function" || typeof fail === "function") { + cordova.callbacks[callbackId] = {success: success, fail: fail}; + } + try { + + + + // callbackOptions param represents additional optional parameters command could pass back, like keepCallback or + // custom callbackId, for example {callbackId: id, keepCallback: true, status: cordova.callbackStatus.JSON_EXCEPTION } + var onSuccess = function (result, callbackOptions) { + callbackOptions = callbackOptions || {}; + var callbackStatus; + // covering both undefined and null. + // strict null comparison was causing callbackStatus to be undefined + // and then no callback was called because of the check in cordova.callbackFromNative + // see CB-8996 Mobilespec app hang on windows + if (callbackOptions.status !== undefined && callbackOptions.status !== null) { + callbackStatus = callbackOptions.status; + } + else { + callbackStatus = cordova.callbackStatus.OK; + } + cordova.callbackSuccess(callbackOptions.callbackId || callbackId, + { + status: callbackStatus, + message: result, + keepCallback: callbackOptions.keepCallback || false + }); + }; + var onError = function (err, callbackOptions) { + callbackOptions = callbackOptions || {}; + var callbackStatus; + // covering both undefined and null. + // strict null comparison was causing callbackStatus to be undefined + // and then no callback was called because of the check in cordova.callbackFromNative + // note: status can be 0 + if (callbackOptions.status !== undefined && callbackOptions.status !== null) { + callbackStatus = callbackOptions.status; + } + else { + callbackStatus = cordova.callbackStatus.OK; + } + cordova.callbackError(callbackOptions.callbackId || callbackId, + { + status: callbackStatus, + message: err, + keepCallback: callbackOptions.keepCallback || false + }); + }; + proxy(onSuccess, onError, args); + + } catch (e) { + console.log("Exception calling native with command :: " + service + " :: " + action + " ::exception=" + e); + } + } else { + + console.log("Error: exec proxy not found for :: " + service + " :: " + action); + + if(typeof fail === "function" ) { + fail("Missing Command Error"); + } + } +}; diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/platform.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/platform.js new file mode 100644 index 000000000..051405945 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/platform.js @@ -0,0 +1,48 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +module.exports = { + id: 'browser', + cordovaVersion: '3.4.0', + + bootstrap: function() { + + var modulemapper = require('cordova/modulemapper'); + var channel = require('cordova/channel'); + + modulemapper.clobbers('cordova/exec/proxy', 'cordova.commandProxy'); + + 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 + } +}; diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/src/browser/CameraProxy.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/src/browser/CameraProxy.js new file mode 100644 index 000000000..021870621 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/src/browser/CameraProxy.js @@ -0,0 +1,125 @@ +cordova.define("cordova-plugin-camera.CameraProxy", 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 HIGHEST_POSSIBLE_Z_INDEX = 2147483647; + +function takePicture(success, error, opts) { + if (opts && opts[2] === 1) { + capture(success, error, opts); + } else { + var input = document.createElement('input'); + input.style.position = 'relative'; + input.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX; + input.className = 'cordova-camera-select'; + input.type = 'file'; + input.name = 'files[]'; + + input.onchange = function(inputEvent) { + var reader = new FileReader(); + reader.onload = function(readerEvent) { + input.parentNode.removeChild(input); + + var imageData = readerEvent.target.result; + + return success(imageData.substr(imageData.indexOf(',') + 1)); + }; + + reader.readAsDataURL(inputEvent.target.files[0]); + }; + + document.body.appendChild(input); + } +} + +function capture(success, errorCallback, opts) { + var localMediaStream; + var targetWidth = opts[3]; + var targetHeight = opts[4]; + + targetWidth = targetWidth == -1?320:targetWidth; + targetHeight = targetHeight == -1?240:targetHeight; + + var video = document.createElement('video'); + var button = document.createElement('button'); + var parent = document.createElement('div'); + parent.style.position = 'relative'; + parent.style.zIndex = HIGHEST_POSSIBLE_Z_INDEX; + parent.className = 'cordova-camera-capture'; + parent.appendChild(video); + parent.appendChild(button); + + video.width = targetWidth; + video.height = targetHeight; + button.innerHTML = 'Capture!'; + + button.onclick = function() { + // create a canvas and capture a frame from video stream + var canvas = document.createElement('canvas'); + canvas.width = targetWidth; + canvas.height = targetHeight; + canvas.getContext('2d').drawImage(video, 0, 0, targetWidth, targetHeight); + + // convert image stored in canvas to base64 encoded image + var imageData = canvas.toDataURL('image/png'); + imageData = imageData.replace('data:image/png;base64,', ''); + + // stop video stream, remove video and button. + // Note that MediaStream.stop() is deprecated as of Chrome 47. + if (localMediaStream.stop) { + localMediaStream.stop(); + } else { + localMediaStream.getTracks().forEach(function (track) { + track.stop(); + }); + } + parent.parentNode.removeChild(parent); + + return success(imageData); + }; + + navigator.getUserMedia = navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia || + navigator.msGetUserMedia; + + var successCallback = function(stream) { + localMediaStream = stream; + video.src = window.URL.createObjectURL(localMediaStream); + video.play(); + + document.body.appendChild(parent); + }; + + if (navigator.getUserMedia) { + navigator.getUserMedia({video: true, audio: true}, successCallback, errorCallback); + } else { + alert('Browser does not support camera :('); + } +} + +module.exports = { + takePicture: takePicture, + cleanup: function(){} +}; + +require("cordova/exec/proxy").add("Camera",module.exports); + +}); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/Camera.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/Camera.js new file mode 100644 index 000000000..83be47c4a --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/Camera.js @@ -0,0 +1,187 @@ +cordova.define("cordova-plugin-camera.camera", 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'), + Camera = require('./Camera'); + // XXX: commented out + //CameraPopoverHandle = require('./CameraPopoverHandle'); + +/** + * @namespace navigator + */ + +/** + * @exports camera + */ +var cameraExport = {}; + +// Tack on the Camera Constants to the base camera plugin. +for (var key in Camera) { + cameraExport[key] = Camera[key]; +} + +/** + * Callback function that provides an error message. + * @callback module:camera.onError + * @param {string} message - The message is provided by the device's native code. + */ + +/** + * Callback function that provides the image data. + * @callback module:camera.onSuccess + * @param {string} imageData - Base64 encoding of the image data, _or_ the image file URI, depending on [`cameraOptions`]{@link module:camera.CameraOptions} in effect. + * @example + * // Show image + * // + * function cameraCallback(imageData) { + * var image = document.getElementById('myImage'); + * image.src = "data:image/jpeg;base64," + imageData; + * } + */ + +/** + * Optional parameters to customize the camera settings. + * * [Quirks](#CameraOptions-quirks) + * @typedef module:camera.CameraOptions + * @type {Object} + * @property {number} [quality=50] - Quality of the saved image, expressed as a range of 0-100, where 100 is typically full resolution with no loss from file compression. (Note that information about the camera's resolution is unavailable.) + * @property {module:Camera.DestinationType} [destinationType=FILE_URI] - Choose the format of the return value. + * @property {module:Camera.PictureSourceType} [sourceType=CAMERA] - Set the source of the picture. + * @property {Boolean} [allowEdit=true] - Allow simple editing of image before selection. + * @property {module:Camera.EncodingType} [encodingType=JPEG] - Choose the returned image file's encoding. + * @property {number} [targetWidth] - Width in pixels to scale image. Must be used with `targetHeight`. Aspect ratio remains constant. + * @property {number} [targetHeight] - Height in pixels to scale image. Must be used with `targetWidth`. Aspect ratio remains constant. + * @property {module:Camera.MediaType} [mediaType=PICTURE] - Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. + * @property {Boolean} [correctOrientation] - Rotate the image to correct for the orientation of the device during capture. + * @property {Boolean} [saveToPhotoAlbum] - Save the image to the photo album on the device after capture. + * @property {module:CameraPopoverOptions} [popoverOptions] - iOS-only options that specify popover location in iPad. + * @property {module:Camera.Direction} [cameraDirection=BACK] - Choose the camera to use (front- or back-facing). + */ + +/** + * @description Takes a photo using the camera, or retrieves a photo from the device's + * image gallery. The image is passed to the success callback as a + * Base64-encoded `String`, or as the URI for the image file. + * + * The `camera.getPicture` function opens the device's default camera + * application that allows users to snap pictures by default - this behavior occurs, + * when `Camera.sourceType` equals [`Camera.PictureSourceType.CAMERA`]{@link module:Camera.PictureSourceType}. + * Once the user snaps the photo, the camera application closes and the application is restored. + * + * If `Camera.sourceType` is `Camera.PictureSourceType.PHOTOLIBRARY` or + * `Camera.PictureSourceType.SAVEDPHOTOALBUM`, then a dialog displays + * that allows users to select an existing image. + * + * The return value is sent to the [`cameraSuccess`]{@link module:camera.onSuccess} callback function, in + * one of the following formats, depending on the specified + * `cameraOptions`: + * + * - A `String` containing the Base64-encoded photo image. + * - A `String` representing the image file location on local storage (default). + * + * You can do whatever you want with the encoded image or URI, for + * example: + * + * - Render the image in an `` tag, as in the example below + * - Save the data locally (`LocalStorage`, [Lawnchair](http://brianleroux.github.com/lawnchair/), etc.) + * - Post the data to a remote server + * + * __NOTE__: Photo resolution on newer devices is quite good. Photos + * selected from the device's gallery are not downscaled to a lower + * quality, even if a `quality` parameter is specified. To avoid common + * memory problems, set `Camera.destinationType` to `FILE_URI` rather + * than `DATA_URL`. + * + * __Supported Platforms__ + * + * - Android + * - BlackBerry + * - Browser + * - Firefox + * - FireOS + * - iOS + * - Windows + * - WP8 + * - Ubuntu + * + * More examples [here](#camera-getPicture-examples). Quirks [here](#camera-getPicture-quirks). + * + * @example + * navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions); + * @param {module:camera.onSuccess} successCallback + * @param {module:camera.onError} errorCallback + * @param {module:camera.CameraOptions} options CameraOptions + */ +cameraExport.getPicture = function(successCallback, errorCallback, options) { + argscheck.checkArgs('fFO', 'Camera.getPicture', arguments); + options = options || {}; + var getValue = argscheck.getValue; + + var quality = getValue(options.quality, 50); + var destinationType = getValue(options.destinationType, Camera.DestinationType.FILE_URI); + var sourceType = getValue(options.sourceType, Camera.PictureSourceType.CAMERA); + var targetWidth = getValue(options.targetWidth, -1); + var targetHeight = getValue(options.targetHeight, -1); + var encodingType = getValue(options.encodingType, Camera.EncodingType.JPEG); + var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE); + var allowEdit = !!options.allowEdit; + var correctOrientation = !!options.correctOrientation; + var saveToPhotoAlbum = !!options.saveToPhotoAlbum; + var popoverOptions = getValue(options.popoverOptions, null); + var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK); + + var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, + mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection]; + + exec(successCallback, errorCallback, "Camera", "takePicture", args); + // XXX: commented out + //return new CameraPopoverHandle(); +}; + +/** + * Removes intermediate image files that are kept in temporary storage + * after calling [`camera.getPicture`]{@link module:camera.getPicture}. Applies only when the value of + * `Camera.sourceType` equals `Camera.PictureSourceType.CAMERA` and the + * `Camera.destinationType` equals `Camera.DestinationType.FILE_URI`. + * + * __Supported Platforms__ + * + * - iOS + * + * @example + * navigator.camera.cleanup(onSuccess, onFail); + * + * function onSuccess() { + * console.log("Camera cleanup success.") + * } + * + * function onFail(message) { + * alert('Failed because: ' + message); + * } + */ +cameraExport.cleanup = function(successCallback, errorCallback) { + exec(successCallback, errorCallback, "Camera", "cleanup", []); +}; + +module.exports = cameraExport; + +}); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraConstants.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraConstants.js new file mode 100644 index 000000000..ac78ad60f --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraConstants.js @@ -0,0 +1,103 @@ +cordova.define("cordova-plugin-camera.Camera", 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. + * +*/ + +/** + * @module Camera + */ +module.exports = { + /** + * @description + * Defines the output format of `Camera.getPicture` call. + * _Note:_ On iOS passing `DestinationType.NATIVE_URI` along with + * `PictureSourceType.PHOTOLIBRARY` or `PictureSourceType.SAVEDPHOTOALBUM` will + * disable any image modifications (resize, quality change, cropping, etc.) due + * to implementation specific. + * + * @enum {number} + */ + DestinationType:{ + /** Return base64 encoded string. DATA_URL can be very memory intensive and cause app crashes or out of memory errors. Use FILE_URI or NATIVE_URI if possible */ + DATA_URL: 0, + /** Return file uri (content://media/external/images/media/2 for Android) */ + FILE_URI: 1, + /** Return native uri (eg. asset-library://... for iOS) */ + NATIVE_URI: 2 + }, + /** + * @enum {number} + */ + EncodingType:{ + /** Return JPEG encoded image */ + JPEG: 0, + /** Return PNG encoded image */ + PNG: 1 + }, + /** + * @enum {number} + */ + MediaType:{ + /** Allow selection of still pictures only. DEFAULT. Will return format specified via DestinationType */ + PICTURE: 0, + /** Allow selection of video only, ONLY RETURNS URL */ + VIDEO: 1, + /** Allow selection from all media types */ + ALLMEDIA : 2 + }, + /** + * @description + * Defines the output format of `Camera.getPicture` call. + * _Note:_ On iOS passing `PictureSourceType.PHOTOLIBRARY` or `PictureSourceType.SAVEDPHOTOALBUM` + * along with `DestinationType.NATIVE_URI` will disable any image modifications (resize, quality + * change, cropping, etc.) due to implementation specific. + * + * @enum {number} + */ + PictureSourceType:{ + /** Choose image from the device's photo library (same as SAVEDPHOTOALBUM for Android) */ + PHOTOLIBRARY : 0, + /** Take picture from camera */ + CAMERA : 1, + /** Choose image only from the device's Camera Roll album (same as PHOTOLIBRARY for Android) */ + SAVEDPHOTOALBUM : 2 + }, + /** + * Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover. + * @enum {number} + */ + PopoverArrowDirection:{ + ARROW_UP : 1, + ARROW_DOWN : 2, + ARROW_LEFT : 4, + ARROW_RIGHT : 8, + ARROW_ANY : 15 + }, + /** + * @enum {number} + */ + Direction:{ + /** Use the back-facing camera */ + BACK: 0, + /** Use the front-facing camera */ + FRONT: 1 + } +}; + +}); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraPopoverOptions.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraPopoverOptions.js new file mode 100644 index 000000000..08d20d3f3 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-camera/www/CameraPopoverOptions.js @@ -0,0 +1,54 @@ +cordova.define("cordova-plugin-camera.CameraPopoverOptions", 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 Camera = require('./Camera'); + +/** + * @namespace navigator + */ + +/** + * iOS-only parameters that specify the anchor element location and arrow + * direction of the popover when selecting images from an iPad's library + * or album. + * Note that the size of the popover may change to adjust to the + * direction of the arrow and orientation of the screen. Make sure to + * account for orientation changes when specifying the anchor element + * location. + * @module CameraPopoverOptions + * @param {Number} [x=0] - x pixel coordinate of screen element onto which to anchor the popover. + * @param {Number} [y=32] - y pixel coordinate of screen element onto which to anchor the popover. + * @param {Number} [width=320] - width, in pixels, of the screen element onto which to anchor the popover. + * @param {Number} [height=480] - height, in pixels, of the screen element onto which to anchor the popover. + * @param {module:Camera.PopoverArrowDirection} [arrowDir=ARROW_ANY] - Direction the arrow on the popover should point. + */ +var CameraPopoverOptions = function (x, y, width, height, arrowDir) { + // information of rectangle that popover should be anchored to + this.x = x || 0; + this.y = y || 32; + this.width = width || 320; + this.height = height || 480; + this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY; +}; + +module.exports = CameraPopoverOptions; + +}); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/src/browser/FileProxy.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/src/browser/FileProxy.js new file mode 100644 index 000000000..ed3b61fc7 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/src/browser/FileProxy.js @@ -0,0 +1,986 @@ +cordova.define("cordova-plugin-file.browserFileProxy", 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. + * + */ +(function() { + /*global require, exports, module*/ + /*global FILESYSTEM_PREFIX*/ + /*global IDBKeyRange*/ + + /* Heavily based on https://github.com/ebidel/idb.filesystem.js */ + + // For chrome we don't need to implement proxy methods + // All functionality can be accessed natively. + if (require('./isChrome')()) { + var pathsPrefix = { + // Read-only directory where the application is installed. + applicationDirectory: location.origin + "/", + // Where to put app-specific data files. + dataDirectory: 'filesystem:file:///persistent/', + // Cached files that should survive app restarts. + // Apps should not rely on the OS to delete files in here. + cacheDirectory: 'filesystem:file:///temporary/', + }; + + exports.requestAllPaths = function(successCallback) { + successCallback(pathsPrefix); + }; + + require("cordova/exec/proxy").add("File", module.exports); + return; + } + + var LocalFileSystem = require('./LocalFileSystem'), + FileSystem = require('./FileSystem'), + FileEntry = require('./FileEntry'), + FileError = require('./FileError'), + DirectoryEntry = require('./DirectoryEntry'), + File = require('./File'); + + (function(exports, global) { + var indexedDB = global.indexedDB || global.mozIndexedDB; + if (!indexedDB) { + throw "Firefox OS File plugin: indexedDB not supported"; + } + + var fs_ = null; + + var idb_ = {}; + idb_.db = null; + var FILE_STORE_ = 'entries'; + + var DIR_SEPARATOR = '/'; + + var pathsPrefix = { + // Read-only directory where the application is installed. + applicationDirectory: location.origin + "/", + // Where to put app-specific data files. + dataDirectory: 'file:///persistent/', + // Cached files that should survive app restarts. + // Apps should not rely on the OS to delete files in here. + cacheDirectory: 'file:///temporary/', + }; + + var unicodeLastChar = 65535; + + /*** Exported functionality ***/ + + exports.requestFileSystem = function(successCallback, errorCallback, args) { + var type = args[0]; + // Size is ignored since IDB filesystem size depends + // on browser implementation and can't be set up by user + var size = args[1]; // jshint ignore: line + + if (type !== LocalFileSystem.TEMPORARY && type !== LocalFileSystem.PERSISTENT) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + var name = type === LocalFileSystem.TEMPORARY ? 'temporary' : 'persistent'; + var storageName = (location.protocol + location.host).replace(/:/g, '_'); + + var root = new DirectoryEntry('', DIR_SEPARATOR); + fs_ = new FileSystem(name, root); + + idb_.open(storageName, function() { + successCallback(fs_); + }, errorCallback); + }; + + // Overridden by Android, BlackBerry 10 and iOS to populate fsMap + require('./fileSystems').getFs = function(name, callback) { + callback(new FileSystem(name, fs_.root)); + }; + + // list a directory's contents (files and folders). + exports.readEntries = function(successCallback, errorCallback, args) { + var fullPath = args[0]; + + if (typeof successCallback !== 'function') { + throw Error('Expected successCallback argument.'); + } + + var path = resolveToFullPath_(fullPath); + + exports.getDirectory(function() { + idb_.getAllEntries(path.fullPath + DIR_SEPARATOR, path.storagePath, function(entries) { + successCallback(entries); + }, errorCallback); + }, function() { + if (errorCallback) { + errorCallback(FileError.NOT_FOUND_ERR); + } + }, [path.storagePath, path.fullPath, {create: false}]); + }; + + exports.getFile = function(successCallback, errorCallback, args) { + var fullPath = args[0]; + var path = args[1]; + var options = args[2] || {}; + + // Create an absolute path if we were handed a relative one. + path = resolveToFullPath_(fullPath, path); + + idb_.get(path.storagePath, function(fileEntry) { + if (options.create === true && options.exclusive === true && fileEntry) { + // If create and exclusive are both true, and the path already exists, + // getFile must fail. + + if (errorCallback) { + errorCallback(FileError.PATH_EXISTS_ERR); + } + } else if (options.create === true && !fileEntry) { + // If create is true, the path doesn't exist, and no other error occurs, + // getFile must create it as a zero-length file and return a corresponding + // FileEntry. + var newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root)); + + newFileEntry.file_ = new MyFile({ + size: 0, + name: newFileEntry.name, + lastModifiedDate: new Date(), + storagePath: path.storagePath + }); + + idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback); + } else if (options.create === true && fileEntry) { + if (fileEntry.isFile) { + // Overwrite file, delete then create new. + idb_['delete'](path.storagePath, function() { + var newFileEntry = new FileEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root)); + + newFileEntry.file_ = new MyFile({ + size: 0, + name: newFileEntry.name, + lastModifiedDate: new Date(), + storagePath: path.storagePath + }); + + idb_.put(newFileEntry, path.storagePath, successCallback, errorCallback); + }, errorCallback); + } else { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + } + } else if ((!options.create || options.create === false) && !fileEntry) { + // If create is not true and the path doesn't exist, getFile must fail. + if (errorCallback) { + errorCallback(FileError.NOT_FOUND_ERR); + } + } else if ((!options.create || options.create === false) && fileEntry && + fileEntry.isDirectory) { + // If create is not true and the path exists, but is a directory, getFile + // must fail. + if (errorCallback) { + errorCallback(FileError.TYPE_MISMATCH_ERR); + } + } else { + // Otherwise, if no other error occurs, getFile must return a FileEntry + // corresponding to path. + + successCallback(fileEntryFromIdbEntry(fileEntry)); + } + }, errorCallback); + }; + + exports.getFileMetadata = function(successCallback, errorCallback, args) { + var fullPath = args[0]; + + exports.getFile(function(fileEntry) { + successCallback(new File(fileEntry.file_.name, fileEntry.fullPath, '', fileEntry.file_.lastModifiedDate, + fileEntry.file_.size)); + }, errorCallback, [fullPath, null]); + }; + + exports.getMetadata = function(successCallback, errorCallback, args) { + exports.getFile(function (fileEntry) { + successCallback( + { + modificationTime: fileEntry.file_.lastModifiedDate, + size: fileEntry.file_.lastModifiedDate + }); + }, errorCallback, args); + }; + + exports.setMetadata = function(successCallback, errorCallback, args) { + var fullPath = args[0]; + var metadataObject = args[1]; + + exports.getFile(function (fileEntry) { + fileEntry.file_.lastModifiedDate = metadataObject.modificationTime; + idb_.put(fileEntry, fileEntry.file_.storagePath, successCallback, errorCallback); + }, errorCallback, [fullPath, null]); + }; + + exports.write = function(successCallback, errorCallback, args) { + var fileName = args[0], + data = args[1], + position = args[2], + isBinary = args[3]; // jshint ignore: line + + if (!data) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + if (typeof data === 'string' || data instanceof String) { + data = new Blob([data]); + } + + exports.getFile(function(fileEntry) { + var blob_ = fileEntry.file_.blob_; + + if (!blob_) { + blob_ = new Blob([data], {type: data.type}); + } else { + // Calc the head and tail fragments + var head = blob_.slice(0, position); + var tail = blob_.slice(position + (data.size || data.byteLength)); + + // Calc the padding + var padding = position - head.size; + if (padding < 0) { + padding = 0; + } + + // Do the "write". In fact, a full overwrite of the Blob. + blob_ = new Blob([head, new Uint8Array(padding), data, tail], + {type: data.type}); + } + + // Set the blob we're writing on this file entry so we can recall it later. + fileEntry.file_.blob_ = blob_; + fileEntry.file_.lastModifiedDate = new Date() || null; + fileEntry.file_.size = blob_.size; + fileEntry.file_.name = blob_.name; + fileEntry.file_.type = blob_.type; + + idb_.put(fileEntry, fileEntry.file_.storagePath, function() { + successCallback(data.size || data.byteLength); + }, errorCallback); + }, errorCallback, [fileName, null]); + }; + + exports.readAsText = function(successCallback, errorCallback, args) { + var fileName = args[0], + enc = args[1], + startPos = args[2], + endPos = args[3]; + + readAs('text', fileName, enc, startPos, endPos, successCallback, errorCallback); + }; + + exports.readAsDataURL = function(successCallback, errorCallback, args) { + var fileName = args[0], + startPos = args[1], + endPos = args[2]; + + readAs('dataURL', fileName, null, startPos, endPos, successCallback, errorCallback); + }; + + exports.readAsBinaryString = function(successCallback, errorCallback, args) { + var fileName = args[0], + startPos = args[1], + endPos = args[2]; + + readAs('binaryString', fileName, null, startPos, endPos, successCallback, errorCallback); + }; + + exports.readAsArrayBuffer = function(successCallback, errorCallback, args) { + var fileName = args[0], + startPos = args[1], + endPos = args[2]; + + readAs('arrayBuffer', fileName, null, startPos, endPos, successCallback, errorCallback); + }; + + exports.removeRecursively = exports.remove = function(successCallback, errorCallback, args) { + if (typeof successCallback !== 'function') { + throw Error('Expected successCallback argument.'); + } + + var fullPath = resolveToFullPath_(args[0]).storagePath; + if (fullPath === pathsPrefix.cacheDirectory || fullPath === pathsPrefix.dataDirectory) { + errorCallback(FileError.NO_MODIFICATION_ALLOWED_ERR); + return; + } + + function deleteEntry(isDirectory) { + // TODO: This doesn't protect against directories that have content in it. + // Should throw an error instead if the dirEntry is not empty. + idb_['delete'](fullPath, function() { + successCallback(); + }, function() { + if (errorCallback) { errorCallback(); } + }, isDirectory); + } + + // We need to to understand what we are deleting: + exports.getDirectory(function(entry) { + deleteEntry(entry.isDirectory); + }, function(){ + //DirectoryEntry was already deleted or entry is FileEntry + deleteEntry(false); + }, [fullPath, null, {create: false}]); + }; + + exports.getDirectory = function(successCallback, errorCallback, args) { + var fullPath = args[0]; + var path = args[1]; + var options = args[2]; + + // Create an absolute path if we were handed a relative one. + path = resolveToFullPath_(fullPath, path); + + idb_.get(path.storagePath, function(folderEntry) { + if (!options) { + options = {}; + } + + if (options.create === true && options.exclusive === true && folderEntry) { + // If create and exclusive are both true, and the path already exists, + // getDirectory must fail. + if (errorCallback) { + errorCallback(FileError.PATH_EXISTS_ERR); + } + // There is a strange bug in mobilespec + FF, which results in coming to multiple else-if's + // so we are shielding from it with returns. + return; + } + + if (options.create === true && !folderEntry) { + // If create is true, the path doesn't exist, and no other error occurs, + // getDirectory must create it as a zero-length file and return a corresponding + // MyDirectoryEntry. + var dirEntry = new DirectoryEntry(path.fileName, path.fullPath, new FileSystem(path.fsName, fs_.root)); + + idb_.put(dirEntry, path.storagePath, successCallback, errorCallback); + return; + } + + if (options.create === true && folderEntry) { + + if (folderEntry.isDirectory) { + // IDB won't save methods, so we need re-create the MyDirectoryEntry. + successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem)); + } else { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + } + return; + } + + if ((!options.create || options.create === false) && !folderEntry) { + // Handle root special. It should always exist. + if (path.fullPath === DIR_SEPARATOR) { + successCallback(fs_.root); + return; + } + + // If create is not true and the path doesn't exist, getDirectory must fail. + if (errorCallback) { + errorCallback(FileError.NOT_FOUND_ERR); + } + + return; + } + if ((!options.create || options.create === false) && folderEntry && folderEntry.isFile) { + // If create is not true and the path exists, but is a file, getDirectory + // must fail. + if (errorCallback) { + errorCallback(FileError.TYPE_MISMATCH_ERR); + } + return; + } + + // Otherwise, if no other error occurs, getDirectory must return a + // MyDirectoryEntry corresponding to path. + + // IDB won't' save methods, so we need re-create MyDirectoryEntry. + successCallback(new DirectoryEntry(folderEntry.name, folderEntry.fullPath, folderEntry.filesystem)); + }, errorCallback); + }; + + exports.getParent = function(successCallback, errorCallback, args) { + if (typeof successCallback !== 'function') { + throw Error('Expected successCallback argument.'); + } + + var fullPath = args[0]; + //fullPath is like this: + //file:///persistent/path/to/file or + //file:///persistent/path/to/directory/ + + if (fullPath === DIR_SEPARATOR || fullPath === pathsPrefix.cacheDirectory || + fullPath === pathsPrefix.dataDirectory) { + successCallback(fs_.root); + return; + } + + //To delete all slashes at the end + while (fullPath[fullPath.length - 1] === '/') { + fullPath = fullPath.substr(0, fullPath.length - 1); + } + + var pathArr = fullPath.split(DIR_SEPARATOR); + pathArr.pop(); + var parentName = pathArr.pop(); + var path = pathArr.join(DIR_SEPARATOR) + DIR_SEPARATOR; + + //To get parent of root files + var joined = path + parentName + DIR_SEPARATOR;//is like this: file:///persistent/ + if (joined === pathsPrefix.cacheDirectory || joined === pathsPrefix.dataDirectory) { + exports.getDirectory(successCallback, errorCallback, [joined, DIR_SEPARATOR, {create: false}]); + return; + } + + exports.getDirectory(successCallback, errorCallback, [path, parentName, {create: false}]); + }; + + exports.copyTo = function(successCallback, errorCallback, args) { + var srcPath = args[0]; + var parentFullPath = args[1]; + var name = args[2]; + + if (name.indexOf('/') !== -1 || srcPath === parentFullPath + name) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + + return; + } + + // Read src file + exports.getFile(function(srcFileEntry) { + + var path = resolveToFullPath_(parentFullPath); + //Check directory + exports.getDirectory(function() { + + // Create dest file + exports.getFile(function(dstFileEntry) { + + exports.write(function() { + successCallback(dstFileEntry); + }, errorCallback, [dstFileEntry.file_.storagePath, srcFileEntry.file_.blob_, 0]); + + }, errorCallback, [parentFullPath, name, {create: true}]); + + }, function() { if (errorCallback) { errorCallback(FileError.NOT_FOUND_ERR); }}, + [path.storagePath, null, {create:false}]); + + }, errorCallback, [srcPath, null]); + }; + + exports.moveTo = function(successCallback, errorCallback, args) { + var srcPath = args[0]; + // parentFullPath and name parameters is ignored because + // args is being passed downstream to exports.copyTo method + var parentFullPath = args[1]; // jshint ignore: line + var name = args[2]; // jshint ignore: line + + exports.copyTo(function (fileEntry) { + + exports.remove(function () { + successCallback(fileEntry); + }, errorCallback, [srcPath]); + + }, errorCallback, args); + }; + + exports.resolveLocalFileSystemURI = function(successCallback, errorCallback, args) { + var path = args[0]; + + // Ignore parameters + if (path.indexOf('?') !== -1) { + path = String(path).split("?")[0]; + } + + // support for encodeURI + if (/\%5/g.test(path) || /\%20/g.test(path)) { + path = decodeURI(path); + } + + if (path.trim()[0] === '/') { + if (errorCallback) { + errorCallback(FileError.ENCODING_ERR); + } + return; + } + + //support for cdvfile + if (path.trim().substr(0,7) === "cdvfile") { + if (path.indexOf("cdvfile://localhost") === -1) { + if (errorCallback) { + errorCallback(FileError.ENCODING_ERR); + } + return; + } + + var indexPersistent = path.indexOf("persistent"); + var indexTemporary = path.indexOf("temporary"); + + //cdvfile://localhost/persistent/path/to/file + if (indexPersistent !== -1) { + path = "file:///persistent" + path.substr(indexPersistent + 10); + } else if (indexTemporary !== -1) { + path = "file:///temporary" + path.substr(indexTemporary + 9); + } else { + if (errorCallback) { + errorCallback(FileError.ENCODING_ERR); + } + return; + } + } + + // to avoid path form of '///path/to/file' + function handlePathSlashes(path) { + var cutIndex = 0; + for (var i = 0; i < path.length - 1; i++) { + if (path[i] === DIR_SEPARATOR && path[i + 1] === DIR_SEPARATOR) { + cutIndex = i + 1; + } else break; + } + + return path.substr(cutIndex); + } + + // Handle localhost containing paths (see specs ) + if (path.indexOf('file://localhost/') === 0) { + path = path.replace('file://localhost/', 'file:///'); + } + + if (path.indexOf(pathsPrefix.dataDirectory) === 0) { + path = path.substring(pathsPrefix.dataDirectory.length - 1); + path = handlePathSlashes(path); + + exports.requestFileSystem(function() { + exports.getFile(successCallback, function() { + exports.getDirectory(successCallback, errorCallback, [pathsPrefix.dataDirectory, path, + {create: false}]); + }, [pathsPrefix.dataDirectory, path, {create: false}]); + }, errorCallback, [LocalFileSystem.PERSISTENT]); + } else if (path.indexOf(pathsPrefix.cacheDirectory) === 0) { + path = path.substring(pathsPrefix.cacheDirectory.length - 1); + path = handlePathSlashes(path); + + exports.requestFileSystem(function() { + exports.getFile(successCallback, function() { + exports.getDirectory(successCallback, errorCallback, [pathsPrefix.cacheDirectory, path, + {create: false}]); + }, [pathsPrefix.cacheDirectory, path, {create: false}]); + }, errorCallback, [LocalFileSystem.TEMPORARY]); + } else if (path.indexOf(pathsPrefix.applicationDirectory) === 0) { + path = path.substring(pathsPrefix.applicationDirectory.length); + //TODO: need to cut out redundant slashes? + + var xhr = new XMLHttpRequest(); + xhr.open("GET", path, true); + xhr.onreadystatechange = function () { + if (xhr.status === 200 && xhr.readyState === 4) { + exports.requestFileSystem(function(fs) { + fs.name = location.hostname; + + //TODO: need to call exports.getFile(...) to handle errors correct + fs.root.getFile(path, {create: true}, writeFile, errorCallback); + }, errorCallback, [LocalFileSystem.PERSISTENT]); + } + }; + + xhr.onerror = function () { + if(errorCallback) { + errorCallback(FileError.NOT_READABLE_ERR); + } + }; + + xhr.send(); + } else { + if(errorCallback) { + errorCallback(FileError.NOT_FOUND_ERR); + } + } + + function writeFile(entry) { + entry.createWriter(function (fileWriter) { + fileWriter.onwriteend = function (evt) { + if (!evt.target.error) { + entry.filesystemName = location.hostname; + successCallback(entry); + } + }; + fileWriter.onerror = function () { + if (errorCallback) { + errorCallback(FileError.NOT_READABLE_ERR); + } + }; + fileWriter.write(new Blob([xhr.response])); + }, errorCallback); + } + }; + + exports.requestAllPaths = function(successCallback) { + successCallback(pathsPrefix); + }; + + /*** Helpers ***/ + + /** + * Interface to wrap the native File interface. + * + * This interface is necessary for creating zero-length (empty) files, + * something the Filesystem API allows you to do. Unfortunately, File's + * constructor cannot be called directly, making it impossible to instantiate + * an empty File in JS. + * + * @param {Object} opts Initial values. + * @constructor + */ + function MyFile(opts) { + var blob_ = new Blob(); + + this.size = opts.size || 0; + this.name = opts.name || ''; + this.type = opts.type || ''; + this.lastModifiedDate = opts.lastModifiedDate || null; + this.storagePath = opts.storagePath || ''; + + // Need some black magic to correct the object's size/name/type based on the + // blob that is saved. + Object.defineProperty(this, 'blob_', { + enumerable: true, + get: function() { + return blob_; + }, + set: function(val) { + blob_ = val; + this.size = blob_.size; + this.name = blob_.name; + this.type = blob_.type; + this.lastModifiedDate = blob_.lastModifiedDate; + }.bind(this) + }); + } + + MyFile.prototype.constructor = MyFile; + + // When saving an entry, the fullPath should always lead with a slash and never + // end with one (e.g. a directory). Also, resolve '.' and '..' to an absolute + // one. This method ensures path is legit! + function resolveToFullPath_(cwdFullPath, path) { + path = path || ''; + var fullPath = path; + var prefix = ''; + + cwdFullPath = cwdFullPath || DIR_SEPARATOR; + if (cwdFullPath.indexOf(FILESYSTEM_PREFIX) === 0) { + prefix = cwdFullPath.substring(0, cwdFullPath.indexOf(DIR_SEPARATOR, FILESYSTEM_PREFIX.length)); + cwdFullPath = cwdFullPath.substring(cwdFullPath.indexOf(DIR_SEPARATOR, FILESYSTEM_PREFIX.length)); + } + + var relativePath = path[0] !== DIR_SEPARATOR; + if (relativePath) { + fullPath = cwdFullPath; + if (cwdFullPath !== DIR_SEPARATOR) { + fullPath += DIR_SEPARATOR + path; + } else { + fullPath += path; + } + } + + // Remove doubled separator substrings + var re = new RegExp(DIR_SEPARATOR + DIR_SEPARATOR, 'g'); + fullPath = fullPath.replace(re, DIR_SEPARATOR); + + // Adjust '..'s by removing parent directories when '..' flows in path. + var parts = fullPath.split(DIR_SEPARATOR); + for (var i = 0; i < parts.length; ++i) { + var part = parts[i]; + if (part === '..') { + parts[i - 1] = ''; + parts[i] = ''; + } + } + fullPath = parts.filter(function(el) { + return el; + }).join(DIR_SEPARATOR); + + // Add back in leading slash. + if (fullPath[0] !== DIR_SEPARATOR) { + fullPath = DIR_SEPARATOR + fullPath; + } + + // Replace './' by current dir. ('./one/./two' -> one/two) + fullPath = fullPath.replace(/\.\//g, DIR_SEPARATOR); + + // Replace '//' with '/'. + fullPath = fullPath.replace(/\/\//g, DIR_SEPARATOR); + + // Replace '/.' with '/'. + fullPath = fullPath.replace(/\/\./g, DIR_SEPARATOR); + + // Remove '/' if it appears on the end. + if (fullPath[fullPath.length - 1] === DIR_SEPARATOR && + fullPath !== DIR_SEPARATOR) { + fullPath = fullPath.substring(0, fullPath.length - 1); + } + + var storagePath = prefix + fullPath; + storagePath = decodeURI(storagePath); + fullPath = decodeURI(fullPath); + + return { + storagePath: storagePath, + fullPath: fullPath, + fileName: fullPath.split(DIR_SEPARATOR).pop(), + fsName: prefix.split(DIR_SEPARATOR).pop() + }; + } + + function fileEntryFromIdbEntry(fileEntry) { + // IDB won't save methods, so we need re-create the FileEntry. + var clonedFileEntry = new FileEntry(fileEntry.name, fileEntry.fullPath, fileEntry.filesystem); + clonedFileEntry.file_ = fileEntry.file_; + + return clonedFileEntry; + } + + function readAs(what, fullPath, encoding, startPos, endPos, successCallback, errorCallback) { + exports.getFile(function(fileEntry) { + var fileReader = new FileReader(), + blob = fileEntry.file_.blob_.slice(startPos, endPos); + + fileReader.onload = function(e) { + successCallback(e.target.result); + }; + + fileReader.onerror = errorCallback; + + switch (what) { + case 'text': + fileReader.readAsText(blob, encoding); + break; + case 'dataURL': + fileReader.readAsDataURL(blob); + break; + case 'arrayBuffer': + fileReader.readAsArrayBuffer(blob); + break; + case 'binaryString': + fileReader.readAsBinaryString(blob); + break; + } + + }, errorCallback, [fullPath, null]); + } + + /*** Core logic to handle IDB operations ***/ + + idb_.open = function(dbName, successCallback, errorCallback) { + var self = this; + + // TODO: FF 12.0a1 isn't liking a db name with : in it. + var request = indexedDB.open(dbName.replace(':', '_')/*, 1 /*version*/); + + request.onerror = errorCallback || onError; + + request.onupgradeneeded = function(e) { + // First open was called or higher db version was used. + + // console.log('onupgradeneeded: oldVersion:' + e.oldVersion, + // 'newVersion:' + e.newVersion); + + self.db = e.target.result; + self.db.onerror = onError; + + if (!self.db.objectStoreNames.contains(FILE_STORE_)) { + self.db.createObjectStore(FILE_STORE_/*,{keyPath: 'id', autoIncrement: true}*/); + } + }; + + request.onsuccess = function(e) { + self.db = e.target.result; + self.db.onerror = onError; + successCallback(e); + }; + + request.onblocked = errorCallback || onError; + }; + + idb_.close = function() { + this.db.close(); + this.db = null; + }; + + idb_.get = function(fullPath, successCallback, errorCallback) { + if (!this.db) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + var tx = this.db.transaction([FILE_STORE_], 'readonly'); + + var request = tx.objectStore(FILE_STORE_).get(fullPath); + + tx.onabort = errorCallback || onError; + tx.oncomplete = function() { + successCallback(request.result); + }; + }; + + idb_.getAllEntries = function(fullPath, storagePath, successCallback, errorCallback) { + if (!this.db) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + var results = []; + + if (storagePath[storagePath.length - 1] === DIR_SEPARATOR) { + storagePath = storagePath.substring(0, storagePath.length - 1); + } + + var range = IDBKeyRange.bound(storagePath + DIR_SEPARATOR + ' ', + storagePath + DIR_SEPARATOR + String.fromCharCode(unicodeLastChar)); + + var tx = this.db.transaction([FILE_STORE_], 'readonly'); + tx.onabort = errorCallback || onError; + tx.oncomplete = function() { + results = results.filter(function(val) { + var pathWithoutSlash = val.fullPath; + + if (val.fullPath[val.fullPath.length - 1] === DIR_SEPARATOR) { + pathWithoutSlash = pathWithoutSlash.substr(0, pathWithoutSlash.length - 1); + } + + var valPartsLen = pathWithoutSlash.split(DIR_SEPARATOR).length; + var fullPathPartsLen = fullPath.split(DIR_SEPARATOR).length; + + /* Input fullPath parameter equals '//' for root folder */ + /* Entries in root folder has valPartsLen equals 2 (see below) */ + if (fullPath[fullPath.length -1] === DIR_SEPARATOR && fullPath.trim().length === 2) { + fullPathPartsLen = 1; + } else if (fullPath[fullPath.length -1] === DIR_SEPARATOR) { + fullPathPartsLen = fullPath.substr(0, fullPath.length - 1).split(DIR_SEPARATOR).length; + } else { + fullPathPartsLen = fullPath.split(DIR_SEPARATOR).length; + } + + if (valPartsLen === fullPathPartsLen + 1) { + // If this a subfolder and entry is a direct child, include it in + // the results. Otherwise, it's not an entry of this folder. + return val; + } else return false; + }); + + successCallback(results); + }; + + var request = tx.objectStore(FILE_STORE_).openCursor(range); + + request.onsuccess = function(e) { + var cursor = e.target.result; + if (cursor) { + var val = cursor.value; + + results.push(val.isFile ? fileEntryFromIdbEntry(val) : new DirectoryEntry(val.name, val.fullPath, val.filesystem)); + cursor['continue'](); + } + }; + }; + + idb_['delete'] = function(fullPath, successCallback, errorCallback, isDirectory) { + if (!idb_.db) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + var tx = this.db.transaction([FILE_STORE_], 'readwrite'); + tx.oncomplete = successCallback; + tx.onabort = errorCallback || onError; + tx.oncomplete = function() { + if (isDirectory) { + //We delete nested files and folders after deleting parent folder + //We use ranges: https://developer.mozilla.org/en-US/docs/Web/API/IDBKeyRange + fullPath = fullPath + DIR_SEPARATOR; + + //Range contains all entries in the form fullPath where + //symbol in the range from ' ' to symbol which has code `unicodeLastChar` + var range = IDBKeyRange.bound(fullPath + ' ', fullPath + String.fromCharCode(unicodeLastChar)); + + var newTx = this.db.transaction([FILE_STORE_], 'readwrite'); + newTx.oncomplete = successCallback; + newTx.onabort = errorCallback || onError; + newTx.objectStore(FILE_STORE_)['delete'](range); + } else { + successCallback(); + } + }; + tx.objectStore(FILE_STORE_)['delete'](fullPath); + }; + + idb_.put = function(entry, storagePath, successCallback, errorCallback) { + if (!this.db) { + if (errorCallback) { + errorCallback(FileError.INVALID_MODIFICATION_ERR); + } + return; + } + + var tx = this.db.transaction([FILE_STORE_], 'readwrite'); + tx.onabort = errorCallback || onError; + tx.oncomplete = function() { + // TODO: Error is thrown if we pass the request event back instead. + successCallback(entry); + }; + + tx.objectStore(FILE_STORE_).put(entry, storagePath); + }; + + // Global error handler. Errors bubble from request, to transaction, to db. + function onError(e) { + switch (e.target.errorCode) { + case 12: + console.log('Error - Attempt to open db with a lower version than the ' + + 'current one.'); + break; + default: + console.log('errorCode: ' + e.target.errorCode); + } + + console.log(e, e.code, e.message); + } + + })(module.exports, window); + + require("cordova/exec/proxy").add("File", module.exports); +})(); + +}); diff --git a/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryEntry.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryEntry.js new file mode 100644 index 000000000..464d33932 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryEntry.js @@ -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/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryReader.js b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryReader.js new file mode 100644 index 000000000..921b48660 --- /dev/null +++ b/cordova-lib/spec-cordova/fixtures/platforms/browser/platform_www/plugins/cordova-plugin-file/www/DirectoryReader.js @@ -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 or + *