Compare commits

..

55 Commits
3.4.x ... 3.5.x

Author SHA1 Message Date
Marcel Kinard
85bcbdc894 CB-7267 update RELEASENOTES for 3.5.1
(cherry picked from commit eb8cf56e8e)
2014-08-28 09:44:29 -04:00
Steven Gill
4d2467670e change version in package.json to 3.5.1 2014-08-04 11:29:17 -07:00
Ian Clelland
ed8d3fd75b Set VERSION to 3.5.1 (via coho) 2014-07-28 16:31:26 -04:00
Ian Clelland
f99a589569 Update JS snapshot to version 3.5.1 (via coho) 2014-07-28 16:31:06 -04:00
Ian Clelland
07f8100058 Filter out non-launchable intents 2014-07-28 16:30:55 -04:00
Ian Clelland
25b8d360da Handle unsupported protocol errors in webview better 2014-07-28 16:30:44 -04:00
Joe Bowser
2ab81bc5ae Update the errorurl to no longer use intents 2014-07-28 16:30:29 -04:00
Joe Bowser
40acaa9e85 Refactoring the URI handling on Cordova, removing dead code 2014-07-28 16:29:52 -04:00
Steven Gill
d20d2781ef updated RELEASENOTES 2014-05-27 14:11:37 -07:00
Steven Gill
82bc714ed9 Set VERSION to 3.5.0 (via coho) 2014-05-08 15:32:23 -07:00
Steven Gill
568d3b5332 Update JS snapshot to version 3.5.0 (via coho) 2014-05-08 15:32:23 -07:00
Joe Bowser
df53dbdbc4 package.json apparently needs to be updated before tagging, re-tagging manually 2014-05-08 13:38:28 -07:00
Joe Bowser
a70191a9a4 OkHttp has broken headers. Updating for ASF compliance. 2014-05-06 16:16:47 -07:00
Joe Bowser
7ec8d08c58 Set VERSION to 3.5.0-rc1 (via coho) 2014-05-06 15:51:13 -07:00
Joe Bowser
6d40adfe33 Update JS snapshot to version 3.5.0-rc1 (via coho) 2014-05-06 15:51:13 -07:00
Joe Bowser
93c8ba920a Added dash to test push 2014-05-06 13:59:13 -07:00
Andrew Grieve
8702c04d39 Revert accidentally removed lines from NOTICE 2014-05-06 15:18:31 -04:00
Steven Gill
c349892c5b CB-6552: updated author to apache software foundation in pacakge.json 2014-04-30 12:55:28 -07:00
Steven Gill
3d4b8ce99b CB-6552: updated test field 2014-04-30 11:59:29 -07:00
Steven Gill
64fd87134f CB-6552: added top level package.json 2014-04-30 10:54:58 -07:00
Marcel Kinard
82bba44538 CB-6491 add CONTRIBUTING.md 2014-04-30 08:44:21 -04:00
Ningxin Hu
e6adbb0e42 CB-6543 Fix cordova/run failure when no custom_rules.xml available
Github: Close #99
2014-04-28 22:50:22 -04:00
Fardjad Davari
11fc6be328 defaults.xml: Add AndroidLaunchMode preference 2014-04-25 00:27:33 +04:30
Andrew Grieve
0ec8f5d283 Add JavaDoc for CordovaResourceApi 2014-04-17 15:51:59 -04:00
Ian Clelland
b872df0f31 CB-6388: Handle binary data correctly in LOAD_URL bridge 2014-04-02 13:42:19 -04:00
Ian Clelland
0add4af208 Update JS snapshot to version 3.5.0-dev-81f9a00 2014-04-02 13:42:19 -04:00
Michal Mocny
298cd9e065 Fix CB-6048: Set launchMode=singleTop so tapping app icon does not always restart app 2014-04-01 11:33:40 -04:00
hadeslee
b715d20385 Remove incorrect usage of AlertDialog.Builder.create
AlertDialog.Builder.show() will create an AlertDialog before it show. This is the source code snippet:

        /**
         * Creates a {@link AlertDialog} with the arguments supplied to this builder and
         * {@link Dialog#show()}'s the dialog.
         */
        public AlertDialog show() {
            AlertDialog dialog = create();
            dialog.show();
            return dialog;
        }

github: close #96
2014-03-28 13:40:43 -04:00
Andrew Grieve
9a00ccdacc Catch uncaught exceptions in from plugins and turn them into error responses.
When a plugin throws an unchecked exception, we're not catching it
anywhere and so the error callback is not being called.

This change adds a try/catch to catch such exceptions.
2014-03-06 21:27:44 -05:00
Andrew Grieve
e8d48e1f43 Add NOTICE file 2014-02-27 15:36:30 -05:00
Andrew Grieve
a2f8c9c75b CB-6047 Fix online sometimes getting in a bad state on page transitions.
The online bridge toggles between on & off. Turns out that starting with
Android 4.3, navigation resets the online state, so the code had a 50/50
chance of being caught in the wrong state.

