mirror of
https://github.com/apache/cordova-android.git
synced 2026-05-11 00:00:05 +08:00
CB-8510 Create a new abstraction for sharing common logic of WebView engines
Having CordovaWebViewImpl separate from CordovaWebViewEngine is helpful because now each webview doesn't have to re-implement non-webview-specific featrues. e.g.: 1. load timeout 2. keyboard events 3. showCustomView 4. lifecycle events Moved AndroidWebView into its own package to ensure that it doesn't use any package-private symbols (since plugins cannot use them).
This commit is contained in:
@@ -23,7 +23,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.apache.cordova.AndroidWebView;
|
||||
import org.apache.cordova.CordovaWebViewEngine;
|
||||
import org.apache.cordova.engine.SystemWebView;
|
||||
|
||||
public class CordovaActivityTest extends BaseCordovaIntegrationTest {
|
||||
private ViewGroup innerContainer;
|
||||
@@ -37,8 +38,9 @@ public class CordovaActivityTest extends BaseCordovaIntegrationTest {
|
||||
}
|
||||
|
||||
public void testBasicLoad() throws Exception {
|
||||
assertTrue(testView instanceof AndroidWebView);
|
||||
assertTrue(testView instanceof SystemWebView);
|
||||
assertTrue(innerContainer instanceof LinearLayout);
|
||||
assertTrue(((CordovaWebViewEngine.EngineView)testView).getCordovaWebView() != null);
|
||||
String onPageFinishedUrl = testActivity.onPageFinishedUrl.take();
|
||||
assertEquals(MainTestActivity.START_URL, onPageFinishedUrl);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.apache.cordova.AndroidWebView;
|
||||
import org.apache.cordova.engine.SystemWebView;
|
||||
|
||||
public class InflateLayoutTest extends ActivityInstrumentationTestCase2<CordovaWebViewTestActivity> {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class InflateLayoutTest extends ActivityInstrumentationTestCase2<CordovaW
|
||||
}
|
||||
|
||||
public void testBasicLoad() throws Exception {
|
||||
assertTrue(testView instanceof AndroidWebView);
|
||||
assertTrue(testView instanceof SystemWebView);
|
||||
assertTrue(innerContainer instanceof LinearLayout);
|
||||
String onPageFinishedUrl = testActivity.onPageFinishedUrl.take();
|
||||
assertEquals(CordovaWebViewTestActivity.START_URL, onPageFinishedUrl);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<org.apache.cordova.AndroidWebView
|
||||
<org.apache.cordova.engine.SystemWebView
|
||||
android:id="@+id/cordovaWebView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
@@ -21,15 +21,12 @@ package org.apache.cordova.test;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
|
||||
import org.apache.cordova.AndroidChromeClient;
|
||||
import org.apache.cordova.AndroidWebView;
|
||||
import org.apache.cordova.AndroidWebViewClient;
|
||||
import org.apache.cordova.Config;
|
||||
import org.apache.cordova.CordovaInterfaceImpl;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CordovaInterface;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.test.R;
|
||||
import org.apache.cordova.CordovaWebViewImpl;
|
||||
import org.apache.cordova.engine.SystemWebView;
|
||||
import org.apache.cordova.engine.SystemWebViewEngine;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
@@ -61,8 +58,8 @@ public class CordovaWebViewTestActivity extends Activity {
|
||||
//CB-7238: This has to be added now, because it got removed from somewhere else
|
||||
Config.init(this);
|
||||
|
||||
AndroidWebView webView = (AndroidWebView) findViewById(R.id.cordovaWebView);
|
||||
cordovaWebView = webView;
|
||||
SystemWebView webView = (SystemWebView) findViewById(R.id.cordovaWebView);
|
||||
cordovaWebView = new CordovaWebViewImpl(this, new SystemWebViewEngine(webView));
|
||||
cordovaWebView.init(cordovaInterface, Config.getPluginEntries(), Config.getPreferences());
|
||||
|
||||
cordovaWebView.loadUrl(START_URL);
|
||||
|
||||
@@ -23,6 +23,9 @@ import android.webkit.WebView;
|
||||
import android.webkit.GeolocationPermissions.Callback;
|
||||
|
||||
import org.apache.cordova.*;
|
||||
import org.apache.cordova.engine.SystemWebChromeClient;
|
||||
import org.apache.cordova.engine.SystemWebViewClient;
|
||||
import org.apache.cordova.engine.SystemWebViewEngine;
|
||||
|
||||
public class userwebview extends MainTestActivity {
|
||||
|
||||
@@ -32,17 +35,19 @@ public class userwebview extends MainTestActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
testViewClient = new TestViewClient(cordovaInterface, ((AndroidWebView)appView));
|
||||
testChromeClient = new TestChromeClient(cordovaInterface, ((AndroidWebView)appView));
|
||||
SystemWebViewEngine engine = (SystemWebViewEngine)appView.getEngine();
|
||||
testViewClient = new TestViewClient(engine);
|
||||
testChromeClient = new TestChromeClient(engine);
|
||||
super.init();
|
||||
((AndroidWebView)appView).setWebViewClient(testViewClient);
|
||||
((AndroidWebView)appView).setWebChromeClient(testChromeClient);
|
||||
WebView webView = (WebView)engine.getView();
|
||||
webView.setWebViewClient(testViewClient);
|
||||
webView.setWebChromeClient(testChromeClient);
|
||||
super.loadUrl("file:///android_asset/www/userwebview/index.html");
|
||||
}
|
||||
|
||||
public class TestChromeClient extends AndroidChromeClient {
|
||||
public TestChromeClient(CordovaInterface ctx, AndroidWebView app) {
|
||||
super(ctx, app);
|
||||
public class TestChromeClient extends SystemWebChromeClient {
|
||||
public TestChromeClient(SystemWebViewEngine parentEngine) {
|
||||
super(parentEngine);
|
||||
LOG.d("userwebview", "TestChromeClient()");
|
||||
}
|
||||
|
||||
@@ -57,9 +62,9 @@ public class userwebview extends MainTestActivity {
|
||||
/**
|
||||
* This class can be used to override the GapViewClient and receive notification of webview events.
|
||||
*/
|
||||
public class TestViewClient extends AndroidWebViewClient {
|
||||
public TestViewClient(CordovaInterface ctx, AndroidWebView app) {
|
||||
super(ctx, app);
|
||||
public class TestViewClient extends SystemWebViewClient {
|
||||
public TestViewClient(SystemWebViewEngine parentEngine) {
|
||||
super(parentEngine);
|
||||
LOG.d("userwebview", "TestViewClient()");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user