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/10/25 03:26:31 UTC

[13/17] git commit: Updated webview reload to take arguments.

Updated webview reload to take arguments.

It now takes and obeys the same arguments as `create` does...
...except Android doesn't switch webview types yet.


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/634b3c4e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/634b3c4e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/634b3c4e

Branch: refs/heads/master
Commit: 634b3c4e3775577bdf9b9b183076701f976aa554
Parents: 7c884d1
Author: Max Woghiren <ma...@gmail.com>
Authored: Mon Oct 6 16:50:32 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Oct 24 21:26:07 2014 -0400

----------------------------------------------------------------------
 AppHarnessUI/AppHarnessUI.m            |  8 +++++--
 AppHarnessUI/android/AppHarnessUI.java | 37 ++++++++++++++++++-----------
 AppHarnessUI/appharnessui.js           |  9 ++++---
 www/cdvah/js/AppHarnessUI.js           |  5 ++--
 www/cdvah/js/AppsService.js            |  9 +++----
 5 files changed, 43 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/634b3c4e/AppHarnessUI/AppHarnessUI.m
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.m b/AppHarnessUI/AppHarnessUI.m
index f795061..006f2c1 100644
--- a/AppHarnessUI/AppHarnessUI.m
+++ b/AppHarnessUI/AppHarnessUI.m
@@ -129,10 +129,14 @@
 }
 
 - (void)reload:(CDVInvokedUrlCommand*)command {
+    NSString* url = [command argumentAtIndex:0];
     if (_slaveCordovaViewController == nil) {
-        NSLog(@"AppHarnessUI.reload: no url to reload");
+        NSLog(@"AppHarnessUI.reload: no webview exists");
     } else {
-        [[_slaveCordovaViewController webView] reload];
+        [_slaveCordovaViewController setStartPage:url];
+        NSURL *urlObj = [NSURL URLWithString:url];
+        NSURLRequest *requestObj = [NSURLRequest requestWithURL:urlObj];
+        [[_slaveCordovaViewController webView] loadRequest:requestObj];
     }
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/634b3c4e/AppHarnessUI/android/AppHarnessUI.java
----------------------------------------------------------------------
diff --git a/AppHarnessUI/android/AppHarnessUI.java b/AppHarnessUI/android/AppHarnessUI.java
index 7ca74a2..48dd225 100644
--- a/AppHarnessUI/android/AppHarnessUI.java
+++ b/AppHarnessUI/android/AppHarnessUI.java
@@ -53,7 +53,6 @@ public class AppHarnessUI extends CordovaPlugin {
     boolean slaveVisible;
     CallbackContext eventsCallback;
     LinearLayoutSoftKeyboardDetect layoutView;
-    String startUrl;
 
     public boolean isSlaveVisible() {
         return slaveVisible;
@@ -67,20 +66,19 @@ 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));
-            }
+            final Set<String> pluginIdWhitelistAsSet = jsonArrayToSet(args.getJSONArray(1));
             this.cordova.getActivity().runOnUiThread(new Runnable() {
                 public void run() {
                     create(url, pluginIdWhitelistAsSet, callbackContext);
                 }
             });
         } else if ("reload".equals(action)) {
+            final String url = args.getString(0);
+            final Set<String> pluginIdWhitelistAsSet = jsonArrayToSet(args.getJSONArray(1));
+            final String webViewType = args.getString(2);
             this.cordova.getActivity().runOnUiThread(new Runnable() {
                 public void run() {
-                    reload(callbackContext);
+                    reload(url, pluginIdWhitelistAsSet, webViewType, callbackContext);
                 }
             });
         } else if ("destroy".equals(action)) {
@@ -111,6 +109,14 @@ public class AppHarnessUI extends CordovaPlugin {
         return true;
     }
 
+    private Set<String> jsonArrayToSet(JSONArray jsonArray) throws JSONException {
+        final Set<String> set = new HashSet<String>(jsonArray.length());
+        for (int i = 0; i < jsonArray.length(); ++i) {
+            set.add(jsonArray.getString(i));
+        }
+        return set;
+    }
+
     public void sendEvent(String eventName) {
         if (eventsCallback != null) {
             PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, eventName);
@@ -129,7 +135,6 @@ public class AppHarnessUI extends CordovaPlugin {
     }
 
     private void create(String url, Set<String> pluginIdWhitelist, CallbackContext callbackContext) {
-        startUrl = url;
         CordovaActivity activity = (CordovaActivity)cordova.getActivity();
 
         if (slaveWebView != null) {
@@ -157,14 +162,14 @@ public class AppHarnessUI extends CordovaPlugin {
         callbackContext.success();
     }
 
-    private void reload(CallbackContext callbackContext) {
+    private void reload(String url, Set<String> pluginIdWhitelist, String webViewType, CallbackContext callbackContext) {
         if (slaveWebView == null) {
             Log.w(LOG_TAG, "reload: no webview exists");
-        } else if (startUrl == null) {
-            Log.w(LOG_TAG, "reload: no recorded start url");
         } else {
+            // TODO(maxw): If the webview type has changed, create a new webview.
+            setPluginEntries(pluginIdWhitelist);
             slaveWebView.clearCache(true);
-            slaveWebView.loadUrl(startUrl);
+            slaveWebView.loadUrl(url);
         }
         callbackContext.success();
     }
@@ -182,7 +187,6 @@ public class AppHarnessUI extends CordovaPlugin {
             slaveWebView.getView().setScaleY(1.0f);
             slaveWebView.setStealTapEvents(false);
             slaveVisible = false;
-            startUrl = null;
             sendEvent("destroyed");
         }
         if (eventsCallback != null) {
@@ -222,7 +226,7 @@ public class AppHarnessUI extends CordovaPlugin {
         }
     }
 
-    private void initWebView(final CustomCordovaWebView newWebView, Set<String> pluginIdWhitelist) {
+    private void setPluginEntries(Set<String> pluginIdWhitelist) {
         CordovaActivity activity = (CordovaActivity)cordova.getActivity();
         ConfigXmlParser parser = new ConfigXmlParser();
         // TODO: Parse the app's config.xml rather than our own config.xml.
@@ -234,7 +238,12 @@ public class AppHarnessUI extends CordovaPlugin {
             }
         }
         slaveWebView.getPluginManager().setPluginEntries(pluginEntries);
+    }
 
+    private void initWebView(final CustomCordovaWebView newWebView, Set<String> pluginIdWhitelist) {
+        setPluginEntries(pluginIdWhitelist);
+
+        CordovaActivity activity = (CordovaActivity)cordova.getActivity();
         if (contentView == null) {
             contentView = (ViewGroup)activity.findViewById(android.R.id.content);
             origMainView = contentView.getChildAt(0);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/634b3c4e/AppHarnessUI/appharnessui.js
----------------------------------------------------------------------
diff --git a/AppHarnessUI/appharnessui.js b/AppHarnessUI/appharnessui.js
index 7335ffb..0a19dcf 100644
--- a/AppHarnessUI/appharnessui.js
+++ b/AppHarnessUI/appharnessui.js
@@ -30,9 +30,12 @@ exports.create = function(url, serviceNameWhitelist, win) {
     exec(win, null, 'AppHarnessUI', 'create', [url, serviceNameWhitelist]);
 };
 
-exports.reload = function(win) {
-    exec(win, null, 'AppHarnessUI', 'reload', []);
-}
+exports.reload = function(url, serviceNameWhitelist, webViewType, win) {
+    if (webViewType != "system" && webViewType != "crosswalk") {
+        return;
+    }
+    exec(win, null, 'AppHarnessUI', 'reload', [url, serviceNameWhitelist, webViewType]);
+};
 
 exports.destroy = function(win) {
     exec(win, null, 'AppHarnessUI', 'destroy', []);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/634b3c4e/www/cdvah/js/AppHarnessUI.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppHarnessUI.js b/www/cdvah/js/AppHarnessUI.js
index 5137c83..f16fbfb 100644
--- a/www/cdvah/js/AppHarnessUI.js
+++ b/www/cdvah/js/AppHarnessUI.js
@@ -49,9 +49,10 @@
                 cordova.plugins.appharnessui.destroy(deferred.resolve);
                 return deferred.promise;
             },
-            reload: function() {
+            reload: function(url, pluginMetadata, webViewType) {
                 var deferred = $q.defer();
-                cordova.plugins.appharnessui.reload(deferred.resolve);
+                var serviceNames = createServiceNameWhitelist(pluginMetadata);
+                cordova.plugins.appharnessui.reload(url, serviceNames, webViewType, deferred.resolve);
                 return deferred.promise;
             },
             setVisible: function(value) {

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/634b3c4e/www/cdvah/js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppsService.js b/www/cdvah/js/AppsService.js
index 9c25391..2dd55c8 100644
--- a/www/cdvah/js/AppsService.js
+++ b/www/cdvah/js/AppsService.js
@@ -140,14 +140,15 @@
 
             launchApp : function(installer) {
                 // Determine whether we're relaunching the same app as is already active.
-                var relaunch = activeInstaller && activeInstaller.appId;
-                relaunch = installer && installer.appId;
-                relaunch = relaunch && (activeInstaller.appId === installer.appId);
+                var activeAppId = activeInstaller && activeInstaller.appId;
+                var newAppId = installer && installer.appId;
+                var relaunch = activeAppId && newAppId && activeAppId === newAppId;
 
                 return $q.when()
                 .then(function() {
                     // If we're relaunching the active app, move on.
                     // Otherwise, quit the active app.
+                    // TODO(maxw): Determine whether we actually ever need to quit the app.
                     if (relaunch) {
                         return $q.when();
                     } else {
@@ -169,7 +170,7 @@
                         // Otherwise, create a new one.
                         // TODO(maxw): Use the existing webview all the time.
                         if (relaunch) {
-                            return AppHarnessUI.reload();
+                            return AppHarnessUI.reload(launchUrl, pluginMetadata, 'system');
                         } else {
                             return AppHarnessUI.create(launchUrl, pluginMetadata);
                         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org