We now forcefully reset the online state on page transitions.
2014-02-26 20:23:07 -05:00
Andrew Grieve
5fb83e7f52 Add another convenience overload for CordovaResourceApi.copyResource 2014-02-26 20:20:10 -05:00
Andrew Grieve
dd6bf568d1 Update framework's .classpath to what Eclipse wants it to be. 2014-02-26 20:18:35 -05:00
Andrew Magee
00ee164cef README.md: android update to android-19. 2014-02-18 22:12:03 -05:00
Andrew Grieve
448071b02d Fix NPE when POLLING bridge mode is used. 2014-02-18 22:11:38 -05:00
Andrew Grieve
4dad9d0e37 Add RELEASENOTES for 3.4.0 2014-02-18 22:11:38 -05:00
Joe Bowser
3a2117c5d3 Updating NOTICE to include Square for OkHttp 2014-02-18 18:31:28 -08:00
Joe Bowser
26a3f6ddc3 Update JS snapshot to version 3.5.0-dev (via coho) 2014-02-14 13:52:31 -08:00
Andrew Grieve
7741312673 CB-5398 Apply KitKat content URI fix to all content URIs 2014-02-14 11:02:17 -05:00
Andrew Grieve
954a1723f1 CB-5398 Work-around for KitKat content: URLs not rendering in <img> tags 2014-02-13 16:10:40 -05:00
Marcel Kinard
87285d94f7 CB-5908: add splascreen images to template
This will enable the default splashscreens to reside in the correct place
after creating a new project. Before only the default icons were present.
I copied these from cordova-app-hello-world.
2014-02-10 16:56:45 -05:00
arudenko
d260d0c182 Added Log.e when Config is not initialised but accessed 2014-02-08 21:24:20 -05:00
Ian Clelland
137eb40fab CB-5395: Make scheme and host (but not path) case-insensitive in whitelist 2014-02-07 15:02:09 -05:00
Andrew Grieve
af440460e1 Fix broken build from prev. commit (copy & paste error?) 2014-02-04 10:00:58 -05:00
Andrew Grieve
a5c8472a37 Ignore multiple onPageFinished() callbacks & onReceivedError due to stopLoading()
I believe this happens only when using custom schemes.
2014-02-04 00:12:11 -05:00
Joe Bowser
dfae37421d Removing addJavascriptInterface support from all Android versions lower than 4.2 due to security vulnerability 2014-02-03 10:11:53 -08:00
Bas Bosman
438a8d8b75 CB-4984 Don't create on CordovaActivity name 2014-01-28 14:25:26 -08:00
Andrew Grieve
ac2034561d CB-5917 Add a loadUrlIntoView overload that doesn't recreate plugins. 2014-01-28 10:30:39 -05:00
Andrew Grieve
c42cd4233d Use thread pool for load timeout. 2014-01-28 10:30:39 -05:00
Andrew Grieve
5b2a73e3eb CB-5715 For CLI, hide assets/www and res/xml/config.xml by default
Add a helper file under assets to say how to re-show the hidden files.
Move the config.xml, www, merges entries to the root to be more discoverable.
2014-01-28 00:28:42 -05:00
Andrew Grieve
6f163a6ba5 CB-5793 ant builds: Rename AndroidManifest during -post-build to avoid Eclipse detecting ant-build/ as a project when importing 2014-01-25 21:58:28 -05:00
Andrew Grieve
cc94cc7d01 CB-5889 Make update script find project name instead of using "null" for CordovaLib 2014-01-24 10:40:40 -05:00
Andrew Grieve
94934ae2cf CB-5889 Add a message in the update script about needing to import CordovaLib when using an IDE. 2014-01-24 10:29:04 -05:00
Joe Bowser
e361f88501 Update JS snapshot to version 3.5.0-dev (via coho) 2014-01-22 16:30:05 -08:00
Joe Bowser
708c042b61 Set VERSION to 3.5.0-dev (via coho) 2014-01-22 16:30:02 -08:00
36 changed files with 625 additions and 258 deletions

