From f38a2ae14a6f9d16b019ac4bd676d4351ff0d3aa Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 21 May 2013 12:32:49 -0400 Subject: [PATCH 01/29] Add a .reviewboardrc file to make using post-review easier. --- .reviewboardrc | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .reviewboardrc diff --git a/.reviewboardrc b/.reviewboardrc new file mode 100644 index 00000000..30e9587a --- /dev/null +++ b/.reviewboardrc @@ -0,0 +1,8 @@ +# +# Settings for post-review (used for uploading diffs to reviews.apache.org). +# +GUESS_FIELDS = True +OPEN_BROWSER = True +TARGET_GROUPS = 'cordova' +REVIEWBOARD_URL = 'http://reviews.apache.org' + From 77eada7dbda77799cfe1781aa6fcd6e8430a81b3 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 21 May 2013 13:32:57 -0700 Subject: [PATCH 02/29] CB-3064: We need to re-create the config object on resume, always create an object on init. --- framework/src/org/apache/cordova/Config.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/Config.java b/framework/src/org/apache/cordova/Config.java index ccf49c54..c2ced34b 100644 --- a/framework/src/org/apache/cordova/Config.java +++ b/framework/src/org/apache/cordova/Config.java @@ -50,9 +50,8 @@ public class Config { private static Config self = null; public static void init(Activity action) { - if (self == null) { - self = new Config(action); - } + //Just re-initialize this! Seriously, we lose this all the time + self = new Config(action); } // Intended to be used for testing only; creates an empty configuration. From c9e16b2c39a892bc7dafec9ad89de483f6ddd403 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 21 May 2013 15:23:36 -0700 Subject: [PATCH 03/29] CB-3364: Updating build instructions --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5d2f7ded..a785943b 100755 --- a/README.md +++ b/README.md @@ -16,23 +16,7 @@ Requires - Android SDK [http://developer.android.com](http://developer.android.com) - Apache Commons Codec [http://commons.apache.org/codec/](http://commons.apache.org/codec/) -Test Requirements ---- -- JUnit - [https://github.com/KentBeck/junit](https://github.com/KentBeck/junit) -Building ---- - -To create your `cordova.jar` file, copy the commons codec: - - mv commons-codec-1.7.jar framework/libs - -then run in the framework directory: - - android update project -p . -t android-17 - ant jar - - Cordova Android Developer Tools --- @@ -93,6 +77,22 @@ Importing a Cordova Android Project into Eclipse 5. Right click on the project root: Run as > Run Configurations 6. Click on the Target tab and select Manual (this way you can choose the emulator or device to build to) +Building without the Tooling +--- +Note: The Developer Tools handle this. This is only to be done if the tooling fails, or if +you are developing directly against the framework. + + +To create your `cordova.jar` file, copy the commons codec: + + mv commons-codec-1.7.jar framework/libs + +then run in the framework directory: + + android update project -p . -t android-17 + ant jar + + Running Tests ---- Please see details under test/README.md. @@ -101,5 +101,5 @@ Further Reading --- - [http://developer.android.com](http://developer.android.com) -- [http://incubator.apache.org/cordova/](http://incubator.apache.org/cordova/) +- [http://cordova.apache.org/](http://cordova.apache.org) - [http://wiki.apache.org/cordova/](http://wiki.apache.org/cordova/) From 01946dd4d6c65670fccbec022a12adb6e05af8e3 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Wed, 22 May 2013 10:33:57 -0400 Subject: [PATCH 04/29] [CB-3430] [CB-1413] Remove Old (2.3.3) HTTP Workaround --- .../src/org/apache/cordova/FileTransfer.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java index c87683f6..784c34c5 100644 --- a/framework/src/org/apache/cordova/FileTransfer.java +++ b/framework/src/org/apache/cordova/FileTransfer.java @@ -178,39 +178,6 @@ public class FileTransfer extends CordovaPlugin { } } - /** - * Works around a bug on Android 2.3. - * http://code.google.com/p/android/issues/detail?id=14562 - */ - private static final class DoneHandlerInputStream extends TrackingHTTPInputStream { - private boolean done; - - public DoneHandlerInputStream(InputStream stream) { - super(stream); - } - - @Override - public int read() throws IOException { - int result = done ? -1 : super.read(); - done = (result == -1); - return result; - } - - @Override - public int read(byte[] buffer) throws IOException { - int result = done ? -1 : super.read(buffer); - done = (result == -1); - return result; - } - - @Override - public int read(byte[] bytes, int offset, int count) throws IOException { - int result = done ? -1 : super.read(bytes, offset, count); - done = (result == -1); - return result; - } - } - @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("upload") || action.equals("download")) { @@ -565,9 +532,6 @@ public class FileTransfer extends CordovaPlugin { } private static TrackingInputStream getInputStream(URLConnection conn) throws IOException { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { - return new DoneHandlerInputStream(conn.getInputStream()); - } String encoding = conn.getContentEncoding(); if (encoding != null && encoding.equalsIgnoreCase("gzip")) { return new TrackingGZIPInputStream(new ExposedGZIPInputStream(conn.getInputStream())); From ee58107caa1b0d8cda1db180cda1d0ac284d29fd Mon Sep 17 00:00:00 2001 From: David Kemp Date: Thu, 23 May 2013 11:55:05 -0400 Subject: [PATCH 05/29] CB-3480: update now uses cordova.js not cordova-.js --- bin/update | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/update b/bin/update index 92ceda82..9a968b1b 100755 --- a/bin/update +++ b/bin/update @@ -45,9 +45,9 @@ fi # cleanup after exit and/or on error function on_exit { - if [ -f "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js ] + if [ -f "$BUILD_PATH"/framework/assets/www/cordova.js ] then - rm "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js + rm "$BUILD_PATH"/framework/assets/www/cordova.js fi if [ -f "$BUILD_PATH"/framework/cordova-$VERSION.jar ] then @@ -122,10 +122,10 @@ fi # copy cordova.js, cordova.jar and res/xml if [ -d "$BUILD_PATH"/framework ] then - cp "$BUILD_PATH"/framework/assets/www/cordova-$VERSION.js "$PROJECT_PATH"/assets/www/cordova-$VERSION.js + cp "$BUILD_PATH"/framework/assets/www/cordova.js "$PROJECT_PATH"/assets/www/cordova.js cp "$BUILD_PATH"/framework/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar else - cp "$BUILD_PATH"/cordova-$VERSION.js "$PROJECT_PATH"/assets/www/cordova-$VERSION.js + cp "$BUILD_PATH"/cordova.js "$PROJECT_PATH"/assets/www/cordova.js cp "$BUILD_PATH"/cordova-$VERSION.jar "$PROJECT_PATH"/libs/cordova-$VERSION.jar fi From 1c9d76e637a40ab9301ef307a410ecd33fae15e0 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 24 May 2013 11:29:28 -0700 Subject: [PATCH 06/29] CB-3496: Fixed streaming audio, this is pretty important for mobile spec --- framework/src/org/apache/cordova/AudioHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java index 20c3c4ef..ef203064 100644 --- a/framework/src/org/apache/cordova/AudioHandler.java +++ b/framework/src/org/apache/cordova/AudioHandler.java @@ -58,7 +58,10 @@ public class AudioHandler extends CordovaPlugin { public String getFilePath(String url, String source){ DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source); - return dataResource.getRealFile().getPath(); + if(dataResource.getUri().getScheme().equals("http") || dataResource.getUri().getScheme().equals("https")) + return dataResource.getUri().toString(); + else + return dataResource.getRealFile().getPath(); } /** From 8077091b34ca3c25f81870a6712e9dd312b41e4a Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Thu, 23 May 2013 00:00:00 -0400 Subject: [PATCH 07/29] Update JS snapshot to version 2.8.0rc1 --- framework/assets/www/cordova.js | 160 +++++++++++++++++++------------- 1 file changed, 97 insertions(+), 63 deletions(-) diff --git a/framework/assets/www/cordova.js b/framework/assets/www/cordova.js index 2941307d..37300475 100644 --- a/framework/assets/www/cordova.js +++ b/framework/assets/www/cordova.js @@ -1,9 +1,5 @@ // Platform: android - -// commit d0ffb852378ff018bac2f3b12c38098a19b8ce00 - -// File generated at :: Thu Apr 18 2013 15:10:54 GMT-0400 (EDT) - +// 2.8.0rc1-0-g22bc4d8 /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file @@ -22,26 +18,36 @@ specific language governing permissions and limitations under the License. */ - ;(function() { - +var CORDOVA_JS_BUILD_LABEL = '2.8.0rc1-0-g22bc4d8'; // file: lib/scripts/require.js var require, define; (function () { - var modules = {}; + var modules = {}, // Stack of moduleIds currently being built. - var requireStack = []; + requireStack = [], // Map of module ID -> index into requireStack of modules currently being built. - var inProgressModules = {}; + inProgressModules = {}, + SEPERATOR = "."; + + function build(module) { - var factory = module.factory; + 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(SEPERATOR)) + SEPERATOR + id.slice(2); + } + return require(resultantId); + }; module.exports = {}; delete module.factory; - factory(require, module.exports, module); + factory(localRequire, module.exports, module); return module.exports; } @@ -1314,8 +1320,6 @@ var CaptureAudioOptions = function(){ this.limit = 1; // Maximum duration of a single sound clip in seconds. this.duration = 0; - // The selected audio mode. Must match with one of the elements in supportedAudioModes array. - this.mode = null; }; module.exports = CaptureAudioOptions; @@ -1356,8 +1360,6 @@ define("cordova/plugin/CaptureImageOptions", function(require, exports, module) var CaptureImageOptions = function(){ // Upper limit of images user can take. Value must be equal or greater than 1. this.limit = 1; - // The selected image mode. Must match with one of the elements in supportedImageModes array. - this.mode = null; }; module.exports = CaptureImageOptions; @@ -1375,8 +1377,6 @@ var CaptureVideoOptions = function(){ this.limit = 1; // Maximum duration of a single video clip in seconds. this.duration = 0; - // The selected video mode. Must match with one of the elements in supportedVideoModes array. - this.mode = null; }; module.exports = CaptureVideoOptions; @@ -5081,12 +5081,16 @@ function Device() { channel.onCordovaReady.subscribe(function() { me.getInfo(function(info) { + var buildLabel = info.cordova; + if (buildLabel != CORDOVA_JS_BUILD_LABEL) { + buildLabel += ' JS=' + CORDOVA_JS_BUILD_LABEL; + } me.available = true; me.platform = info.platform; me.version = info.version; me.name = info.name; me.uuid = info.uuid; - me.cordova = info.cordova; + me.cordova = buildLabel; me.model = info.model; channel.onCordovaInfoReady.fire(); },function(e) { @@ -5843,10 +5847,13 @@ var exec = require('cordova/exec'); var utils = require('cordova/utils'); var UseConsole = true; +var UseLogger = true; var Queued = []; var DeviceReady = false; var CurrentLevel; +var originalConsole = console; + /** * Logging levels */ @@ -5907,8 +5914,7 @@ logger.level = function (value) { * Getter/Setter for the useConsole functionality * * When useConsole is true, the logger will log via the - * browser 'console' object. Otherwise, it will use the - * native Logger plugin. + * browser 'console' object. */ logger.useConsole = function (value) { if (arguments.length) UseConsole = !!value; @@ -5932,6 +5938,18 @@ logger.useConsole = function (value) { return UseConsole; }; +/** + * Getter/Setter for the useLogger functionality + * + * When useLogger is true, the logger will log via the + * native Logger plugin. + */ +logger.useLogger = function (value) { + // Enforce boolean + if (arguments.length) UseLogger = !!value; + return UseLogger; +}; + /** * Logs a message at the LOG level. * @@ -6001,24 +6019,26 @@ logger.logLevel = function(level /* , ... */) { return; } - // if not using the console, use the native logger - if (!UseConsole) { + // Log using the native logger if that is enabled + if (UseLogger) { exec(null, null, "Logger", "logLevel", [level, message]); - return; } - // make sure console is not using logger - if (console.__usingCordovaLogger) { - throw new Error("console and logger are too intertwingly"); - } + // Log using the console if that is enabled + if (UseConsole) { + // make sure console is not using logger + if (console.__usingCordovaLogger) { + throw new Error("console and logger are too intertwingly"); + } - // log to the console - switch (level) { - case logger.LOG: console.log(message); break; - case logger.ERROR: console.log("ERROR: " + message); break; - case logger.WARN: console.log("WARN: " + message); break; - case logger.INFO: console.log("INFO: " + message); break; - case logger.DEBUG: console.log("DEBUG: " + message); break; + // log to the console + switch (level) { + case logger.LOG: originalConsole.log(message); break; + case logger.ERROR: originalConsole.log("ERROR: " + message); break; + case logger.WARN: originalConsole.log("WARN: " + message); break; + case logger.INFO: originalConsole.log("INFO: " + message); break; + case logger.DEBUG: originalConsole.log("DEBUG: " + message); break; + } } }; @@ -6279,7 +6299,7 @@ module.exports = { // Some platforms take an array of button label names. // Other platforms take a comma separated list. // For compatibility, we convert to the desired type based on the platform. - if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone") { + if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone" || platform.id == "blackberry10") { if (typeof _buttonLabels === 'string') { var buttonLabelString = _buttonLabels; _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here @@ -6303,12 +6323,14 @@ module.exports = { * @param {Function} resultCallback The callback that is called when user clicks on a button. * @param {String} title Title of the dialog (default: "Prompt") * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) + * @param {String} defaultText Textbox input value (default: "Default text") */ - prompt: function(message, resultCallback, title, buttonLabels) { + prompt: function(message, resultCallback, title, buttonLabels, defaultText) { var _message = (message || "Prompt message"); var _title = (title || "Prompt"); var _buttonLabels = (buttonLabels || ["OK","Cancel"]); - exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]); + var _defaultText = (defaultText || "Default text"); + exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); }, /** @@ -6650,9 +6672,7 @@ function UUIDcreatePart(length) { }); - window.cordova = require('cordova'); - // file: lib/scripts/bootstrap.js (function (context) { @@ -6768,7 +6788,7 @@ require('cordova/channel').onNativeReady.fire(); // 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 XHR response handler will just call finishPluginLoading(). - function handlePluginsObject(modules) { + function handlePluginsObject(modules, path) { // First create the callback for when all plugins are loaded. var mapper = context.cordova.require('cordova/modulemapper'); onScriptLoadingComplete = function() { @@ -6802,35 +6822,49 @@ require('cordova/channel').onNativeReady.fire(); // Now inject the scripts. for (var i = 0; i < modules.length; i++) { - injectScript(modules[i].file); + injectScript(path + modules[i].file); } } - - // Try to XHR the cordova_plugins.json file asynchronously. - try { // we commented we were going to try, so let us actually try and catch - var xhr = new context.XMLHttpRequest(); - xhr.onload = function() { - // If the response is a JSON string which composes an array, call handlePluginsObject. - // If the request fails, or the response is not a JSON array, just call finishPluginLoading. - var obj = JSON.parse(this.responseText); - if (obj && obj instanceof Array && obj.length > 0) { - handlePluginsObject(obj); - } else { - finishPluginLoading(); - } - }; - xhr.onerror = function() { - finishPluginLoading(); - }; - xhr.open('GET', 'cordova_plugins.json', true); // Async - xhr.send(); + // Find the root of the app + var path = ''; + var scripts = document.getElementsByTagName('script'); + var term = 'cordova.js'; + for (var n = scripts.length-1; n>-1; n--) { + var src = scripts[n].src; + if (src.indexOf(term) == (src.length - term.length)) { + path = src.substring(0, src.length - term.length); + break; + } } - catch(err){ + // Try to XHR the cordova_plugins.json file asynchronously. + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + // If the response is a JSON string which composes an array, call handlePluginsObject. + // If the request fails, or the response is not a JSON array, just call finishPluginLoading. + var obj; + try { + obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText); + } catch (err) { + // obj will be undefined. + } + if (Array.isArray(obj) && obj.length > 0) { + handlePluginsObject(obj, path); + } else { + finishPluginLoading(); + } + }; + xhr.onerror = function() { + finishPluginLoading(); + }; + var plugins_json = path + 'cordova_plugins.json'; + try { // we commented we were going to try, so let us actually try and catch + xhr.open('GET', plugins_json, true); // Async + xhr.send(); + } catch(err){ finishPluginLoading(); } }(window)); - })(); \ No newline at end of file From 78efe2a960ba2b320680da18b7c0fc20d442c604 Mon Sep 17 00:00:00 2001 From: David Kemp Date: Thu, 23 May 2013 10:23:25 -0400 Subject: [PATCH 08/29] CB-3358: Change Commons-codec:base64 to Android:Base64 --- README.md | 7 +--- bin/create | 10 ----- bin/create.js | 42 ------------------- bin/update | 10 ----- bin/update.js | 42 ------------------- framework/build.xml | 16 ------- .../org/apache/cordova/CameraLauncher.java | 4 +- .../src/org/apache/cordova/FileUtils.java | 4 +- 8 files changed, 5 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index a785943b..0b145518 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Requires - Java JDK 1.5 or greater - Apache ANT 1.8.0 or greater - Android SDK [http://developer.android.com](http://developer.android.com) -- Apache Commons Codec [http://commons.apache.org/codec/](http://commons.apache.org/codec/) Cordova Android Developer Tools @@ -83,11 +82,7 @@ Note: The Developer Tools handle this. This is only to be done if the tooling f you are developing directly against the framework. -To create your `cordova.jar` file, copy the commons codec: - - mv commons-codec-1.7.jar framework/libs - -then run in the framework directory: +To create your `cordova.jar` file, run in the framework directory: android update project -p . -t android-17 ant jar diff --git a/bin/create b/bin/create index 39aff6b8..71f98bc6 100755 --- a/bin/create +++ b/bin/create @@ -99,16 +99,6 @@ then # update the cordova-android framework for the desired target "$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null - if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then - # Use curl to get the jar (TODO: Support Apache Mirrors) - curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null - unzip commons-codec-1.7-bin.zip &> /dev/null - mkdir -p "$BUILD_PATH"/framework/libs - cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs - # cleanup yo - rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7 - fi - # compile cordova.js and cordova.jar pushd "$BUILD_PATH"/framework > /dev/null ant jar > /dev/null diff --git a/bin/create.js b/bin/create.js index b1de5fe1..07c2e569 100644 --- a/bin/create.js +++ b/bin/create.js @@ -120,46 +120,6 @@ function cleanup() { } } -function downloadCommonsCodec() { - if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) { - // We need the .jar - var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip'; - var libsPath = ROOT + '\\framework\\libs'; - var savePath = libsPath + '\\commons-codec-1.7-bin.zip'; - if (!fso.FileExists(savePath)) { - if(!fso.FolderExists(ROOT + '\\framework\\libs')) { - fso.CreateFolder(libsPath); - } - // We need the zip to get the jar - var xhr = WScript.CreateObject('MSXML2.XMLHTTP'); - xhr.open('GET', url, false); - xhr.send(); - if (xhr.status == 200) { - var stream = WScript.CreateObject('ADODB.Stream'); - stream.Open(); - stream.Type = 1; - stream.Write(xhr.ResponseBody); - stream.Position = 0; - stream.SaveToFile(savePath); - stream.Close(); - } else { - Log('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.'); - } - } - var app = WScript.CreateObject('Shell.Application'); - var source = app.NameSpace(savePath).Items(); - var target = app.NameSpace(ROOT + '\\framework\\libs'); - target.CopyHere(source, 256); - - // Move the jar into libs - fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar'); - - // Clean up - fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip'); - fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true); - } -} - // working dir var ROOT = WScript.ScriptFullName.split('\\bin\\create.js').join(''); if (args.Count() > 0) { @@ -206,8 +166,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') && Log("Building jar and js files..."); // update the cordova framework project to a target that exists on this machine exec('android.bat update project --target "'+TARGET+'" --path "'+ROOT+'\\framework"'); - // pull down commons codec if necessary - downloadCommonsCodec(); exec('ant.bat -f "'+ ROOT +'\\framework\\build.xml" jar'); } diff --git a/bin/update b/bin/update index 9a968b1b..2e716a7d 100755 --- a/bin/update +++ b/bin/update @@ -105,16 +105,6 @@ then # update the cordova-android framework for the desired target "$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null - if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then - # Use curl to get the jar (TODO: Support Apache Mirrors) - curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null - unzip commons-codec-1.7-bin.zip &> /dev/null - mkdir -p "$BUILD_PATH"/framework/libs - cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs - # cleanup yo - rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7 - fi - # compile cordova.js and cordova.jar (cd "$BUILD_PATH"/framework && ant jar &> /dev/null ) fi diff --git a/bin/update.js b/bin/update.js index 748d6026..8396d6fe 100644 --- a/bin/update.js +++ b/bin/update.js @@ -96,46 +96,6 @@ function cleanup() { } } -function downloadCommonsCodec() { - if (!fso.FileExists(ROOT + '\\framework\\libs\\commons-codec-1.7.jar')) { - // We need the .jar - var url = 'http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip'; - var libsPath = ROOT + '\\framework\\libs'; - var savePath = libsPath + '\\commons-codec-1.7-bin.zip'; - if (!fso.FileExists(savePath)) { - if(!fso.FolderExists(ROOT + '\\framework\\libs')) { - fso.CreateFolder(libsPath); - } - // We need the zip to get the jar - var xhr = WScript.CreateObject('MSXML2.XMLHTTP'); - xhr.open('GET', url, false); - xhr.send(); - if (xhr.status == 200) { - var stream = WScript.CreateObject('ADODB.Stream'); - stream.Open(); - stream.Type = 1; - stream.Write(xhr.ResponseBody); - stream.Position = 0; - stream.SaveToFile(savePath); - stream.Close(); - } else { - WScript.Echo('Could not retrieve the commons-codec. Please download it yourself and put into the framework/libs directory. This process may fail now. Sorry.'); - } - } - var app = WScript.CreateObject('Shell.Application'); - var source = app.NameSpace(savePath).Items(); - var target = app.NameSpace(ROOT + '\\framework\\libs'); - target.CopyHere(source, 256); - - // Move the jar into libs - fso.MoveFile(ROOT + '\\framework\\libs\\commons-codec-1.7\\commons-codec-1.7.jar', ROOT + '\\framework\\libs\\commons-codec-1.7.jar'); - - // Clean up - fso.DeleteFile(ROOT + '\\framework\\libs\\commons-codec-1.7-bin.zip'); - fso.DeleteFolder(ROOT + '\\framework\\libs\\commons-codec-1.7', true); - } -} - var args = WScript.Arguments, PROJECT_PATH="example", shell=WScript.CreateObject("WScript.Shell"); @@ -161,8 +121,6 @@ if (!fso.FileExists(ROOT+'\\cordova-'+VERSION+'.jar') && WScript.Echo("Building jar and js files..."); // update the cordova framework project to a target that exists on this machine exec('android.bat update project --target '+TARGET+' --path '+ROOT+'\\framework'); - // pull down commons codec if necessary - downloadCommonsCodec(); exec('ant.bat -f \"'+ ROOT +'\\framework\\build.xml\" jar'); } diff --git a/framework/build.xml b/framework/build.xml index 989dbb2f..46242aa1 100644 --- a/framework/build.xml +++ b/framework/build.xml @@ -31,22 +31,6 @@ - - - - - - - - - - - Cordova Android === diff --git a/bin/check_reqs.bat b/bin/check_reqs.bat index 65514c85..12da1e74 100644 --- a/bin/check_reqs.bat +++ b/bin/check_reqs.bat @@ -1,3 +1,20 @@ +:: 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. + @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%check_reqs.js ( @@ -6,4 +23,4 @@ IF EXIST %full_path%check_reqs.js ( ECHO. ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/build.bat b/bin/templates/cordova/build.bat index 7aa7c75d..392f374a 100644 --- a/bin/templates/cordova/build.bat +++ b/bin/templates/cordova/build.bat @@ -1,2 +1,18 @@ +:: 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. @ECHO OFF -%~dp0\cordova.bat build %* \ No newline at end of file +%~dp0\cordova.bat build %* diff --git a/bin/templates/cordova/clean.bat b/bin/templates/cordova/clean.bat index b41bdc91..643c8d59 100644 --- a/bin/templates/cordova/clean.bat +++ b/bin/templates/cordova/clean.bat @@ -1,2 +1,18 @@ +:: 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. @ECHO OFF %~dp0\cordova.bat clean %* diff --git a/bin/templates/cordova/cordova.bat b/bin/templates/cordova/cordova.bat index 9b561993..6235fdb7 100644 --- a/bin/templates/cordova/cordova.bat +++ b/bin/templates/cordova/cordova.bat @@ -1,5 +1,3 @@ -@ECHO OFF -GOTO BEGIN :: 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 @@ -16,7 +14,7 @@ GOTO BEGIN :: KIND, either express or implied. See the License for the :: specific language governing permissions and limitations :: under the License. -:BEGIN +@ECHO OFF IF NOT DEFINED JAVA_HOME GOTO MISSING FOR %%X in (java.exe ant.bat android.bat) do ( SET FOUND=%%~$PATH:X diff --git a/bin/templates/cordova/lib/install-device.bat b/bin/templates/cordova/lib/install-device.bat index 52d97759..b00e757b 100644 --- a/bin/templates/cordova/lib/install-device.bat +++ b/bin/templates/cordova/lib/install-device.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/lib/install-emulator.bat b/bin/templates/cordova/lib/install-emulator.bat index d11a7be3..2b886304 100644 --- a/bin/templates/cordova/lib/install-emulator.bat +++ b/bin/templates/cordova/lib/install-emulator.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/lib/list-devices.bat b/bin/templates/cordova/lib/list-devices.bat index c146f105..3840d129 100644 --- a/bin/templates/cordova/lib/list-devices.bat +++ b/bin/templates/cordova/lib/list-devices.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/lib/list-emulator-images.bat b/bin/templates/cordova/lib/list-emulator-images.bat index 172520b3..e21aafe9 100644 --- a/bin/templates/cordova/lib/list-emulator-images.bat +++ b/bin/templates/cordova/lib/list-emulator-images.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/lib/list-started-emulators.bat b/bin/templates/cordova/lib/list-started-emulators.bat index f1b3c5d3..eb9f3b62 100644 --- a/bin/templates/cordova/lib/list-started-emulators.bat +++ b/bin/templates/cordova/lib/list-started-emulators.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/lib/start-emulator.bat b/bin/templates/cordova/lib/start-emulator.bat index 4f3fb5d8..758c854c 100644 --- a/bin/templates/cordova/lib/start-emulator.bat +++ b/bin/templates/cordova/lib/start-emulator.bat @@ -1,3 +1,19 @@ +:: 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. @ECHO OFF SET full_path=%~dp0 IF EXIST %full_path%cordova.js ( @@ -6,4 +22,4 @@ IF EXIST %full_path%cordova.js ( ECHO. ECHO ERROR: Could not find 'cordova.js' in cordova/lib, aborting...>&2 EXIT /B 1 -) \ No newline at end of file +) diff --git a/bin/templates/cordova/log.bat b/bin/templates/cordova/log.bat index 2c492e75..c2598026 100644 --- a/bin/templates/cordova/log.bat +++ b/bin/templates/cordova/log.bat @@ -1,2 +1,18 @@ +:: 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. @ECHO OFF %~dp0\cordova.bat log %* diff --git a/bin/templates/cordova/run.bat b/bin/templates/cordova/run.bat index b1cab648..f191f675 100644 --- a/bin/templates/cordova/run.bat +++ b/bin/templates/cordova/run.bat @@ -1,2 +1,18 @@ +:: 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. @ECHO OFF -%~dp0\cordova.bat run %* \ No newline at end of file +%~dp0\cordova.bat run %* diff --git a/framework/res/xml/config.xml b/framework/res/xml/config.xml index 935eda4f..5b5a2700 100644 --- a/framework/res/xml/config.xml +++ b/framework/res/xml/config.xml @@ -1,18 +1,21 @@ # Android Native Tests # These tests are designed to verify Android native features and other Android specific features. diff --git a/test/res/xml/config.xml b/test/res/xml/config.xml index d3ea4d86..5ad2b25a 100644 --- a/test/res/xml/config.xml +++ b/test/res/xml/config.xml @@ -1,4 +1,22 @@ + From 0e572aea364fb089908af8cf648d438c44f7a94f Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Wed, 29 May 2013 10:23:00 -0400 Subject: [PATCH 13/29] [CB-3340] Add copying of the version script to bin/create --- bin/create | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/create b/bin/create index 71f98bc6..134100dd 100755 --- a/bin/create +++ b/bin/create @@ -143,6 +143,7 @@ cp "$BUILD_PATH"/bin/templates/cordova/build "$PROJECT_PATH"/cordova/build cp "$BUILD_PATH"/bin/templates/cordova/clean "$PROJECT_PATH"/cordova/clean cp "$BUILD_PATH"/bin/templates/cordova/log "$PROJECT_PATH"/cordova/log cp "$BUILD_PATH"/bin/templates/cordova/run "$PROJECT_PATH"/cordova/run +cp "$BUILD_PATH"/bin/templates/cordova/version "$PROJECT_PATH"/cordova/version cp "$BUILD_PATH"/bin/templates/cordova/lib/cordova "$PROJECT_PATH"/cordova/lib/cordova cp "$BUILD_PATH"/bin/templates/cordova/lib/install-device "$PROJECT_PATH"/cordova/lib/install-device cp "$BUILD_PATH"/bin/templates/cordova/lib/install-emulator "$PROJECT_PATH"/cordova/lib/install-emulator From dfb89df4f16104961f6493dfa815909cdfaf51bd Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 31 May 2013 10:38:57 -0400 Subject: [PATCH 14/29] [CB-3561] Update documentation comments to match implementation Affects CordovaInterface and CordovaActivity. There should probably be a concerted effort to update this across the entire project. --- framework/src/org/apache/cordova/CordovaActivity.java | 6 +----- framework/src/org/apache/cordova/api/CordovaInterface.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 4042b6be..b165815c 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -64,11 +64,10 @@ import android.widget.LinearLayout; * As an example: * * package org.apache.cordova.examples; - * import android.app.Activity; * import android.os.Bundle; * import org.apache.cordova.*; * - * public class Examples extends DroidGap { + * public class Example extends CordovaActivity { * @Override * public void onCreate(Bundle savedInstanceState) { * super.onCreate(savedInstanceState); @@ -77,9 +76,6 @@ import android.widget.LinearLayout; * super.setStringProperty("loadingDialog", "Title,Message"); // show loading dialog * super.setStringProperty("errorUrl", "file:///android_asset/www/error.html"); // if error loading file in super.loadUrl(). * - * // Initialize activity - * super.init(); - * * // Clear cache if you want * super.appView.clearCache(true); * diff --git a/framework/src/org/apache/cordova/api/CordovaInterface.java b/framework/src/org/apache/cordova/api/CordovaInterface.java index aaa5885a..8ef8ed01 100755 --- a/framework/src/org/apache/cordova/api/CordovaInterface.java +++ b/framework/src/org/apache/cordova/api/CordovaInterface.java @@ -24,7 +24,7 @@ import android.content.Intent; import java.util.concurrent.ExecutorService; /** - * The Cordova activity abstract class that is extended by DroidGap. + * The Activity interface that is implemented by CordovaActivity. * It is used to isolate plugin development, and remove dependency on entire Cordova library. */ public interface CordovaInterface { From 9ac9fd4fe90742f8d00fdc7ef43e74c6352f4122 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 31 May 2013 10:45:25 -0400 Subject: [PATCH 15/29] [CB-3563] Change default logging tag from DroidGap to CordovaActivity --- framework/src/org/apache/cordova/CordovaActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index b165815c..c59e1ee3 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -134,7 +134,7 @@ import android.widget.LinearLayout; * */ public class CordovaActivity extends Activity implements CordovaInterface { - public static String TAG = "DroidGap"; + public static String TAG = "CordovaActivity"; // The webview for our app protected CordovaWebView appView; From fb89cef256be6521ce3b1178fbd392cddd2a4686 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 31 May 2013 11:16:09 -0400 Subject: [PATCH 16/29] [CB-3563] Replace instances of DroidGap in log messages with more appropriate symbols --- framework/src/org/apache/cordova/App.java | 2 +- .../src/org/apache/cordova/CordovaActivity.java | 14 +++++++------- .../org/apache/cordova/CordovaChromeClient.java | 2 +- .../src/org/apache/cordova/CordovaWebView.java | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index afdbf3f2..965f9de7 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -198,7 +198,7 @@ public class App extends CordovaPlugin { * @param override T=override, F=cancel override */ public void overrideButton(String button, boolean override) { - LOG.i("DroidGap", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!"); + LOG.i("App", "WARNING: Volume Button Default Behaviour will be overridden. The volume event will be fired!"); webView.bindButton(button, override); } diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index c59e1ee3..097b3252 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -259,7 +259,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { @Override public void onCreate(Bundle savedInstanceState) { Config.init(this); - LOG.d(TAG, "DroidGap.onCreate()"); + LOG.d(TAG, "CordovaActivity.onCreate()"); super.onCreate(savedInstanceState); if(savedInstanceState != null) @@ -332,7 +332,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { */ @SuppressLint("NewApi") public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { - LOG.d(TAG, "DroidGap.init()"); + LOG.d(TAG, "CordovaActivity.init()"); // Set up web container this.appView = webView; @@ -595,7 +595,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param value */ public void setBooleanProperty(String name, boolean value) { - Log.d(TAG, "Setting boolean properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml"); + Log.d(TAG, "Setting boolean properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml"); this.getIntent().putExtra(name, value); } @@ -606,7 +606,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param value */ public void setIntegerProperty(String name, int value) { - Log.d(TAG, "Setting integer properties in DroidGap will be deprecated in 3.1 on August 2013, please use config.xml"); + Log.d(TAG, "Setting integer properties in CordovaActivity will be deprecated in 3.1 on August 2013, please use config.xml"); this.getIntent().putExtra(name, value); } @@ -617,7 +617,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param value */ public void setStringProperty(String name, String value) { - Log.d(TAG, "Setting string properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml"); + Log.d(TAG, "Setting string properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml"); this.getIntent().putExtra(name, value); } @@ -628,7 +628,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param value */ public void setDoubleProperty(String name, double value) { - Log.d(TAG, "Setting double properties in DroidGap will be deprecated in 3.0 on July 2013, please use config.xml"); + Log.d(TAG, "Setting double properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml"); this.getIntent().putExtra(name, value); } @@ -712,7 +712,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * The final call you receive before your activity is destroyed. */ public void onDestroy() { - LOG.d(TAG, "onDestroy()"); + LOG.d(TAG, "CordovaActivity.onDestroy()"); super.onDestroy(); // hide the splash screen to avoid leaking a window diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index d9da6baf..93833a5c 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -286,7 +286,7 @@ public class CordovaChromeClient extends WebChromeClient { public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { - LOG.d(TAG, "DroidGap: onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); + LOG.d(TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); if (estimatedSize < MAX_QUOTA) { diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index c57cd505..afb1e7f7 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -485,7 +485,7 @@ public class CordovaWebView extends WebView { // If first page, then show splashscreen else { - LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time); + LOG.d(TAG, "loadUrlIntoView(%s, %d)", url, time); // Send message to show splashscreen now if desired this.postMessage("splashscreen", "show"); From c509c8e7e53bdd0dd78481c6f0bdada8bf0800ee Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 31 May 2013 11:20:33 -0400 Subject: [PATCH 17/29] [CB-3563] Update references to DroidGap in code comments --- framework/src/org/apache/cordova/App.java | 4 ++-- framework/src/org/apache/cordova/CordovaActivity.java | 6 +++--- framework/src/org/apache/cordova/CordovaWebView.java | 4 ++-- framework/src/org/apache/cordova/Device.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 965f9de7..627d072d 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -30,7 +30,7 @@ import org.json.JSONObject; import java.util.HashMap; /** - * This class exposes methods in DroidGap that can be called from JavaScript. + * This class exposes methods in Cordova that can be called from JavaScript. */ public class App extends CordovaPlugin { @@ -104,7 +104,7 @@ public class App extends CordovaPlugin { * Load the url into the webview. * * @param url - * @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...) + * @param props Properties that can be passed in to the Cordova activity (i.e. loadingDialog, wait, ...) * @throws JSONException */ public void loadUrl(String url, JSONObject props) throws JSONException { diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 097b3252..c9580fbd 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -117,7 +117,7 @@ import android.widget.LinearLayout; * Cordova.xml configuration: * Cordova uses a configuration file at res/xml/cordova.xml to specify the following settings. * - * Approved list of URLs that can be loaded into DroidGap + * Approved list of URLs that can be loaded into Cordova * * Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR) * @@ -952,7 +952,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { } /* - * Hook in DroidGap for menu plugins + * Hook in Cordova for menu plugins * */ @Override @@ -991,7 +991,7 @@ public class CordovaActivity extends Activity implements CordovaInterface { * @param url The url to load. * @param openExternal Load url in browser instead of Cordova webview. * @param clearHistory Clear the history stack, so new page becomes top of history - * @param params DroidGap parameters for new app + * @param params Parameters for new app */ public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap params) { if (this.appView != null) { diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index afb1e7f7..9796ed83 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -555,7 +555,7 @@ public class CordovaWebView extends WebView { * @param url The url to load. * @param openExternal Load url in browser instead of Cordova webview. * @param clearHistory Clear the history stack, so new page becomes top of history - * @param params DroidGap parameters for new app + * @param params Parameters for new app */ public void showWebPage(String url, boolean openExternal, boolean clearHistory, HashMap params) { LOG.d(TAG, "showWebPage(%s, %b, %b, HashMap", url, openExternal, clearHistory); @@ -601,7 +601,7 @@ public class CordovaWebView extends WebView { /** * Check configuration parameters from Config. - * Approved list of URLs that can be loaded into DroidGap + * Approved list of URLs that can be loaded into Cordova * * Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR) * diff --git a/framework/src/org/apache/cordova/Device.java b/framework/src/org/apache/cordova/Device.java index d9d99282..b1cb2bb8 100644 --- a/framework/src/org/apache/cordova/Device.java +++ b/framework/src/org/apache/cordova/Device.java @@ -101,7 +101,7 @@ public class Device extends CordovaPlugin { /** * Listen for telephony events: RINGING, OFFHOOK and IDLE * Send these events to all plugins using - * DroidGap.onMessage("telephone", "ringing" | "offhook" | "idle") + * CordovaActivity.onMessage("telephone", "ringing" | "offhook" | "idle") */ private void initTelephonyReceiver() { IntentFilter intentFilter = new IntentFilter(); From c28a3133743567808d022b04ce028c30cca86b83 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Mon, 3 Jun 2013 15:03:47 -0400 Subject: [PATCH 18/29] [CB-3569] Allow FileTransfer.upload to reference android_assets --- .../src/org/apache/cordova/FileHelper.java | 16 +++++++++++----- .../src/org/apache/cordova/FileTransfer.java | 19 +++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java index 8bc24aa1..0d13c127 100644 --- a/framework/src/org/apache/cordova/FileHelper.java +++ b/framework/src/org/apache/cordova/FileHelper.java @@ -94,12 +94,18 @@ public class FileHelper { if (uriString.startsWith("content:")) { Uri uri = Uri.parse(uriString); return cordova.getActivity().getContentResolver().openInputStream(uri); - } else if (uriString.startsWith("file:///android_asset/")) { - Uri uri = Uri.parse(uriString); - String relativePath = uri.getPath().substring(15); - return cordova.getActivity().getAssets().open(relativePath); } else if (uriString.startsWith("file://")) { - return new FileInputStream(getRealPath(uriString, cordova)); + int question = uriString.indexOf("?"); + if (question > -1) { + uriString = uriString.substring(0,question); + } + if (uriString.startsWith("file:///android_asset/")) { + Uri uri = Uri.parse(uriString); + String relativePath = uri.getPath().substring(15); + return cordova.getActivity().getAssets().open(relativePath); + } else { + return new FileInputStream(getRealPath(uriString, cordova)); + } } else { return null; } diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java index 784c34c5..1b45fef2 100644 --- a/framework/src/org/apache/cordova/FileTransfer.java +++ b/framework/src/org/apache/cordova/FileTransfer.java @@ -855,20 +855,15 @@ public class FileTransfer extends CordovaPlugin { * @throws FileNotFoundException */ private InputStream getPathFromUri(String path) throws FileNotFoundException { - if (path.startsWith("content:")) { - Uri uri = Uri.parse(path); - return cordova.getActivity().getContentResolver().openInputStream(uri); - } - else if (path.startsWith("file://")) { - int question = path.indexOf("?"); - if (question == -1) { - return new FileInputStream(path.substring(7)); + try { + InputStream stream = FileHelper.getInputStreamFromUriString(path, cordova); + if (stream == null) { + return new FileInputStream(path); } else { - return new FileInputStream(path.substring(7, question)); + return stream; } - } - else { - return new FileInputStream(path); + } catch (IOException e) { + throw new FileNotFoundException(); } } From bc52345f05416df974d8df48cfc2ea96f14f37d9 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Mon, 3 Jun 2013 14:45:27 -0700 Subject: [PATCH 19/29] CB-3548: Throwing this one over the fence, but this change appears sane. We should just return false. --- framework/src/org/apache/cordova/CordovaChromeClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index 93833a5c..4d338a53 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -222,6 +222,7 @@ public class CordovaChromeClient extends WebChromeClient { result.confirm(r == null ? "" : r); } catch (JSONException e) { e.printStackTrace(); + return false; } } From 0dd4951be70b5216c96aab90f6e3eba2710a61e6 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 4 Jun 2013 14:28:16 -0700 Subject: [PATCH 20/29] Forgot to update this so that it doesn't destroy someone's project, FAIL --- bin/update | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/update b/bin/update index 2e716a7d..20440d48 100755 --- a/bin/update +++ b/bin/update @@ -64,8 +64,6 @@ function createAppInfoJar { function on_error { echo "An unexpected error occurred: $previous_command exited with $?" - echo "Deleting project..." - [ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH" exit 1 } @@ -105,6 +103,16 @@ then # update the cordova-android framework for the desired target "$ANDROID_BIN" update project --target $TARGET --path "$BUILD_PATH"/framework &> /dev/null + if [ ! -e "$BUILD_PATH"/framework/libs/commons-codec-1.7.jar ]; then + # Use curl to get the jar (TODO: Support Apache Mirrors) + curl -OL http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.7-bin.zip &> /dev/null + unzip commons-codec-1.7-bin.zip &> /dev/null + mkdir -p "$BUILD_PATH"/framework/libs + cp commons-codec-1.7/commons-codec-1.7.jar "$BUILD_PATH"/framework/libs + # cleanup yo + rm commons-codec-1.7-bin.zip && rm -rf commons-codec-1.7 + fi + # compile cordova.js and cordova.jar (cd "$BUILD_PATH"/framework && ant jar &> /dev/null ) fi From c3b8b279b091c4394dcf297566cfe453f58a1f82 Mon Sep 17 00:00:00 2001 From: David Kemp Date: Tue, 4 Jun 2013 13:37:26 -0400 Subject: [PATCH 21/29] CB-3420: add hidden option to InAppBrowser --- .../src/org/apache/cordova/InAppBrowser.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java index 8e78baa2..7a39c5bb 100644 --- a/framework/src/org/apache/cordova/InAppBrowser.java +++ b/framework/src/org/apache/cordova/InAppBrowser.java @@ -69,8 +69,9 @@ public class InAppBrowser extends CordovaPlugin { private static final String SELF = "_self"; private static final String SYSTEM = "_system"; // private static final String BLANK = "_blank"; - private static final String LOCATION = "location"; private static final String EXIT_EVENT = "exit"; + private static final String LOCATION = "location"; + private static final String HIDDEN = "hidden"; private static final String LOAD_START_EVENT = "loadstart"; private static final String LOAD_STOP_EVENT = "loadstop"; private static final String LOAD_ERROR_EVENT = "loaderror"; @@ -80,8 +81,9 @@ public class InAppBrowser extends CordovaPlugin { private Dialog dialog; private WebView inAppWebView; private EditText edittext; - private boolean showLocationBar = true; private CallbackContext callbackContext; + private boolean showLocationBar = true; + private boolean openWindowHidden = false; private String buttonLabel = "Done"; /** @@ -185,6 +187,16 @@ public class InAppBrowser extends CordovaPlugin { } injectDeferredObject(args.getString(0), jsWrapper); } + else if (action.equals("show")) { + Runnable runnable = new Runnable() { + @Override + public void run() { + dialog.show(); + } + }; + this.cordova.getActivity().runOnUiThread(runnable); + this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + } else { return false; } @@ -361,11 +373,16 @@ public class InAppBrowser extends CordovaPlugin { public String showWebPage(final String url, HashMap features) { // Determine if we should hide the location bar. showLocationBar = true; + openWindowHidden = false; if (features != null) { Boolean show = features.get(LOCATION); if (show != null) { showLocationBar = show.booleanValue(); } + Boolean hidden = features.get(HIDDEN); + if(hidden != null) { + openWindowHidden = hidden.booleanValue(); + } } final CordovaWebView thatWebView = this.webView; @@ -549,6 +566,11 @@ public class InAppBrowser extends CordovaPlugin { dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); + // the goal of openhidden is to load the url and not display it + // Show() needs to be called to cause the URL to be loaded + if(openWindowHidden) { + dialog.hide(); + } } }; this.cordova.getActivity().runOnUiThread(runnable); From e518eacbdedd523141c29571e6ea4c3f0be27a3a Mon Sep 17 00:00:00 2001 From: Braden Shepherdson Date: Thu, 6 Jun 2013 12:00:33 -0400 Subject: [PATCH 22/29] Replace naive relative path in version script with proper one --- bin/templates/cordova/version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/templates/cordova/version b/bin/templates/cordova/version index 21147abd..5760e95a 100755 --- a/bin/templates/cordova/version +++ b/bin/templates/cordova/version @@ -24,7 +24,7 @@ PROJECT_PATH="$(dirname "$CORDOVA_PATH")" VERSION_FILE_PATH="$PROJECT_PATH/assets/www/cordova.js" if [ -f "$VERSION_FILE_PATH" ]; then - JSVersion=$(sed -n '2,2p' assets/www/cordova.js) + JSVersion=$(sed -n '2,2p' $VERSION_FILE_PATH) echo $JSVersion | sed -e 's/\/\/ //'| cut -f 1 -d '-' else echo "The file \"$VERSION_FILE_PATH\" does not exist." From 43172cf53035e91125606fbb0046059c05c5a227 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Mon, 27 May 2013 22:20:01 -0400 Subject: [PATCH 23/29] Revert "CB-3496: Fixed streaming audio, this is pretty important for mobile spec" This reverts commit aa81966e0bf1460c6e40b9f5cc7290247cc84786. Going to revert all DataResource changes for on the 2.8.x branch. --- framework/src/org/apache/cordova/AudioHandler.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java index ef203064..20c3c4ef 100644 --- a/framework/src/org/apache/cordova/AudioHandler.java +++ b/framework/src/org/apache/cordova/AudioHandler.java @@ -58,10 +58,7 @@ public class AudioHandler extends CordovaPlugin { public String getFilePath(String url, String source){ DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source); - if(dataResource.getUri().getScheme().equals("http") || dataResource.getUri().getScheme().equals("https")) - return dataResource.getUri().toString(); - else - return dataResource.getRealFile().getPath(); + return dataResource.getRealFile().getPath(); } /** From 2f9c512b5942ae2c04002fe8c5581b6d514b8c52 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Mon, 27 May 2013 22:21:50 -0400 Subject: [PATCH 24/29] Revert "DataResource bugfix WebviewClient logs error for http urls." This reverts commit 8f91ebf194baa8028367e9e41f2e5ee2ff099b88. Reverting all DataResource changes for the 2.8.0 release. Conflicts: framework/src/org/apache/cordova/FileHelper.java framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java --- framework/src/org/apache/cordova/FileHelper.java | 2 +- .../org/apache/cordova/IceCreamCordovaWebViewClient.java | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java index 0d13c127..69c7f489 100644 --- a/framework/src/org/apache/cordova/FileHelper.java +++ b/framework/src/org/apache/cordova/FileHelper.java @@ -107,7 +107,7 @@ public class FileHelper { return new FileInputStream(getRealPath(uriString, cordova)); } } else { - return null; + return new FileInputStream(getRealPath(uriString, cordova)); } } diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java index d68b6b81..4b3408c9 100644 --- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java @@ -19,7 +19,6 @@ package org.apache.cordova; import java.io.IOException; -import java.io.InputStream; import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.DataResource; @@ -56,12 +55,7 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient { if(ret == null) { try { - InputStream is = dataResource.getInputStream(); - if(is != null) { - String mimeType = dataResource.getMimeType(); - // If we don't know how to open this file, let the browser continue loading - ret = new WebResourceResponse(mimeType, "UTF-8", is); - } + ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream()); } catch(IOException e) { LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e); } From e3989bcc2b23588def3948239fc73630192a543b Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Mon, 27 May 2013 22:22:14 -0400 Subject: [PATCH 25/29] Revert "DataRequest code cleaned up." This reverts commit a001d8cfb71930bf21ccc0b85715385ef409d8e0. Reverting all DataResource changes for the 2.8.0 release. Conflicts: framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java --- .../org/apache/cordova/CameraLauncher.java | 12 +++--- .../src/org/apache/cordova/FileHelper.java | 20 ++++++---- .../src/org/apache/cordova/FileUtils.java | 2 +- .../cordova/IceCreamCordovaWebViewClient.java | 7 +++- .../org/apache/cordova/api/CordovaPlugin.java | 4 +- .../org/apache/cordova/api/DataResource.java | 37 +++++++++---------- .../cordova/api/DataResourceContext.java | 9 ++++- .../org/apache/cordova/api/PluginManager.java | 9 ++--- 8 files changed, 55 insertions(+), 45 deletions(-) diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index 134cf098..f434661a 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -342,7 +342,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Add compressed version of captured image to returned media store Uri DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent"); - OutputStream os = dataResource.getOutputStream(); + OutputStream os = dataResource.getOs(); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); @@ -540,9 +540,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect private void writeUncompressedImage(Uri uri) throws FileNotFoundException, IOException { DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage"); - InputStream fis = inputDataResource.getInputStream(); + InputStream fis = inputDataResource.getIs(); DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage"); - OutputStream os = outDataResource.getOutputStream(); + OutputStream os = outDataResource.getOs(); if(fis == null) { throw new FileNotFoundException("Could not get the input file"); } else if(os == null) { @@ -592,13 +592,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If no new width or height were specified return the original bitmap DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap"); if (this.targetWidth <= 0 && this.targetHeight <= 0) { - return BitmapFactory.decodeStream(dataResource.getInputStream()); + return BitmapFactory.decodeStream(dataResource.getIs()); } // figure out the original width and height of the image BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(dataResource.getInputStream(), null, options); + BitmapFactory.decodeStream(dataResource.getIs(), null, options); //CB-2292: WTF? Why is the width null? if(options.outWidth == 0 || options.outHeight == 0) @@ -612,7 +612,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Load in the smallest bitmap possible that is closest to the size we want options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight); - Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getInputStream(), null, options); + Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getIs(), null, options); if (unscaledBitmap == null) { return null; } diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java index 69c7f489..e7bf98a8 100644 --- a/framework/src/org/apache/cordova/FileHelper.java +++ b/framework/src/org/apache/cordova/FileHelper.java @@ -130,27 +130,33 @@ public class FileHelper { */ public static boolean isUriWritable(String uriString) { String scheme = uriString.split(":")[0]; + String writableSchemes[] = new String[]{ "content" }; if(scheme.equals("file")){ // special case file - return !uriString.startsWith("file:///android_asset/"); + if(uriString.startsWith("file:///android_asset/")){ + return false; + } else { + return true; + } } - return "content".equals(scheme); + for(int i = writableSchemes.length - 1; i >= 0 ; i--){ + if(writableSchemes[i].equals(scheme)){ + return true; + } + } + return false; } /** * Ensures the "file://" prefix exists for the given string - * If the given URI string already has a scheme, it is returned unchanged + * If the given URI string has a "file://" prefix, it is returned unchanged * * @param path - the path string to operate on * @return a String with the "file://" scheme set */ public static String insertFileProtocol(String path) { if(!path.matches("^[a-z0-9+.-]+:.*")){ - //Ensure it is not a relative path - if(!path.startsWith("/")){ - throw new IllegalArgumentException("Relative paths" + path + "are not allowed."); - } path = "file://" + path; } return path; diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 4b136ed2..fe5a4ab1 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -897,7 +897,7 @@ public class FileUtils extends CordovaPlugin { public void run() { try { DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs"); - byte[] bytes = readAsBinaryHelper(dataResource.getInputStream(), start, end); + byte[] bytes = readAsBinaryHelper(dataResource.getIs(), start, end); PluginResult result; switch (resultType) { diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java index 4b3408c9..2a686d8a 100644 --- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java @@ -46,13 +46,16 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient { public WebResourceResponse shouldInterceptRequest(WebView view, String url) { // We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism. DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova, - "WebViewClient.shouldInterceptRequest"); + new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/)); url = dataResource.getUri().toString(); // This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it. //Check if plugins intercept the request WebResourceResponse ret = super.shouldInterceptRequest(view, url); - +// The below bugfix is taken care of by the dataResource mechanism +// if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){ +// ret = generateWebResourceResponse(url); +// } if(ret == null) { try { ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream()); diff --git a/framework/src/org/apache/cordova/api/CordovaPlugin.java b/framework/src/org/apache/cordova/api/CordovaPlugin.java index 866677c3..69f8fdeb 100644 --- a/framework/src/org/apache/cordova/api/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/api/CordovaPlugin.java @@ -182,10 +182,10 @@ public class CordovaPlugin { * * @param dataResource The resource to be loaded. * @param dataResourceContext Context associated with the resource load - * @return Return a new DataResource if the plugin wants to assist in loading the request or null if it doesn't. + * @return Return a new DataResource if the plugin wants o assist in loading the request or null if it doesn't. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public DataResource handleDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) { + public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) { return null; } diff --git a/framework/src/org/apache/cordova/api/DataResource.java b/framework/src/org/apache/cordova/api/DataResource.java index 5c1bb18e..38bf31bf 100644 --- a/framework/src/org/apache/cordova/api/DataResource.java +++ b/framework/src/org/apache/cordova/api/DataResource.java @@ -42,13 +42,10 @@ public class DataResource { private String mimeType; private Boolean writable; private File realFile; - private boolean retryIsLoad = true; - private boolean retryOsLoad = true; - private boolean retryMimeTypeLoad = true; - private boolean retryWritableLoad = true; - private boolean retryRealFileLoad = true; + private boolean retryLoad = true; public DataResource(CordovaInterface cordova, Uri uri) { + super(); this.cordova = cordova; this.uri = uri; } @@ -64,61 +61,61 @@ public class DataResource { // Uri is always provided return uri; } - public InputStream getInputStream() throws IOException { - if(is == null && retryIsLoad) { + public InputStream getIs() throws IOException { + if(is == null && retryLoad) { try { is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova); } finally { // We failed loading once, don't try loading anymore if(is == null) { - retryIsLoad = false; + retryLoad = false; } } } return is; } - public OutputStream getOutputStream() throws FileNotFoundException { - if(os == null && retryOsLoad) { + public OutputStream getOs() throws FileNotFoundException { + if(os == null && retryLoad) { try { os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova); } finally { // We failed loading once, don't try loading anymore if(os == null) { - retryOsLoad = false; + retryLoad = false; } } } return os; } public String getMimeType() { - if(mimeType == null && retryMimeTypeLoad) { + if(mimeType == null && retryLoad) { try { mimeType = FileHelper.getMimeType(uri.toString(), cordova); } finally { // We failed loading once, don't try loading anymore if(mimeType == null) { - retryMimeTypeLoad = false; + retryLoad = false; } } } return mimeType; } public boolean isWritable() { - if(writable == null && retryWritableLoad) { + if(writable == null && retryLoad) { try { writable = FileHelper.isUriWritable(uri.toString()); } finally { // We failed loading once, don't try loading anymore if(writable == null) { - retryWritableLoad = false; + retryLoad = false; } } } // default to false - return writable != null && writable.booleanValue(); + return writable != null? writable.booleanValue() : false; } public File getRealFile() { - if(realFile == null && retryRealFileLoad) { + if(realFile == null && retryLoad) { try { String realPath = FileHelper.getRealPath(uri, cordova); if(realPath != null) { @@ -127,7 +124,7 @@ public class DataResource { } finally { // We failed loading once, don't try loading anymore if(realFile == null) { - retryRealFileLoad = false; + retryLoad = false; } } } @@ -141,7 +138,7 @@ public class DataResource { return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag); } public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){ - return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag)); + return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag, false /* Assume, not a browser request by default */ )); } public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){ // if no protocol is specified, assume its file: @@ -152,7 +149,7 @@ public class DataResource { DataResource dataResource = new DataResource(cordova, uri); if (pluginManager != null) { // get the resource as returned by plugins - dataResource = pluginManager.handleDataResourceRequestWithPlugins(dataResource, dataResourceContext); + dataResource = pluginManager.shouldInterceptDataResourceRequest(dataResource, dataResourceContext); } return dataResource; } diff --git a/framework/src/org/apache/cordova/api/DataResourceContext.java b/framework/src/org/apache/cordova/api/DataResourceContext.java index 9cfe7bcc..55bbc1d0 100644 --- a/framework/src/org/apache/cordova/api/DataResourceContext.java +++ b/framework/src/org/apache/cordova/api/DataResourceContext.java @@ -30,11 +30,15 @@ public class DataResourceContext { // A tag associated with the source of this dataResourceContext private String source; // If needed, any data associated with core plugins can be a part of the context object + // This field indicates whether the request came from a browser network request + private boolean isFromBrowser; // If needed, any data associated with non core plugins should store data in a Map so as to not clutter the context object private Map dataMap; - public DataResourceContext(String source) { + public DataResourceContext(String source, boolean isFromBrowser) { + super(); this.requestId = new Random().nextInt(); this.source = source; + this.isFromBrowser = isFromBrowser; this.dataMap = new HashMap(); } public int getRequestId() { @@ -43,6 +47,9 @@ public class DataResourceContext { public String getSource() { return source; } + public boolean isFromBrowser() { + return isFromBrowser; + } public Map getDataMap() { return dataMap; } diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java index e0ceabfb..36ac357e 100755 --- a/framework/src/org/apache/cordova/api/PluginManager.java +++ b/framework/src/org/apache/cordova/api/PluginManager.java @@ -54,7 +54,6 @@ public class PluginManager { // Map URL schemes like foo: to plugins that want to handle those schemes // This would allow how all URLs are handled to be offloaded to a plugin protected HashMap urlMap = new HashMap(); - private int MAX_REPITIONS = 1000; /** * Constructor. @@ -410,15 +409,13 @@ public class PluginManager { * @param dataResourceContext The context of the dataResource request * @return Return the resource request that will be loaded. The returned request may be modified or unchanged. */ - public DataResource handleDataResourceRequestWithPlugins(DataResource dataResource, DataResourceContext dataResourceContext){ - int repetitions = 0; + public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext){ boolean requestModified = true; - while(requestModified && repetitions < MAX_REPITIONS) { + while(requestModified) { requestModified = false; - repetitions ++; for (PluginEntry entry : this.entries.values()) { if (entry.plugin != null) { - DataResource ret = entry.plugin.handleDataResourceRequest(dataResource, dataResourceContext); + DataResource ret = entry.plugin.shouldInterceptDataResourceRequest(dataResource, dataResourceContext); if(ret != null) { dataResource = ret; requestModified = true; From c5b37cc7e7d5bc96d98fd17ea70a165c08761682 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Mon, 27 May 2013 22:22:16 -0400 Subject: [PATCH 26/29] Revert "Changed all usages of FileHelper to use the new DataResource mechanism." This reverts commit 867358ea81619ce2b0e674758f1d66f1bc22172c. Reverting all DataResource changes for the 2.8.0 release. Conflicts: framework/src/org/apache/cordova/FileUtils.java --- .../src/org/apache/cordova/AudioHandler.java | 13 +- .../org/apache/cordova/CameraLauncher.java | 61 ++++----- framework/src/org/apache/cordova/Capture.java | 13 +- .../src/org/apache/cordova/FileUtils.java | 119 +++++++++++------- .../cordova/IceCreamCordovaWebViewClient.java | 1 - 5 files changed, 107 insertions(+), 100 deletions(-) diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java index 20c3c4ef..fd8c9df0 100644 --- a/framework/src/org/apache/cordova/AudioHandler.java +++ b/framework/src/org/apache/cordova/AudioHandler.java @@ -20,7 +20,7 @@ package org.apache.cordova; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; -import org.apache.cordova.api.DataResource; + import android.content.Context; import android.media.AudioManager; @@ -56,11 +56,6 @@ public class AudioHandler extends CordovaPlugin { this.pausedForPhone = new ArrayList(); } - public String getFilePath(String url, String source){ - DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source); - return dataResource.getRealFile().getPath(); - } - /** * Executes the request and returns PluginResult. * @param action The action to execute. @@ -73,13 +68,13 @@ public class AudioHandler extends CordovaPlugin { String result = ""; if (action.equals("startRecordingAudio")) { - this.startRecordingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startRecordingAudio")); + this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1))); } else if (action.equals("stopRecordingAudio")) { this.stopRecordingAudio(args.getString(0)); } else if (action.equals("startPlayingAudio")) { - this.startPlayingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startPlayingAudio")); + this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1))); } else if (action.equals("seekToAudio")) { this.seekToAudio(args.getString(0), args.getInt(1)); @@ -107,7 +102,7 @@ public class AudioHandler extends CordovaPlugin { } else if (action.equals("create")) { String id = args.getString(0); - String src = getFilePath(args.getString(1), "AudioHandler.create"); + String src = FileHelper.stripFileProtocol(args.getString(1)); AudioPlayer audio = new AudioPlayer(this, id, src); this.players.put(id, audio); } diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java index f434661a..8e43786c 100755 --- a/framework/src/org/apache/cordova/CameraLauncher.java +++ b/framework/src/org/apache/cordova/CameraLauncher.java @@ -20,15 +20,14 @@ package org.apache.cordova; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; -import org.apache.cordova.api.DataResource; import org.apache.cordova.api.LOG; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; @@ -42,6 +41,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.Bitmap.CompressFormat; +import android.graphics.Rect; import android.media.MediaScannerConnection; import android.media.MediaScannerConnection.MediaScannerConnectionClient; import android.net.Uri; @@ -290,7 +290,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // If sending base64 image back if (destType == DATA_URL) { - bitmap = getScaledBitmap(imageUri.toString()); + bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (bitmap == null) { // Try to get the bitmap from intent. bitmap = (Bitmap)intent.getExtras().get("data"); @@ -316,9 +316,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); //Just because we have a media URI doesn't mean we have a real file, we need to make it - DataResource dataResource = DataResource.initiateNewDataRequestForUri(inputUri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent"); - File file = dataResource.getRealFile(); - uri = Uri.fromFile(file); + uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); } else { uri = Uri.fromFile(new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg")); } @@ -334,15 +332,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect this.callbackContext.success(uri.toString()); } else { - bitmap = getScaledBitmap(imageUri.toString()); + bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString())); if (rotate != 0 && this.correctOrientation) { bitmap = getRotatedBitmap(rotate, bitmap, exif); } // Add compressed version of captured image to returned media store Uri - DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent"); - OutputStream os = dataResource.getOs(); + OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); @@ -350,7 +347,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect if (this.encodingType == JPEG) { String exifPath; if (this.saveToPhotoAlbum) { - exifPath = dataResource.getRealFile().getPath(); + exifPath = FileHelper.getRealPath(uri, this.cordova); } else { exifPath = uri.getPath(); } @@ -401,9 +398,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect this.callbackContext.success(uri.toString()); } else { String uriString = uri.toString(); - DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent"); // Get the path to the image. Makes loading so much easier. - String mimeType = dataResource.getMimeType(); + String mimeType = FileHelper.getMimeType(uriString, this.cordova); // If we don't have a valid image so quit. if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); @@ -444,8 +440,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Create an ExifHelper to save the exif data that is lost during compression String resizePath = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg"; // Some content: URIs do not map to file paths (e.g. picasa). - File realFile = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent").getRealFile(); - String realPath = realFile != null? realFile.getPath() : null; + String realPath = FileHelper.getRealPath(uri, this.cordova); ExifHelper exif = new ExifHelper(); if (realPath != null && this.encodingType == JPEG) { try { @@ -539,15 +534,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect */ private void writeUncompressedImage(Uri uri) throws FileNotFoundException, IOException { - DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage"); - InputStream fis = inputDataResource.getIs(); - DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage"); - OutputStream os = outDataResource.getOs(); - if(fis == null) { - throw new FileNotFoundException("Could not get the input file"); - } else if(os == null) { - throw new FileNotFoundException("Could not get the output file"); - } + FileInputStream fis = new FileInputStream(FileHelper.stripFileProtocol(imageUri.toString())); + OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri); byte[] buffer = new byte[4096]; int len; while ((len = fis.read(buffer)) != -1) { @@ -590,15 +578,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect */ private Bitmap getScaledBitmap(String imageUrl) throws IOException { // If no new width or height were specified return the original bitmap - DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap"); if (this.targetWidth <= 0 && this.targetHeight <= 0) { - return BitmapFactory.decodeStream(dataResource.getIs()); + return BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova)); } // figure out the original width and height of the image BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - BitmapFactory.decodeStream(dataResource.getIs(), null, options); + BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options); //CB-2292: WTF? Why is the width null? if(options.outWidth == 0 || options.outHeight == 0) @@ -612,7 +599,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect // Load in the smallest bitmap possible that is closest to the size we want options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight); - Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getIs(), null, options); + Bitmap unscaledBitmap = BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options); if (unscaledBitmap == null) { return null; } @@ -711,20 +698,16 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect bitmap.recycle(); } - DataResource dataResource = DataResource.initiateNewDataRequestForUri(oldImage, webView.pluginManager, cordova, "CameraLauncher.cleanup"); - File file = dataResource.getRealFile(); - if(file != null) { - // Clean up initial camera-written image file. - file.delete(); + // Clean up initial camera-written image file. + (new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete(); - checkForDuplicateImage(imageType); - // Scan for the gallery to update pic refs in gallery - if (this.saveToPhotoAlbum && newImage != null) { - this.scanForGallery(newImage); - } - - System.gc(); + checkForDuplicateImage(imageType); + // Scan for the gallery to update pic refs in gallery + if (this.saveToPhotoAlbum && newImage != null) { + this.scanForGallery(newImage); } + + System.gc(); } /** diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java index d7ad419e..5f737ca7 100644 --- a/framework/src/org/apache/cordova/Capture.java +++ b/framework/src/org/apache/cordova/Capture.java @@ -26,7 +26,6 @@ import java.io.OutputStream; import android.os.Build; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; -import org.apache.cordova.api.DataResource; import org.apache.cordova.api.LOG; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; @@ -130,8 +129,7 @@ public class Capture extends CordovaPlugin { // If the mimeType isn't set the rest will fail // so let's see if we can determine it. if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.dataResource"); - mimeType = dataResource.getMimeType(); + mimeType = FileHelper.getMimeType(filePath, cordova); } Log.d(LOG_TAG, "Mime type = " + mimeType); @@ -158,8 +156,7 @@ public class Capture extends CordovaPlugin { private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.getImageData"); - BitmapFactory.decodeFile(dataResource.getRealFile().getPath(), options); + BitmapFactory.decodeFile(FileHelper.stripFileProtocol(filePath), options); obj.put("height", options.outHeight); obj.put("width", options.outWidth); return obj; @@ -351,8 +348,7 @@ public class Capture extends CordovaPlugin { * @throws IOException */ private JSONObject createMediaFile(Uri data) { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(data, webView.pluginManager, cordova, "Capture.createMediaFile"); - File fp = dataResource.getRealFile(); + File fp = new File(FileHelper.getRealPath(data, this.cordova)); JSONObject obj = new JSONObject(); try { @@ -362,7 +358,6 @@ public class Capture extends CordovaPlugin { // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it // is stored in the audio or video content store. - if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) { if (data.toString().contains("/audio/")) { obj.put("type", AUDIO_3GPP); @@ -370,7 +365,7 @@ public class Capture extends CordovaPlugin { obj.put("type", VIDEO_3GPP); } } else { - obj.put("type", dataResource.getMimeType()); + obj.put("type", FileHelper.getMimeType(fp.getAbsolutePath(), cordova)); } obj.put("lastModifiedDate", fp.lastModified()); diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index fe5a4ab1..f6db0ac7 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -18,6 +18,8 @@ */ package org.apache.cordova; +import android.database.Cursor; +import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.util.Base64; @@ -25,7 +27,6 @@ import android.util.Log; import org.apache.cordova.api.CallbackContext; import org.apache.cordova.api.CordovaPlugin; -import org.apache.cordova.api.DataResource; import org.apache.cordova.api.PluginResult; import org.apache.cordova.file.EncodingException; import org.apache.cordova.file.FileExistsException; @@ -45,6 +46,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; import java.nio.channels.FileChannel; /** @@ -231,7 +234,7 @@ public class FileUtils extends CordovaPlugin { * @param filePath the path to check */ private void notifyDelete(String filePath) { - String newFilePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.notifyDelete").getRealFile().getPath(); + String newFilePath = FileHelper.getRealPath(filePath, cordova); try { this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.DATA + " = ?", @@ -253,10 +256,37 @@ public class FileUtils extends CordovaPlugin { * @throws IOException if the user can't read the file * @throws JSONException */ + @SuppressWarnings("deprecation") private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException { - File fp = DataResource.initiateNewDataRequestForUri(url, webView.pluginManager, cordova, "FileUtils.resolveLocalFileSystemURI").getRealFile(); + String decoded = URLDecoder.decode(url, "UTF-8"); - if (fp == null || !fp.exists()) { + File fp = null; + + // Handle the special case where you get an Android content:// uri. + if (decoded.startsWith("content:")) { + Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null); + // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data" + int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); + cursor.moveToFirst(); + fp = new File(cursor.getString(column_index)); + } else { + // Test to see if this is a valid URL first + @SuppressWarnings("unused") + URL testUrl = new URL(decoded); + + if (decoded.startsWith("file://")) { + int questionMark = decoded.indexOf("?"); + if (questionMark < 0) { + fp = new File(decoded.substring(7, decoded.length())); + } else { + fp = new File(decoded.substring(7, questionMark)); + } + } else { + fp = new File(decoded); + } + } + + if (!fp.exists()) { throw new FileNotFoundException(); } if (!fp.canRead()) { @@ -274,9 +304,9 @@ public class FileUtils extends CordovaPlugin { * @throws JSONException */ private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException { - File fp = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile(); + File fp = createFileObject(fileName); - if (fp == null || !fp.exists()) { + if (!fp.exists()) { // The directory we are listing doesn't exist so we should fail. throw new FileNotFoundException(); } @@ -311,10 +341,8 @@ public class FileUtils extends CordovaPlugin { * @throws FileExistsException */ private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException { - DataResource dataResourceFrom = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.transferTo"); - String newFileName = dataResourceFrom.getRealFile().getPath(); - DataResource dataResourceTo = DataResource.initiateNewDataRequestForUri(newParent, webView.pluginManager, cordova, "FileUtils.transferTo"); - newParent = dataResourceTo.getRealFile().getPath(); + String newFileName = FileHelper.getRealPath(fileName, cordova); + newParent = FileHelper.getRealPath(newParent, cordova); // Check for invalid file name if (newName != null && newName.contains(":")) { @@ -585,7 +613,7 @@ public class FileUtils extends CordovaPlugin { * @throws FileExistsException */ private boolean removeRecursively(String filePath) throws FileExistsException { - File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile(); + File fp = createFileObject(filePath); // You can't delete the root directory. if (atRootDirectory(filePath)) { @@ -626,7 +654,7 @@ public class FileUtils extends CordovaPlugin { * @throws InvalidModificationException */ private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException { - File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile(); + File fp = createFileObject(filePath); // You can't delete the root directory. if (atRootDirectory(filePath)) { @@ -670,8 +698,7 @@ public class FileUtils extends CordovaPlugin { throw new EncodingException("This file has a : in it's name"); } - String filePath = getFullFilePath(dirPath, fileName); - File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getFile").getRealFile(); + File fp = createFileObject(dirPath, fileName); if (create) { if (exclusive && fp.exists()) { @@ -713,14 +740,15 @@ public class FileUtils extends CordovaPlugin { * @param fileName new file name * @return */ - private String getFullFilePath(String dirPath, String fileName) { + private File createFileObject(String dirPath, String fileName) { + File fp = null; if (fileName.startsWith("/")) { - return fileName; + fp = new File(fileName); } else { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(dirPath, webView.pluginManager, cordova, "FileUtils.getFullFilePath"); - dirPath = dataResource.getRealFile().getPath(); - return dirPath + File.separator + fileName; + dirPath = FileHelper.getRealPath(dirPath, cordova); + fp = new File(dirPath + File.separator + fileName); } + return fp; } /** @@ -732,13 +760,12 @@ public class FileUtils extends CordovaPlugin { * @throws JSONException */ private JSONObject getParent(String filePath) throws JSONException { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getParent"); - filePath = dataResource.getRealFile().getPath(); + filePath = FileHelper.getRealPath(filePath, cordova); if (atRootDirectory(filePath)) { return getEntry(filePath); } - return getEntry(dataResource.getRealFile().getParent()); + return getEntry(new File(filePath).getParent()); } /** @@ -749,7 +776,7 @@ public class FileUtils extends CordovaPlugin { * @return true if we are at the root, false otherwise. */ private boolean atRootDirectory(String filePath) { - filePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.atRootDirectory").getRealFile().getPath(); + filePath = FileHelper.getRealPath(filePath, cordova); if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") || filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) || @@ -759,6 +786,19 @@ public class FileUtils extends CordovaPlugin { return false; } + /** + * Create a File object from the passed in path + * + * @param filePath + * @return + */ + private File createFileObject(String filePath) { + filePath = FileHelper.getRealPath(filePath, cordova); + + File file = new File(filePath); + return file; + } + /** * Look up metadata about this entry. * @@ -767,9 +807,9 @@ public class FileUtils extends CordovaPlugin { * @throws FileNotFoundException */ private long getMetadata(String filePath) throws FileNotFoundException { - File file = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata").getRealFile(); + File file = createFileObject(filePath); - if (file == null || !file.exists()) { + if (!file.exists()) { throw new FileNotFoundException("Failed to find file in getMetadata"); } @@ -785,16 +825,15 @@ public class FileUtils extends CordovaPlugin { * @throws JSONException */ private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata"); - File file = dataResource.getRealFile(); + File file = createFileObject(filePath); - if (file == null || !file.exists()) { + if (!file.exists()) { throw new FileNotFoundException("File: " + filePath + " does not exist."); } JSONObject metadata = new JSONObject(); metadata.put("size", file.length()); - metadata.put("type", dataResource.getMimeType()); + metadata.put("type", FileHelper.getMimeType(filePath, cordova)); metadata.put("name", file.getName()); metadata.put("fullPath", filePath); metadata.put("lastModifiedDate", file.lastModified()); @@ -896,8 +935,7 @@ public class FileUtils extends CordovaPlugin { this.cordova.getThreadPool().execute(new Runnable() { public void run() { try { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs"); - byte[] bytes = readAsBinaryHelper(dataResource.getIs(), start, end); + byte[] bytes = readAsBinaryHelper(filename, start, end); PluginResult result; switch (resultType) { @@ -938,9 +976,10 @@ public class FileUtils extends CordovaPlugin { * @return Contents of the file as a byte[]. * @throws IOException */ - private byte[] readAsBinaryHelper(InputStream inputStream, int start, int end) throws IOException { + private byte[] readAsBinaryHelper(String filename, int start, int end) throws IOException { int numBytesToRead = end - start; byte[] bytes = new byte[numBytesToRead]; + InputStream inputStream = FileHelper.getInputStreamFromUriString(filename, cordova); int numBytesRead = 0; if (start > 0) { @@ -969,8 +1008,7 @@ public class FileUtils extends CordovaPlugin { throw new NoModificationAllowedException("Couldn't write to file given its content URI"); } - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.write"); - filename = dataResource.getRealFile().getPath(); + filename = FileHelper.getRealPath(filename, cordova); boolean append = false; if (offset > 0) { @@ -999,16 +1037,13 @@ public class FileUtils extends CordovaPlugin { * @throws NoModificationAllowedException */ private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException { - DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.truncateFile"); - if(!dataResource.isWritable()) { - throw new NoModificationAllowedException("Couldn't truncate file as it is not writable"); - } - File file = dataResource.getRealFile(); - if(file == null) { - throw new FileNotFoundException("Couldn't get the file"); + if (filename.startsWith("content://")) { + throw new NoModificationAllowedException("Couldn't truncate file given its content URI"); } - RandomAccessFile raf = new RandomAccessFile(file, "rw"); + filename = FileHelper.getRealPath(filename, cordova); + + RandomAccessFile raf = new RandomAccessFile(filename, "rw"); try { if (raf.length() >= size) { FileChannel channel = raf.getChannel(); diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java index 2a686d8a..d71fbe86 100644 --- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java @@ -49,7 +49,6 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient { new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/)); url = dataResource.getUri().toString(); - // This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it. //Check if plugins intercept the request WebResourceResponse ret = super.shouldInterceptRequest(view, url); // The below bugfix is taken care of by the dataResource mechanism From 979d8e66f26d27a132d7514386b777fc8fc234f3 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Mon, 27 May 2013 22:22:18 -0400 Subject: [PATCH 27/29] Revert "Added "DataResource" - allows many plugins to intercept a single request" This reverts commit 62c3e4652975f3e23a2f5a203dc13f7d4c98a30e. Reverting all DataResource changes for the 2.8.0 release. Conflicts: framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java framework/src/org/apache/cordova/api/DataResource.java framework/src/org/apache/cordova/api/DataResourceContext.java --- .../src/org/apache/cordova/FileHelper.java | 58 +------ .../cordova/IceCreamCordovaWebViewClient.java | 50 ++++-- .../org/apache/cordova/api/CordovaPlugin.java | 14 -- .../org/apache/cordova/api/DataResource.java | 156 ------------------ .../cordova/api/DataResourceContext.java | 56 ------- .../org/apache/cordova/api/PluginManager.java | 26 --- 6 files changed, 36 insertions(+), 324 deletions(-) delete mode 100644 framework/src/org/apache/cordova/api/DataResource.java delete mode 100644 framework/src/org/apache/cordova/api/DataResourceContext.java diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java index e7bf98a8..ebbdc8df 100644 --- a/framework/src/org/apache/cordova/FileHelper.java +++ b/framework/src/org/apache/cordova/FileHelper.java @@ -26,11 +26,10 @@ import org.apache.cordova.api.CordovaInterface; import org.apache.cordova.api.LOG; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; +import java.net.URLConnection; +import java.util.Locale; public class FileHelper { private static final String LOG_TAG = "FileUtils"; @@ -91,7 +90,7 @@ public class FileHelper { * @throws IOException */ public static InputStream getInputStreamFromUriString(String uriString, CordovaInterface cordova) throws IOException { - if (uriString.startsWith("content:")) { + if (uriString.startsWith("content")) { Uri uri = Uri.parse(uriString); return cordova.getActivity().getContentResolver().openInputStream(uri); } else if (uriString.startsWith("file://")) { @@ -111,57 +110,6 @@ public class FileHelper { } } - public static OutputStream getOutputStreamFromUriString(String uriString, CordovaInterface cordova) throws FileNotFoundException{ - if (uriString.startsWith("content:")) { - Uri uri = Uri.parse(uriString); - return cordova.getActivity().getContentResolver().openOutputStream(uri); - } else if (uriString.startsWith("file:") && !uriString.startsWith("file:///android_asset/")) { - String realPath = uriString.substring(7); - return new FileOutputStream(realPath); - } else { - return null; - } - } - /** - * Returns whether the uri can be written to by openeing a File to that uri - * - * @param the URI to test - * @return boolean indicating whether the uri is writable - */ - public static boolean isUriWritable(String uriString) { - String scheme = uriString.split(":")[0]; - String writableSchemes[] = new String[]{ "content" }; - - if(scheme.equals("file")){ - // special case file - if(uriString.startsWith("file:///android_asset/")){ - return false; - } else { - return true; - } - } - for(int i = writableSchemes.length - 1; i >= 0 ; i--){ - if(writableSchemes[i].equals(scheme)){ - return true; - } - } - return false; - } - - /** - * Ensures the "file://" prefix exists for the given string - * If the given URI string has a "file://" prefix, it is returned unchanged - * - * @param path - the path string to operate on - * @return a String with the "file://" scheme set - */ - public static String insertFileProtocol(String path) { - if(!path.matches("^[a-z0-9+.-]+:.*")){ - path = "file://" + path; - } - return path; - } - /** * Removes the "file://" prefix from the given URI string, if applicable. * If the given URI string doesn't have a "file://" prefix, it is returned unchanged. diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java index d71fbe86..847972ee 100644 --- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java @@ -19,10 +19,9 @@ package org.apache.cordova; import java.io.IOException; +import java.io.InputStream; import org.apache.cordova.api.CordovaInterface; -import org.apache.cordova.api.DataResource; -import org.apache.cordova.api.DataResourceContext; import org.apache.cordova.api.LOG; import android.annotation.TargetApi; @@ -44,24 +43,41 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient { @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { - // We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism. - DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova, - new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/)); - url = dataResource.getUri().toString(); - //Check if plugins intercept the request WebResourceResponse ret = super.shouldInterceptRequest(view, url); -// The below bugfix is taken care of by the dataResource mechanism -// if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){ -// ret = generateWebResourceResponse(url); -// } - if(ret == null) { - try { - ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream()); - } catch(IOException e) { - LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e); - } + if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){ + ret = generateWebResourceResponse(url); } return ret; } + + private WebResourceResponse generateWebResourceResponse(String url) { + if (url.startsWith("file:///android_asset/")) { + String mimetype = FileHelper.getMimeType(url, cordova); + + try { + InputStream stream = FileHelper.getInputStreamFromUriString(url, cordova); + WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8", stream); + return response; + } catch (IOException e) { + LOG.e("generateWebResourceResponse", e.getMessage(), e); + } + } + return null; + } + + private static boolean needsIceCreamSpaceInAssetUrlFix(String url) { + if (!url.contains("%20")){ + return false; + } + + switch(android.os.Build.VERSION.SDK_INT){ + case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH: + case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1: + return true; + default: + return false; + } + } + } diff --git a/framework/src/org/apache/cordova/api/CordovaPlugin.java b/framework/src/org/apache/cordova/api/CordovaPlugin.java index 69f8fdeb..2b225e64 100644 --- a/framework/src/org/apache/cordova/api/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/api/CordovaPlugin.java @@ -175,20 +175,6 @@ public class CordovaPlugin { return null; } - /** - * All plugins can now choose if they want to modify any uri requests. This includes all webview requests, opening of files, content uri's etc. - * This mechanism allows several plugins to modify the same request - * @param requestSource The source of the incoming request - * - * @param dataResource The resource to be loaded. - * @param dataResourceContext Context associated with the resource load - * @return Return a new DataResource if the plugin wants o assist in loading the request or null if it doesn't. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) { - return null; - } - /** * Called when the WebView does a top-level navigation or refreshes. * diff --git a/framework/src/org/apache/cordova/api/DataResource.java b/framework/src/org/apache/cordova/api/DataResource.java deleted file mode 100644 index 38bf31bf..00000000 --- a/framework/src/org/apache/cordova/api/DataResource.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - 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. -*/ -package org.apache.cordova.api; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.apache.cordova.FileHelper; - -import android.net.Uri; - -/* - * All requests to access files, browser network requests etc have to go through this class. - */ -public class DataResource { - private CordovaInterface cordova; - - // Uri of the request. Always required. - private Uri uri; - // Remaining fields may or may not be null - private InputStream is; - private OutputStream os; - private String mimeType; - private Boolean writable; - private File realFile; - private boolean retryLoad = true; - - public DataResource(CordovaInterface cordova, Uri uri) { - super(); - this.cordova = cordova; - this.uri = uri; - } - public DataResource(CordovaInterface cordova, Uri uri, InputStream is, - OutputStream os, String mimeType, boolean writable, File realFile) { - this(cordova, uri); - this.is = is; - this.mimeType = mimeType; - this.writable = Boolean.valueOf(writable); - this.realFile = realFile; - } - public Uri getUri() { - // Uri is always provided - return uri; - } - public InputStream getIs() throws IOException { - if(is == null && retryLoad) { - try { - is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova); - } finally { - // We failed loading once, don't try loading anymore - if(is == null) { - retryLoad = false; - } - } - } - return is; - } - public OutputStream getOs() throws FileNotFoundException { - if(os == null && retryLoad) { - try { - os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova); - } finally { - // We failed loading once, don't try loading anymore - if(os == null) { - retryLoad = false; - } - } - } - return os; - } - public String getMimeType() { - if(mimeType == null && retryLoad) { - try { - mimeType = FileHelper.getMimeType(uri.toString(), cordova); - } finally { - // We failed loading once, don't try loading anymore - if(mimeType == null) { - retryLoad = false; - } - } - } - return mimeType; - } - public boolean isWritable() { - if(writable == null && retryLoad) { - try { - writable = FileHelper.isUriWritable(uri.toString()); - } finally { - // We failed loading once, don't try loading anymore - if(writable == null) { - retryLoad = false; - } - } - } - // default to false - return writable != null? writable.booleanValue() : false; - } - public File getRealFile() { - if(realFile == null && retryLoad) { - try { - String realPath = FileHelper.getRealPath(uri, cordova); - if(realPath != null) { - realFile = new File(realPath); - } - } finally { - // We failed loading once, don't try loading anymore - if(realFile == null) { - retryLoad = false; - } - } - } - return realFile; - } - - // static instantiation methods - public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){ - // if no protocol is specified, assume its file: - uriString = FileHelper.insertFileProtocol(uriString); - return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag); - } - public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){ - return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag, false /* Assume, not a browser request by default */ )); - } - public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){ - // if no protocol is specified, assume its file: - uriString = FileHelper.insertFileProtocol(uriString); - return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, dataResourceContext); - } - public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){ - DataResource dataResource = new DataResource(cordova, uri); - if (pluginManager != null) { - // get the resource as returned by plugins - dataResource = pluginManager.shouldInterceptDataResourceRequest(dataResource, dataResourceContext); - } - return dataResource; - } -} diff --git a/framework/src/org/apache/cordova/api/DataResourceContext.java b/framework/src/org/apache/cordova/api/DataResourceContext.java deleted file mode 100644 index 55bbc1d0..00000000 --- a/framework/src/org/apache/cordova/api/DataResourceContext.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - 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. -*/ -package org.apache.cordova.api; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -/* - * Some context information associated with a DataRequest. - */ -public class DataResourceContext { - // A random id that is unique for a particular request. - private int requestId; - // A tag associated with the source of this dataResourceContext - private String source; - // If needed, any data associated with core plugins can be a part of the context object - // This field indicates whether the request came from a browser network request - private boolean isFromBrowser; - // If needed, any data associated with non core plugins should store data in a Map so as to not clutter the context object - private Map dataMap; - public DataResourceContext(String source, boolean isFromBrowser) { - super(); - this.requestId = new Random().nextInt(); - this.source = source; - this.isFromBrowser = isFromBrowser; - this.dataMap = new HashMap(); - } - public int getRequestId() { - return requestId; - } - public String getSource() { - return source; - } - public boolean isFromBrowser() { - return isFromBrowser; - } - public Map getDataMap() { - return dataMap; - } -} diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java index 36ac357e..71fc2581 100755 --- a/framework/src/org/apache/cordova/api/PluginManager.java +++ b/framework/src/org/apache/cordova/api/PluginManager.java @@ -400,30 +400,4 @@ public class PluginManager { LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml"); LOG.e(TAG, "====================================================================================="); } - - /** - * Called when the any resource is going to be loaded - either from the webview, files or any other resource - * - * - * @param dataResource The resource request to be loaded. - * @param dataResourceContext The context of the dataResource request - * @return Return the resource request that will be loaded. The returned request may be modified or unchanged. - */ - public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext){ - boolean requestModified = true; - while(requestModified) { - requestModified = false; - for (PluginEntry entry : this.entries.values()) { - if (entry.plugin != null) { - DataResource ret = entry.plugin.shouldInterceptDataResourceRequest(dataResource, dataResourceContext); - if(ret != null) { - dataResource = ret; - requestModified = true; - break; - } - } - } - } - return dataResource; - } } From 3753e3f3532da0f4dbd08ee1c1b68cf5be6465b9 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Thu, 6 Jun 2013 14:35:12 -0700 Subject: [PATCH 28/29] Trying to get DataResource reverted so that we don't have to worry about this blowing up while we're breaking things out. DataResource should be on a branch until it's ready! --- framework/src/org/apache/cordova/FileUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index f6db0ac7..aeca5057 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -949,7 +949,7 @@ public class FileUtils extends CordovaPlugin { result = new PluginResult(PluginResult.Status.OK, bytes, true); break; default: // Base64. - String contentType = dataResource.getMimeType(); + String contentType = FileHelper.getMimeType(filename, cordova); byte[] base64 = Base64.encode(bytes, Base64.DEFAULT); String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII"); result = new PluginResult(PluginResult.Status.OK, s); From e52d4fc0035546c6bbd93a60f02bd887fddab7cc Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 7 Jun 2013 16:43:53 -0700 Subject: [PATCH 29/29] CB-3736: Cleaning up code so that this makes more sense. Variables are OK --- framework/src/org/apache/cordova/Globalization.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/Globalization.java b/framework/src/org/apache/cordova/Globalization.java index 5c75e100..4fac0746 100644 --- a/framework/src/org/apache/cordova/Globalization.java +++ b/framework/src/org/apache/cordova/Globalization.java @@ -260,12 +260,13 @@ public class Globalization extends CordovaPlugin { String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) - if (options.getJSONObject(0).length() > 1){ + boolean test = options.getJSONObject(0).has(OPTIONS); + if (options.getJSONObject(0).has(OPTIONS)){ //options were included - + JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option - if (!((JSONObject)options.getJSONObject(0).get(OPTIONS)).isNull(FORMATLENGTH)){ - String fmtOpt = (String)((JSONObject)options.getJSONObject(0).get(OPTIONS)).get(FORMATLENGTH); + if (!innerOptions.isNull(FORMATLENGTH)){ + String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)){//medium fmtDate = (SimpleDateFormat)android.text.format.DateFormat.getMediumDateFormat(this.cordova.getActivity()); }else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)){ //long/full @@ -275,8 +276,8 @@ public class Globalization extends CordovaPlugin { //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); - if (!((JSONObject)options.getJSONObject(0).get(OPTIONS)).isNull(SELECTOR)){ - String selOpt = (String)((JSONObject)options.getJSONObject(0).get(OPTIONS)).get(SELECTOR); + if (!innerOptions.isNull(SELECTOR)){ + String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)){ fmt = fmtDate.toLocalizedPattern(); }else if (selOpt.equalsIgnoreCase(TIME)){