mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-01 02:12:58 +08:00
Rolling back half-baked change that broke the code in the branch, we need to rethink the Callback Server
This commit is contained in:
parent
628f88cf79
commit
e77f9bb8fc
@ -44,7 +44,7 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
|
|
||||||
private String TAG = "CordovaLog";
|
private String TAG = "CordovaLog";
|
||||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||||
private Context ctx;
|
private DroidGap ctx;
|
||||||
private CordovaWebView appView;
|
private CordovaWebView appView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,8 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public CordovaChromeClient(Context ctx) {
|
public CordovaChromeClient(Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = (DroidGap) ctx;
|
||||||
|
appView = this.ctx.appView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CordovaChromeClient(Context ctx, CordovaWebView app)
|
public CordovaChromeClient(Context ctx, CordovaWebView app)
|
||||||
@ -172,15 +173,10 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
||||||
|
|
||||||
if(appView == null)
|
|
||||||
{
|
|
||||||
appView = (CordovaWebView) view;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Security check to make sure any requests are coming from the page initially
|
// Security check to make sure any requests are coming from the page initially
|
||||||
// loaded in webview and not another loaded in an iframe.
|
// loaded in webview and not another loaded in an iframe.
|
||||||
boolean reqOk = false;
|
boolean reqOk = false;
|
||||||
if (url.startsWith("file://") || appView.isUrlWhiteListed(url)) {
|
if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
||||||
reqOk = true;
|
reqOk = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +199,7 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
|
|
||||||
// Polling for JavaScript messages
|
// Polling for JavaScript messages
|
||||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
|
else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
|
||||||
|
String r = ctx.callbackServer.getJavascript();
|
||||||
|
|
||||||
String r = appView.callbackServer.getJavascript();
|
|
||||||
result.confirm(r);
|
result.confirm(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,16 +207,16 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
|
else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
|
||||||
String r = "";
|
String r = "";
|
||||||
if (message.equals("usePolling")) {
|
if (message.equals("usePolling")) {
|
||||||
r = ""+ appView.callbackServer.usePolling();
|
r = ""+ ctx.callbackServer.usePolling();
|
||||||
}
|
}
|
||||||
else if (message.equals("restartServer")) {
|
else if (message.equals("restartServer")) {
|
||||||
appView.callbackServer.restartServer();
|
ctx.callbackServer.restartServer();
|
||||||
}
|
}
|
||||||
else if (message.equals("getPort")) {
|
else if (message.equals("getPort")) {
|
||||||
r = Integer.toString(appView.callbackServer.getPort());
|
r = Integer.toString(ctx.callbackServer.getPort());
|
||||||
}
|
}
|
||||||
else if (message.equals("getToken")) {
|
else if (message.equals("getToken")) {
|
||||||
r = appView.callbackServer.getToken();
|
r = ctx.callbackServer.getToken();
|
||||||
}
|
}
|
||||||
result.confirm(r);
|
result.confirm(r);
|
||||||
}
|
}
|
||||||
@ -230,11 +224,8 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
// Cordova JS has initialized, so show webview
|
// Cordova JS has initialized, so show webview
|
||||||
// (This solves white flash seen when rendering HTML)
|
// (This solves white flash seen when rendering HTML)
|
||||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
|
else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
|
||||||
if (ctx.getClass().equals(DroidGap.class) && ((DroidGap) ctx).splashscreen != 0) {
|
ctx.appView.setVisibility(View.VISIBLE);
|
||||||
((DroidGap) ctx).root.setBackgroundResource(0);
|
ctx.spinnerStop();
|
||||||
((DroidGap) ctx).spinnerStop();
|
|
||||||
}
|
|
||||||
appView.setVisibility(View.VISIBLE);
|
|
||||||
result.confirm("OK");
|
result.confirm("OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,9 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.webkit.WebChromeClient;
|
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
import android.webkit.WebViewClient;
|
|
||||||
|
|
||||||
public class CordovaWebView extends WebView {
|
public class CordovaWebView extends WebView {
|
||||||
|
|
||||||
@ -32,8 +30,7 @@ public class CordovaWebView extends WebView {
|
|||||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
|
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
|
||||||
protected PluginManager pluginManager;
|
protected PluginManager pluginManager;
|
||||||
public CallbackServer callbackServer;
|
|
||||||
|
|
||||||
/** Actvities and other important classes **/
|
/** Actvities and other important classes **/
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
private CordovaWebViewClient viewClient;
|
private CordovaWebViewClient viewClient;
|
||||||
@ -42,7 +39,7 @@ public class CordovaWebView extends WebView {
|
|||||||
public CordovaWebView(Context context) {
|
public CordovaWebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mCtx = context;
|
mCtx = context;
|
||||||
//setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CordovaWebView(Context context, AttributeSet attrs) {
|
public CordovaWebView(Context context, AttributeSet attrs) {
|
||||||
@ -64,7 +61,7 @@ public class CordovaWebView extends WebView {
|
|||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setup()
|
private void setup()
|
||||||
{
|
{
|
||||||
this.setInitialScale(0);
|
this.setInitialScale(0);
|
||||||
this.setVerticalScrollBarEnabled(false);
|
this.setVerticalScrollBarEnabled(false);
|
||||||
@ -246,28 +243,4 @@ public class CordovaWebView extends WebView {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWebViewClient(WebViewClient client) {
|
|
||||||
if(client.getClass().equals(CordovaWebView.class)) {
|
|
||||||
viewClient = (CordovaWebViewClient) client;
|
|
||||||
super.setWebViewClient(viewClient);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//This should throw an exception!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setWebChromeClient(WebChromeClient client) {
|
|
||||||
if(client.getClass().equals(CordovaWebView.class)) {
|
|
||||||
chromeClient = (CordovaChromeClient) client;
|
|
||||||
super.setWebChromeClient(chromeClient);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//This should throw an exception!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ package org.apache.cordova;
|
|||||||
|
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
@ -42,8 +41,7 @@ import android.webkit.WebViewClient;
|
|||||||
public class CordovaWebViewClient extends WebViewClient {
|
public class CordovaWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
private static final String TAG = "Cordova";
|
private static final String TAG = "Cordova";
|
||||||
Context ctx;
|
DroidGap ctx;
|
||||||
DroidGap droidGap;
|
|
||||||
CordovaWebView appView;
|
CordovaWebView appView;
|
||||||
private boolean doClearHistory = false;
|
private boolean doClearHistory = false;
|
||||||
|
|
||||||
@ -52,16 +50,14 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
*
|
*
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public CordovaWebViewClient(Context ctx) {
|
public CordovaWebViewClient(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
//appView = ctx.appView;
|
appView = ctx.appView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CordovaWebViewClient(Context ctx, CordovaWebView view)
|
public CordovaWebViewClient(Context ctx, CordovaWebView view)
|
||||||
{
|
{
|
||||||
this.ctx = ctx;
|
this.ctx = (DroidGap) ctx;
|
||||||
if(ctx.getClass().equals(DroidGap.class))
|
|
||||||
this.droidGap = (DroidGap) ctx;
|
|
||||||
appView = view;
|
appView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +146,8 @@ 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.
|
// 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.
|
// Our app continues to run. When BACK is pressed, our app is redisplayed.
|
||||||
//if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
||||||
if (url.startsWith("file://") || appView.isUrlWhiteListed(url)) {
|
this.ctx.loadUrl(url);
|
||||||
appView.loadUrl(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not our application, let default viewer handle
|
// If not our application, let default viewer handle
|
||||||
@ -226,35 +221,28 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear timeout flag
|
// Clear timeout flag
|
||||||
//this.ctx.loadUrlTimeout++;
|
this.ctx.loadUrlTimeout++;
|
||||||
|
|
||||||
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
||||||
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
// 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.
|
// from the JS side when the JS gets to that code.
|
||||||
if (!url.equals("about:blank")) {
|
if (!url.equals("about:blank")) {
|
||||||
appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
ctx.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||||
//appView.postMessage("onNativeReady", null);
|
this.ctx.postMessage("onNativeReady", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
|
// Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
|
||||||
if (appView.getVisibility() == View.INVISIBLE) {
|
if (ctx.appView.getVisibility() == View.INVISIBLE) {
|
||||||
Thread t = new Thread(new Runnable() {
|
Thread t = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
((Activity) ctx).runOnUiThread(new Runnable() {
|
ctx.runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if(droidGap != null)
|
ctx.appView.setVisibility(View.VISIBLE);
|
||||||
{
|
ctx.spinnerStop();
|
||||||
if (droidGap.splashscreen != 0) {
|
|
||||||
droidGap.root.setBackgroundResource(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
appView.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,11 +253,10 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
// Shutdown if blank loaded
|
// Shutdown if blank loaded
|
||||||
if (url.equals("about:blank")) {
|
if (url.equals("about:blank")) {
|
||||||
if (appView.callbackServer != null) {
|
if (this.ctx.callbackServer != null) {
|
||||||
appView.callbackServer.destroy();
|
this.ctx.callbackServer.destroy();
|
||||||
}
|
}
|
||||||
if(droidGap != null)
|
this.ctx.endActivity();
|
||||||
droidGap.endActivity();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,17 +273,14 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||||
LOG.d(TAG, "DroidGap: GapViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
|
LOG.d(TAG, "DroidGap: GapViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
|
||||||
|
|
||||||
if(droidGap != null)
|
// Clear timeout flag
|
||||||
{
|
this.ctx.loadUrlTimeout++;
|
||||||
// Clear timeout flag
|
|
||||||
this.droidGap.loadUrlTimeout++;
|
|
||||||
|
|
||||||
// Stop "app loading" spinner if showing
|
// Stop "app loading" spinner if showing
|
||||||
this.droidGap.spinnerStop();
|
this.ctx.spinnerStop();
|
||||||
|
|
||||||
// Handle error
|
// Handle error
|
||||||
this.droidGap.onReceivedError(errorCode, description, failingUrl);
|
this.ctx.onReceivedError(errorCode, description, failingUrl);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
||||||
@ -326,9 +310,8 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
* If you do a document.location.href the url does not get pushed on the stack
|
* If you do a document.location.href the url does not get pushed on the stack
|
||||||
* so we do a check here to see if the url should be pushed.
|
* so we do a check here to see if the url should be pushed.
|
||||||
*/
|
*/
|
||||||
|
if (!this.ctx.peekAtUrlStack().equals(url)) {
|
||||||
if (this.droidGap != null && !this.droidGap.peekAtUrlStack().equals(url)) {
|
this.ctx.pushUrl(url);
|
||||||
droidGap.pushUrl(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
f Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
distributed with this work for additional information
|
distributed with this work for additional information
|
||||||
regarding copyright ownership. The ASF licenses this file
|
regarding copyright ownership. The ASF licenses this file
|
||||||
@ -155,6 +155,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
|
|
||||||
protected LinearLayout root;
|
protected LinearLayout root;
|
||||||
public boolean bound = false;
|
public boolean bound = false;
|
||||||
|
public CallbackServer callbackServer;
|
||||||
protected boolean cancelLoadUrl = false;
|
protected boolean cancelLoadUrl = false;
|
||||||
protected ProgressDialog spinnerDialog = null;
|
protected ProgressDialog spinnerDialog = null;
|
||||||
|
|
||||||
@ -277,7 +278,6 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
// white list of allowed URLs
|
// white list of allowed URLs
|
||||||
// debug setting
|
// debug setting
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.appView.setup();
|
|
||||||
|
|
||||||
this.appView.setLayoutParams(new LinearLayout.LayoutParams(
|
this.appView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.FILL_PARENT,
|
ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
@ -379,12 +379,12 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
me.appView.clearHistory();
|
me.appView.clearHistory();
|
||||||
|
|
||||||
// Create callback server and plugin manager
|
// Create callback server and plugin manager
|
||||||
if (me.appView.callbackServer == null) {
|
if (me.callbackServer == null) {
|
||||||
me.appView.callbackServer = new CallbackServer();
|
me.callbackServer = new CallbackServer();
|
||||||
me.appView.callbackServer.init(url);
|
me.callbackServer.init(url);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
me.appView.callbackServer.reinit(url);
|
me.callbackServer.reinit(url);
|
||||||
}
|
}
|
||||||
appView.pluginManager.init();
|
appView.pluginManager.init();
|
||||||
|
|
||||||
@ -832,8 +832,8 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
*/
|
*/
|
||||||
public void sendJavascript(String statement) {
|
public void sendJavascript(String statement) {
|
||||||
//We need to check for the null case on the Kindle Fire beacuse it changes the width and height on load
|
//We need to check for the null case on the Kindle Fire beacuse it changes the width and height on load
|
||||||
if(this.appView.callbackServer != null)
|
if(this.callbackServer != null)
|
||||||
this.appView.callbackServer.sendJavascript(statement);
|
this.callbackServer.sendJavascript(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user