16
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,16 @@
# Contributing to Apache Cordova
Anyone can contribute to Cordova. And we need your contributions.
There are multiple ways to contribute: report bugs, improve the docs, and
contribute code.
For instructions on this, start with the
[contribution overview](http://cordova.apache.org/#contribute).
The details are explained there, but the important items are:
- Sign and submit an Apache ICLA (Contributor License Agreement).
- Have a Jira issue open that corresponds to your contribution.
- Run the tests so your patch doesn't break existing functionality.
We look forward to your contributions!

8
NOTICE
View File

@@ -1,5 +1,5 @@
Apache Cordova
Copyright 2012 The Apache Software Foundation
Copyright 2014 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org)
@@ -10,8 +10,8 @@ The Apache Software Foundation (http://www.apache.org)
== in this case for the Android-specific code. ==
=========================================================================
Android Code
Copyright 2005-2008 The Android Open Source Project
This product includes software developed as part of
The Android Open Source Project (http://source.android.com).
This software includes software developed at Square, Inc.
Copyright (C) 2013 Square, Inc.

View File

@@ -75,7 +75,7 @@ you are developing directly against the framework.
To create your `cordova.jar` file, run in the framework directory:
android update project -p . -t android-18
android update project -p . -t android-19
ant jar
@@ -84,7 +84,7 @@ Running Tests
Please see details under test/README.md.
Further Reading
---
----
- [http://developer.android.com](http://developer.android.com)
- [http://cordova.apache.org/](http://cordova.apache.org)

View File

@@ -7,9 +7,9 @@
# 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
@@ -20,27 +20,68 @@
-->
## Release Notes for Cordova (Android) ##
### 3.5.1 (August 2014) ###
This was a security update to address CVE-2014-3500, CVE-2014-3501,
and CVE-2014-3502. For more information, see
http://cordova.apache.org/announcements/2014/08/04/android-351.html
* Filter out non-launchable intents
* Handle unsupported protocol errors in webview better
* Update the errorurl to no longer use intents
* Refactoring the URI handling on Cordova, removing dead code
### 3.5.0 (May 2014) ###
* OkHttp has broken headers. Updating for ASF compliance.
* Revert accidentally removed lines from NOTICE
* CB-6552: added top level package.json
* CB-6491 add CONTRIBUTING.md
* CB-6543 Fix cordova/run failure when no custom_rules.xml available
* defaults.xml: Add AndroidLaunchMode preference
* Add JavaDoc for CordovaResourceApi
* CB-6388: Handle binary data correctly in LOAD_URL bridge
* Fix CB-6048: Set launchMode=singleTop so tapping app icon does not always restart app
* Remove incorrect usage of AlertDialog.Builder.create
* Catch uncaught exceptions in from plugins and turn them into error responses.
* Add NOTICE file
* CB-6047 Fix online sometimes getting in a bad state on page transitions.
* Add another convenience overload for CordovaResourceApi.copyResource
* Update framework's .classpath to what Eclipse wants it to be.
* README.md: `android update` to `android-19`.
* Fix NPE when POLLING bridge mode is used.
* Updating NOTICE to include Square for OkHttp
* CB-5398 Apply KitKat content URI fix to all content URIs
* CB-5398 Work-around for KitKat content: URLs not rendering in <img> tags
* CB-5908: add splascreen images to template
* CB-5395: Make scheme and host (but not path) case-insensitive in whitelist
* Ignore multiple onPageFinished() callbacks & onReceivedError due to stopLoading()
* Removing addJavascriptInterface support from all Android versions lower than 4.2 due to security vu
* CB-4984 Don't create on CordovaActivity name
* CB-5917 Add a loadUrlIntoView overload that doesn't recreate plugins.
* Use thread pool for load timeout.
* CB-5715 For CLI, hide assets/www and res/xml/config.xml by default
* CB-5793 ant builds: Rename AndroidManifest during -post-build to avoid Eclipse detecting ant-build/
* CB-5889 Make update script find project name instead of using "null" for CordovaLib
* CB-5889 Add a message in the update script about needing to import CordovaLib when using an IDE.
### 3.4.0 (Feb 2014) ###
37 commits from 10 authors. Highlights include:
43 commits from 10 authors. Highlights include:
* Security Fix for Android 4.2.1 and lower (disabling addJavascriptInterface as a bridge option)
* CB-5793 Make ant work-around work on windows.
* Removing addJavascriptInterface support from all Android versions lower than 4.2 due to security vulnerability
* CB-5917 Add a loadUrlIntoView overload that doesn't recreate plugins.
* CB-5889 Make update script find project name instead of using "null" for CordovaLib
* CB-5889 Add a message in the update script about needing to import CordovaLib when using an IDE.
* CB-5793 Don't clean before build and change output directory to ant-build to avoid conflicts with Eclipse.
* CB-4910 Fix CLI's eclipse project template not working on windows due to "*" in the virtual folder name.
* CB-5803 Fix cordova/emulate on windows.
* CB-5801 exec->spawn in build to make sure compile errors are shown.
* CB-5799 Update version of OkHTTP to 1.3
* Remove package.json within bin/ since we never intend to ship bin/ as an npm module
* CB-4910 Update CLI project template to point to config.xml at the root now that it's not in www/ by default.
* Silence excessive logging from scroll events
* CB-5504: Adding onDestroy to app plugin to deregister telephonyReceiver
* CB-5715 Add Eclipse .project file to create template.
* CB-5504 Adding onDestroy to app plugin to deregister telephonyReceiver
* CB-5715 Add Eclipse .project file to create template. For CLI projects, it adds refs for root www/ & config.xml and hides platform versions
* CB-5447 Removed android:debuggable=“true” from project template.
* CB-5714 Fix of android build when too big output stops build with error due to buffer overflow.
* Fix incorrect MIME type for .js files loaded through CordovaResourceAPI.
* Remove 2 X console.log from exec.js
* CB-5592 Set MIME type for openExternal when scheme is file:
### 3.3.0 (Dec 2013) ###

View File

@@ -1 +1 @@
3.4.0
3.5.1

View File

@@ -149,6 +149,10 @@ exports.createProject = function(project_path, package_name, project_name, proje
return Q.reject('Package name must look like: com.company.Name');
}
if (project_name === 'CordovaActivity') {
return Q.reject('Project name cannot be CordovaActivity');
}
// Check that requirements are met and proper targets are installed
return check_reqs.run()
.then(function() {

View File

@@ -23,6 +23,7 @@
<!-- Preferences for Android -->
<preference name="loglevel" value="DEBUG" />
<preference name="AndroidLaunchMode" value="singleTop" />
<!-- This is required for native Android hooks -->
<feature name="App">

View File

@@ -74,7 +74,12 @@ module.exports.run = function(build_type) {
* the script will error out. (should we error or just return undefined?)
*/
module.exports.get_apk = function() {
var binDir = path.join(ROOT, 'ant-build');
var binDir = '';
if(!hasCustomRules()) {
binDir = path.join(ROOT, 'bin');
} else {
binDir = path.join(ROOT, 'ant-build');
}
if (fs.existsSync(binDir)) {
var candidates = fs.readdirSync(binDir).filter(function(p) {
// Need to choose between release and debug .apk.
@@ -87,13 +92,13 @@ module.exports.get_apk = function() {
a.t < b.t ? 1 : 0;
});
if (candidates.length === 0) {
console.error('ERROR : No .apk found in \'ant-build\' directory');
console.error('ERROR : No .apk found in ' + binDir + ' directory');
process.exit(2);
}
console.log('Using apk: ' + candidates[0].p);
return candidates[0].p;
} else {
console.error('ERROR : unable to find project ant-build directory, could not locate .apk');
console.error('ERROR : unable to find project ' + binDir + ' directory, could not locate .apk');
process.exit(2);
}
}

View File

@@ -20,6 +20,6 @@
*/
// Coho updates this line:
var VERSION = "3.4.0";
var VERSION = "3.5.1";
console.log(VERSION);

View File

@@ -32,7 +32,7 @@
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:hardwareAccelerated="true">
<activity android:name="__ACTIVITY__" android:label="@string/app_name"
<activity android:name="__ACTIVITY__" android:label="@string/app_name" android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale">
<intent-filter>

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 KiB

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

View File

@@ -1,5 +1,5 @@
// Platform: android
// 3.4.0
// 3.5.1
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -19,7 +19,7 @@
under the License.
*/
;(function() {
var CORDOVA_JS_BUILD_LABEL = '3.4.0';
var CORDOVA_JS_BUILD_LABEL = '3.5.1';
// file: src/scripts/require.js
/*jshint -W079 */
@@ -437,6 +437,16 @@ base64.fromArrayBuffer = function(arrayBuffer) {
return uint8ToBase64(array);
};
base64.toArrayBuffer = function(str) {
var decodedStr = typeof atob != 'undefined' ? atob(str) : new Buffer(str,'base64').toString('binary');
var arrayBuffer = new ArrayBuffer(decodedStr.length);
var array = new Uint8Array(arrayBuffer);
for (var i=0, len=decodedStr.length; i < len; i++) {
array[i] = decodedStr.charCodeAt(i);
}
return arrayBuffer;
};
//------------------------------------------------------------------------------
/* This code is based on the performance tests at http://jsperf.com/b64tests
@@ -815,6 +825,7 @@ channel.createSticky('onNativeReady');
channel.createSticky('onCordovaReady');
// Event to indicate that all automatically loaded JS plugins are loaded and ready.
// FIXME remove this
channel.createSticky('onPluginsReady');
// Event to indicate that Cordova is ready
@@ -919,7 +930,7 @@ function androidExec(success, fail, service, action, args) {
androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
return;
} else {
androidExec.processMessages(messages);
androidExec.processMessages(messages, true);
}
}
}
@@ -963,7 +974,6 @@ androidExec.nativeToJsModes = nativeToJsModes;
androidExec.setJsToNativeBridgeMode = function(mode) {
if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
console.log('Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.');
mode = jsToNativeModes.PROMPT;
}
nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
@@ -1028,48 +1038,64 @@ function processMessage(message) {
}
cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
} else {
console.log("processMessage failed: invalid message:" + message);
console.log("processMessage failed: invalid message: " + JSON.stringify(message));
}
} catch (e) {
console.log("processMessage failed: Message: " + message);
console.log("processMessage failed: Error: " + e);
console.log("processMessage failed: Stack: " + e.stack);
console.log("processMessage failed: Message: " + message);
}
}
var isProcessing = false;
// This is called from the NativeToJsMessageQueue.java.
androidExec.processMessages = function(messages) {
androidExec.processMessages = function(messages, opt_useTimeout) {
if (messages) {
messagesFromNative.push(messages);
// Check for the reentrant case, and enqueue the message if that's the case.
if (messagesFromNative.length > 1) {
return;
}
}
// Check for the reentrant case.
if (isProcessing) {
return;
}
if (opt_useTimeout) {
window.setTimeout(androidExec.processMessages, 0);
return;
}
isProcessing = true;
try {
// TODO: add setImmediate polyfill and process only one message at a time.
while (messagesFromNative.length) {
// Don't unshift until the end so that reentrancy can be detected.
messages = messagesFromNative[0];
var msg = popMessageFromQueue();
// The Java side can send a * message to indicate that it
// still has messages waiting to be retrieved.
if (messages == '*') {
messagesFromNative.shift();
window.setTimeout(pollOnce, 0);
if (msg == '*' && messagesFromNative.length === 0) {
setTimeout(pollOnce, 0);
return;
}
var spaceIdx = messages.indexOf(' ');
var msgLen = +messages.slice(0, spaceIdx);
var message = messages.substr(spaceIdx + 1, msgLen);
messages = messages.slice(spaceIdx + msgLen + 1);
processMessage(message);
if (messages) {
messagesFromNative[0] = messages;
} else {
messagesFromNative.shift();
}
processMessage(msg);
}
} finally {
isProcessing = false;
}
};
function popMessageFromQueue() {
var messageBatch = messagesFromNative.shift();
if (messageBatch == '*') {
return '*';
}
var spaceIdx = messageBatch.indexOf(' ');
var msgLen = +messageBatch.slice(0, spaceIdx);
var message = messageBatch.substr(spaceIdx + 1, msgLen);
messageBatch = messageBatch.slice(spaceIdx + msgLen + 1);
if (messageBatch) {
messagesFromNative.unshift(messageBatch);
}
return message;
}
module.exports = androidExec;
});
@@ -1191,9 +1217,13 @@ modulemapper.clobbers('cordova/exec', 'Cordova.exec');
// Call the platform-specific initialization.
platform.bootstrap && platform.bootstrap();
pluginloader.load(function() {
channel.onPluginsReady.fire();
});
// Wrap in a setTimeout to support the use-case of having plugin JS appended to cordova.js.
// The delay allows the attached modules to be defined before the plugin loader looks for them.
setTimeout(function() {
pluginloader.load(function() {
channel.onPluginsReady.fire();
});
}, 0);
/**
* Create all cordova objects once native side is ready.
@@ -1216,6 +1246,111 @@ channel.join(function() {
}, platformInitChannelsArray);
});
// file: src/common/init_b.js
define("cordova/init_b", function(require, exports, module) {
var channel = require('cordova/channel');
var cordova = require('cordova');
var platform = require('cordova/platform');
var platformInitChannelsArray = [channel.onDOMContentLoaded, channel.onNativeReady];
// setting exec
cordova.exec = require('cordova/exec');
function logUnfiredChannels(arr) {
for (var i = 0; i < arr.length; ++i) {
if (arr[i].state != 2) {
console.log('Channel not fired: ' + arr[i].type);
}
}
}
window.setTimeout(function() {
if (channel.onDeviceReady.state != 2) {
console.log('deviceready has not fired after 5 seconds.');
logUnfiredChannels(platformInitChannelsArray);
logUnfiredChannels(channel.deviceReadyChannelsArray);
}
}, 5000);
// Replace navigator before any modules are required(), to ensure it happens as soon as possible.
// We replace it so that properties that can't be clobbered can instead be overridden.
function replaceNavigator(origNavigator) {
var CordovaNavigator = function() {};
CordovaNavigator.prototype = origNavigator;
var newNavigator = new CordovaNavigator();
// This work-around really only applies to new APIs that are newer than Function.bind.
// Without it, APIs such as getGamepads() break.
if (CordovaNavigator.bind) {
for (var key in origNavigator) {
if (typeof origNavigator[key] == 'function') {
newNavigator[key] = origNavigator[key].bind(origNavigator);
}
}
}
return newNavigator;
}
if (window.navigator) {
window.navigator = replaceNavigator(window.navigator);
}
if (!window.console) {
window.console = {
log: function(){}
};
}
if (!window.console.warn) {
window.console.warn = function(msg) {
this.log("warn: " + msg);
};
}
// Register pause, resume and deviceready channels as events on document.
channel.onPause = cordova.addDocumentEventHandler('pause');
channel.onResume = cordova.addDocumentEventHandler('resume');
channel.onDeviceReady = cordova.addStickyDocumentEventHandler('deviceready');
// Listen for DOMContentLoaded and notify our channel subscribers.
if (document.readyState == 'complete' || document.readyState == 'interactive') {
channel.onDOMContentLoaded.fire();
} else {
document.addEventListener('DOMContentLoaded', function() {
channel.onDOMContentLoaded.fire();
}, false);
}
// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since
// it may be called before any cordova JS is ready.
if (window._nativeReady) {
channel.onNativeReady.fire();
}
// Call the platform-specific initialization.
platform.bootstrap && platform.bootstrap();
/**
* Create all cordova objects once native side is ready.
*/
channel.join(function() {
platform.initialize && platform.initialize();
// Fire event to notify that all objects are created
channel.onCordovaReady.fire();
// Fire onDeviceReady event once page has fully loaded, all
// constructors have run and cordova info has been received from native
// side.
channel.join(function() {
require('cordova').fireDocumentEvent('deviceready');
}, channel.deviceReadyChannelsArray);
}, platformInitChannelsArray);
});
// file: src/common/modulemapper.js
@@ -1444,43 +1579,51 @@ var modulemapper = require('cordova/modulemapper');
var urlutil = require('cordova/urlutil');
// Helper function to inject a <script> tag.
function injectScript(url, onload, onerror) {
// Exported for testing.
exports.injectScript = function(url, onload, onerror) {
var script = document.createElement("script");
// onload fires even when script fails loads with an error.
script.onload = onload;
script.onerror = onerror || onload;
// onerror fires for malformed URLs.
script.onerror = onerror;
script.src = url;
document.head.appendChild(script);
};
function injectIfNecessary(id, url, onload, onerror) {
onerror = onerror || onload;
if (id in define.moduleMap) {
onload();
} else {
exports.injectScript(url, function() {
if (id in define.moduleMap) {
onload();
} else {
onerror();
}
}, onerror);
}
}
function onScriptLoadingComplete(moduleList, finishPluginLoading) {
// Loop through all the plugins and then through their clobbers and merges.
for (var i = 0, module; module = moduleList[i]; i++) {
if (module) {
try {
if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) {
modulemapper.clobbers(module.id, module.clobbers[j]);
}
}
if (module.merges && module.merges.length) {
for (var k = 0; k < module.merges.length; k++) {
modulemapper.merges(module.id, module.merges[k]);
}
}
// Finally, if runs is truthy we want to simply require() the module.
// This can be skipped if it had any merges or clobbers, though,
// since the mapper will already have required the module.
if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
modulemapper.runs(module.id);
}
if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) {
modulemapper.clobbers(module.id, module.clobbers[j]);
}
catch(err) {
// error with module, most likely clobbers, should we continue?
}
if (module.merges && module.merges.length) {
for (var k = 0; k < module.merges.length; k++) {
modulemapper.merges(module.id, module.merges[k]);
}
}
// Finally, if runs is truthy we want to simply require() the module.
if (module.runs) {
modulemapper.runs(module.id);
}
}
finishPluginLoading();
@@ -1505,32 +1648,16 @@ function handlePluginsObject(path, moduleList, finishPluginLoading) {
}
for (var i = 0; i < moduleList.length; i++) {
injectScript(path + moduleList[i].file, scriptLoadedCallback);
injectIfNecessary(moduleList[i].id, path + moduleList[i].file, scriptLoadedCallback);
}
}
function injectPluginScript(pathPrefix, finishPluginLoading) {
var pluginPath = pathPrefix + 'cordova_plugins.js';
injectScript(pluginPath, function() {
try {
var moduleList = require("cordova/plugin_list");
handlePluginsObject(pathPrefix, moduleList, finishPluginLoading);
}
catch (e) {
// Error loading cordova_plugins.js, file not found or something
// this is an acceptable error, pre-3.0.0, so we just move on.
finishPluginLoading();
}
}, finishPluginLoading); // also, add script load error handler for file not found
}
function findCordovaPath() {
var path = null;
var scripts = document.getElementsByTagName('script');
var term = 'cordova.js';
for (var n = scripts.length-1; n>-1; n--) {
var src = scripts[n].src;
var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
if (src.indexOf(term) == (src.length - term.length)) {
path = src.substring(0, src.length - term.length);
break;
@@ -1548,7 +1675,10 @@ exports.load = function(callback) {
console.log('Could not find cordova.js script tag. Plugin loading may fail.');
pathPrefix = '';
}
injectPluginScript(pathPrefix, callback);
injectIfNecessary('cordova/plugin_list', pathPrefix + 'cordova_plugins.js', function() {
var moduleList = require("cordova/plugin_list");
handlePluginsObject(pathPrefix, moduleList, callback);
}, callback);
};

View File

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed 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 com.squareup.okhttp.internal.spdy;
public enum ErrorCode {

View File

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed 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 com.squareup.okhttp.internal.spdy;
import java.io.DataInputStream;

View File

@@ -1,3 +1,19 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed 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 com.squareup.okhttp.internal.spdy;
import com.squareup.okhttp.internal.Util;

View File

@@ -20,21 +20,16 @@
package org.apache.cordova;
import java.io.IOException;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.cordova.LOG;
import org.xmlpull.v1.XmlPullParserException;
import android.app.Activity;
import android.content.res.XmlResourceParser;
import android.graphics.Color;
import android.util.Log;
public class Config {
@@ -44,6 +39,8 @@ public class Config {
private Whitelist whitelist = new Whitelist();
private String startUrl;
private static String errorUrl;
private static Config self = null;
public static void init(Activity action) {
@@ -156,6 +153,10 @@ public class Config {
boolean value = xml.getAttributeValue(null, "value").equals("true");
action.getIntent().putExtra(name, value);
}
else if(name.equalsIgnoreCase("errorurl"))
{
errorUrl = xml.getAttributeValue(null, "value");
}
else
{
String value = xml.getAttributeValue(null, "value");
@@ -204,6 +205,7 @@ public class Config {
*/
public static void addWhiteListEntry(String origin, boolean subdomains) {
if (self == null) {
Log.e(TAG, "Config was not initialised. Did you forget to Config.init(this)?");
return;
}
self.whitelist.addWhiteListEntry(origin, subdomains);
@@ -217,6 +219,7 @@ public class Config {
*/
public static boolean isUrlWhiteListed(String url) {
if (self == null) {
Log.e(TAG, "Config was not initialised. Did you forget to Config.init(this)?");
return false;
}
return self.whitelist.isUrlWhiteListed(url);
@@ -228,4 +231,8 @@ public class Config {
}
return self.startUrl;
}
public static String getErrorUrl() {
return errorUrl;
}
}

View File

@@ -715,7 +715,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
//Code to test CB-3064
String errorUrl = this.getStringProperty("ErrorUrl", null);
String errorUrl = Config.getErrorUrl();
LOG.d(TAG, "CB-3064: The errorUrl is " + errorUrl);
if (this.activityState == ACTIVITY_STARTING) {

View File

@@ -139,7 +139,6 @@ public class CordovaChromeClient extends WebChromeClient {
return true;
}
});
dlg.create();
dlg.show();
return true;
}
@@ -188,7 +187,6 @@ public class CordovaChromeClient extends WebChromeClient {
return true;
}
});
dlg.create();
dlg.show();
return true;
}
@@ -280,7 +278,6 @@ public class CordovaChromeClient extends WebChromeClient {
res.cancel();
}
});
dlg.create();
dlg.show();
}
return true;

View File

@@ -45,6 +45,27 @@ import java.net.URL;
import java.nio.channels.FileChannel;
import java.util.Locale;
/**
* What this class provides:
* 1. Helpers for reading & writing to URLs.
* - E.g. handles assets, resources, content providers, files, data URIs, http[s]
* - E.g. Can be used to query for mime-type & content length.
*
* 2. To allow plugins to redirect URLs (via remapUrl).
* - All plugins should call remapUrl() on URLs they receive from JS *before*
* passing the URL onto other utility functions in this class.
* - For an example usage of this, refer to the org.apache.cordova.file plugin.
*
* 3. It exposes a way to use the OkHttp library that ships with Cordova.
* - Through createHttpConnection().
*
* Future Work:
* - Consider using a Cursor to query content URLs for their size (like the file plugin does).
* - Allow plugins to remapUri to "cdv-plugin://plugin-name/$ID", which CordovaResourceApi
* would then delegate to pluginManager.getPlugin(plugin-name).openForRead($ID)
* - Currently, plugins *can* do this by remapping to a data: URL, but it's inefficient
* for large payloads.
*/
public class CordovaResourceApi {
@SuppressWarnings("unused")
private static final String LOG_TAG = "CordovaResourceApi";
@@ -346,6 +367,10 @@ public class CordovaResourceApi {
copyResource(openForRead(sourceUri), outputStream);
}
// Added in 3.5.0.
public void copyResource(Uri sourceUri, Uri dstUri) throws IOException {
copyResource(openForRead(sourceUri), openOutputStream(dstUri));
}
private void assertBackgroundThread() {
if (threadCheckingEnabled) {

View File

@@ -0,0 +1,115 @@
/*
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;
import org.json.JSONException;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.webkit.WebView;
public class CordovaUriHelper {
private static final String TAG = "CordovaUriHelper";
private static final String CORDOVA_EXEC_URL_PREFIX = "http://cdv_exec/";
private CordovaWebView appView;
private CordovaInterface cordova;
CordovaUriHelper(CordovaInterface cdv, CordovaWebView webView)
{
appView = webView;
cordova = cdv;
}
// Parses commands sent by setting the webView's URL to:
// cdvbrg:service/action/callbackId#jsonArgs
void handleExecUrl(String url) {
int idx1 = CORDOVA_EXEC_URL_PREFIX.length();
int idx2 = url.indexOf('#', idx1 + 1);
int idx3 = url.indexOf('#', idx2 + 1);
int idx4 = url.indexOf('#', idx3 + 1);
if (idx1 == -1 || idx2 == -1 || idx3 == -1 || idx4 == -1) {
Log.e(TAG, "Could not decode URL command: " + url);
return;
}
String service = url.substring(idx1, idx2);
String action = url.substring(idx2 + 1, idx3);
String callbackId = url.substring(idx3 + 1, idx4);
String jsonArgs = url.substring(idx4 + 1);
appView.pluginManager.exec(service, action, callbackId, jsonArgs);
//There is no reason to not send this directly to the pluginManager
}
/**
* Give the host application a chance to take over the control when a new url
* is about to be loaded in the current WebView.
*
* @param view The WebView that is initiating the callback.
* @param url The url to be loaded.
* @return true to override, false for default behavior
*/
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// The WebView should support http and https when going on the Internet
if(url.startsWith("http:") || url.startsWith("https:"))
{
// Check if it's an exec() bridge command message.
if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(CORDOVA_EXEC_URL_PREFIX)) {
handleExecUrl(url);
}
// We only need to whitelist sites on the Internet!
else if(Config.isUrlWhiteListed(url))
{
return false;
}
}
// Give plugins the chance to handle the url
else if (this.appView.pluginManager.onOverrideUrlLoading(url)) {
}
else if(url.startsWith("file://") | url.startsWith("data:"))
{
//This directory on WebKit/Blink based webviews contains SQLite databases!
//DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING!
return url.contains("app_webview");
}
else
{
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setComponent(null);
intent.setSelector(null);
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
}
//Default behaviour should be to load the default intent, let's see what happens!
return true;
}
}

View File

@@ -68,7 +68,7 @@ import android.widget.FrameLayout;
public class CordovaWebView extends WebView {
public static final String TAG = "CordovaWebView";
public static final String CORDOVA_VERSION = "3.4.0";
public static final String CORDOVA_VERSION = "3.5.1";
private ArrayList<Integer> keyDownCodes = new ArrayList<Integer>();
private ArrayList<Integer> keyUpCodes = new ArrayList<Integer>();
@@ -406,17 +406,7 @@ public class CordovaWebView extends WebView {
this.loadUrlNow(url);
}
else {
String initUrl = this.getProperty("url", null);
// If first page of app, then set URL to load to be the one passed in
if (initUrl == null) {
this.loadUrlIntoView(url);
}
// Otherwise use the URL specified in the activity's extras bundle
else {
this.loadUrlIntoView(initUrl);
}
this.loadUrlIntoView(url);
}
}
@@ -427,16 +417,15 @@ public class CordovaWebView extends WebView {
* @param url
* @param time The number of ms to wait before loading webview
*/
@Deprecated
public void loadUrl(final String url, int time) {
String initUrl = this.getProperty("url", null);
// If first page of app, then set URL to load to be the one passed in
if (initUrl == null) {
this.loadUrlIntoView(url, time);
if(url == null)
{
this.loadUrlIntoView(Config.getStartUrl());
}
// Otherwise use the URL specified in the activity's extras bundle
else {
this.loadUrlIntoView(initUrl);
else
{
this.loadUrlIntoView(url);
}
}
@@ -494,8 +483,7 @@ public class CordovaWebView extends WebView {
// Load url
this.cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
Thread thread = new Thread(timeoutCheck);
thread.start();
cordova.getThreadPool().execute(timeoutCheck);
me.loadUrlNow(url);
}
});
@@ -542,6 +530,11 @@ public class CordovaWebView extends WebView {
this.loadUrlIntoView(url);
}
@Override
public void stopLoading() {
viewClient.isCurrentlyLoading = false;
super.stopLoading();
}
public void onScrollChanged(int l, int t, int oldl, int oldt)
{

View File

@@ -61,7 +61,9 @@ public class CordovaWebViewClient extends WebViewClient {
private static final String CORDOVA_EXEC_URL_PREFIX = "http://cdv_exec/";
CordovaInterface cordova;
CordovaWebView appView;
CordovaUriHelper helper;
private boolean doClearHistory = false;
boolean isCurrentlyLoading;
/** The authorization tokens. */
private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
@@ -84,6 +86,7 @@ public class CordovaWebViewClient extends WebViewClient {
public CordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) {
this.cordova = cordova;
this.appView = view;
helper = new CordovaUriHelper(cordova, view);
}
/**
@@ -93,6 +96,7 @@ public class CordovaWebViewClient extends WebViewClient {
*/
public void setWebView(CordovaWebView view) {
this.appView = view;
helper = new CordovaUriHelper(cordova, view);
}
@@ -124,112 +128,7 @@ public class CordovaWebViewClient extends WebViewClient {
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Check if it's an exec() bridge command message.
if (NativeToJsMessageQueue.ENABLE_LOCATION_CHANGE_EXEC_MODE && url.startsWith(CORDOVA_EXEC_URL_PREFIX)) {
handleExecUrl(url);
}
// Give plugins the chance to handle the url
else if ((this.appView.pluginManager != null) && this.appView.pluginManager.onOverrideUrlLoading(url)) {
}
// If dialing phone (tel:5551212)
else if (url.startsWith(WebView.SCHEME_TEL)) {
try {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error dialing " + url + ": " + e.toString());
}
}
// If displaying map (geo:0,0?q=address)
else if (url.startsWith("geo:")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error showing map " + url + ": " + e.toString());
}
}
// If sending email (mailto:abc@corp.com)
else if (url.startsWith(WebView.SCHEME_MAILTO)) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error sending email " + url + ": " + e.toString());
}
}
// If sms:5551212?body=This is the message
else if (url.startsWith("sms:")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
// Get address
String address = null;
int parmIndex = url.indexOf('?');
if (parmIndex == -1) {
address = url.substring(4);
}
else {
address = url.substring(4, parmIndex);
// If body, then set sms body
Uri uri = Uri.parse(url);
String query = uri.getQuery();
if (query != null) {
if (query.startsWith("body=")) {
intent.putExtra("sms_body", query.substring(5));
}
}
}
intent.setData(Uri.parse("sms:" + address));
intent.putExtra("address", address);
intent.setType("vnd.android-dir/mms-sms");
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error sending sms " + url + ":" + e.toString());
}
}
//Android Market
else if(url.startsWith("market:")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading Google Play Store: " + url, e);
}
}
// All else
else {
// If our app or file:, then load into a new Cordova webview container by starting a new instance of our activity.
// Our app continues to run. When BACK is pressed, our app is redisplayed.
if (url.startsWith("file://") || url.startsWith("data:") || Config.isUrlWhiteListed(url)) {
return false;
}
// If not our application, let default viewer handle
else {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
this.cordova.getActivity().startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
LOG.e(TAG, "Error loading url " + url, e);
}
}
}
return true;
return helper.shouldOverrideUrlLoading(view, url);
}
/**
@@ -266,7 +165,9 @@ public class CordovaWebViewClient extends WebViewClient {
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
isCurrentlyLoading = true;
LOG.d(TAG, "onPageStarted(" + url + ")");
// Flush stale messages.
this.appView.jsMessageQueue.reset();
@@ -290,6 +191,11 @@ public class CordovaWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Ignore excessive calls.
if (!isCurrentlyLoading) {
return;
}
isCurrentlyLoading = false;
LOG.d(TAG, "onPageFinished(" + url + ")");
/**
@@ -344,12 +250,28 @@ public class CordovaWebViewClient extends WebViewClient {
*/
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// Ignore error due to stopLoading().
if (!isCurrentlyLoading) {
return;
}
LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
// Clear timeout flag
this.appView.loadUrlTimeout++;
// Handle error
// If this is a "Protocol Not Supported" error, then revert to the previous
// page. If there was no previous page, then punt. The application's config
// is likely incorrect (start page set to sms: or something like that)
if (errorCode == WebViewClient.ERROR_UNSUPPORTED_SCHEME) {
if (view.canGoBack()) {
view.goBack();
return;
} else {
super.onReceivedError(view, errorCode, description, failingUrl);
}
}
// Handle other errors by passing them to the webview in JS
JSONObject data = new JSONObject();
try {
data.put("errorCode", errorCode);

View File

@@ -35,6 +35,7 @@ import android.webkit.WebView;
public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
private static final String TAG = "IceCreamCordovaWebViewClient";
private CordovaUriHelper helper;
public IceCreamCordovaWebViewClient(CordovaInterface cordova) {
super(cordova);
@@ -47,8 +48,9 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
try {
// Check the against the white-list.
if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
// Check the against the whitelist and lock out access to the WebView directory
// Changing this will cause problems for your application
if (isUrlHarmful(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
@@ -59,7 +61,7 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) {
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
@@ -74,6 +76,15 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
}
}
private boolean isUrlHarmful(String url) {
return ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url))
|| url.contains("app_webview");
}
private static boolean needsKitKatContentUrlFix(Uri uri) {
return android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && "content".equals(uri.getScheme());
}
private static boolean needsSpecialsInAssetUrlFix(Uri uri) {
if (CordovaResourceApi.getUriType(uri) != CordovaResourceApi.URI_TYPE_ASSET) {
return false;

View File

@@ -83,7 +83,7 @@ public class NativeToJsMessageQueue {
this.cordova = cordova;
this.webView = webView;
registeredListeners = new BridgeMode[4];
registeredListeners[0] = null; // Polling. Requires no logic.
registeredListeners[0] = new PollingBridgeMode();
registeredListeners[1] = new LoadUrlBridgeMode();
registeredListeners[2] = new OnlineEventsBridgeMode();
registeredListeners[3] = new PrivateApiBridgeMode();
@@ -102,7 +102,8 @@ public class NativeToJsMessageQueue {
synchronized (this) {
activeListenerIndex = value;
BridgeMode activeListener = registeredListeners[value];
if (!paused && !queue.isEmpty() && activeListener != null) {
activeListener.reset();
if (!paused && !queue.isEmpty()) {
activeListener.onNativeToJsMessageAvailable();
}
}
@@ -117,6 +118,7 @@ public class NativeToJsMessageQueue {
synchronized (this) {
queue.clear();
setBridgeMode(DEFAULT_BRIDGE_MODE);
registeredListeners[activeListenerIndex].reset();
}
}
@@ -249,7 +251,7 @@ public class NativeToJsMessageQueue {
private void enqueueMessage(JsMessage message) {
synchronized (this) {
queue.add(message);
if (!paused && registeredListeners[activeListenerIndex] != null) {
if (!paused) {
registeredListeners[activeListenerIndex].onNativeToJsMessageAvailable();
}
}
@@ -264,7 +266,7 @@ public class NativeToJsMessageQueue {
paused = value;
if (!value) {
synchronized (this) {
if (!queue.isEmpty() && registeredListeners[activeListenerIndex] != null) {
if (!queue.isEmpty()) {
registeredListeners[activeListenerIndex].onNativeToJsMessageAvailable();
}
}
@@ -278,8 +280,15 @@ public class NativeToJsMessageQueue {
private abstract class BridgeMode {
abstract void onNativeToJsMessageAvailable();
void notifyOfFlush(boolean fromOnlineEvent) {}
void reset() {}
}
/** Uses JS polls for messages on a timer.. */
private class PollingBridgeMode extends BridgeMode {
@Override void onNativeToJsMessageAvailable() {
}
}
/** Uses webView.loadUrl("javascript:") to execute messages. */
private class LoadUrlBridgeMode extends BridgeMode {
final Runnable runnable = new Runnable() {
@@ -298,7 +307,7 @@ public class NativeToJsMessageQueue {
/** Uses online/offline events to tell the JS when to poll for messages. */
private class OnlineEventsBridgeMode extends BridgeMode {
boolean online = false;
private boolean online;
final Runnable runnable = new Runnable() {
public void run() {
if (!queue.isEmpty()) {
@@ -306,7 +315,8 @@ public class NativeToJsMessageQueue {
}
}
};
OnlineEventsBridgeMode() {
@Override void reset() {
online = false;
webView.setNetworkAvailable(true);
}
@Override void onNativeToJsMessageAvailable() {
@@ -484,9 +494,22 @@ public class NativeToJsMessageQueue {
.append(success)
.append(",")
.append(status)
.append(",[")
.append(pluginResult.getMessage())
.append("],")
.append(",[");
switch (pluginResult.getMessageType()) {
case PluginResult.MESSAGE_TYPE_BINARYSTRING:
sb.append("atob('")
.append(pluginResult.getMessage())
.append("')");
break;
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
sb.append("cordova.require('cordova/base64').toArrayBuffer('")
.append(pluginResult.getMessage())
.append("')");
break;
default:
sb.append(pluginResult.getMessage());
}
sb.append("],")
.append(pluginResult.getKeepCallback())
.append(");");
}

View File

@@ -236,22 +236,25 @@ public class PluginManager {
app.sendPluginResult(cr, callbackId);
return;
}
CallbackContext callbackContext = new CallbackContext(callbackId, app);
try {
CallbackContext callbackContext = new CallbackContext(callbackId, app);
long pluginStartTime = System.currentTimeMillis();
boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext);
long duration = System.currentTimeMillis() - pluginStartTime;
if (duration > SLOW_EXEC_WARNING_THRESHOLD) {
Log.w(TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool().");
}
if (!wasValidAction) {
PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION);
app.sendPluginResult(cr, callbackId);
callbackContext.sendPluginResult(cr);
}
} catch (JSONException e) {
PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
app.sendPluginResult(cr, callbackId);
callbackContext.sendPluginResult(cr);
} catch (Exception e) {
Log.e(TAG, "Uncaught exception from plugin", e);
callbackContext.error(e.getMessage());
}
}

View File

@@ -55,14 +55,14 @@ public class Whitelist {
if (scheme == null || "*".equals(scheme)) {
this.scheme = null;
} else {
this.scheme = Pattern.compile(regexFromPattern(scheme, false));
this.scheme = Pattern.compile(regexFromPattern(scheme, false), Pattern.CASE_INSENSITIVE);
}
if ("*".equals(host)) {
this.host = null;
} else if (host.startsWith("*.")) {
this.host = Pattern.compile("([a-z0-9.-]*\\.)?" + regexFromPattern(host.substring(2), false));
this.host = Pattern.compile("([a-z0-9.-]*\\.)?" + regexFromPattern(host.substring(2), false), Pattern.CASE_INSENSITIVE);
} else {
this.host = Pattern.compile(regexFromPattern(host, false));
this.host = Pattern.compile(regexFromPattern(host, false), Pattern.CASE_INSENSITIVE);
}
if (port == null || "*".equals(port)) {
this.port = null;
@@ -120,7 +120,7 @@ public class Whitelist {
whiteList = null;
}
else { // specific access
Pattern parts = Pattern.compile("^((\\*|[a-z-]+)://)?(\\*|((\\*\\.)?[^*/:]+))?(:(\\d+))?(/.*)?");
Pattern parts = Pattern.compile("^((\\*|[A-Za-z-]+)://)?(\\*|((\\*\\.)?[^*/:]+))?(:(\\d+))?(/.*)?");
Matcher m = parts.matcher(origin);
if (m.matches()) {
String scheme = m.group(2);

21
package.json Normal file
View File

@@ -0,0 +1,21 @@
{
"name": "cordova-android",
"version": "3.5.1",
"description": "cordova-android release",
"main": "bin/create",
"repository": {
"type": "git",
"url": "https://git-wip-us.apache.org/repos/asf/cordova-android.git"
},
"keywords": [
"android",
"cordova",
"apache"
],
"author": "Apache Software Foundation",
"license": "Apache version 2.0",
"dependencies": {
"q": "^0.9.0",
"shelljs": "^0.2.6"
}
}