summaryrefslogtreecommitdiff
path: root/plugins/cordova-plugin-crosswalk-webview
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-09-23 15:45:30 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-09-23 15:45:30 -0400
commit1d1c2168ff30ac9452b0929db4ae1f5baa83657a (patch)
tree1967e3ca3898bf2f33938e89bd1e6add6e49a570 /plugins/cordova-plugin-crosswalk-webview
parent26821696678cf84ee19f4eb803807e41a7b56780 (diff)
updates
Diffstat (limited to 'plugins/cordova-plugin-crosswalk-webview')
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/README.md59
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/hooks/after_plugin_install/000-shared_mode_special.js100
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/hooks/before_plugin_uninstall/000-shared_mode_special.js60
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/package.json8
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/plugin.xml40
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java53
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java231
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java193
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java108
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java52
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java174
-rw-r--r--plugins/cordova-plugin-crosswalk-webview/src/android/xwalk.gradle93
12 files changed, 242 insertions, 929 deletions
diff --git a/plugins/cordova-plugin-crosswalk-webview/README.md b/plugins/cordova-plugin-crosswalk-webview/README.md
index cb5d8f9a..768990a8 100644
--- a/plugins/cordova-plugin-crosswalk-webview/README.md
+++ b/plugins/cordova-plugin-crosswalk-webview/README.md
@@ -3,11 +3,27 @@
Makes your Cordova application use the [Crosswalk WebView](https://crosswalk-project.org/)
instead of the System WebView. Requires cordova-android 4.0 or greater.
+### Benefits
+
+* WebView doesn't change depending on Android version
+* Capabilities: such as WebRTC, WebAudio, Web Components
+* Performance improvements (compared to older system webviews)
+
+
+### Drawbacks
+
+* Increased memory footprint
+ * An overhead of ~30MB (as reported by the RSS column of ps)
+* Increased APK size (about 17MB)
+* Increased size on disk when installed (about 50MB)
+* Crosswalk WebView stores data (IndexedDB, LocalStorage, etc) separately from System WebView
+ * You'll need to manually migrate local data when switching between the two (note: this is fixed in Crosswalk 15)
+
### Install
The following directions are for cordova-cli (most people). Alternatively you can use the [Android platform scripts workflow](PlatformScriptsWorkflow.md).
-* Open an existing cordova project, with cordova-android 4.0.0+, and using the latest CLI.
+* Open an existing cordova project, with cordova-android 4.0.0+, and using the latest CLI. Crosswalk variables can be configured as an option when installing the plugin
* Add this plugin
```
@@ -35,25 +51,54 @@ To build Crosswalk-enabled apks, add this plugin and run:
To build System-webview apk, remove this plugin and run:
- $ cordova build --release -- --android-minSdkVersion=21
+ $ cordova build --release -- --minSdkVersion=21
### Configure
-You can try out a different Crosswalk version using a `<preference>` tag within your `config.xml`. Some examples:
+You can try out a different Crosswalk version by specifying certain variables while installing the plugin, or by changing the value of `xwalkVersion` in your `config.xml` after installing the plugin. Some examples:
+
+ <!-- These are all equivalent -->
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="org.xwalk:xwalk_core_library:14+"
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="xwalk_core_library:14+"
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="14+"
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="14"
+ <preference name="xwalkVersion" value="org.xwalk:xwalk_core_library:14+" />
+ <preference name="xwalkVersion" value="xwalk_core_library:14+" />
+ <preference name="xwalkVersion" value="14+" />
+ <preference name="xwalkVersion" value="14" />
+
+You can also use a Crosswalk beta version. Some examples:
<!-- These are all equivalent -->
- <preference name="xwalkVersion" value="org.xwalk:xwalk_core_library_beta:13+" />
- <preference name="xwalkVersion" value="xwalk_core_library_beta:13+" />
- <preference name="xwalkVersion" value="13+" />
- <preference name="xwalkVersion" value="13" />
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="org.xwalk:xwalk_core_library_beta:14+"
+ <preference name="xwalkVersion" value="org.xwalk:xwalk_core_library_beta:14+" />
You can set [command-line flags](http://peter.sh/experiments/chromium-command-line-switches/) as well:
<!-- This is the default -->
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_COMMANDLINE="--disable-pull-to-refresh-effect"
<preference name="xwalkCommandLine" value="--disable-pull-to-refresh-effect" />
+You can use the Crosswalk [shared mode](https://crosswalk-project.org/documentation/shared_mode.html) which allows multiple Crosswalk applications to share one Crosswalk runtime downloaded from the Play Store.
+
+ <!-- These are all equivalent -->
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_MODE="shared"
+ <preference name="xwalkMode" value="shared" />
+Note that if you want to specify the Crosswalk version when using shared mode, you need to use the shared version of the library, e.g.:
+
+ <!-- Using a Crosswalk shared mode beta version -->
+ cordova plugin add cordova-plugin-crosswalk-webview --variable XWALK_VERSION="org.xwalk:xwalk_shared_library_beta:14+"
+
+
### Release Notes
+#### 1.3.0 (August 28, 2015)
+* Crosswalk variables can be configured as an option via CLI
+* Support for [Crosswalk's shared mode](https://crosswalk-project.org/documentation/shared_mode.html) via the XWALK_MODE install variable or xwalkMode preference
+* Uses the latest Crosswalk 14 stable version by default
+* The ANIMATABLE_XWALK_VIEW preference is false by default
+* Doesn't work with Crosswalk 14.43.343.17 and earlier
+
#### 1.2.0 (April 22, 2015)
* Made Crosswalk command-line configurable via `<preference name="xwalkCommandLine" value="..." />`
* Disabled pull-down-to-refresh by default
diff --git a/plugins/cordova-plugin-crosswalk-webview/hooks/after_plugin_install/000-shared_mode_special.js b/plugins/cordova-plugin-crosswalk-webview/hooks/after_plugin_install/000-shared_mode_special.js
new file mode 100644
index 00000000..b0581b02
--- /dev/null
+++ b/plugins/cordova-plugin-crosswalk-webview/hooks/after_plugin_install/000-shared_mode_special.js
@@ -0,0 +1,100 @@
+#!/usr/bin/env node
+
+module.exports = function(context) {
+
+ /** @external */
+ var fs = context.requireCordovaModule('fs'),
+ path = context.requireCordovaModule('path'),
+ deferral = context.requireCordovaModule('q').defer(),
+ ConfigParser = context.requireCordovaModule("cordova-lib/src/configparser/ConfigParser"),
+ XmlHelpers = context.requireCordovaModule("cordova-lib/src/util/xml-helpers"),
+ et = context.requireCordovaModule('elementtree');
+
+ /** @defaults */
+ var xwalkVariables = {'xwalkVersion':'14+', 'xwalkCommandLine':'--disable-pull-to-refresh-effect',
+ 'xwalkMode':'embedded'},
+ argumentsString = context.cmdLine,
+ androidPlatformDir = path.join(context.opts.projectRoot,
+ 'platforms', 'android'),
+ projectConfigurationFile = path.join(context.opts.projectRoot,
+ 'config.xml'),
+ projectManifestFile = path.join(androidPlatformDir,
+ 'AndroidManifest.xml'),
+ platformJsonFile = path.join(context.opts.projectRoot,
+ 'plugins', 'android.json');
+
+ /** Init */
+ var CordovaConfig = new ConfigParser(projectConfigurationFile);
+
+ var addPermission = function() {
+ var projectManifestXmlRoot = XmlHelpers.parseElementtreeSync(projectManifestFile);
+ var child = et.XML('<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />');
+ XmlHelpers.graftXML(projectManifestXmlRoot, [child], '/manifest');
+ fs.writeFileSync(projectManifestFile, projectManifestXmlRoot.write({indent: 4}), 'utf-8');
+ }
+
+ /** Set preference */
+ var addPreferences = function() {
+ var configXmlRoot = XmlHelpers.parseElementtreeSync(projectConfigurationFile);
+ for (name in xwalkVariables) {
+ var child = et.XML('<preference name="' + name + '" value="' + xwalkVariables[name] + '" />');
+ XmlHelpers.graftXML(configXmlRoot, [child], '/*');
+ }
+ fs.writeFileSync(projectConfigurationFile, configXmlRoot.write({indent: 4}), 'utf-8');
+ }
+
+ /** The style of name align with config.xml */
+ var setConfigPreference = function(name, value) {
+ var localName = null;
+ if (name == 'XWALK_VERSION') {
+ localName = 'xwalkVersion';
+ } else if (name == 'XWALK_COMMANDLINE') {
+ localName = 'xwalkCommandLine';
+ } else if (name == 'XWALK_MODE') {
+ localName = 'xwalkMode';
+ }
+
+ if (localName) {
+ xwalkVariables[localName] = value;
+ }
+ }
+
+ /** Pase the cli command to get the specific preferece*/
+ var parseCliPreference = function() {
+ var commandlineVariablesList = argumentsString.split('variable');
+ if (commandlineVariablesList) {
+ commandlineVariablesList.forEach(function(element) {
+ var spaceList = element.split(' ');
+ if (spaceList) {
+ spaceList.forEach(function(element) {
+ var preference = element.split('=');
+ if (preference && preference.length == 2) {
+ setConfigPreference(preference[0].toUpperCase(), preference[1]);
+ }
+ });
+ }
+ });
+ }
+ }
+
+ /** Main method */
+ var main = function() {
+ // Parse cli preference
+ parseCliPreference();
+
+ // Add xwalk preference to config.xml
+ addPreferences();
+
+ if (xwalkVariables['xwalkMode'] == 'shared') {
+ // Add the permission of write_external_storage in shared mode
+ addPermission();
+ }
+
+ deferral.resolve();
+ };
+
+ main();
+
+ return deferral.promise;
+
+};
diff --git a/plugins/cordova-plugin-crosswalk-webview/hooks/before_plugin_uninstall/000-shared_mode_special.js b/plugins/cordova-plugin-crosswalk-webview/hooks/before_plugin_uninstall/000-shared_mode_special.js
new file mode 100644
index 00000000..2cc741d3
--- /dev/null
+++ b/plugins/cordova-plugin-crosswalk-webview/hooks/before_plugin_uninstall/000-shared_mode_special.js
@@ -0,0 +1,60 @@
+#!/usr/bin/env node
+
+module.exports = function(context) {
+
+ /** @external */
+ var fs = context.requireCordovaModule('fs'),
+ path = context.requireCordovaModule('path'),
+ deferral = context.requireCordovaModule('q').defer(),
+ ConfigParser = context.requireCordovaModule("cordova-lib/src/configparser/ConfigParser"),
+ XmlHelpers = context.requireCordovaModule("cordova-lib/src/util/xml-helpers"),
+ et = context.requireCordovaModule('elementtree');
+
+ /** @defaults */
+ var xwalkVariables = ['xwalkVersion', 'xwalkCommandLine', 'xwalkMode'];
+ androidPlatformDir = path.join(context.opts.projectRoot,
+ 'platforms', 'android'),
+ projectConfigurationFile = path.join(context.opts.projectRoot,
+ 'config.xml'),
+ projectManifestFile = path.join(androidPlatformDir,
+ 'AndroidManifest.xml');
+
+ /** Init */
+ var CordovaConfig = new ConfigParser(projectConfigurationFile);
+
+ var removePermission = function() {
+ var projectManifestXmlRoot = XmlHelpers.parseElementtreeSync(projectManifestFile);
+ var child = et.XML('<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />');
+ XmlHelpers.pruneXML(projectManifestXmlRoot, [child], '/manifest');
+ fs.writeFileSync(projectManifestFile, projectManifestXmlRoot.write({indent: 4}), 'utf-8');
+ }
+
+ var removeXWalkVariables = function() {
+ var configXmlRoot = XmlHelpers.parseElementtreeSync(projectConfigurationFile);
+ for (var index = 0; index < xwalkVariables.length; index++) {
+ var child = configXmlRoot.find('./preference[@name="' + xwalkVariables[index] + '"]');
+ if (child) {
+ XmlHelpers.pruneXML(configXmlRoot, [child], '/*');
+ }
+ }
+ fs.writeFileSync(projectConfigurationFile, configXmlRoot.write({indent: 4}), 'utf-8');
+ }
+
+ /** Main method */
+ var main = function() {
+ // Remove the xwalk variables
+ removeXWalkVariables();
+
+ if (CordovaConfig.getGlobalPreference('xwalkMode') == 'shared') {
+ // Add the permission of write_external_storage in shared mode
+ removePermission();
+ }
+
+ deferral.resolve();
+ };
+
+ main();
+
+ return deferral.promise;
+
+};
diff --git a/plugins/cordova-plugin-crosswalk-webview/package.json b/plugins/cordova-plugin-crosswalk-webview/package.json
index 0ad32912..c4c95f1f 100644
--- a/plugins/cordova-plugin-crosswalk-webview/package.json
+++ b/plugins/cordova-plugin-crosswalk-webview/package.json
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-crosswalk-webview",
- "version": "1.2.0",
+ "version": "1.3.1",
"description": "Changes the default WebView to CrossWalk",
"cordova": {
"id": "cordova-plugin-crosswalk-webview",
@@ -10,7 +10,7 @@
},
"repository": {
"type": "git",
- "url": "https://github.com/MobileChromeApps/cordova-crosswalk-engine.git"
+ "url": "https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview.git"
},
"keywords": [
"cordova",
@@ -34,7 +34,7 @@
"author": "",
"license": "Apache 2.0",
"bugs": {
- "url": "https://github.com/MobileChromeApps/cordova-crosswalk-engine/issues"
+ "url": "https://crosswalk-project.org/jira"
},
- "homepage": "https://github.com/MobileChromeApps/cordova-crosswalk-engine"
+ "homepage": "https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview"
}
diff --git a/plugins/cordova-plugin-crosswalk-webview/plugin.xml b/plugins/cordova-plugin-crosswalk-webview/plugin.xml
index ac5aac07..95f35dc8 100644
--- a/plugins/cordova-plugin-crosswalk-webview/plugin.xml
+++ b/plugins/cordova-plugin-crosswalk-webview/plugin.xml
@@ -1,33 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
- id="cordova-plugin-crosswalk-webview"
- version="1.2.0">
+ id="cordova-plugin-crosswalk-webview"
+ version="1.3.1">
<name>Crosswalk WebView Engine</name>
<description>Changes the default WebView to CrossWalk</description>
<license>Apache 2.0</license>
<keywords>cordova,chromium,crosswalk,webview</keywords>
- <repo>https://github.com/MobileChromeApps/cordova-crosswalk-engine.git</repo>
- <issue>https://github.com/MobileChromeApps/cordova-crosswalk-engine/issues</issue>
+ <repo>https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview</repo>
+ <issue>https://crosswalk-project.org/jira</issue>
<engines>
- <engine name="cordova-android" version=">=4" />
- <engine name="cordova-plugman" version=">=4.2.0" /><!-- needed for gradleReference support -->
+ <engine name="cordova-android" version=">=4"/>
+ <engine name="cordova-plugman" version=">=4.2.0"/><!-- needed for gradleReference support -->
</engines>
+ <!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
- <preference name="webView" value="org.crosswalk.engine.XWalkWebViewEngine" />
+ <preference name="webView" value="org.crosswalk.engine.XWalkWebViewEngine"/>
+ <preference name="xwalkVersion" default="14+"/>
+ <preference name="xwalkCommandLine" default="--disable-pull-to-refresh-effect"/>
+ <preference name="xwalkMode" default="embedded" />
</config-file>
- <source-file src="src/android/XWalkWebViewEngine.java" target-dir="src/org/crosswalk/engine" />
- <source-file src="src/android/XWalkExposedJsApi.java" target-dir="src/org/crosswalk/engine" />
- <source-file src="src/android/XWalkCordovaResourceClient.java" target-dir="src/org/crosswalk/engine" />
- <source-file src="src/android/XWalkCordovaUiClient.java" target-dir="src/org/crosswalk/engine" />
- <source-file src="src/android/XWalkCordovaView.java" target-dir="src/org/crosswalk/engine" />
- <source-file src="src/android/XWalkCordovaCookieManager.java" target-dir="src/org/crosswalk/engine" />
+ <config-file target="AndroidManifest.xml" parent="/*">
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+ </config-file>
+
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkWebViewEngine.java" target-dir="src/org/crosswalk/engine"/>
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkExposedJsApi.java" target-dir="src/org/crosswalk/engine"/>
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkCordovaResourceClient.java" target-dir="src/org/crosswalk/engine"/>
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkCordovaUiClient.java" target-dir="src/org/crosswalk/engine"/>
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkCordovaView.java" target-dir="src/org/crosswalk/engine"/>
+ <source-file src="platforms/android/src/org/crosswalk/engine/XWalkCordovaCookieManager.java" target-dir="src/org/crosswalk/engine"/>
+
+ <framework src="platforms/android/xwalk.gradle" custom="true" type="gradleReference"/>
- <framework src="src/android/xwalk.gradle" custom="true" type="gradleReference" />
+ <hook type="after_plugin_install" src="hooks/after_plugin_install/000-shared_mode_special.js"/>
+ <hook type="before_plugin_uninstall" src="hooks/before_plugin_uninstall/000-shared_mode_special.js"/>
</platform>
</plugin>
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java
deleted file mode 100644
index 43f170d2..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaCookieManager.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-package org.crosswalk.engine;
-
-import org.apache.cordova.ICordovaCookieManager;
-import org.xwalk.core.internal.XWalkCookieManager;
-
-class XWalkCordovaCookieManager implements ICordovaCookieManager {
-
- protected XWalkCookieManager cookieManager = null;
-
- public XWalkCordovaCookieManager() {
- cookieManager = new XWalkCookieManager();
- }
-
- public void setCookiesEnabled(boolean accept) {
- cookieManager.setAcceptCookie(accept);
- }
-
- public void setCookie(final String url, final String value) {
- cookieManager.setCookie(url, value);
- }
-
- public String getCookie(final String url) {
- return cookieManager.getCookie(url);
- }
-
- public void clearCookies() {
- cookieManager.removeAllCookie();
- }
-
- public void flush() {
- cookieManager.flushCookieStore();
- }
-};
-
-
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java
deleted file mode 100644
index 57d0b0f9..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaResourceClient.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-package org.crosswalk.engine;
-
-import android.net.Uri;
-import android.webkit.WebResourceResponse;
-
-import org.apache.cordova.CordovaResourceApi;
-import org.apache.cordova.CordovaResourceApi.OpenForReadResult;
-import org.apache.cordova.LOG;
-import org.chromium.net.NetError;
-import org.xwalk.core.XWalkResourceClient;
-import org.xwalk.core.XWalkView;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-
-public class XWalkCordovaResourceClient extends XWalkResourceClient {
-
- private static final String TAG = "XWalkCordovaResourceClient";
- protected XWalkWebViewEngine parentEngine;
-
- // Success
- public static final int ERROR_OK = 0;
- // Generic error
- public static final int ERROR_UNKNOWN = -1;
- // Server or proxy hostname lookup failed
- public static final int ERROR_HOST_LOOKUP = -2;
- // Unsupported authentication scheme (not basic or digest)
- public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3;
- // User authentication failed on server
- public static final int ERROR_AUTHENTICATION = -4;
- // User authentication failed on proxy
- public static final int ERROR_PROXY_AUTHENTICATION = -5;
- // Failed to connect to the server
- public static final int ERROR_CONNECT = -6;
- // Failed to read or write to the server
- public static final int ERROR_IO = -7;
- // Connection timed out
- public static final int ERROR_TIMEOUT = -8;
- // Too many redirects
- public static final int ERROR_REDIRECT_LOOP = -9;
- // Unsupported URI scheme
- public static final int ERROR_UNSUPPORTED_SCHEME = -10;
- // Failed to perform SSL handshake
- public static final int ERROR_FAILED_SSL_HANDSHAKE = -11;
- // Malformed URL
- public static final int ERROR_BAD_URL = -12;
- // Generic file error
- public static final int ERROR_FILE = -13;
- // File not found
- public static final int ERROR_FILE_NOT_FOUND = -14;
- // Too many requests during this load
- public static final int ERROR_TOO_MANY_REQUESTS = -15;
-
- public XWalkCordovaResourceClient(XWalkWebViewEngine parentEngine) {
- super(parentEngine.webView);
- this.parentEngine = parentEngine;
- }
-
- // Map XWalk error code about loading a page to Android specific ones.
- // XWalk shares the error code with chromium currently.
- static int convertErrorCode(int netError) {
- // Note: many NetError.Error constants don't have an obvious mapping.
- // These will be handled by the default case, ERROR_UNKNOWN.
- switch (netError) {
- case NetError.ERR_UNSUPPORTED_AUTH_SCHEME:
- return ERROR_UNSUPPORTED_AUTH_SCHEME;
-
- case NetError.ERR_INVALID_AUTH_CREDENTIALS:
- case NetError.ERR_MISSING_AUTH_CREDENTIALS:
- case NetError.ERR_MISCONFIGURED_AUTH_ENVIRONMENT:
- return ERROR_AUTHENTICATION;
-
- case NetError.ERR_TOO_MANY_REDIRECTS:
- return ERROR_REDIRECT_LOOP;
-
- case NetError.ERR_UPLOAD_FILE_CHANGED:
- return ERROR_FILE_NOT_FOUND;
-
- case NetError.ERR_INVALID_URL:
- return ERROR_BAD_URL;
-
- case NetError.ERR_DISALLOWED_URL_SCHEME:
- case NetError.ERR_UNKNOWN_URL_SCHEME:
- return ERROR_UNSUPPORTED_SCHEME;
-
- case NetError.ERR_IO_PENDING:
- case NetError.ERR_NETWORK_IO_SUSPENDED:
- return ERROR_IO;
-
- case NetError.ERR_CONNECTION_TIMED_OUT:
- case NetError.ERR_TIMED_OUT:
- return ERROR_TIMEOUT;
-
- case NetError.ERR_FILE_TOO_BIG:
- return ERROR_FILE;
-
- case NetError.ERR_HOST_RESOLVER_QUEUE_TOO_LARGE:
- case NetError.ERR_INSUFFICIENT_RESOURCES:
- case NetError.ERR_OUT_OF_MEMORY:
- return ERROR_TOO_MANY_REQUESTS;
-
- case NetError.ERR_CONNECTION_CLOSED:
- case NetError.ERR_CONNECTION_RESET:
- case NetError.ERR_CONNECTION_REFUSED:
- case NetError.ERR_CONNECTION_ABORTED:
- case NetError.ERR_CONNECTION_FAILED:
- case NetError.ERR_SOCKET_NOT_CONNECTED:
- return ERROR_CONNECT;
-
- case NetError.ERR_INTERNET_DISCONNECTED:
- case NetError.ERR_ADDRESS_INVALID:
- case NetError.ERR_ADDRESS_UNREACHABLE:
- case NetError.ERR_NAME_NOT_RESOLVED:
- case NetError.ERR_NAME_RESOLUTION_FAILED:
- return ERROR_HOST_LOOKUP;
-
- case NetError.ERR_SSL_PROTOCOL_ERROR:
- case NetError.ERR_SSL_CLIENT_AUTH_CERT_NEEDED:
- case NetError.ERR_TUNNEL_CONNECTION_FAILED:
- case NetError.ERR_NO_SSL_VERSIONS_ENABLED:
- case NetError.ERR_SSL_VERSION_OR_CIPHER_MISMATCH:
- case NetError.ERR_SSL_RENEGOTIATION_REQUESTED:
- case NetError.ERR_CERT_ERROR_IN_SSL_RENEGOTIATION:
- case NetError.ERR_BAD_SSL_CLIENT_AUTH_CERT:
- case NetError.ERR_SSL_NO_RENEGOTIATION:
- case NetError.ERR_SSL_DECOMPRESSION_FAILURE_ALERT:
- case NetError.ERR_SSL_BAD_RECORD_MAC_ALERT:
- case NetError.ERR_SSL_UNSAFE_NEGOTIATION:
- case NetError.ERR_SSL_WEAK_SERVER_EPHEMERAL_DH_KEY:
- case NetError.ERR_SSL_CLIENT_AUTH_PRIVATE_KEY_ACCESS_DENIED:
- case NetError.ERR_SSL_CLIENT_AUTH_CERT_NO_PRIVATE_KEY:
- return ERROR_FAILED_SSL_HANDSHAKE;
-
- case NetError.ERR_PROXY_AUTH_UNSUPPORTED:
- case NetError.ERR_PROXY_AUTH_REQUESTED:
- case NetError.ERR_PROXY_CONNECTION_FAILED:
- case NetError.ERR_UNEXPECTED_PROXY_AUTH:
- return ERROR_PROXY_AUTHENTICATION;
-
- // The certificate errors are handled by onReceivedSslError
- // and don't need to be reported here.
- case NetError.ERR_CERT_COMMON_NAME_INVALID:
- case NetError.ERR_CERT_DATE_INVALID:
- case NetError.ERR_CERT_AUTHORITY_INVALID:
- case NetError.ERR_CERT_CONTAINS_ERRORS:
- case NetError.ERR_CERT_NO_REVOCATION_MECHANISM:
- case NetError.ERR_CERT_UNABLE_TO_CHECK_REVOCATION:
- case NetError.ERR_CERT_REVOKED:
- case NetError.ERR_CERT_INVALID:
- case NetError.ERR_CERT_WEAK_SIGNATURE_ALGORITHM:
- case NetError.ERR_CERT_NON_UNIQUE_NAME:
- return ERROR_OK;
-
- default:
- return ERROR_UNKNOWN;
- }
- }
-
- /**
- * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
- * The errorCode parameter corresponds to one of the ERROR_* constants.
- *
- * @param view The WebView that is initiating the callback.
- * @param errorCode The error code corresponding to an ERROR_* value.
- * @param description A String describing the error.
- * @param failingUrl The url that failed to load.
- */
- @Override
- public void onReceivedLoadError(XWalkView view, int errorCode, String description,
- String failingUrl) {
- LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
-
- // Convert the XWalk error code to Cordova error code, which follows the Android spec,
- // http://developer.android.com/reference/android/webkit/WebViewClient.html.
- errorCode = XWalkCordovaResourceClient.convertErrorCode(errorCode);
- parentEngine.client.onReceivedError(errorCode, description, failingUrl);
- }
-
- @Override
- public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
- try {
- // Check the against the white-list.
- if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
- LOG.w(TAG, "URL blocked by whitelist: " + url);
- // Results in a 404.
- return new WebResourceResponse("text/plain", "UTF-8", null);
- }
-
- CordovaResourceApi resourceApi = parentEngine.resourceApi;
- Uri origUri = Uri.parse(url);
- // Allow plugins to intercept WebView requests.
- Uri remappedUri = resourceApi.remapUri(origUri);
-
- if (!origUri.equals(remappedUri)) {
- OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
- return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
- }
- // If we don't need to special-case the request, let the browser load it.
- return null;
- } catch (IOException e) {
- if (!(e instanceof FileNotFoundException)) {
- LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
- }
- // Results in a 404.
- return new WebResourceResponse("text/plain", "UTF-8", null);
- }
- }
-
- @Override
- public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
- return parentEngine.client.onNavigationAttempt(url);
- }
-}
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java
deleted file mode 100644
index a5a20b70..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaUiClient.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-package org.crosswalk.engine;
-
-import android.app.Activity;
-import android.content.ActivityNotFoundException;
-import android.content.Intent;
-import android.net.Uri;
-import android.util.Log;
-import android.webkit.ValueCallback;
-
-import org.apache.cordova.CordovaDialogsHelper;
-import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.LOG;
-import org.xwalk.core.XWalkJavascriptResult;
-import org.xwalk.core.XWalkUIClient;
-import org.xwalk.core.XWalkView;
-
-public class XWalkCordovaUiClient extends XWalkUIClient {
- private static final String TAG = "XWalkCordovaUiClient";
- protected final CordovaDialogsHelper dialogsHelper;
- protected final XWalkWebViewEngine parentEngine;
-
- private static final int FILECHOOSER_RESULTCODE = 5173;
-
- public XWalkCordovaUiClient(XWalkWebViewEngine parentEngine) {
- super(parentEngine.webView);
- this.parentEngine = parentEngine;
- dialogsHelper = new CordovaDialogsHelper(parentEngine.webView.getContext());
- }
-
- @Override
- public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url,
- String message, String defaultValue, XWalkJavascriptResult result) {
- switch (type) {
- case JAVASCRIPT_ALERT:
- return onJsAlert(view, url, message, result);
- case JAVASCRIPT_CONFIRM:
- return onJsConfirm(view, url, message, result);
- case JAVASCRIPT_PROMPT:
- return onJsPrompt(view, url, message, defaultValue, result);
- case JAVASCRIPT_BEFOREUNLOAD:
- // Reuse onJsConfirm to show the dialog.
- return onJsConfirm(view, url, message, result);
- default:
- break;
- }
- assert (false);
- return false;
- }
-
- /**
- * Tell the client to display a javascript alert dialog.
- */
- private boolean onJsAlert(XWalkView view, String url, String message,
- final XWalkJavascriptResult result) {
- dialogsHelper.showAlert(message, new CordovaDialogsHelper.Result() {
- @Override
- public void gotResult(boolean success, String value) {
- if (success) {
- result.confirm();
- } else {
- result.cancel();
- }
- }
- });
- return true;
- }
-
- /**
- * Tell the client to display a confirm dialog to the user.
- */
- private boolean onJsConfirm(XWalkView view, String url, String message,
- final XWalkJavascriptResult result) {
- dialogsHelper.showConfirm(message, new CordovaDialogsHelper.Result() {
- @Override
- public void gotResult(boolean success, String value) {
- if (success) {
- result.confirm();
- } else {
- result.cancel();
- }
- }
- });
- return true;
- }
-
- /**
- * Tell the client to display a prompt dialog to the user.
- * If the client returns true, WebView will assume that the client will
- * handle the prompt dialog and call the appropriate JsPromptResult method.
- * <p/>
- * Since we are hacking prompts for our own purposes, we should not be using them for
- * this purpose, perhaps we should hack console.log to do this instead!
- */
- private boolean onJsPrompt(XWalkView view, String origin, String message, String defaultValue,
- final XWalkJavascriptResult result) {
- // Unlike the @JavascriptInterface bridge, this method is always called on the UI thread.
- String handledRet = parentEngine.bridge.promptOnJsPrompt(origin, message, defaultValue);
- if (handledRet != null) {
- result.confirmWithResult(handledRet);
- } else {
- dialogsHelper.showPrompt(message, defaultValue, new CordovaDialogsHelper.Result() {
- @Override
- public void gotResult(boolean success, String value) {
- if (success) {
- result.confirmWithResult(value);
- } else {
- result.cancel();
- }
- }
- });
-
- }
- return true;
- }
-
- /**
- * Notify the host application that a page has started loading.
- * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
- * one time for the main frame. This also means that onPageStarted will not be called when the contents of an
- * embedded frame changes, i.e. clicking a link whose target is an iframe.
- *
- * @param view The webView initiating the callback.
- * @param url The url of the page.
- */
- @Override
- public void onPageLoadStarted(XWalkView view, String url) {
-
- // Only proceed if this is a top-level navigation
- if (view.getUrl() != null && view.getUrl().equals(url)) {
- // Flush stale messages.
- parentEngine.client.onPageStarted(url);
- parentEngine.bridge.reset();
- }
- }
-
- /**
- * Notify the host application that a page has stopped loading.
- * This method is called only for main frame. When onPageLoadStopped() is called, the rendering picture may not be updated yet.
- *
- * @param view The webView initiating the callback.
- * @param url The url of the page.
- * @param status The load status of the webView, can be FINISHED, CANCELLED or FAILED.
- */
- @Override
- public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) {
- LOG.d(TAG, "onPageFinished(" + url + ")");
- if (status == LoadStatus.FINISHED) {
- parentEngine.client.onPageFinishedLoading(url);
- } else if (status == LoadStatus.FAILED) {
- // TODO: Should this call parentEngine.client.onReceivedError()?
- // Right now we call this from ResourceClient, but maybe that is just for sub-resources?
- }
- }
-
- // File Chooser
- @Override
- public void openFileChooser(XWalkView view, final ValueCallback<Uri> uploadFile, String acceptType, String capture) {
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- i.setType("*/*"); // TODO: wire this to acceptType.
- Intent intent = Intent.createChooser(i, "File Browser");
- try {
- parentEngine.cordova.startActivityForResult(new CordovaPlugin() {
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
- uploadFile.onReceiveValue(result);
- }
- }, intent, FILECHOOSER_RESULTCODE);
- } catch (ActivityNotFoundException e) {
- Log.w("No activity found to handle file chooser intent.", e);
- uploadFile.onReceiveValue(null);
- }
- }
-}
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java
deleted file mode 100644
index 0be2e998..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkCordovaView.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.crosswalk.engine;
-
-import org.apache.cordova.CordovaPreferences;
-import org.xwalk.core.XWalkPreferences;
-import org.xwalk.core.XWalkResourceClient;
-import org.xwalk.core.XWalkUIClient;
-import org.xwalk.core.XWalkView;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.util.AttributeSet;
-import android.view.KeyEvent;
-
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.CordovaWebViewEngine;
-
-public class XWalkCordovaView extends XWalkView implements CordovaWebViewEngine.EngineView {
- protected XWalkCordovaResourceClient resourceClient;
- protected XWalkCordovaUiClient uiClient;
- protected XWalkWebViewEngine parentEngine;
-
- private static boolean hasSetStaticPref;
- // This needs to run before the super's constructor.
- private static Context setGlobalPrefs(Context context, CordovaPreferences preferences) {
- if (!hasSetStaticPref) {
- hasSetStaticPref = true;
- ApplicationInfo ai = null;
- try {
- ai = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
- } catch (PackageManager.NameNotFoundException e) {
- throw new RuntimeException(e);
- }
- boolean prefAnimatable = preferences == null ? false : preferences.getBoolean("CrosswalkAnimatable", false);
- boolean manifestAnimatable = ai.metaData == null ? false : ai.metaData.getBoolean("CrosswalkAnimatable");
- if (prefAnimatable || manifestAnimatable) {
- // Slows it down a bit, but allows for it to be animated by Android View properties.
- XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);
- }
- if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
- XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
- }
- XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true);
- XWalkPreferences.setValue(XWalkPreferences.ALLOW_UNIVERSAL_ACCESS_FROM_FILE, true);
- }
- return context;
- }
-
- public XWalkCordovaView(Context context, CordovaPreferences preferences) {
- super(setGlobalPrefs(context, preferences), (AttributeSet)null);
- }
-
- public XWalkCordovaView(Context context, AttributeSet attrs) {
- super(setGlobalPrefs(context, null), attrs);
- }
-
- void init(XWalkWebViewEngine parentEngine) {
- this.parentEngine = parentEngine;
- if (resourceClient == null) {
- setResourceClient(new XWalkCordovaResourceClient(parentEngine));
- }
- if (uiClient == null) {
- setUIClient(new XWalkCordovaUiClient(parentEngine));
- }
- }
-
- @Override
- public void setResourceClient(XWalkResourceClient client) {
- // XWalk calls this method from its constructor.
- if (client instanceof XWalkCordovaResourceClient) {
- this.resourceClient = (XWalkCordovaResourceClient)client;
- }
- super.setResourceClient(client);
- }
-
- @Override
- public void setUIClient(XWalkUIClient client) {
- // XWalk calls this method from its constructor.
- if (client instanceof XWalkCordovaUiClient) {
- this.uiClient = (XWalkCordovaUiClient)client;
- }
- super.setUIClient(client);
- }
-
- @Override
- public boolean dispatchKeyEvent(KeyEvent event) {
- Boolean ret = parentEngine.client.onDispatchKeyEvent(event);
- if (ret != null) {
- return ret.booleanValue();
- }
- return super.dispatchKeyEvent(event);
- }
-
- @Override
- public void pauseTimers() {
- // This is called by XWalkViewInternal.onActivityStateChange().
- // We don't want them paused by default though.
- }
-
- public void pauseTimersForReal() {
- super.pauseTimers();
- }
-
- @Override
- public CordovaWebView getCordovaWebView() {
- return parentEngine == null ? null : parentEngine.getCordovaWebView();
- }
-}
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java
deleted file mode 100644
index 25715216..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkExposedJsApi.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-package org.crosswalk.engine;
-
-import android.os.Looper;
-
-import org.apache.cordova.CordovaBridge;
-import org.apache.cordova.ExposedJsApi;
-import org.json.JSONException;
-import org.xwalk.core.JavascriptInterface;
-
-class XWalkExposedJsApi implements ExposedJsApi {
- private final CordovaBridge bridge;
-
- XWalkExposedJsApi(CordovaBridge bridge) {
- this.bridge = bridge;
- }
-
- @JavascriptInterface
- public String exec(int bridgeSecret, String service, String action, String callbackId, String arguments) throws JSONException, IllegalAccessException {
- if (Looper.myLooper() == null) {
- Looper.prepare();
- }
- return bridge.jsExec(bridgeSecret, service, action, callbackId, arguments);
- }
-
- @JavascriptInterface
- public void setNativeToJsBridgeMode(int bridgeSecret, int value) throws IllegalAccessException {
- bridge.jsSetNativeToJsBridgeMode(bridgeSecret, value);
- }
-
- @JavascriptInterface
- public String retrieveJsMessages(int bridgeSecret, boolean fromOnlineEvent) throws IllegalAccessException {
- return bridge.jsRetrieveJsMessages(bridgeSecret, fromOnlineEvent);
- }
-}
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java b/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java
deleted file mode 100644
index 9e94edbe..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/XWalkWebViewEngine.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-package org.crosswalk.engine;
-
-import android.content.Context;
-import android.view.View;
-
-import org.apache.cordova.CordovaBridge;
-import org.apache.cordova.CordovaInterface;
-import org.apache.cordova.CordovaPreferences;
-import org.apache.cordova.CordovaResourceApi;
-import org.apache.cordova.CordovaWebView;
-import org.apache.cordova.CordovaWebViewEngine;
-import org.apache.cordova.ICordovaCookieManager;
-import org.apache.cordova.NativeToJsMessageQueue;
-import org.apache.cordova.PluginManager;
-import org.xwalk.core.XWalkNavigationHistory;
-import org.xwalk.core.XWalkView;
-
-/**
- * Glue class between CordovaWebView (main Cordova logic) and XWalkCordovaView (the actual View).
- */
-public class XWalkWebViewEngine implements CordovaWebViewEngine {
-
- public static final String TAG = "XWalkWebViewEngine";
-
- protected final XWalkCordovaView webView;
- protected XWalkCordovaCookieManager cookieManager;
- protected CordovaBridge bridge;
- protected CordovaWebViewEngine.Client client;
- protected CordovaWebView parentWebView;
- protected CordovaInterface cordova;
- protected PluginManager pluginManager;
- protected CordovaResourceApi resourceApi;
- protected NativeToJsMessageQueue nativeToJsMessageQueue;
-
- /** Used when created via reflection. */
- public XWalkWebViewEngine(Context context, CordovaPreferences preferences) {
- this(new XWalkCordovaView(context, preferences));
- }
-
- public XWalkWebViewEngine(XWalkCordovaView webView) {
- this.webView = webView;
- cookieManager = new XWalkCordovaCookieManager();
- }
-
- // Use two-phase init so that the control will work with XML layouts.
-
- @Override
- public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
- CordovaResourceApi resourceApi, PluginManager pluginManager,
- NativeToJsMessageQueue nativeToJsMessageQueue) {
- if (this.cordova != null) {
- throw new IllegalStateException();
- }
- this.parentWebView = parentWebView;
- this.cordova = cordova;
- this.client = client;
- this.resourceApi = resourceApi;
- this.pluginManager = pluginManager;
- this.nativeToJsMessageQueue = nativeToJsMessageQueue;
-
- webView.init(this);
- initWebViewSettings();
-
- nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
- @Override
- public void setNetworkAvailable(boolean value) {
- webView.setNetworkAvailable(value);
- }
- @Override
- public void runOnUiThread(Runnable r) {
- XWalkWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
- }
- }));
- bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
- exposeJsInterface(webView, bridge);
- }
-
- @Override
- public CordovaWebView getCordovaWebView() {
- return parentWebView;
- }
-
- @Override
- public View getView() {
- return webView;
- }
-
- private void initWebViewSettings() {
- webView.setVerticalScrollBarEnabled(false);
- }
-
- private static void exposeJsInterface(XWalkView webView, CordovaBridge bridge) {
- XWalkExposedJsApi exposedJsApi = new XWalkExposedJsApi(bridge);
- webView.addJavascriptInterface(exposedJsApi, "_cordovaNative");
- }
-
- @Override
- public boolean canGoBack() {
- return this.webView.getNavigationHistory().canGoBack();
- }
-
- @Override
- public boolean goBack() {
- if (this.webView.getNavigationHistory().canGoBack()) {
- this.webView.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.BACKWARD, 1);
- return true;
- }
- return false;
- }
-
- @Override
- public void setPaused(boolean value) {
- if (value) {
- // TODO: I think this has been fixed upstream and we don't need to override pauseTimers() anymore.
- webView.pauseTimersForReal();
- } else {
- webView.resumeTimers();
- }
- }
-
- @Override
- public void destroy() {
- webView.onDestroy();
- }
-
- @Override
- public void clearHistory() {
- this.webView.getNavigationHistory().clear();
- }
-
- @Override
- public void stopLoading() {
- this.webView.stopLoading();
- }
-
- @Override
- public void clearCache() {
- webView.clearCache(true);
- }
-
- @Override
- public String getUrl() {
- return this.webView.getUrl();
- }
-
- @Override
- public ICordovaCookieManager getCookieManager() {
- return cookieManager;
- }
-
- @Override
- public void loadUrl(String url, boolean clearNavigationStack) {
- webView.load(url, null);
- }
-}
diff --git a/plugins/cordova-plugin-crosswalk-webview/src/android/xwalk.gradle b/plugins/cordova-plugin-crosswalk-webview/src/android/xwalk.gradle
deleted file mode 100644
index 3c0a23ee..00000000
--- a/plugins/cordova-plugin-crosswalk-webview/src/android/xwalk.gradle
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-*/
-
-def DEFAULT_VERSION = "org.xwalk:xwalk_core_library_beta:13+"
-def DEFAULT_COMMAND_LINE = "--disable-pull-to-refresh-effect"
-
-repositories {
- maven {
- url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
- }
-}
-
-if (cdvBuildMultipleApks == null) {
- ext.cdvBuildMultipleApks = true
-}
-if (cdvMinSdkVersion == null) {
- ext.cdvMinSdkVersion = 14
-}
-
-def getConfigPreference(name, defaultValue) {
- name = name.toLowerCase()
- def xml = file("res/xml/config.xml").getText()
- // Disable namespace awareness since Cordova doesn't use them properly
- def root = new XmlParser(false, false).parseText(xml)
-
- def ret = defaultValue
- root.preference.each { it ->
- def attrName = it.attribute("name")
- if (attrName && attrName.toLowerCase() == name) {
- ret = it.attribute("value")
- }
- }
- return ret
-}
-
-// Set defaults before project's build-extras.gradle
-if (!project.hasProperty('xwalkVersion')) {
- ext.xwalkVersion = getConfigPreference("xwalkversion", DEFAULT_VERSION)
-}
-if (!project.hasProperty('xwalkCommandLine')) {
- ext.xwalkCommandLine = getConfigPreference("xwalkcommandline", DEFAULT_COMMAND_LINE)
-}
-
-// Apply values after project's build-extras.gradle
-cdvPluginPostBuildExtras.add({
-
- def xwalkSpec = xwalkVersion
- if ((xwalkSpec =~ /:/).count == 1) {
- xwalkSpec = "org.xwalk:${xwalkSpec}"
- } else if ((xwalkSpec =~ /:/).count == 0) {
- if (xwalkSpec ==~ /\d+/) {
- xwalkSpec = "${xwalkSpec}+"
- }
- xwalkSpec = "org.xwalk:xwalk_core_library_beta:${xwalkSpec}"
- }
-
- dependencies {
- compile xwalkSpec
- }
-
- if (file('assets/xwalk-command-line').exists()) {
- println('Not writing assets/xwalk-command-line since file already exists.')
- return
- }
- android.applicationVariants.all { variant ->
- def variantName = variant.name.capitalize()
- def mergeTask = tasks["merge${variantName}Assets"]
- def processTask = tasks["process${variantName}Resources"]
- def outFile = new File (mergeTask.outputDir, "xwalk-command-line")
- def newTask = project.task("createXwalkCommandLineFile${variantName}") << {
- mergeTask.outputDir.mkdirs()
- outFile.write("xwalk ${xwalkCommandLine}\n")
- }
- newTask.dependsOn(mergeTask)
- processTask.dependsOn(newTask)
- }
-})