forked from github/cordova-android
Compare commits
88 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5462eddfdb | ||
|
|
fef51f12c6 | ||
|
|
5cd17730b1 | ||
|
|
cb192056f8 | ||
|
|
892f96e305 | ||
|
|
13ef58a5bb | ||
|
|
a45d5a98dd | ||
|
|
a31714f8a4 | ||
|
|
23d2a806f0 | ||
|
|
c20b2330ab | ||
|
|
8613551aec | ||
|
|
2ab01dadc0 | ||
|
|
790636c8cd | ||
|
|
23938830f7 | ||
|
|
674b87057a | ||
|
|
83d9248ec8 | ||
|
|
f9d27e4a67 | ||
|
|
2683803ef3 | ||
|
|
dd86d7a5ed | ||
|
|
1246a81d39 | ||
|
|
8ab7278db2 | ||
|
|
db099e7722 | ||
|
|
fcc01bc37e | ||
|
|
a18dacf5f2 | ||
|
|
77f9cae50b | ||
|
|
3610bbf21b | ||
|
|
d5e3be9a55 | ||
|
|
80b369d6d5 | ||
|
|
d29eb84010 | ||
|
|
381ce535bf | ||
|
|
2e20bb0639 | ||
|
|
56cd24797e | ||
|
|
431ca99c23 | ||
|
|
6ced2ff293 | ||
|
|
31055bb303 | ||
|
|
24a53e39dd | ||
|
|
2ab113b695 | ||
|
|
9a0481a750 | ||
|
|
09035eb4c4 | ||
|
|
1adf268e71 | ||
|
|
23f57ad5a7 | ||
|
|
d9b15cf69e | ||
|
|
dbfe12a993 | ||
|
|
2b32dfd99d | ||
|
|
679de40780 | ||
|
|
66f15fdd37 | ||
|
|
038f0e45b1 | ||
|
|
033bfcc804 | ||
|
|
fa87c08a29 | ||
|
|
dfb799739a | ||
|
|
1193f7ed22 | ||
|
|
7530c21a9f | ||
|
|
a120614617 | ||
|
|
0311f0db38 | ||
|
|
547b683e61 | ||
|
|
ff1d943a69 | ||
|
|
15a5c89e86 | ||
|
|
03b974ee3f | ||
|
|
f145605c63 | ||
|
|
29230d0316 | ||
|
|
57fc49ddc2 | ||
|
|
5ac6853fed | ||
|
|
b870214cca | ||
|
|
55074b925f | ||
|
|
958424ce59 | ||
|
|
d04fc289ac | ||
|
|
e14edf134d | ||
|
|
dbb127447f | ||
|
|
dc94fc39ec | ||
|
|
6db9a7cb12 | ||
|
|
1f39386616 | ||
|
|
25aef945d1 | ||
|
|
c9aa43afe0 | ||
|
|
913e177f6f | ||
|
|
ae431aec12 | ||
|
|
8ac15048cd | ||
|
|
a1cfe87f1e | ||
|
|
c130396d4e | ||
|
|
bc2e7cf317 | ||
|
|
7ace1d652d | ||
|
|
26effd1def | ||
|
|
5f6824e5dd | ||
|
|
4589bdd31f | ||
|
|
72e0b49e0b | ||
|
|
552885dbd3 | ||
|
|
c8ec7e5191 | ||
|
|
a0d2b96de6 | ||
|
|
5ca233779d |
16
README.md
16
README.md
@@ -1,16 +1,12 @@
|
||||
Cordova Android
|
||||
===
|
||||
|
||||
Cordova Android is an Android application library that allows for Cordova based projects to be built for the Android Platform. Cordova based applications are, at the core, an application written with web technology: HTML, CSS and JavaScript.
|
||||
Cordova Android is an Android application library that allows for Cordova-based
|
||||
projects to be built for the Android Platform. Cordova based applications are,
|
||||
at the core, applications written with web technology: HTML, CSS and JavaScript.
|
||||
|
||||
[Apache Cordova](http://cordova.io) is a project at The Apache Software Foundation (ASF).
|
||||
|
||||
Apache Cordova is an effort undergoing incubation at The Apache
|
||||
Software Foundation (ASF), sponsored by the Apache Incubator project.
|
||||
Incubation is required of all newly accepted projects until a further
|
||||
review indicates that the infrastructure, communications, and decision
|
||||
making process have stabilized in a manner consistent with other
|
||||
successful ASF projects. While incubation status is not necessarily
|
||||
a reflection of the completeness or stability of the code, it does
|
||||
indicate that the project has yet to be fully endorsed by the ASF.
|
||||
|
||||
Requires
|
||||
---
|
||||
@@ -27,7 +23,7 @@ Test Requirements
|
||||
Building
|
||||
---
|
||||
|
||||
To create your cordova.jar, copy the commons codec:
|
||||
To create your `cordova.jar` file, copy the commons codec:
|
||||
|
||||
mv commons-codec-1.7.jar framework/libs
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ function on_error {
|
||||
echo "An unexpected error occurred: $previous_command exited with $?"
|
||||
echo "Deleting project..."
|
||||
[ -d "$PROJECT_PATH" ] && rm -rf "$PROJECT_PATH"
|
||||
exit "$?"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function replace {
|
||||
@@ -98,6 +98,13 @@ MANIFEST_PATH="$PROJECT_PATH"/AndroidManifest.xml
|
||||
TARGET=$("$ANDROID_BIN" list targets | grep id: | tail -1 | cut -f 2 -d ' ' )
|
||||
API_LEVEL=$("$ANDROID_BIN" list target | grep "API level:" | tail -n 1 | cut -f 2 -d ':' | tr -d ' ')
|
||||
|
||||
# check that build targets exist
|
||||
if [ -z "$TARGET" ] || [ -z "$API_LEVEL" ]
|
||||
then
|
||||
echo "No Android Targets are installed. Please install at least one via the android SDK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if this a distribution release no need to build a jar
|
||||
if [ ! -e "$BUILD_PATH"/cordova-$VERSION.jar ] && [ -d "$BUILD_PATH"/framework ]
|
||||
then
|
||||
|
||||
@@ -33,12 +33,22 @@ function read(filename) {
|
||||
f.Close();
|
||||
return s;
|
||||
}
|
||||
|
||||
function checkTargets(targets) {
|
||||
if(!targets) {
|
||||
WScript.Echo("You do not have any android targets setup. Please create at least one target with the `android` command");
|
||||
WScript.Quit(69);
|
||||
}
|
||||
}
|
||||
|
||||
function setTarget() {
|
||||
var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s\d+/g);
|
||||
checkTargets(targets);
|
||||
return targets[targets.length - 1].replace(/id: /, ""); // TODO: give users the option to set their target
|
||||
}
|
||||
function setApiLevel() {
|
||||
var targets = shell.Exec('android.bat list targets').StdOut.ReadAll().match(/API level:\s\d+/g);
|
||||
checkTargets(targets);
|
||||
return targets[targets.length - 1].replace(/API level: /, "");
|
||||
}
|
||||
function write(filename, contents) {
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package __ID__;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
@@ -29,7 +28,9 @@ public class __ACTIVITY__ extends DroidGap
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
super.loadUrl("file:///android_asset/www/index.html");
|
||||
// Set by <content src="index.html" /> in config.xml
|
||||
super.loadUrl(Config.getStartUrl());
|
||||
//super.loadUrl("file:///android_asset/www/index.html")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
|
||||
package="__PACKAGE__" android:versionName="1.1" android:versionCode="5" android:hardwareAccelerated="true">
|
||||
package="__PACKAGE__" android:versionName="1.0" android:versionCode="1" android:hardwareAccelerated="true">
|
||||
<supports-screens
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<p class="event received">Device is Ready</p>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="cordova-2.3.0.js"></script>
|
||||
<script type="text/javascript" src="cordova-2.5.0rc1.js"></script>
|
||||
<script type="text/javascript" src="js/index.js"></script>
|
||||
<script type="text/javascript">
|
||||
app.initialize();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
|
||||
package="org.apache.cordova" android:versionName="1.1" android:versionCode="5">
|
||||
package="org.apache.cordova" android:versionName="1.0" android:versionCode="1">
|
||||
<supports-screens
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<script src="cordova-2.3.0.js"></script>
|
||||
<script src="cordova-2.5.0rc1.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
|
||||
<access origin=".*"/>
|
||||
|
||||
<!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
|
||||
<content src="index.html" />
|
||||
|
||||
<log level="DEBUG"/>
|
||||
<preference name="useBrowserHistory" value="true" />
|
||||
<preference name="exit-on-suspend" value="false" />
|
||||
|
||||
@@ -64,7 +64,7 @@ public class App extends CordovaPlugin {
|
||||
this.loadUrl(args.getString(0), args.optJSONObject(1));
|
||||
}
|
||||
else if (action.equals("cancelLoadUrl")) {
|
||||
this.cancelLoadUrl();
|
||||
//this.cancelLoadUrl();
|
||||
}
|
||||
else if (action.equals("clearHistory")) {
|
||||
this.clearHistory();
|
||||
@@ -160,14 +160,6 @@ public class App extends CordovaPlugin {
|
||||
this.webView.showWebPage(url, openExternal, clearHistory, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel loadUrl before it has been loaded (Only works on a CordovaInterface class)
|
||||
*/
|
||||
@Deprecated
|
||||
public void cancelLoadUrl() {
|
||||
this.cordova.cancelLoadUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear page history for the app.
|
||||
*/
|
||||
|
||||
@@ -58,6 +58,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
|
||||
private static final int DATA_URL = 0; // Return base64 encoded string
|
||||
private static final int FILE_URI = 1; // Return file uri (content://media/external/images/media/2 for Android)
|
||||
private static final int NATIVE_URI = 2; // On Android, this is the same as FILE_URI
|
||||
|
||||
private static final int PHOTOLIBRARY = 0; // Choose image from picture library (same as SAVEDPHOTOALBUM for Android)
|
||||
private static final int CAMERA = 1; // Take picture from camera
|
||||
@@ -310,7 +311,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
}
|
||||
|
||||
// If sending filename back
|
||||
else if (destType == FILE_URI) {
|
||||
else if (destType == FILE_URI || destType == NATIVE_URI) {
|
||||
if (!this.saveToPhotoAlbum) {
|
||||
uri = Uri.fromFile(new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg"));
|
||||
} else {
|
||||
@@ -322,7 +323,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
}
|
||||
|
||||
// If all this is true we shouldn't compress the image.
|
||||
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 && rotate == 0) {
|
||||
if (this.targetHeight == -1 && this.targetWidth == -1 && this.mQuality == 100 &&
|
||||
!this.correctOrientation) {
|
||||
writeUncompressedImage(uri);
|
||||
|
||||
this.callbackContext.success(uri.toString());
|
||||
@@ -387,9 +389,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
}
|
||||
else {
|
||||
// This is a special case to just return the path as no scaling,
|
||||
// rotating or compression needs to be done
|
||||
// rotating, nor compressing needs to be done
|
||||
if (this.targetHeight == -1 && this.targetWidth == -1 &&
|
||||
this.mQuality == 100 && destType == FILE_URI && !this.correctOrientation) {
|
||||
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation) {
|
||||
this.callbackContext.success(uri.toString());
|
||||
} else {
|
||||
// Get the path to the image. Makes loading so much easier.
|
||||
@@ -433,7 +435,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
}
|
||||
|
||||
// If sending filename back
|
||||
else if (destType == FILE_URI) {
|
||||
else if (destType == FILE_URI || destType == NATIVE_URI) {
|
||||
// Do we need to scale the returned file
|
||||
if (this.targetHeight > 0 && this.targetWidth > 0) {
|
||||
try {
|
||||
@@ -570,7 +572,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(imagePath, options);
|
||||
|
||||
|
||||
//CB-2292: WTF? Why is the width null?
|
||||
if(options.outWidth == 0 || options.outHeight == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// determine the correct aspect ratio
|
||||
int[] widthHeight = calculateAspectRatio(options.outWidth, options.outHeight);
|
||||
|
||||
|
||||
273
framework/src/org/apache/cordova/Config.java
Normal file
273
framework/src/org/apache/cordova/Config.java
Normal file
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
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 java.io.IOException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.cordova.api.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 {
|
||||
|
||||
public static final String TAG = "Config";
|
||||
|
||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
||||
private String startUrl;
|
||||
|
||||
private static Config self = null;
|
||||
|
||||
public static void init(Activity action) {
|
||||
if (self == null) {
|
||||
self = new Config(action);
|
||||
}
|
||||
}
|
||||
|
||||
// Intended to be used for testing only; creates an empty configuration.
|
||||
public static void init() {
|
||||
if (self == null) {
|
||||
self = new Config();
|
||||
}
|
||||
}
|
||||
|
||||
// Intended to be used for testing only; creates an empty configuration.
|
||||
private Config() {
|
||||
}
|
||||
|
||||
private Config(Activity action) {
|
||||
if (action == null) {
|
||||
LOG.i("CordovaLog", "There is no activity. Is this on the lock screen?");
|
||||
return;
|
||||
}
|
||||
|
||||
int id = action.getResources().getIdentifier("config", "xml", action.getPackageName());
|
||||
if (id == 0) {
|
||||
id = action.getResources().getIdentifier("cordova", "xml", action.getPackageName());
|
||||
LOG.i("CordovaLog", "config.xml missing, reverting to cordova.xml");
|
||||
}
|
||||
if (id == 0) {
|
||||
LOG.i("CordovaLog", "cordova.xml missing. Ignoring...");
|
||||
return;
|
||||
}
|
||||
|
||||
XmlResourceParser xml = action.getResources().getXml(id);
|
||||
int eventType = -1;
|
||||
while (eventType != XmlResourceParser.END_DOCUMENT) {
|
||||
if (eventType == XmlResourceParser.START_TAG) {
|
||||
String strNode = xml.getName();
|
||||
|
||||
if (strNode.equals("access")) {
|
||||
String origin = xml.getAttributeValue(null, "origin");
|
||||
String subdomains = xml.getAttributeValue(null, "subdomains");
|
||||
if (origin != null) {
|
||||
this._addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
|
||||
}
|
||||
}
|
||||
else if (strNode.equals("log")) {
|
||||
String level = xml.getAttributeValue(null, "level");
|
||||
LOG.i("CordovaLog", "Found log level %s", level);
|
||||
if (level != null) {
|
||||
LOG.setLogLevel(level);
|
||||
}
|
||||
}
|
||||
else if (strNode.equals("preference")) {
|
||||
String name = xml.getAttributeValue(null, "name");
|
||||
/* Java 1.6 does not support switch-based strings
|
||||
Java 7 does, but we're using Dalvik, which is apparently not Java.
|
||||
Since we're reading XML, this has to be an ugly if/else.
|
||||
|
||||
Also, due to cast issues, each of them has to call their separate putExtra!
|
||||
Wheee!!! Isn't Java FUN!?!?!?
|
||||
|
||||
Note: We should probably pass in the classname for the variable splash on splashscreen!
|
||||
*/
|
||||
if(name.equals("splashscreen")) {
|
||||
String value = xml.getAttributeValue(null, "value");
|
||||
int resource = 0;
|
||||
if (value != null)
|
||||
{
|
||||
value = "splash";
|
||||
}
|
||||
resource = action.getResources().getIdentifier(value, "drawable", action.getPackageName());
|
||||
|
||||
action.getIntent().putExtra(name, resource);
|
||||
LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + value);
|
||||
}
|
||||
else if(name.equals("backgroundColor")) {
|
||||
int value = xml.getAttributeIntValue(null, "value", Color.BLACK);
|
||||
action.getIntent().putExtra(name, value);
|
||||
LOG.i("CordovaLog", "Found preference for %s=%d", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + Integer.toString(value));
|
||||
}
|
||||
else if(name.equals("loadUrlTimeoutValue")) {
|
||||
int value = xml.getAttributeIntValue(null, "value", 20000);
|
||||
action.getIntent().putExtra(name, value);
|
||||
LOG.i("CordovaLog", "Found preference for %s=%d", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + Integer.toString(value));
|
||||
}
|
||||
else if(name.equals("keepRunning"))
|
||||
{
|
||||
boolean value = xml.getAttributeValue(null, "value").equals("true");
|
||||
action.getIntent().putExtra(name, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
String value = xml.getAttributeValue(null, "value");
|
||||
action.getIntent().putExtra(name, value);
|
||||
LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + value);
|
||||
}
|
||||
/*
|
||||
LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + value);
|
||||
*/
|
||||
}
|
||||
else if (strNode.equals("content")) {
|
||||
String src = xml.getAttributeValue(null, "src");
|
||||
|
||||
LOG.i("CordovaLog", "Found start page location: %s", src);
|
||||
|
||||
if (src != null) {
|
||||
Pattern schemeRegex = Pattern.compile("^[a-z]+://");
|
||||
Matcher matcher = schemeRegex.matcher(src);
|
||||
if (matcher.find()) {
|
||||
startUrl = src;
|
||||
} else {
|
||||
if (src.charAt(0) == '/') {
|
||||
src = src.substring(1);
|
||||
}
|
||||
startUrl = "file:///android_asset/www/" + src;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
eventType = xml.next();
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add entry to approved list of URLs (whitelist)
|
||||
*
|
||||
* @param origin URL regular expression to allow
|
||||
* @param subdomains T=include all subdomains under origin
|
||||
*/
|
||||
public static void addWhiteListEntry(String origin, boolean subdomains) {
|
||||
if (self == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
self._addWhiteListEntry(origin, subdomains);
|
||||
}
|
||||
|
||||
|
||||
private void _addWhiteListEntry(String origin, boolean subdomains) {
|
||||
try {
|
||||
// Unlimited access to network resources
|
||||
if (origin.compareTo("*") == 0) {
|
||||
LOG.d(TAG, "Unlimited access to network resources");
|
||||
this.whiteList.add(Pattern.compile(".*"));
|
||||
} else { // specific access
|
||||
// check if subdomains should be included
|
||||
// TODO: we should not add more domains if * has already been added
|
||||
if (subdomains) {
|
||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||
if (origin.startsWith("http")) {
|
||||
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
|
||||
} else {
|
||||
this.whiteList.add(Pattern.compile("^https?://(.*\\.)?" + origin));
|
||||
}
|
||||
LOG.d(TAG, "Origin to allow with subdomains: %s", origin);
|
||||
} else {
|
||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||
if (origin.startsWith("http")) {
|
||||
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
|
||||
} else {
|
||||
this.whiteList.add(Pattern.compile("^https?://" + origin));
|
||||
}
|
||||
LOG.d(TAG, "Origin to allow: %s", origin);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.d(TAG, "Failed to add origin %s", origin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if URL is in approved list of URLs to load.
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUrlWhiteListed(String url) {
|
||||
if (self == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check to see if we have matched url previously
|
||||
if (self.whiteListCache.get(url) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Look for match in white list
|
||||
Iterator<Pattern> pit = self.whiteList.iterator();
|
||||
while (pit.hasNext()) {
|
||||
Pattern p = pit.next();
|
||||
Matcher m = p.matcher(url);
|
||||
|
||||
// If match found, then cache it to speed up subsequent comparisons
|
||||
if (m.find()) {
|
||||
self.whiteListCache.put(url, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getStartUrl() {
|
||||
if (self == null || self.startUrl == null) {
|
||||
return "file:///android_asset/www/index.html";
|
||||
}
|
||||
return self.startUrl;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ package org.apache.cordova;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
|
||||
@@ -860,8 +860,7 @@ public class ContactAccessorSdk5 extends ContactAccessor {
|
||||
im.put("id", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im._ID)));
|
||||
im.put("pref", false); // Android does not store pref attribute
|
||||
im.put("value", cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)));
|
||||
String type = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.PROTOCOL));
|
||||
im.put("type", getImType(new Integer(type).intValue()));
|
||||
im.put("type", getImType(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Im.PROTOCOL))));
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
}
|
||||
|
||||
112
framework/src/org/apache/cordova/CordovaArgs.java
Normal file
112
framework/src/org/apache/cordova/CordovaArgs.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
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.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
public class CordovaArgs {
|
||||
private JSONArray baseArgs;
|
||||
|
||||
public CordovaArgs(JSONArray args) {
|
||||
this.baseArgs = args;
|
||||
}
|
||||
|
||||
|
||||
// Pass through the basics to the base args.
|
||||
public Object get(int index) throws JSONException {
|
||||
return baseArgs.get(index);
|
||||
}
|
||||
|
||||
public boolean getBoolean(int index) throws JSONException {
|
||||
return baseArgs.getBoolean(index);
|
||||
}
|
||||
|
||||
public double getDouble(int index) throws JSONException {
|
||||
return baseArgs.getDouble(index);
|
||||
}
|
||||
|
||||
public int getInt(int index) throws JSONException {
|
||||
return baseArgs.getInt(index);
|
||||
}
|
||||
|
||||
public JSONArray getJSONArray(int index) throws JSONException {
|
||||
return baseArgs.getJSONArray(index);
|
||||
}
|
||||
|
||||
public Object getJSONObject(int index) throws JSONException {
|
||||
return baseArgs.getJSONObject(index);
|
||||
}
|
||||
|
||||
public long getLong(int index) throws JSONException {
|
||||
return baseArgs.getLong(index);
|
||||
}
|
||||
|
||||
public String getString(int index) throws JSONException {
|
||||
return baseArgs.getString(index);
|
||||
}
|
||||
|
||||
|
||||
public Object opt(int index) {
|
||||
return baseArgs.opt(index);
|
||||
}
|
||||
|
||||
public boolean optBoolean(int index) {
|
||||
return baseArgs.optBoolean(index);
|
||||
}
|
||||
|
||||
public double optDouble(int index) {
|
||||
return baseArgs.optDouble(index);
|
||||
}
|
||||
|
||||
public int optInt(int index) {
|
||||
return baseArgs.optInt(index);
|
||||
}
|
||||
|
||||
public JSONArray optJSONArray(int index) {
|
||||
return baseArgs.optJSONArray(index);
|
||||
}
|
||||
|
||||
public Object optJSONObject(int index) {
|
||||
return baseArgs.optJSONObject(index);
|
||||
}
|
||||
|
||||
public long optLong(int index) {
|
||||
return baseArgs.optLong(index);
|
||||
}
|
||||
|
||||
public String optString(int index) {
|
||||
return baseArgs.optString(index);
|
||||
}
|
||||
|
||||
public boolean isNull(int index) {
|
||||
return baseArgs.isNull(index);
|
||||
}
|
||||
|
||||
|
||||
// The interesting custom helpers.
|
||||
public byte[] getArrayBuffer(int index) throws JSONException {
|
||||
String encoded = baseArgs.getString(index);
|
||||
return Base64.decode(encoded, Base64.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.json.JSONException;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
@@ -33,6 +35,7 @@ import android.view.ViewGroup.LayoutParams;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.JsPromptResult;
|
||||
import android.webkit.JsResult;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebStorage;
|
||||
import android.webkit.WebView;
|
||||
@@ -47,6 +50,8 @@ import android.widget.RelativeLayout;
|
||||
*/
|
||||
public class CordovaChromeClient extends WebChromeClient {
|
||||
|
||||
public static final int FILECHOOSER_RESULTCODE = 5173;
|
||||
private static final String LOG_TAG = "CordovaChromeClient";
|
||||
private String TAG = "CordovaLog";
|
||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||
private CordovaInterface cordova;
|
||||
@@ -55,6 +60,9 @@ public class CordovaChromeClient extends WebChromeClient {
|
||||
// the video progress view
|
||||
private View mVideoProgressView;
|
||||
|
||||
// File Chooser
|
||||
public ValueCallback<Uri> mUploadMessage;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -197,7 +205,7 @@ public class CordovaChromeClient extends WebChromeClient {
|
||||
// Security check to make sure any requests are coming from the page initially
|
||||
// loaded in webview and not another loaded in an iframe.
|
||||
boolean reqOk = false;
|
||||
if (url.startsWith("file://") || url.indexOf(this.appView.baseUrl) == 0 || this.appView.isUrlWhiteListed(url)) {
|
||||
if (url.startsWith("file://") || url.indexOf(this.appView.baseUrl) == 0 || Config.isUrlWhiteListed(url)) {
|
||||
reqOk = true;
|
||||
}
|
||||
|
||||
@@ -369,5 +377,26 @@ public class CordovaChromeClient extends WebChromeClient {
|
||||
}
|
||||
return mVideoProgressView;
|
||||
}
|
||||
|
||||
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
||||
this.openFileChooser(uploadMsg, "*/*");
|
||||
}
|
||||
|
||||
public void openFileChooser( ValueCallback<Uri> uploadMsg, String acceptType ) {
|
||||
this.openFileChooser(uploadMsg, acceptType, null);
|
||||
}
|
||||
|
||||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)
|
||||
{
|
||||
mUploadMessage = uploadMsg;
|
||||
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
i.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
i.setType("*/*");
|
||||
this.cordova.getActivity().startActivityForResult(Intent.createChooser(i, "File Browser"),
|
||||
FILECHOOSER_RESULTCODE);
|
||||
}
|
||||
|
||||
public ValueCallback<Uri> getValueCallback() {
|
||||
return this.mUploadMessage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,30 +19,24 @@
|
||||
|
||||
package org.apache.cordova;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.cordova.Config;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.PluginManager;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -65,15 +59,12 @@ public class CordovaWebView extends WebView {
|
||||
|
||||
public static final String TAG = "CordovaWebView";
|
||||
|
||||
/** The whitelist **/
|
||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
||||
private ArrayList<Integer> keyDownCodes = new ArrayList<Integer>();
|
||||
private ArrayList<Integer> keyUpCodes = new ArrayList<Integer>();
|
||||
|
||||
public PluginManager pluginManager;
|
||||
private boolean paused;
|
||||
|
||||
|
||||
private BroadcastReceiver receiver;
|
||||
|
||||
|
||||
@@ -105,6 +96,23 @@ public class CordovaWebView extends WebView {
|
||||
/** custom view created by the browser (a video player for example) */
|
||||
private View mCustomView;
|
||||
private WebChromeClient.CustomViewCallback mCustomViewCallback;
|
||||
|
||||
private ActivityResult mResult = null;
|
||||
|
||||
class ActivityResult {
|
||||
|
||||
int request;
|
||||
int result;
|
||||
Intent incoming;
|
||||
|
||||
public ActivityResult(int req, int res, Intent intent) {
|
||||
request = req;
|
||||
result = res;
|
||||
incoming = intent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
|
||||
new FrameLayout.LayoutParams(
|
||||
@@ -254,6 +262,7 @@ public class CordovaWebView extends WebView {
|
||||
settings.setDatabaseEnabled(true);
|
||||
String databasePath = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
||||
settings.setDatabasePath(databasePath);
|
||||
settings.setGeolocationDatabasePath(databasePath);
|
||||
|
||||
// Enable DOM storage
|
||||
settings.setDomStorageEnabled(true);
|
||||
@@ -261,6 +270,13 @@ public class CordovaWebView extends WebView {
|
||||
// Enable built-in geolocation
|
||||
settings.setGeolocationEnabled(true);
|
||||
|
||||
// Enable AppCache
|
||||
// Fix for CB-2282
|
||||
settings.setAppCacheMaxSize(5 * 1048576);
|
||||
String pathToCache = this.cordova.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
||||
settings.setAppCachePath(pathToCache);
|
||||
settings.setAppCacheEnabled(true);
|
||||
|
||||
// Fix for CB-1405
|
||||
// Google issue 4641
|
||||
this.updateUserAgentString();
|
||||
@@ -324,71 +340,9 @@ public class CordovaWebView extends WebView {
|
||||
this.chromeClient = client;
|
||||
super.setWebChromeClient(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add entry to approved list of URLs (whitelist)
|
||||
*
|
||||
* @param origin URL regular expression to allow
|
||||
* @param subdomains T=include all subdomains under origin
|
||||
*/
|
||||
public void addWhiteListEntry(String origin, boolean subdomains) {
|
||||
try {
|
||||
// Unlimited access to network resources
|
||||
if (origin.compareTo("*") == 0) {
|
||||
LOG.d(TAG, "Unlimited access to network resources");
|
||||
this.whiteList.add(Pattern.compile(".*"));
|
||||
} else { // specific access
|
||||
// check if subdomains should be included
|
||||
// TODO: we should not add more domains if * has already been added
|
||||
if (subdomains) {
|
||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||
if (origin.startsWith("http")) {
|
||||
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
|
||||
} else {
|
||||
this.whiteList.add(Pattern.compile("^https?://(.*\\.)?" + origin));
|
||||
}
|
||||
LOG.d(TAG, "Origin to allow with subdomains: %s", origin);
|
||||
} else {
|
||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||
if (origin.startsWith("http")) {
|
||||
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
|
||||
} else {
|
||||
this.whiteList.add(Pattern.compile("^https?://" + origin));
|
||||
}
|
||||
LOG.d(TAG, "Origin to allow: %s", origin);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.d(TAG, "Failed to add origin %s", origin);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if URL is in approved list of URLs to load.
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public boolean isUrlWhiteListed(String url) {
|
||||
|
||||
// Check to see if we have matched url previously
|
||||
if (this.whiteListCache.get(url) != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Look for match in white list
|
||||
Iterator<Pattern> pit = this.whiteList.iterator();
|
||||
while (pit.hasNext()) {
|
||||
Pattern p = pit.next();
|
||||
Matcher m = p.matcher(url);
|
||||
|
||||
// If match found, then cache it to speed up subsequent comparisons
|
||||
if (m.find()) {
|
||||
this.whiteListCache.put(url, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
public CordovaChromeClient getWebChromeClient() {
|
||||
return this.chromeClient;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -514,8 +468,8 @@ public class CordovaWebView extends WebView {
|
||||
if (LOG.isLoggable(LOG.DEBUG) && !url.startsWith("javascript:")) {
|
||||
LOG.d(TAG, ">>> loadUrlNow()");
|
||||
}
|
||||
if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || url.startsWith("javascript:") || this.isUrlWhiteListed(url)) {
|
||||
super.loadUrl(url);
|
||||
if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) {
|
||||
super.loadUrl(url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,15 +561,14 @@ public class CordovaWebView extends WebView {
|
||||
|
||||
// Check webview first to see if there is a history
|
||||
// This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
|
||||
if (super.canGoBack()) {
|
||||
if (super.canGoBack() && this.useBrowserHistory) {
|
||||
printBackForwardList();
|
||||
super.goBack();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// If our managed history has prev url
|
||||
if (this.urls.size() > 1 && !this.useBrowserHistory) {
|
||||
else if (this.urls.size() > 1 && !this.useBrowserHistory) {
|
||||
this.urls.pop(); // Pop current url
|
||||
String url = this.urls.pop(); // Pop prev url that we want to load, since it will be added back by loadUrl()
|
||||
this.loadUrl(url);
|
||||
@@ -631,10 +584,10 @@ public class CordovaWebView extends WebView {
|
||||
* @return
|
||||
*/
|
||||
public boolean canGoBack() {
|
||||
if (super.canGoBack()) {
|
||||
if (super.canGoBack() && this.useBrowserHistory) {
|
||||
return true;
|
||||
}
|
||||
if (this.urls.size() > 1) {
|
||||
else if (this.urls.size() > 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -662,7 +615,7 @@ public class CordovaWebView extends WebView {
|
||||
if (!openExternal) {
|
||||
|
||||
// Make sure url is in whitelist
|
||||
if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || isUrlWhiteListed(url)) {
|
||||
if (url.startsWith("file://") || url.indexOf(this.baseUrl) == 0 || Config.isUrlWhiteListed(url)) {
|
||||
// TODO: What about params?
|
||||
|
||||
// Clear out current url from history, since it will be replacing it
|
||||
@@ -699,68 +652,14 @@ public class CordovaWebView extends WebView {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Cordova configuration from res/xml/cordova.xml.
|
||||
* Check configuration parameters from Config.
|
||||
* Approved list of URLs that can be loaded into DroidGap
|
||||
* <access origin="http://server regexp" subdomains="true" />
|
||||
* Log level: ERROR, WARN, INFO, DEBUG, VERBOSE (default=ERROR)
|
||||
* <log level="DEBUG" />
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
Activity action = this.cordova.getActivity();
|
||||
if(action == null)
|
||||
{
|
||||
LOG.i("CordovaLog", "There is no activity. Is this on the lock screen?");
|
||||
return;
|
||||
}
|
||||
int id = getResources().getIdentifier("config", "xml", this.cordova.getActivity().getPackageName());
|
||||
if(id == 0)
|
||||
{
|
||||
id = getResources().getIdentifier("cordova", "xml", this.cordova.getActivity().getPackageName());
|
||||
Log.i("CordovaLog", "config.xml missing, reverting to cordova.xml");
|
||||
}
|
||||
if (id == 0) {
|
||||
LOG.i("CordovaLog", "cordova.xml missing. Ignoring...");
|
||||
return;
|
||||
}
|
||||
XmlResourceParser xml = getResources().getXml(id);
|
||||
int eventType = -1;
|
||||
while (eventType != XmlResourceParser.END_DOCUMENT) {
|
||||
if (eventType == XmlResourceParser.START_TAG) {
|
||||
String strNode = xml.getName();
|
||||
if (strNode.equals("access")) {
|
||||
String origin = xml.getAttributeValue(null, "origin");
|
||||
String subdomains = xml.getAttributeValue(null, "subdomains");
|
||||
if (origin != null) {
|
||||
this.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
|
||||
}
|
||||
}
|
||||
else if (strNode.equals("log")) {
|
||||
String level = xml.getAttributeValue(null, "level");
|
||||
LOG.i("CordovaLog", "Found log level %s", level);
|
||||
if (level != null) {
|
||||
LOG.setLogLevel(level);
|
||||
}
|
||||
}
|
||||
else if (strNode.equals("preference")) {
|
||||
String name = xml.getAttributeValue(null, "name");
|
||||
String value = xml.getAttributeValue(null, "value");
|
||||
|
||||
LOG.i("CordovaLog", "Found preference for %s=%s", name, value);
|
||||
Log.d("CordovaLog", "Found preference for " + name + "=" + value);
|
||||
|
||||
// Save preferences in Intent
|
||||
this.cordova.getActivity().getIntent().putExtra(name, value);
|
||||
}
|
||||
}
|
||||
try {
|
||||
eventType = xml.next();
|
||||
} catch (XmlPullParserException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Config has already been loaded, and it stores these preferences on the Intent.
|
||||
if("false".equals(this.getProperty("useBrowserHistory", "true")))
|
||||
{
|
||||
//Switch back to the old browser history and state the six month policy
|
||||
@@ -856,7 +755,9 @@ public class CordovaWebView extends WebView {
|
||||
// If not, then invoke default behaviour
|
||||
else {
|
||||
//this.activityState = ACTIVITY_EXITING;
|
||||
return false;
|
||||
//return false;
|
||||
// If they hit back button when app is initializing, app should exit instead of hang until initilazation (CB2-458)
|
||||
this.cordova.getActivity().finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -939,9 +840,8 @@ public class CordovaWebView extends WebView {
|
||||
public void handleResume(boolean keepRunning, boolean activityResultKeepRunning)
|
||||
{
|
||||
|
||||
// Send resume event to JavaScript
|
||||
this.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};");
|
||||
|
||||
|
||||
// Forward to plugins
|
||||
if (this.pluginManager != null) {
|
||||
this.pluginManager.onResume(keepRunning);
|
||||
@@ -955,7 +855,8 @@ public class CordovaWebView extends WebView {
|
||||
public void handleDestroy()
|
||||
{
|
||||
// Send destroy event to JavaScript
|
||||
this.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
|
||||
// Since baseUrl is set in loadUrlIntoView, if user hit Back button before loadUrl was called, we'll get an NPE on baseUrl (CB-2458)
|
||||
this.loadUrlIntoView("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
|
||||
|
||||
// Load blank page so that JavaScript onunload is called
|
||||
this.loadUrl("about:blank");
|
||||
@@ -1018,11 +919,14 @@ public class CordovaWebView extends WebView {
|
||||
{
|
||||
WebBackForwardList currentList = this.copyBackForwardList();
|
||||
WebHistoryItem item = currentList.getItemAtIndex(0);
|
||||
String url = item.getUrl();
|
||||
String currentUrl = this.getUrl();
|
||||
LOG.d(TAG, "The current URL is: " + currentUrl);
|
||||
LOG.d(TAG, "The URL at item 0 is:" + url);
|
||||
return currentUrl.equals(url);
|
||||
if( item!=null){ // Null-fence in case they haven't called loadUrl yet (CB-2458)
|
||||
String url = item.getUrl();
|
||||
String currentUrl = this.getUrl();
|
||||
LOG.d(TAG, "The current URL is: " + currentUrl);
|
||||
LOG.d(TAG, "The URL at item 0 is:" + url);
|
||||
return currentUrl.equals(url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
|
||||
@@ -1077,4 +981,17 @@ public class CordovaWebView extends WebView {
|
||||
public boolean isCustomViewShowing() {
|
||||
return mCustomView != null;
|
||||
}
|
||||
|
||||
public WebBackForwardList restoreState(Bundle savedInstanceState)
|
||||
{
|
||||
WebBackForwardList myList = super.restoreState(savedInstanceState);
|
||||
Log.d(TAG, "WebView restoration crew now restoring!");
|
||||
//Initialize the plugin manager once more
|
||||
this.pluginManager.init();
|
||||
return myList;
|
||||
}
|
||||
|
||||
public void storeResult(int requestCode, int resultCode, Intent intent) {
|
||||
mResult = new ActivityResult(requestCode, resultCode, intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ package org.apache.cordova;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.json.JSONException;
|
||||
@@ -193,7 +192,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
||||
|
||||
// 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:") || url.indexOf(this.appView.baseUrl) == 0 || this.appView.isUrlWhiteListed(url)) {
|
||||
if (url.startsWith("file://") || url.startsWith("data:") || url.indexOf(this.appView.baseUrl) == 0 || Config.isUrlWhiteListed(url)) {
|
||||
//This will fix iFrames
|
||||
if (appView.useBrowserHistory || url.startsWith("data:"))
|
||||
return false;
|
||||
@@ -231,6 +230,10 @@ public class CordovaWebViewClient extends WebViewClient {
|
||||
AuthenticationToken token = this.getAuthenticationToken(host, realm);
|
||||
if (token != null) {
|
||||
handler.proceed(token.getUserName(), token.getPassword());
|
||||
}
|
||||
else {
|
||||
// Handle 401 like we'd normally do!
|
||||
super.onReceivedHttpAuthRequest(view, handler, host, realm);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +298,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
||||
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
||||
// from the JS side when the JS gets to that code.
|
||||
if (!url.equals("about:blank")) {
|
||||
LOG.d(TAG, "Trying to fire onNativeReady");
|
||||
this.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||
this.appView.postMessage("onNativeReady", null);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.CordovaInterface;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -39,7 +38,7 @@ import android.telephony.TelephonyManager;
|
||||
public class Device extends CordovaPlugin {
|
||||
public static final String TAG = "Device";
|
||||
|
||||
public static String cordovaVersion = "2.3.0"; // Cordova version
|
||||
public static String cordovaVersion = "2.5.0rc1"; // Cordova version
|
||||
public static String platform = "Android"; // Device OS
|
||||
public static String uuid; // Device UUID
|
||||
|
||||
|
||||
@@ -38,8 +38,10 @@ import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
@@ -48,7 +50,7 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
@@ -170,7 +172,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
// Draw a splash screen using an image located in the drawable resource directory.
|
||||
// This is not the same as calling super.loadSplashscreen(url)
|
||||
protected int splashscreen = 0;
|
||||
protected int splashscreenTime = 0;
|
||||
protected int splashscreenTime = 3000;
|
||||
|
||||
// LoadUrl timeout value in msec (default of 20 sec)
|
||||
protected int loadUrlTimeoutValue = 20000;
|
||||
@@ -180,6 +182,18 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
// when another application (activity) is started.
|
||||
protected boolean keepRunning = true;
|
||||
|
||||
private int lastRequestCode;
|
||||
|
||||
private Object responseCode;
|
||||
|
||||
private Intent lastIntent;
|
||||
|
||||
private Object lastResponseCode;
|
||||
|
||||
private String initCallbackClass;
|
||||
|
||||
private Object LOG_TAG;
|
||||
|
||||
/**
|
||||
* Sets the authentication token.
|
||||
*
|
||||
@@ -246,11 +260,15 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
//preferences = new PreferenceSet();
|
||||
|
||||
Config.init(this);
|
||||
LOG.d(TAG, "DroidGap.onCreate()");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if(savedInstanceState != null)
|
||||
{
|
||||
initCallbackClass = savedInstanceState.getString("callbackClass");
|
||||
}
|
||||
|
||||
if(!this.getBooleanProperty("showTitle", false))
|
||||
{
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
@@ -338,6 +356,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
|
||||
// Clear cancel flag
|
||||
this.cancelLoadUrl = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -571,6 +590,7 @@ public class DroidGap 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");
|
||||
this.getIntent().putExtra(name, value);
|
||||
}
|
||||
|
||||
@@ -581,6 +601,7 @@ public class DroidGap 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");
|
||||
this.getIntent().putExtra(name, value);
|
||||
}
|
||||
|
||||
@@ -591,6 +612,7 @@ public class DroidGap 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");
|
||||
this.getIntent().putExtra(name, value);
|
||||
}
|
||||
|
||||
@@ -601,6 +623,7 @@ public class DroidGap 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");
|
||||
this.getIntent().putExtra(name, value);
|
||||
}
|
||||
|
||||
@@ -800,9 +823,35 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
||||
*/
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||
LOG.d(TAG, "Incoming Result");
|
||||
super.onActivityResult(requestCode, resultCode, intent);
|
||||
Log.d(TAG, "Request code = " + requestCode);
|
||||
ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
|
||||
if (requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
|
||||
Log.d(TAG, "did we get here?");
|
||||
if (null == mUploadMessage)
|
||||
return;
|
||||
Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
|
||||
Log.d(TAG, "result = " + result);
|
||||
// Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
|
||||
// Log.d(TAG, "result = " + filepath);
|
||||
mUploadMessage.onReceiveValue(result);
|
||||
mUploadMessage = null;
|
||||
}
|
||||
CordovaPlugin callback = this.activityResultCallback;
|
||||
if (callback != null) {
|
||||
if(callback == null)
|
||||
{
|
||||
if(initCallbackClass != null)
|
||||
{
|
||||
this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
|
||||
callback = activityResultCallback;
|
||||
LOG.d(TAG, "We have a callback to send this result to");
|
||||
callback.onActivityResult(requestCode, resultCode, intent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.d(TAG, "We have a callback to send this result to");
|
||||
callback.onActivityResult(requestCode, resultCode, intent);
|
||||
}
|
||||
}
|
||||
@@ -824,7 +873,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
|
||||
// If errorUrl specified, then load it
|
||||
final String errorUrl = me.getStringProperty("errorUrl", null);
|
||||
if ((errorUrl != null) && (errorUrl.startsWith("file://") || this.appView.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) {
|
||||
if ((errorUrl != null) && (errorUrl.startsWith("file://") || Config.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) {
|
||||
|
||||
// Load URL on UI thread
|
||||
me.runOnUiThread(new Runnable() {
|
||||
@@ -840,8 +889,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
|
||||
me.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (exit)
|
||||
{
|
||||
if (exit) {
|
||||
me.appView.setVisibility(View.GONE);
|
||||
me.displayError("Application Error", description + " (" + failingUrl + ")", "OK", exit);
|
||||
}
|
||||
@@ -892,11 +940,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
* @return
|
||||
*/
|
||||
public boolean isUrlWhiteListed(String url) {
|
||||
// Check to see if we have matched url previously
|
||||
if (this.appView != null) {
|
||||
return this.appView.isUrlWhiteListed(url);
|
||||
}
|
||||
return false;
|
||||
return Config.isUrlWhiteListed(url);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1053,9 +1097,9 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
}
|
||||
else {
|
||||
// If the splash dialog is showing don't try to show it again
|
||||
if (this.splashDialog != null && !this.splashDialog.isShowing()) {
|
||||
this.splashscreen = this.getIntegerProperty("splashscreen", 0);
|
||||
this.showSplashScreen(this.splashscreenTime);
|
||||
if (this.splashDialog == null || !this.splashDialog.isShowing()) {
|
||||
this.splashscreen = this.getIntegerProperty("splashscreen", 0);
|
||||
this.showSplashScreen(this.splashscreenTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1082,4 +1126,15 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
public ExecutorService getThreadPool() {
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
protected void onSaveInstanceState(Bundle outState)
|
||||
{
|
||||
super.onSaveInstanceState(outState);
|
||||
if(this.activityResultCallback != null)
|
||||
{
|
||||
String cClass = this.activityResultCallback.getClass().getName();
|
||||
outState.putString("callbackClass", cClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,24 +20,28 @@ package org.apache.cordova;
|
||||
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
public class Echo extends CordovaPlugin {
|
||||
|
||||
@Override
|
||||
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
||||
final String result = args.isNull(0) ? null : args.getString(0);
|
||||
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
|
||||
if ("echo".equals(action)) {
|
||||
final String result = args.isNull(0) ? null : args.getString(0);
|
||||
callbackContext.success(result);
|
||||
return true;
|
||||
} else if ("echoAsync".equals(action)) {
|
||||
final String result = args.isNull(0) ? null : args.getString(0);
|
||||
cordova.getThreadPool().execute(new Runnable() {
|
||||
public void run() {
|
||||
callbackContext.success(result);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if ("echoArrayBuffer".equals(action)) {
|
||||
final byte[] result = args.getArrayBuffer(0);
|
||||
callbackContext.success(result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.apache.cordova;
|
||||
|
||||
import android.webkit.JavascriptInterface;
|
||||
import org.apache.cordova.api.PluginManager;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.apache.cordova;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -33,6 +32,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
@@ -77,6 +77,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
private static final class RequestContext {
|
||||
String source;
|
||||
String target;
|
||||
File targetFile;
|
||||
CallbackContext callbackContext;
|
||||
InputStream currentInputStream;
|
||||
OutputStream currentOutputStream;
|
||||
@@ -200,7 +201,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
return;
|
||||
}
|
||||
final boolean useHttps = url.getProtocol().toLowerCase().equals("https");
|
||||
final boolean useHttps = url.getProtocol().equals("https");
|
||||
|
||||
final RequestContext context = new RequestContext(source, target, callbackContext);
|
||||
synchronized (activeRequests) {
|
||||
@@ -215,6 +216,8 @@ public class FileTransfer extends CordovaPlugin {
|
||||
HttpURLConnection conn = null;
|
||||
HostnameVerifier oldHostnameVerifier = null;
|
||||
SSLSocketFactory oldSocketFactory = null;
|
||||
int totalBytes = 0;
|
||||
int fixedLength = -1;
|
||||
try {
|
||||
// Create return object
|
||||
FileUploadResult result = new FileUploadResult();
|
||||
@@ -256,7 +259,6 @@ public class FileTransfer extends CordovaPlugin {
|
||||
|
||||
// Use a post method.
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Connection", "Keep-Alive");
|
||||
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + BOUNDARY);
|
||||
|
||||
// Set the cookies on the response
|
||||
@@ -289,38 +291,35 @@ public class FileTransfer extends CordovaPlugin {
|
||||
* Store the non-file portions of the multipart data as a string, so that we can add it
|
||||
* to the contentSize, since it is part of the body of the HTTP request.
|
||||
*/
|
||||
String extraParams = "";
|
||||
StringBuilder beforeData = new StringBuilder();
|
||||
try {
|
||||
for (Iterator<?> iter = params.keys(); iter.hasNext();) {
|
||||
Object key = iter.next();
|
||||
if(!String.valueOf(key).equals("headers"))
|
||||
{
|
||||
extraParams += LINE_START + BOUNDARY + LINE_END;
|
||||
extraParams += "Content-Disposition: form-data; name=\"" + key.toString() + "\";";
|
||||
extraParams += LINE_END + LINE_END;
|
||||
extraParams += params.getString(key.toString());
|
||||
extraParams += LINE_END;
|
||||
beforeData.append(LINE_START).append(BOUNDARY).append(LINE_END);
|
||||
beforeData.append("Content-Disposition: form-data; name=\"").append(key.toString()).append('"');
|
||||
beforeData.append(LINE_END).append(LINE_END);
|
||||
beforeData.append(params.getString(key.toString()));
|
||||
beforeData.append(LINE_END);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
}
|
||||
|
||||
extraParams += LINE_START + BOUNDARY + LINE_END;
|
||||
extraParams += "Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"";
|
||||
byte[] extraBytes = extraParams.getBytes("UTF-8");
|
||||
|
||||
String midParams = "\"" + LINE_END + "Content-Type: " + mimeType + LINE_END + LINE_END;
|
||||
String tailParams = LINE_END + LINE_START + BOUNDARY + LINE_START + LINE_END;
|
||||
byte[] fileNameBytes = fileName.getBytes("UTF-8");
|
||||
beforeData.append(LINE_START).append(BOUNDARY).append(LINE_END);
|
||||
beforeData.append("Content-Disposition: form-data; name=\"").append(fileKey).append("\";");
|
||||
beforeData.append(" filename=\"").append(fileName).append('"').append(LINE_END);
|
||||
beforeData.append("Content-Type: ").append(mimeType).append(LINE_END).append(LINE_END);
|
||||
byte[] beforeDataBytes = beforeData.toString().getBytes("UTF-8");
|
||||
byte[] tailParamsBytes = (LINE_END + LINE_START + BOUNDARY + LINE_START + LINE_END).getBytes("UTF-8");
|
||||
|
||||
|
||||
// Get a input stream of the file on the phone
|
||||
InputStream sourceInputStream = getPathFromUri(source);
|
||||
|
||||
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
||||
Log.d(LOG_TAG, "String Length: " + stringLength);
|
||||
int fixedLength = -1;
|
||||
int stringLength = beforeDataBytes.length + tailParamsBytes.length;
|
||||
if (sourceInputStream instanceof FileInputStream) {
|
||||
fixedLength = (int) ((FileInputStream)sourceInputStream).getChannel().size() + stringLength;
|
||||
progress.setLengthComputable(true);
|
||||
@@ -332,7 +331,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
// It also causes OOM if HTTPS is used, even on newer devices.
|
||||
boolean useChunkedMode = chunkedMode && (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO || useHttps);
|
||||
useChunkedMode = useChunkedMode || (fixedLength == -1);
|
||||
|
||||
|
||||
if (useChunkedMode) {
|
||||
conn.setChunkedStreamingMode(MAX_BUFFER_SIZE);
|
||||
// Although setChunkedStreamingMode sets this header, setting it explicitly here works
|
||||
@@ -342,19 +341,20 @@ public class FileTransfer extends CordovaPlugin {
|
||||
conn.setFixedLengthStreamingMode(fixedLength);
|
||||
}
|
||||
|
||||
DataOutputStream dos = null;
|
||||
conn.connect();
|
||||
|
||||
OutputStream sendStream = null;
|
||||
try {
|
||||
dos = new DataOutputStream( conn.getOutputStream() );
|
||||
sendStream = conn.getOutputStream();
|
||||
synchronized (context) {
|
||||
if (context.aborted) {
|
||||
return;
|
||||
}
|
||||
context.currentOutputStream = dos;
|
||||
context.currentOutputStream = sendStream;
|
||||
}
|
||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
||||
dos.write(extraBytes);
|
||||
dos.write(fileNameBytes);
|
||||
dos.writeBytes(midParams);
|
||||
sendStream.write(beforeDataBytes);
|
||||
totalBytes += beforeDataBytes.length;
|
||||
|
||||
// create a buffer of maximum size
|
||||
int bytesAvailable = sourceInputStream.available();
|
||||
@@ -363,13 +363,12 @@ public class FileTransfer extends CordovaPlugin {
|
||||
|
||||
// read file and write it into form...
|
||||
int bytesRead = sourceInputStream.read(buffer, 0, bufferSize);
|
||||
long totalBytes = 0;
|
||||
|
||||
long prevBytesRead = 0;
|
||||
while (bytesRead > 0) {
|
||||
totalBytes += bytesRead;
|
||||
result.setBytesSent(totalBytes);
|
||||
dos.write(buffer, 0, bufferSize);
|
||||
sendStream.write(buffer, 0, bytesRead);
|
||||
totalBytes += bytesRead;
|
||||
if (totalBytes > prevBytesRead + 102400) {
|
||||
prevBytesRead = totalBytes;
|
||||
Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
|
||||
@@ -386,17 +385,21 @@ public class FileTransfer extends CordovaPlugin {
|
||||
}
|
||||
|
||||
// send multipart form data necessary after file data...
|
||||
dos.writeBytes(tailParams);
|
||||
dos.flush();
|
||||
sendStream.write(tailParamsBytes);
|
||||
totalBytes += tailParamsBytes.length;
|
||||
sendStream.flush();
|
||||
} finally {
|
||||
safeClose(sourceInputStream);
|
||||
safeClose(dos);
|
||||
safeClose(sendStream);
|
||||
}
|
||||
context.currentOutputStream = null;
|
||||
Log.d(LOG_TAG, "Sent " + totalBytes + " of " + fixedLength);
|
||||
|
||||
//------------------ read the SERVER RESPONSE
|
||||
String responseString;
|
||||
int responseCode = conn.getResponseCode();
|
||||
Log.d(LOG_TAG, "response code: " + responseCode);
|
||||
Log.d(LOG_TAG, "response headers: " + conn.getHeaderFields());
|
||||
InputStream inStream = null;
|
||||
try {
|
||||
inStream = getInputStream(conn);
|
||||
@@ -407,8 +410,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
context.currentInputStream = inStream;
|
||||
}
|
||||
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(1024, conn.getContentLength()));
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead = 0;
|
||||
// write bytes to file
|
||||
@@ -436,6 +438,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
} catch (IOException e) {
|
||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, conn);
|
||||
Log.e(LOG_TAG, error.toString(), e);
|
||||
Log.e(LOG_TAG, "Failed after uploading " + totalBytes + " of " + fixedLength + " bytes.");
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
@@ -458,8 +461,6 @@ public class FileTransfer extends CordovaPlugin {
|
||||
https.setHostnameVerifier(oldHostnameVerifier);
|
||||
https.setSSLSocketFactory(oldSocketFactory);
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -475,7 +476,7 @@ public class FileTransfer extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private static InputStream getInputStream(HttpURLConnection conn) throws IOException {
|
||||
private static InputStream getInputStream(URLConnection conn) throws IOException {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
return new DoneHandlerInputStream(conn.getInputStream());
|
||||
}
|
||||
@@ -526,13 +527,15 @@ public class FileTransfer extends CordovaPlugin {
|
||||
return oldFactory;
|
||||
}
|
||||
|
||||
private static JSONObject createFileTransferError(int errorCode, String source, String target, HttpURLConnection connection) {
|
||||
private static JSONObject createFileTransferError(int errorCode, String source, String target, URLConnection connection) {
|
||||
|
||||
Integer httpStatus = null;
|
||||
int httpStatus = 0;
|
||||
|
||||
if (connection != null) {
|
||||
try {
|
||||
httpStatus = connection.getResponseCode();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
httpStatus = ((HttpURLConnection)connection).getResponseCode();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.w(LOG_TAG, "Error getting HTTP status code from connection.", e);
|
||||
}
|
||||
@@ -601,9 +604,9 @@ public class FileTransfer extends CordovaPlugin {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
return;
|
||||
}
|
||||
final boolean useHttps = url.getProtocol().toLowerCase().equals("https");
|
||||
|
||||
if (!webView.isUrlWhiteListed(source)) {
|
||||
final boolean useHttps = url.getProtocol().equals("https");
|
||||
|
||||
if (!Config.isUrlWhiteListed(source)) {
|
||||
Log.w(LOG_TAG, "Source URL is not in white list: '" + source + "'");
|
||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, 401);
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
@@ -621,14 +624,16 @@ public class FileTransfer extends CordovaPlugin {
|
||||
if (context.aborted) {
|
||||
return;
|
||||
}
|
||||
HttpURLConnection connection = null;
|
||||
URLConnection connection = null;
|
||||
HostnameVerifier oldHostnameVerifier = null;
|
||||
SSLSocketFactory oldSocketFactory = null;
|
||||
File file = null;
|
||||
PluginResult result = null;
|
||||
|
||||
try {
|
||||
|
||||
file = getFileFromPath(target);
|
||||
context.targetFile = file;
|
||||
// create needed directories
|
||||
File file = getFileFromPath(target);
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
// connect to server
|
||||
@@ -653,10 +658,12 @@ public class FileTransfer extends CordovaPlugin {
|
||||
}
|
||||
// Return a standard HTTP connection
|
||||
else {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection = url.openConnection();
|
||||
}
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
((HttpURLConnection)connection).setRequestMethod("GET");
|
||||
}
|
||||
|
||||
//Add cookie support
|
||||
String cookie = CookieManager.getInstance().getCookie(source);
|
||||
@@ -676,11 +683,12 @@ public class FileTransfer extends CordovaPlugin {
|
||||
progress.setTotal(connection.getContentLength());
|
||||
}
|
||||
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
FileOutputStream outputStream = null;
|
||||
InputStream inputStream = null;
|
||||
|
||||
try {
|
||||
inputStream = getInputStream(connection);
|
||||
outputStream = new FileOutputStream(file);
|
||||
synchronized (context) {
|
||||
if (context.aborted) {
|
||||
return;
|
||||
@@ -713,22 +721,22 @@ public class FileTransfer extends CordovaPlugin {
|
||||
FileUtils fileUtil = new FileUtils();
|
||||
JSONObject fileEntry = fileUtil.getEntry(file);
|
||||
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.OK, fileEntry));
|
||||
result = new PluginResult(PluginResult.Status.OK, fileEntry);
|
||||
} catch (FileNotFoundException e) {
|
||||
JSONObject error = createFileTransferError(FILE_NOT_FOUND_ERR, source, target, connection);
|
||||
Log.e(LOG_TAG, error.toString(), e);
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||
} catch (IOException e) {
|
||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
|
||||
Log.e(LOG_TAG, error.toString(), e);
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
|
||||
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
} catch (Throwable e) {
|
||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, connection);
|
||||
Log.e(LOG_TAG, error.toString(), e);
|
||||
context.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, error);
|
||||
} finally {
|
||||
synchronized (activeRequests) {
|
||||
activeRequests.remove(objectId);
|
||||
@@ -741,9 +749,16 @@ public class FileTransfer extends CordovaPlugin {
|
||||
https.setHostnameVerifier(oldHostnameVerifier);
|
||||
https.setSSLSocketFactory(oldSocketFactory);
|
||||
}
|
||||
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
result = new PluginResult(PluginResult.Status.ERROR, createFileTransferError(CONNECTION_ERR, source, target, connection));
|
||||
}
|
||||
// Remove incomplete download.
|
||||
if (result.getStatus() != PluginResult.Status.OK.ordinal() && file != null) {
|
||||
file.delete();
|
||||
}
|
||||
context.sendPluginResult(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -806,6 +821,10 @@ public class FileTransfer extends CordovaPlugin {
|
||||
context = activeRequests.remove(objectId);
|
||||
}
|
||||
if (context != null) {
|
||||
File file = context.targetFile;
|
||||
if (file != null) {
|
||||
file.delete();
|
||||
}
|
||||
// Trigger the abort callback immediately to minimize latency between it and abort() being called.
|
||||
JSONObject error = createFileTransferError(ABORTED_ERR, context.source, context.target, -1);
|
||||
synchronized (context) {
|
||||
|
||||
@@ -43,7 +43,6 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
//import android.app.Activity;
|
||||
@@ -89,7 +88,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* Executes the request and returns whether the action was valid.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param args JSONArray of arguments for the plugin.
|
||||
* @param callbackContext The callback context used when calling back into JavaScript.
|
||||
* @return True if the action was valid, false otherwise.
|
||||
*/
|
||||
@@ -112,11 +111,29 @@ public class FileUtils extends CordovaPlugin {
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, b));
|
||||
}
|
||||
else if (action.equals("readAsText")) {
|
||||
String s = this.readAsText(args.getString(0), args.getString(1));
|
||||
int start = 0;
|
||||
int end = Integer.MAX_VALUE;
|
||||
if (args.length() >= 3) {
|
||||
start = args.getInt(2);
|
||||
}
|
||||
if (args.length() >= 4) {
|
||||
end = args.getInt(3);
|
||||
}
|
||||
|
||||
String s = this.readAsText(args.getString(0), args.getString(1), start, end);
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s));
|
||||
}
|
||||
else if (action.equals("readAsDataURL")) {
|
||||
String s = this.readAsDataURL(args.getString(0));
|
||||
int start = 0;
|
||||
int end = Integer.MAX_VALUE;
|
||||
if (args.length() >= 2) {
|
||||
start = args.getInt(1);
|
||||
}
|
||||
if (args.length() >= 3) {
|
||||
end = args.getInt(2);
|
||||
}
|
||||
|
||||
String s = this.readAsDataURL(args.getString(0), start, end);
|
||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, s));
|
||||
}
|
||||
else if (action.equals("write")) {
|
||||
@@ -220,10 +237,16 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param filePath the path to check
|
||||
*/
|
||||
private void notifyDelete(String filePath) {
|
||||
String newFilePath = stripFileProtocol(filePath);
|
||||
this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
MediaStore.Images.Media.DATA + " = ?",
|
||||
new String[] { newFilePath });
|
||||
String newFilePath = getRealPathFromURI(Uri.parse(filePath), cordova);
|
||||
try {
|
||||
this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
MediaStore.Images.Media.DATA + " = ?",
|
||||
new String[] { newFilePath });
|
||||
} catch (UnsupportedOperationException t) {
|
||||
// Was seeing this on the File mobile-spec tests on 4.0.3 x86 emulator.
|
||||
// The ContentResolver applies only when the file was registered in the
|
||||
// first case, which is generally only the case with images.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,18 +341,18 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws InvalidModificationException
|
||||
* @throws EncodingException
|
||||
* @throws JSONException
|
||||
* @throws FileExistsException
|
||||
* @throws FileExistsException
|
||||
*/
|
||||
private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
|
||||
fileName = stripFileProtocol(fileName);
|
||||
newParent = stripFileProtocol(newParent);
|
||||
String newFileName = getRealPathFromURI(Uri.parse(fileName), cordova);
|
||||
newParent = getRealPathFromURI(Uri.parse(newParent), cordova);
|
||||
|
||||
// Check for invalid file name
|
||||
if (newName != null && newName.contains(":")) {
|
||||
throw new EncodingException("Bad file name");
|
||||
}
|
||||
|
||||
File source = new File(fileName);
|
||||
File source = new File(newFileName);
|
||||
|
||||
if (!source.exists()) {
|
||||
// The file/directory we are copying doesn't exist so we should fail.
|
||||
@@ -361,7 +384,14 @@ public class FileUtils extends CordovaPlugin {
|
||||
}
|
||||
} else {
|
||||
if (move) {
|
||||
return moveFile(source, destination);
|
||||
JSONObject newFileEntry = moveFile(source, destination);
|
||||
|
||||
// If we've moved a file given its content URI, we need to clean up.
|
||||
if (fileName.startsWith("content://")) {
|
||||
notifyDelete(fileName);
|
||||
}
|
||||
|
||||
return newFileEntry;
|
||||
} else {
|
||||
return copyFile(source, destination);
|
||||
}
|
||||
@@ -459,7 +489,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
if (!destinationDir.exists()) {
|
||||
if (!destinationDir.mkdir()) {
|
||||
// If we can't create the directory then fail
|
||||
throw new NoModificationAllowedException("Couldn't create the destination direcotry");
|
||||
throw new NoModificationAllowedException("Couldn't create the destination directory");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,8 +567,8 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws JSONException
|
||||
* @throws IOException
|
||||
* @throws InvalidModificationException
|
||||
* @throws NoModificationAllowedException
|
||||
* @throws FileExistsException
|
||||
* @throws NoModificationAllowedException
|
||||
* @throws FileExistsException
|
||||
*/
|
||||
private JSONObject moveDirectory(File srcDir, File destinationDir) throws IOException, JSONException, InvalidModificationException, NoModificationAllowedException, FileExistsException {
|
||||
// Renaming a file to an existing directory should fail
|
||||
@@ -718,7 +748,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
if (fileName.startsWith("/")) {
|
||||
fp = new File(fileName);
|
||||
} else {
|
||||
dirPath = stripFileProtocol(dirPath);
|
||||
dirPath = getRealPathFromURI(Uri.parse(dirPath), cordova);
|
||||
fp = new File(dirPath + File.separator + fileName);
|
||||
}
|
||||
return fp;
|
||||
@@ -733,7 +763,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @throws JSONException
|
||||
*/
|
||||
private JSONObject getParent(String filePath) throws JSONException {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
filePath = getRealPathFromURI(Uri.parse(filePath), cordova);
|
||||
|
||||
if (atRootDirectory(filePath)) {
|
||||
return getEntry(filePath);
|
||||
@@ -749,7 +779,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return true if we are at the root, false otherwise.
|
||||
*/
|
||||
private boolean atRootDirectory(String filePath) {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
filePath = getRealPathFromURI(Uri.parse(filePath), cordova);
|
||||
|
||||
if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
|
||||
filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
|
||||
@@ -779,7 +809,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return
|
||||
*/
|
||||
private File createFileObject(String filePath) {
|
||||
filePath = stripFileProtocol(filePath);
|
||||
filePath = getRealPathFromURI(Uri.parse(filePath), cordova);
|
||||
|
||||
File file = new File(filePath);
|
||||
return file;
|
||||
@@ -821,7 +851,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
metadata.put("size", file.length());
|
||||
metadata.put("type", getMimeType(filePath));
|
||||
metadata.put("name", file.getName());
|
||||
metadata.put("fullPath", file.getAbsolutePath());
|
||||
metadata.put("fullPath", filePath);
|
||||
metadata.put("lastModifiedDate", file.lastModified());
|
||||
|
||||
return metadata;
|
||||
@@ -932,17 +962,27 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param filename The name of the file.
|
||||
* @param encoding The encoding to return contents as. Typical value is UTF-8.
|
||||
* (see http://www.iana.org/assignments/character-sets)
|
||||
* @param start Start position in the file.
|
||||
* @param end End position to stop at (exclusive).
|
||||
* @return Contents of file.
|
||||
* @throws FileNotFoundException, IOException
|
||||
*/
|
||||
public String readAsText(String filename, String encoding) throws FileNotFoundException, IOException {
|
||||
public String readAsText(String filename, String encoding, int start, int end) throws FileNotFoundException, IOException {
|
||||
int diff = end - start;
|
||||
byte[] bytes = new byte[1000];
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
int numRead = 0;
|
||||
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
|
||||
|
||||
if (start > 0) {
|
||||
bis.skip(start);
|
||||
}
|
||||
|
||||
while ( diff > 0 && (numRead = bis.read(bytes, 0, Math.min(1000, diff))) >= 0) {
|
||||
diff -= numRead;
|
||||
bos.write(bytes, 0, numRead);
|
||||
}
|
||||
|
||||
return new String(bos.toByteArray(), encoding);
|
||||
}
|
||||
|
||||
@@ -953,12 +993,19 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return Contents of file = data:<media type>;base64,<data>
|
||||
* @throws FileNotFoundException, IOException
|
||||
*/
|
||||
public String readAsDataURL(String filename) throws FileNotFoundException, IOException {
|
||||
public String readAsDataURL(String filename, int start, int end) throws FileNotFoundException, IOException {
|
||||
int diff = end - start;
|
||||
byte[] bytes = new byte[1000];
|
||||
BufferedInputStream bis = new BufferedInputStream(getPathFromUri(filename), 1024);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
int numRead = 0;
|
||||
while ((numRead = bis.read(bytes, 0, 1000)) >= 0) {
|
||||
|
||||
if (start > 0) {
|
||||
bis.skip(start);
|
||||
}
|
||||
|
||||
while (diff > 0 && (numRead = bis.read(bytes, 0, Math.min(1000, diff))) >= 0) {
|
||||
diff -= numRead;
|
||||
bos.write(bytes, 0, numRead);
|
||||
}
|
||||
|
||||
@@ -984,15 +1031,21 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @return a mime type
|
||||
*/
|
||||
public static String getMimeType(String filename) {
|
||||
// Stupid bug in getFileExtensionFromUrl when the file name has a space
|
||||
// So we need to replace the space with a url encoded %20
|
||||
String url = filename.replace(" ", "%20");
|
||||
MimeTypeMap map = MimeTypeMap.getSingleton();
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
||||
if (extension.toLowerCase().equals("3ga")) {
|
||||
return "audio/3gpp";
|
||||
if (filename != null) {
|
||||
// Stupid bug in getFileExtensionFromUrl when the file name has a space
|
||||
// So we need to replace the space with a url encoded %20
|
||||
|
||||
// CB-2185: Stupid bug not putting JPG extension in the mime-type map
|
||||
String url = filename.replace(" ", "%20").toLowerCase();
|
||||
MimeTypeMap map = MimeTypeMap.getSingleton();
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
|
||||
if (extension.toLowerCase().equals("3ga")) {
|
||||
return "audio/3gpp";
|
||||
} else {
|
||||
return map.getMimeTypeFromExtension(extension);
|
||||
}
|
||||
} else {
|
||||
return map.getMimeTypeFromExtension(extension);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,10 +1056,15 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param data The contents of the file.
|
||||
* @param offset The position to begin writing the file.
|
||||
* @throws FileNotFoundException, IOException
|
||||
* @throws NoModificationAllowedException
|
||||
*/
|
||||
/**/
|
||||
public long write(String filename, String data, int offset) throws FileNotFoundException, IOException {
|
||||
filename = stripFileProtocol(filename);
|
||||
public long write(String filename, String data, int offset) throws FileNotFoundException, IOException, NoModificationAllowedException {
|
||||
if (filename.startsWith("content://")) {
|
||||
throw new NoModificationAllowedException("Couldn't write to file given its content URI");
|
||||
}
|
||||
|
||||
filename = getRealPathFromURI(Uri.parse(filename), cordova);
|
||||
|
||||
boolean append = false;
|
||||
if (offset > 0) {
|
||||
@@ -1032,9 +1090,14 @@ public class FileUtils extends CordovaPlugin {
|
||||
* @param filename
|
||||
* @param size
|
||||
* @throws FileNotFoundException, IOException
|
||||
* @throws NoModificationAllowedException
|
||||
*/
|
||||
private long truncateFile(String filename, long size) throws FileNotFoundException, IOException {
|
||||
filename = stripFileProtocol(filename);
|
||||
private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
|
||||
if (filename.startsWith("content://")) {
|
||||
throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
|
||||
}
|
||||
|
||||
filename = getRealPathFromURI(Uri.parse(filename), cordova);
|
||||
|
||||
RandomAccessFile raf = new RandomAccessFile(filename, "rw");
|
||||
try {
|
||||
@@ -1043,7 +1106,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
channel.truncate(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
return raf.length();
|
||||
} finally {
|
||||
raf.close();
|
||||
@@ -1063,7 +1126,7 @@ public class FileUtils extends CordovaPlugin {
|
||||
return cordova.getActivity().getContentResolver().openInputStream(uri);
|
||||
}
|
||||
else {
|
||||
path = stripFileProtocol(path);
|
||||
path = getRealPathFromURI(Uri.parse(path), cordova);
|
||||
return new FileInputStream(path);
|
||||
}
|
||||
}
|
||||
@@ -1078,8 +1141,10 @@ public class FileUtils extends CordovaPlugin {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface cordova) {
|
||||
final String scheme = contentUri.getScheme();
|
||||
|
||||
if (scheme.compareTo("content") == 0) {
|
||||
|
||||
if (scheme == null) {
|
||||
return contentUri.toString();
|
||||
} else if (scheme.compareTo("content") == 0) {
|
||||
String[] proj = { _DATA };
|
||||
Cursor cursor = cordova.getActivity().managedQuery(contentUri, proj, null, null, null);
|
||||
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -48,6 +49,7 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebStorage;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
@@ -67,13 +69,14 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private static final String EXIT_EVENT = "exit";
|
||||
private static final String LOAD_START_EVENT = "loadstart";
|
||||
private static final String LOAD_STOP_EVENT = "loadstop";
|
||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||
|
||||
private Dialog dialog;
|
||||
private WebView inAppWebView;
|
||||
private EditText edittext;
|
||||
private boolean showLocationBar = true;
|
||||
private CallbackContext callbackContext;
|
||||
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
@@ -105,9 +108,20 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
Log.d(LOG_TAG, "in self");
|
||||
// load in webview
|
||||
if (url.startsWith("file://") || url.startsWith("javascript:")
|
||||
|| this.webView.isUrlWhiteListed(url)) {
|
||||
|| Config.isUrlWhiteListed(url)) {
|
||||
this.webView.loadUrl(url);
|
||||
}
|
||||
//Load the dialer
|
||||
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(LOG_TAG, "Error dialing " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
// load in InAppBrowser
|
||||
else {
|
||||
result = this.showWebPage(url, features);
|
||||
@@ -401,7 +415,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
// WebView
|
||||
inAppWebView = new WebView(cordova.getActivity());
|
||||
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||
inAppWebView.setWebChromeClient(new WebChromeClient());
|
||||
inAppWebView.setWebChromeClient(new InAppChromeClient());
|
||||
WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
|
||||
inAppWebView.setWebViewClient(client);
|
||||
WebSettings settings = inAppWebView.getSettings();
|
||||
@@ -414,6 +428,9 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
*/
|
||||
// @TODO: replace with settings.setPluginState(android.webkit.WebSettings.PluginState.ON)
|
||||
settings.setPluginsEnabled(true);
|
||||
settings.setDatabaseEnabled(true);
|
||||
String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
|
||||
settings.setDatabasePath(databasePath);
|
||||
settings.setDomStorageEnabled(true);
|
||||
inAppWebView.loadUrl(url);
|
||||
inAppWebView.setId(6);
|
||||
@@ -465,6 +482,40 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
this.callbackContext.sendPluginResult(result);
|
||||
}
|
||||
|
||||
public class InAppChromeClient extends WebChromeClient {
|
||||
|
||||
/**
|
||||
* Handle database quota exceeded notification.
|
||||
*
|
||||
* @param url
|
||||
* @param databaseIdentifier
|
||||
* @param currentQuota
|
||||
* @param estimatedSize
|
||||
* @param totalUsedQuota
|
||||
* @param quotaUpdater
|
||||
*/
|
||||
@Override
|
||||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
||||
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
||||
{
|
||||
LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
|
||||
|
||||
if (estimatedSize < MAX_QUOTA)
|
||||
{
|
||||
//increase for 1Mb
|
||||
long newQuota = estimatedSize;
|
||||
LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
|
||||
quotaUpdater.updateQuota(newQuota);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the quota to whatever it is and force an error
|
||||
// TODO: get docs on how to handle this properly
|
||||
quotaUpdater.updateQuota(currentQuota);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The webview client receives notifications about appView
|
||||
*/
|
||||
@@ -528,4 +579,4 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,8 @@ public class NativeToJsMessageQueue {
|
||||
}
|
||||
|
||||
private void packMessage(JsMessage message, StringBuilder sb) {
|
||||
sb.append(message.calculateEncodedLength())
|
||||
int len = message.calculateEncodedLength();
|
||||
sb.append(len)
|
||||
.append(' ');
|
||||
message.encodeAsMessage(sb);
|
||||
}
|
||||
@@ -166,7 +167,8 @@ public class NativeToJsMessageQueue {
|
||||
// Attach a char to indicate that there are more messages pending.
|
||||
sb.append('*');
|
||||
}
|
||||
return sb.toString();
|
||||
String ret = sb.toString();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +211,8 @@ public class NativeToJsMessageQueue {
|
||||
for (int i = willSendAllMessages ? 1 : 0; i < numMessagesToSend; ++i) {
|
||||
sb.append('}');
|
||||
}
|
||||
return sb.toString();
|
||||
String ret = sb.toString();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,6 +409,9 @@ public class NativeToJsMessageQueue {
|
||||
case PluginResult.MESSAGE_TYPE_STRING: // s
|
||||
ret += 1 + pluginResult.getStrMessage().length();
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
|
||||
ret += 1 + pluginResult.getMessage().length();
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_JSON:
|
||||
default:
|
||||
ret += pluginResult.getMessage().length();
|
||||
@@ -445,6 +451,10 @@ public class NativeToJsMessageQueue {
|
||||
sb.append('s');
|
||||
sb.append(pluginResult.getStrMessage());
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_ARRAYBUFFER:
|
||||
sb.append('A');
|
||||
sb.append(pluginResult.getMessage());
|
||||
break;
|
||||
case PluginResult.MESSAGE_TYPE_JSON:
|
||||
default:
|
||||
sb.append(pluginResult.getMessage()); // [ or {
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.io.File;
|
||||
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -71,6 +71,15 @@ public class CallbackContext {
|
||||
sendPluginResult(new PluginResult(PluginResult.Status.OK, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for success callbacks that just returns the Status.OK by default
|
||||
*
|
||||
* @param message The message to add to the success result.
|
||||
*/
|
||||
public void success(byte[] message) {
|
||||
sendPluginResult(new PluginResult(PluginResult.Status.OK, message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for success callbacks that just returns the Status.OK by default
|
||||
*
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -54,11 +53,6 @@ public interface CordovaInterface {
|
||||
*/
|
||||
public abstract Activity getActivity();
|
||||
|
||||
@Deprecated
|
||||
public abstract Context getContext();
|
||||
|
||||
@Deprecated
|
||||
public abstract void cancelLoadUrl();
|
||||
|
||||
/**
|
||||
* Called when a message is sent to plugin.
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
*/
|
||||
package org.apache.cordova.api;
|
||||
|
||||
import org.apache.cordova.CordovaArgs;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import android.content.Intent;
|
||||
|
||||
|
||||
/**
|
||||
* Plugins must extend this class and override one of the execute methods.
|
||||
*/
|
||||
@@ -76,9 +76,28 @@ public class CordovaPlugin {
|
||||
* @return Whether the action was valid.
|
||||
*/
|
||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||
CordovaArgs cordovaArgs = new CordovaArgs(args);
|
||||
return execute(action, cordovaArgs, callbackContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
* This method is called from the WebView thread. To do a non-trivial amount of work, use:
|
||||
* cordova.getThreadPool().execute(runnable);
|
||||
*
|
||||
* To run on the UI thread, use:
|
||||
* cordova.getActivity().runOnUiThread(runnable);
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args The exec() arguments, wrapped with some Cordova helpers.
|
||||
* @param callbackContext The callback context used when calling back into JavaScript.
|
||||
* @return Whether the action was valid.
|
||||
*/
|
||||
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the system is about to start resuming a previous activity.
|
||||
*
|
||||
|
||||
@@ -43,7 +43,6 @@ public class LegacyContext implements CordovaInterface {
|
||||
@Deprecated
|
||||
public void cancelLoadUrl() {
|
||||
Log.i(LOG_TAG, "Replace ctx.cancelLoadUrl() with cordova.cancelLoadUrl()");
|
||||
this.cordova.cancelLoadUrl();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -55,7 +54,7 @@ public class LegacyContext implements CordovaInterface {
|
||||
@Deprecated
|
||||
public Context getContext() {
|
||||
Log.i(LOG_TAG, "Replace ctx.getContext() with cordova.getContext()");
|
||||
return this.cordova.getContext();
|
||||
return this.cordova.getActivity();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
||||
@@ -22,17 +22,13 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.XmlResourceParser;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* PluginManager is exposed to JavaScript in the Cordova WebView.
|
||||
@@ -248,7 +244,7 @@ public class PluginManager {
|
||||
* @param service The name of the service.
|
||||
* @return CordovaPlugin or null
|
||||
*/
|
||||
private CordovaPlugin getPlugin(String service) {
|
||||
public CordovaPlugin getPlugin(String service) {
|
||||
PluginEntry entry = this.entries.get(service);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
|
||||
@@ -21,6 +21,8 @@ package org.apache.cordova.api;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
public class PluginResult {
|
||||
private final int status;
|
||||
private final int messageType;
|
||||
@@ -68,6 +70,12 @@ public class PluginResult {
|
||||
this.encodedMessage = Boolean.toString(b);
|
||||
}
|
||||
|
||||
public PluginResult(Status status, byte[] data) {
|
||||
this.status = status.ordinal();
|
||||
this.messageType = MESSAGE_TYPE_ARRAYBUFFER;
|
||||
this.encodedMessage = Base64.encodeToString(data, Base64.NO_WRAP);
|
||||
}
|
||||
|
||||
public void setKeepCallback(boolean b) {
|
||||
this.keepCallback = b;
|
||||
}
|
||||
@@ -79,7 +87,7 @@ public class PluginResult {
|
||||
public int getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
|
||||
public String getMessage() {
|
||||
if (encodedMessage == null) {
|
||||
encodedMessage = JSONObject.quote(strMessage);
|
||||
@@ -134,7 +142,8 @@ public class PluginResult {
|
||||
public static final int MESSAGE_TYPE_NUMBER = 3;
|
||||
public static final int MESSAGE_TYPE_BOOLEAN = 4;
|
||||
public static final int MESSAGE_TYPE_NULL = 5;
|
||||
|
||||
public static final int MESSAGE_TYPE_ARRAYBUFFER = 6;
|
||||
|
||||
public static String[] StatusMessages = new String[] {
|
||||
"No result",
|
||||
"OK",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
under the License.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:windowSoftInputMode="adjustPan"
|
||||
package="org.apache.cordova.test" android:versionName="1.1" android:versionCode="5">
|
||||
package="org.apache.cordova.test" android:versionName="1.0" android:versionCode="1">
|
||||
<supports-screens
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,5 +8,5 @@
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-16
|
||||
target=android-17
|
||||
android.library.reference.1=../framework
|
||||
|
||||
@@ -45,12 +45,13 @@
|
||||
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
|
||||
<plugin name="Notification" value="org.apache.cordova.Notification"/>
|
||||
<plugin name="Storage" value="org.apache.cordova.Storage"/>
|
||||
<plugin name="Temperature" value="org.apache.cordova.TempListener"/>
|
||||
<plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
|
||||
<plugin name="Capture" value="org.apache.cordova.Capture"/>
|
||||
<plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
|
||||
<plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
|
||||
<plugin name="Echo" value="org.apache.cordova.Echo" />
|
||||
<plugin name="Globalization" value="org.apache.cordova.Globalization"/>
|
||||
<plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser"/>
|
||||
</plugins>
|
||||
</cordova>
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<cordova>
|
||||
<!--
|
||||
access elements control the Android whitelist.
|
||||
Domains are assumed blocked unless set otherwise
|
||||
-->
|
||||
|
||||
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
|
||||
|
||||
<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
|
||||
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
|
||||
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->
|
||||
|
||||
<log level="DEBUG"/>
|
||||
<preference name="useBrowserHistory" value="true" />
|
||||
</cordova>
|
||||
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<plugins>
|
||||
<plugin name="App" value="org.apache.cordova.App"/>
|
||||
<plugin name="Activity" value="org.apache.cordova.test.ActivityPlugin"/>
|
||||
<plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/>
|
||||
<plugin name="Device" value="org.apache.cordova.Device"/>
|
||||
<plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/>
|
||||
<plugin name="Compass" value="org.apache.cordova.CompassListener"/>
|
||||
<plugin name="Media" value="org.apache.cordova.AudioHandler"/>
|
||||
<plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
|
||||
<plugin name="Contacts" value="org.apache.cordova.ContactManager"/>
|
||||
<plugin name="File" value="org.apache.cordova.FileUtils"/>
|
||||
<plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
|
||||
<plugin name="Notification" value="org.apache.cordova.Notification"/>
|
||||
<plugin name="Storage" value="org.apache.cordova.Storage"/>
|
||||
<plugin name="Temperature" value="org.apache.cordova.TempListener"/>
|
||||
<plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/>
|
||||
<plugin name="Capture" value="org.apache.cordova.Capture"/>
|
||||
<plugin name="Battery" value="org.apache.cordova.BatteryListener"/>
|
||||
<plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
|
||||
</plugins>
|
||||
@@ -18,19 +18,21 @@
|
||||
*/
|
||||
package org.apache.cordova.test;
|
||||
|
||||
import org.apache.cordova.CordovaArgs;
|
||||
import org.apache.cordova.api.LOG;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import org.apache.cordova.api.Plugin;
|
||||
import org.apache.cordova.api.CallbackContext;
|
||||
import org.apache.cordova.api.CordovaPlugin;
|
||||
import org.apache.cordova.api.PluginResult;
|
||||
|
||||
/**
|
||||
* This class provides a service.
|
||||
*/
|
||||
public class ActivityPlugin extends Plugin {
|
||||
public class ActivityPlugin extends CordovaPlugin {
|
||||
|
||||
static String TAG = "ActivityPlugin";
|
||||
|
||||
@@ -48,19 +50,21 @@ public class ActivityPlugin extends Plugin {
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
@Override
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.OK;
|
||||
String result = "";
|
||||
|
||||
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) {
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, "");
|
||||
try {
|
||||
if (action.equals("start")) {
|
||||
this.startActivity(args.getString(0));
|
||||
callbackContext.sendPluginResult(result);
|
||||
callbackContext.success();
|
||||
return true;
|
||||
}
|
||||
return new PluginResult(status, result);
|
||||
} catch (JSONException e) {
|
||||
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
||||
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, "JSON Exception");
|
||||
callbackContext.sendPluginResult(result);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@@ -69,9 +73,9 @@ public class ActivityPlugin extends Plugin {
|
||||
|
||||
public void startActivity(String className) {
|
||||
try {
|
||||
Intent intent = new Intent().setClass(this.ctx.getActivity(), Class.forName(className));
|
||||
Intent intent = new Intent().setClass(this.cordova.getActivity(), Class.forName(className));
|
||||
LOG.d(TAG, "Starting activity %s", className);
|
||||
this.ctx.getActivity().startActivity(intent);
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
LOG.e(TAG, "Error starting activity %s", className);
|
||||
|
||||
@@ -21,14 +21,72 @@ package org.apache.cordova.test;
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.test.util.Purity;
|
||||
import org.apache.cordova.test.actions.iframe;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.TouchUtils;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class IFrameTest extends ActivityInstrumentationTestCase2<iframe> {
|
||||
public class IFrameTest extends ActivityInstrumentationTestCase2 {
|
||||
|
||||
public IFrameTest() {
|
||||
super("org.apache.cordova.test",iframe.class);
|
||||
}
|
||||
|
||||
private Instrumentation mInstr;
|
||||
private Activity testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private CordovaWebView testView;
|
||||
private TouchUtils touch;
|
||||
private Purity touchTool;
|
||||
|
||||
public IFrameTest() {
|
||||
super("org.apache.cordova.test",iframe.class);
|
||||
}
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mInstr = this.getInstrumentation();
|
||||
testActivity = this.getActivity();
|
||||
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||
testView = (CordovaWebView) innerContainer.getChildAt(0);
|
||||
touch = new TouchUtils();
|
||||
touchTool = new Purity(testActivity, getInstrumentation());
|
||||
}
|
||||
|
||||
|
||||
public void testIframeDest()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
sleep(3000);
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
sleep(1000);
|
||||
String url = testView.getUrl();
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
|
||||
public void testIframeHistory()
|
||||
{
|
||||
testView.sendJavascript("loadUrl('http://maps.google.com/maps?output=embed');");
|
||||
sleep(3000);
|
||||
testView.sendJavascript("loadUrl('index2.html')");
|
||||
sleep(1000);
|
||||
String url = testView.getUrl();
|
||||
testView.backHistory();
|
||||
sleep(1000);
|
||||
assertTrue(url.endsWith("index.html"));
|
||||
}
|
||||
|
||||
private void sleep(int timeout) {
|
||||
try {
|
||||
Thread.sleep(timeout);
|
||||
} catch (InterruptedException e) {
|
||||
fail("Unexpected Timeout");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,55 @@ package org.apache.cordova.test;
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.test.util.Purity;
|
||||
import org.apache.cordova.test.actions.jqmtabbackbutton;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class JQMTabTest extends ActivityInstrumentationTestCase2<jqmtabbackbutton> {
|
||||
|
||||
public JQMTabTest(Class<jqmtabbackbutton> activityClass) {
|
||||
super(activityClass);
|
||||
// TODO Auto-generated constructor stub
|
||||
private Instrumentation mInstr;
|
||||
private jqmtabbackbutton testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private CordovaWebView testView;
|
||||
private Purity touchTool;
|
||||
|
||||
public JQMTabTest()
|
||||
{
|
||||
super("org.apache.cordova.test.activity", jqmtabbackbutton.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mInstr = this.getInstrumentation();
|
||||
testActivity = this.getActivity();
|
||||
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||
testView = (CordovaWebView) innerContainer.getChildAt(0);
|
||||
touchTool = new Purity(testActivity, getInstrumentation());
|
||||
}
|
||||
|
||||
|
||||
public void testTouch()
|
||||
{
|
||||
sleep(5000);
|
||||
int viewportHeight = touchTool.getViewportHeight() - 40;
|
||||
int viewportWidth = touchTool.getViewportWidth();
|
||||
touchTool.touch(50, viewportHeight);
|
||||
sleep(10000);
|
||||
}
|
||||
|
||||
private void sleep(int timeout) {
|
||||
try {
|
||||
Thread.sleep(timeout);
|
||||
} catch (InterruptedException e) {
|
||||
fail("Unexpected Timeout");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ public class basicauth extends DroidGap {
|
||||
super.setAuthenticationToken(token, "browserspy.dk:80", "BrowserSpy.dk - HTTP Password Test");
|
||||
|
||||
// Add web site to whitelist
|
||||
super.appView.addWhiteListEntry("http://browserspy.dk*", true);
|
||||
Config.init();
|
||||
Config.addWhiteListEntry("http://browserspy.dk*", true);
|
||||
|
||||
// Load test
|
||||
super.loadUrl("file:///android_asset/www/basicauth/index.html");
|
||||
|
||||
171
test/src/org/apache/cordova/test/util/Purity.java
Normal file
171
test/src/org/apache/cordova/test/util/Purity.java
Normal file
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Purity is a small set of Android utility methods that allows us to simulate touch events on
|
||||
* Android applications. This is important for simulating some of the most annoying tests.
|
||||
*/
|
||||
|
||||
package org.apache.cordova.test.util;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Picture;
|
||||
import android.os.SystemClock;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.MotionEvent;
|
||||
import android.webkit.WebView;
|
||||
|
||||
|
||||
public class Purity {
|
||||
|
||||
Instrumentation inst;
|
||||
int width, height;
|
||||
float density;
|
||||
Bitmap state;
|
||||
boolean fingerDown = false;
|
||||
|
||||
public Purity(Context ctx, Instrumentation i)
|
||||
{
|
||||
inst = i;
|
||||
DisplayMetrics display = ctx.getResources().getDisplayMetrics();
|
||||
density = display.density;
|
||||
width = display.widthPixels;
|
||||
height = display.heightPixels;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* WebKit doesn't give you real pixels anymore, this is done for subpixel fonts to appear on
|
||||
* iOS and Android. However, Android automation requires real pixels
|
||||
*/
|
||||
private int getRealCoord(int coord)
|
||||
{
|
||||
return (int) (coord * density);
|
||||
}
|
||||
|
||||
public int getViewportWidth()
|
||||
{
|
||||
return (int) (width/density);
|
||||
}
|
||||
|
||||
public int getViewportHeight()
|
||||
{
|
||||
return (int) (height/density);
|
||||
}
|
||||
|
||||
public void touch(int x, int y)
|
||||
{
|
||||
int realX = getRealCoord(x);
|
||||
int realY = getRealCoord(y);
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
// event time MUST be retrieved only by this way!
|
||||
long eventTime = SystemClock.uptimeMillis();
|
||||
if(!fingerDown)
|
||||
{
|
||||
MotionEvent downEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
|
||||
inst.sendPointerSync(downEvent);
|
||||
}
|
||||
MotionEvent upEvent = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, realX, realY, 0);
|
||||
inst.sendPointerSync(upEvent);
|
||||
}
|
||||
|
||||
public void touchStart(int x, int y)
|
||||
{
|
||||
int realX = getRealCoord(x);
|
||||
int realY = getRealCoord(y);
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
// event time MUST be retrieved only by this way!
|
||||
long eventTime = SystemClock.uptimeMillis();
|
||||
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
|
||||
inst.sendPointerSync(event);
|
||||
fingerDown = true;
|
||||
}
|
||||
|
||||
//Move from the touch start
|
||||
public void touchMove(int x, int y)
|
||||
{
|
||||
if(!fingerDown)
|
||||
touchStart(x,y);
|
||||
else
|
||||
{
|
||||
int realX = getRealCoord(x);
|
||||
int realY = getRealCoord(y);
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
// event time MUST be retrieved only by this way!
|
||||
long eventTime = SystemClock.uptimeMillis();
|
||||
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, realX, realY, 0);
|
||||
inst.sendPointerSync(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void touchEnd(int x, int y)
|
||||
{
|
||||
if(!fingerDown)
|
||||
{
|
||||
touch(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
int realX = getRealCoord(x);
|
||||
int realY = getRealCoord(y);
|
||||
long downTime = SystemClock.uptimeMillis();
|
||||
// event time MUST be retrieved only by this way!
|
||||
long eventTime = SystemClock.uptimeMillis();
|
||||
MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
|
||||
inst.sendPointerSync(event);
|
||||
fingerDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setBitmap(WebView view)
|
||||
{
|
||||
Picture p = view.capturePicture();
|
||||
state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
}
|
||||
|
||||
public boolean checkRenderView(WebView view)
|
||||
{
|
||||
if(state == null)
|
||||
{
|
||||
setBitmap(view);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Picture p = view.capturePicture();
|
||||
Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
boolean result = newState.equals(state);
|
||||
newState.recycle();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public void clearBitmap()
|
||||
{
|
||||
if(state != null)
|
||||
state.recycle();
|
||||
}
|
||||
|
||||
protected void finalize()
|
||||
{
|
||||
clearBitmap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user