You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/06/20 19:24:05 UTC
[1/2] git commit: Fix cordova_plugins.js not being used on Android &
restrict plugins on native side to only those that should be loaded.
Repository: cordova-app-harness
Updated Branches:
refs/heads/master 48ac896cc -> 6362305fa
Fix cordova_plugins.js not being used on Android & restrict plugins on native side to only those that should be loaded.
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/6362305f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/6362305f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/6362305f
Branch: refs/heads/master
Commit: 6362305fa726ea65bf3288539371a43965e33eb5
Parents: 4eedf4d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jun 20 12:37:48 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jun 20 13:23:59 2014 -0400
----------------------------------------------------------------------
AppHarnessUI/AppHarnessUI.java | 14 ++++++-
AppHarnessUI/appharnessui.js | 4 +-
createproject.sh | 3 ++
template-overrides/after-hook.js | 79 +++++++++++++++++++++++++++++++++++
www/cdvah/harnessmenu.html | 2 +
www/cdvah/js/AppHarnessUI.js | 24 +++++++++--
www/cdvah/js/AppsService.js | 11 +++--
www/cdvah/js/Installer.js | 1 +
8 files changed, 128 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/AppHarnessUI/AppHarnessUI.java
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.java b/AppHarnessUI/AppHarnessUI.java
index bc0db41..834603b 100644
--- a/AppHarnessUI/AppHarnessUI.java
+++ b/AppHarnessUI/AppHarnessUI.java
@@ -18,6 +18,9 @@
*/
package org.apache.appharness;
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.cordova.AndroidChromeClient;
import org.apache.cordova.AndroidWebView;
import org.apache.cordova.CallbackContext;
@@ -29,6 +32,7 @@ import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.IceCreamCordovaWebViewClient;
import org.apache.cordova.LinearLayoutSoftKeyboardDetect;
import org.apache.cordova.PluginResult;
+import org.json.JSONArray;
import org.json.JSONException;
import android.annotation.SuppressLint;
@@ -58,9 +62,14 @@ public class AppHarnessUI extends CordovaPlugin {
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
if ("create".equals(action)) {
final String url = args.getString(0);
+ JSONArray pluginIdWhitelist = args.getJSONArray(1);
+ final Set<String> pluginIdWhitelistAsSet = new HashSet<String>(pluginIdWhitelist.length());
+ for (int i = 0; i < pluginIdWhitelist.length(); ++i) {
+ pluginIdWhitelistAsSet.add(pluginIdWhitelist.getString(i));
+ }
this.cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
- create(url, callbackContext);
+ create(url, pluginIdWhitelistAsSet, callbackContext);
}
});
} else if ("destroy".equals(action)) {
@@ -113,7 +122,7 @@ public class AppHarnessUI extends CordovaPlugin {
callbackContext.success();
}
- private void create(String url, CallbackContext callbackContext) {
+ private void create(String url, Set<String> pluginIdWhitelist, CallbackContext callbackContext) {
CordovaActivity activity = (CordovaActivity)cordova.getActivity();
if (slaveWebView != null) {
@@ -126,6 +135,7 @@ public class AppHarnessUI extends CordovaPlugin {
}
slaveWebView.clearCache(true);
slaveWebView.clearHistory();
+ slaveWebView.getPluginManager().setPluginIdWhitelist(pluginIdWhitelist);
slaveWebView.loadUrl(url);
View newView = (View)slaveWebView.getParent();
contentView.addView(newView);
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/AppHarnessUI/appharnessui.js
----------------------------------------------------------------------
diff --git a/AppHarnessUI/appharnessui.js b/AppHarnessUI/appharnessui.js
index a902f60..db46720 100644
--- a/AppHarnessUI/appharnessui.js
+++ b/AppHarnessUI/appharnessui.js
@@ -25,9 +25,9 @@ function eventHandler(type) {
exports.onEvent = null;
-exports.create = function(url, win) {
+exports.create = function(url, serviceNameWhitelist, win) {
exec(eventHandler, null, 'AppHarnessUI', 'events', []);
- exec(win, null, 'AppHarnessUI', 'create', [url]);
+ exec(win, null, 'AppHarnessUI', 'create', [url, serviceNameWhitelist]);
};
exports.destroy = function(win) {
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/createproject.sh
----------------------------------------------------------------------
diff --git a/createproject.sh b/createproject.sh
index accb639..d806841 100755
--- a/createproject.sh
+++ b/createproject.sh
@@ -92,6 +92,9 @@ set -x
$CORDOVA platform add $PLATFORM_ARGS || exit 1
set +x
+mkdir -p hooks/after_prepare
+cp "$AH_PATH"/template-overrides/after-hook.js hooks/after_prepare
+
# if [[ $PLATFORMS = *ios* ]]; then
# ../../cordova-ios/bin/update_cordova_subproject platforms/ios/CordovaAppHarness.xcodeproj
# fi
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/template-overrides/after-hook.js
----------------------------------------------------------------------
diff --git a/template-overrides/after-hook.js b/template-overrides/after-hook.js
new file mode 100755
index 0000000..fb6bc52
--- /dev/null
+++ b/template-overrides/after-hook.js
@@ -0,0 +1,79 @@
+#!/usr/bin/env node
+/*
+ * 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.
+*/
+
+var fs = require('fs');
+var path = require('path');
+
+var preparedWwwPathMap = {
+ 'android': path.join('platforms', 'android', 'assets' , 'www'),
+ 'ios': path.join('platforms', 'ios', 'www')
+};
+
+var platforms = process.env['CORDOVA_PLATFORMS'].split(',').filter(function(name) { return name in preparedWwwPathMap; });
+if (platforms.length === 0) {
+ return;
+}
+
+function generatePluginToServiceNamesFile() {
+ var idToServiceNameMap = {};
+
+ function extractServiceNames(p) {
+ var contents = fs.readFileSync(p, 'utf8');
+ var foundNames = {};
+ var pattern = /<feature\s+name="(.+?)"/g;
+ var match;
+ while (match = pattern.exec(contents)) {
+ foundNames[match[1]] = true;
+ }
+ return Object.keys(foundNames);
+ }
+
+ fs.readdirSync('plugins').forEach(function(p) {
+ var pluginXmlPath = path.join('plugins', p, 'plugin.xml');
+ if (fs.existsSync(pluginXmlPath)) {
+ idToServiceNameMap[p] = extractServiceNames(pluginXmlPath);
+ }
+ });
+
+ var fileContents = 'myApp.value("pluginIdToServiceNames", ' + JSON.stringify(idToServiceNameMap, null, 4) + ');\n'
+
+ platforms.forEach(function(platformId) {
+ var wwwPath = preparedWwwPathMap[platformId];
+ if (!fs.existsSync(path.join(wwwPath, 'cdvah', 'generated'))) {
+ fs.mkdirSync(path.join(wwwPath, 'cdvah', 'generated'));
+ }
+ var outPath = path.join(wwwPath, 'cdvah', 'generated', 'pluginIdToServiceNames.js');
+ fs.writeFileSync(outPath, fileContents);
+ console.log('Wrote ' + outPath);
+ });
+}
+
+// This is required only on Android, and it's required because URL remapping
+// does not work when the file exists on disk. E.g. the harness creates a new
+// cordova_plugins.js, but it doesn't get noticed due to the existing one.
+function renameCordovaPluginsFile() {
+ platforms.forEach(function(platformId) {
+ var wwwPath = preparedWwwPathMap[platformId];
+ fs.renameSync(path.join(wwwPath, 'cordova_plugins.js'), path.join(wwwPath, 'cordova_plugins_harness.js'));
+ console.log('Renamed cordova_plugins.js -> ' + path.join(wwwPath, 'cordova_plugins_harness.js'));
+ });
+}
+generatePluginToServiceNamesFile();
+renameCordovaPluginsFile();
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/www/cdvah/harnessmenu.html
----------------------------------------------------------------------
diff --git a/www/cdvah/harnessmenu.html b/www/cdvah/harnessmenu.html
index 21e0505..c4a2598 100644
--- a/www/cdvah/harnessmenu.html
+++ b/www/cdvah/harnessmenu.html
@@ -21,6 +21,7 @@
<head>
<title>Cordova App Harness</title>
<script type="text/javascript" src="../cordova.js"></script>
+ <script type="text/javascript" src="../cordova_plugins_harness.js"></script>
<script type="text/javascript" src="js/libs/angular.js"></script>
<script type="text/javascript" src="js/libs/angular-route.js"></script>
<script type="text/javascript" src="js/libs/moment.min.js"></script>
@@ -40,6 +41,7 @@
<script type="text/javascript" src="js/HttpServer.js"></script>
<script type="text/javascript" src="js/HarnessServer.js"></script>
<link rel="stylesheet" type="text/css" href="css/topcoat-mobile-light.min.css" />
+ <script type="text/javascript" src="generated/pluginIdToServiceNames.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body ng-cloak>
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/www/cdvah/js/AppHarnessUI.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppHarnessUI.js b/www/cdvah/js/AppHarnessUI.js
index 9413255..dfd84c7 100644
--- a/www/cdvah/js/AppHarnessUI.js
+++ b/www/cdvah/js/AppHarnessUI.js
@@ -19,11 +19,29 @@
(function() {
'use strict';
/* global myApp */
- myApp.factory('AppHarnessUI', ['$q', function($q) {
+ myApp.factory('AppHarnessUI', ['$q', 'pluginIdToServiceNames', function($q, pluginIdToServiceNames) {
+ function createServiceNameWhitelist(pluginMetadata) {
+ var ret = [];
+ Object.keys(pluginMetadata).forEach(function(pluginId) {
+ var serviceNames = pluginIdToServiceNames[pluginId];
+ if (serviceNames) {
+ ret.push.apply(ret, serviceNames);
+ }
+ });
+ if (cordova.platformId == 'android') {
+ // This is a plugin bundled with the platform.
+ ret.push('App');
+ // Needed for launching to work.
+ ret.push('UrlRemap');
+ }
+ return ret;
+ }
+
return {
- create: function(url) {
+ create: function(url, pluginMetadata) {
var deferred = $q.defer();
- cordova.plugins.appharnessui.create(url, deferred.resolve);
+ var serviceNames = createServiceNameWhitelist(pluginMetadata);
+ cordova.plugins.appharnessui.create(url, serviceNames, deferred.resolve);
return deferred.promise;
},
destroy: function() {
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index 27218b4..14b8c5c 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -146,12 +146,17 @@
}).then(function(launchUrl) {
// Don't just use ResourcesLoader.doesFileExist because remaps might make it exist.
return ResourcesLoader.xhrGet(launchUrl)
- .then(function() {
- return AppHarnessUI.create(launchUrl);
- }, function() {
+ .then(null, function() {
throw new Error('Start file does not exist: ' + launchUrl.replace(/.*?\/www\//, 'www/'));
}).then(function() {
+ return installer.getPluginMetadata();
+ }).then(function(pluginMetadata) {
$location.path('/inappmenu');
+ return AppHarnessUI.create(launchUrl, pluginMetadata);
+ }).then(function() {
+ if (AppsService.onAppListChange) {
+ AppsService.onAppListChange();
+ }
});
});
},
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/6362305f/www/cdvah/js/Installer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/Installer.js b/www/cdvah/js/Installer.js
index 3084bbb..44d5d07 100644
--- a/www/cdvah/js/Installer.js
+++ b/www/cdvah/js/Installer.js
@@ -135,6 +135,7 @@
if (useRemapper) {
// Override cordova.js, and www/plugins to point at bundled plugins.
+ // Note: Due to the remapper's inability to remap files that exist, this isn't strictly necessary.
UrlRemap.aliasUri('^(?!app-harness://).*/www/cordova\\.js.*', '.+', 'app-harness:///cordova.js', false /* redirect */, true /* allowFurtherRemapping */);
UrlRemap.aliasUri('^(?!app-harness://).*/www/plugins/.*', '^.*?/www/plugins/' , 'app-harness:///plugins/', false /* redirect */, true /* allowFurtherRemapping */);
[2/2] git commit: Switch to using cordova-android 4.0.x branch
Posted by ag...@apache.org.
Switch to using cordova-android 4.0.x branch
Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/4eedf4d1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/4eedf4d1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/4eedf4d1
Branch: refs/heads/master
Commit: 4eedf4d1ddcad774fa6514148ba3ef982d13123d
Parents: 48ac896
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jun 20 13:18:15 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jun 20 13:23:59 2014 -0400
----------------------------------------------------------------------
AppHarnessUI/AppHarnessUI.java | 17 +++++++----------
createproject.sh | 8 +++++++-
2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/4eedf4d1/AppHarnessUI/AppHarnessUI.java
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.java b/AppHarnessUI/AppHarnessUI.java
index 588109f..bc0db41 100644
--- a/AppHarnessUI/AppHarnessUI.java
+++ b/AppHarnessUI/AppHarnessUI.java
@@ -18,12 +18,13 @@
*/
package org.apache.appharness;
+import org.apache.cordova.AndroidChromeClient;
+import org.apache.cordova.AndroidWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaChromeClient;
import org.apache.cordova.CordovaPlugin;
-import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.IceCreamCordovaWebViewClient;
import org.apache.cordova.LinearLayoutSoftKeyboardDetect;
@@ -121,7 +122,7 @@ public class AppHarnessUI extends CordovaPlugin {
slaveWebView = new CustomCordovaWebView(activity);
initWebView(slaveWebView);
if (activity.getBooleanProperty("DisallowOverscroll", false)) {
- slaveWebView.setOverScrollMode(CordovaWebView.OVER_SCROLL_NEVER);
+ slaveWebView.setOverScrollMode(View.OVER_SCROLL_NEVER);
}
slaveWebView.clearCache(true);
slaveWebView.clearHistory();
@@ -180,7 +181,7 @@ public class AppHarnessUI extends CordovaPlugin {
}
}
- private void initWebView(final CordovaWebView newWebView) {
+ private void initWebView(final AndroidWebView newWebView) {
CordovaActivity activity = (CordovaActivity)cordova.getActivity();
if (contentView == null) {
contentView = (ViewGroup)activity.findViewById(android.R.id.content);
@@ -193,12 +194,8 @@ public class AppHarnessUI extends CordovaPlugin {
// layoutView.setBackground(origRootView.getBackground());
layoutView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.BOTTOM | Gravity.LEFT));
- if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
- newWebView.setWebViewClient(new CordovaWebViewClient(cordova, newWebView));
- } else {
- newWebView.setWebViewClient(new IceCreamCordovaWebViewClient(cordova, newWebView));
- }
- newWebView.setWebChromeClient(new CordovaChromeClient(cordova, newWebView));
+ newWebView.setWebViewClient((CordovaWebViewClient)new IceCreamCordovaWebViewClient(cordova, newWebView));
+ newWebView.setWebChromeClient((CordovaChromeClient)new AndroidChromeClient(cordova, newWebView));
newWebView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
@@ -247,7 +244,7 @@ public class AppHarnessUI extends CordovaPlugin {
}
- private class CustomCordovaWebView extends CordovaWebView {
+ private class CustomCordovaWebView extends AndroidWebView {
TwoFingerDoubleTapGestureDetector twoFingerTapDetector;
boolean stealTapEvents;
http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/4eedf4d1/createproject.sh
----------------------------------------------------------------------
diff --git a/createproject.sh b/createproject.sh
index 9eabd5c..accb639 100755
--- a/createproject.sh
+++ b/createproject.sh
@@ -26,6 +26,7 @@ if [[ $# -eq 0 || "$1" = "--help" ]]; then
echo ' APP_ID="org.apache.AppHarness"'
echo ' APP_NAME="CordovaAppHarness"'
echo ' APP_VERSION="0.0.1"'
+ echo ' ANDROID_PATH="path/to/cordova-android"'
exit 1
fi
@@ -57,6 +58,7 @@ if [[ -n "$COHO_PATH" ]]; then
CDV_PATH="$(dirname $(dirname "$COHO_PATH"))"
AddSearchPathIfExists "$CDV_PATH"
AddSearchPathIfExists "$CDV_PATH/cordova-plugins"
+ ANDROID_PATH=${ANDROID_PATH-$CDV_PATH/cordova-android}
else
# For when repos are cloned as siblings.
AddSearchPathIfExists "$(dirname "$AH_PATH")"
@@ -81,9 +83,13 @@ perl -i -pe "s/{ID}/$APP_ID/g" config.xml || exit 1
perl -i -pe "s/{NAME}/$APP_NAME/g" config.xml || exit 1
perl -i -pe "s/{VERSION}/$APP_VERSION/g" config.xml || exit 1
+PLATFORM_ARGS="$PLATFORMS"
+if [[ -n "$ANDROID_PATH" ]]; then
+ PLATFORM_ARGS="${PLATFORMS/android/$ANDROID_PATH}"
+fi
set -x
-$CORDOVA platform add $PLATFORMS || exit 1
+$CORDOVA platform add $PLATFORM_ARGS || exit 1
set +x
# if [[ $PLATFORMS = *ios* ]]; then