You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2012/04/24 01:33:19 UTC

android commit: Starting to move the history into the CordovaWebView, and getting the WebDriver working again

Updated Branches:
  refs/heads/CordovaWebView 483bb53d9 -> 99b3693f4


Starting to move the history into the CordovaWebView, and getting the WebDriver working again


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/99b3693f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/99b3693f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/99b3693f

Branch: refs/heads/CordovaWebView
Commit: 99b3693f40224fdafffc1d9ba2ae01c3d668dc98
Parents: 483bb53
Author: Joe Bowser <bo...@apache.org>
Authored: Mon Apr 23 16:32:59 2012 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Mon Apr 23 16:32:59 2012 -0700

----------------------------------------------------------------------
 framework/src/org/apache/cordova/App.java          |    4 +-
 .../org/apache/cordova/CordovaChromeClient.java    |    5 +-
 .../src/org/apache/cordova/CordovaWebView.java     |   84 ++++++++++++---
 .../org/apache/cordova/CordovaWebViewClient.java   |    5 +
 framework/src/org/apache/cordova/DroidGap.java     |   29 +----
 .../org/apache/cordova/test/PhoneGapSplash.java    |    2 +-
 .../src/org/apache/cordova/test/WebDriverTest.java |    2 +
 7 files changed, 90 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index 5bf232e..664fe35 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -161,7 +161,7 @@ public class App extends Plugin {
      * Clear page history for the app.
      */
     public void clearHistory() {
-    	((DroidGap)this.ctx).clearHistory();
+        webView.clearHistory();
     }
     
     /**
@@ -169,7 +169,7 @@ public class App extends Plugin {
      * This is the same as pressing the backbutton on Android device.
      */
     public void backHistory() {
-        ((DroidGap)this.ctx).backHistory();
+        webView.backHistory();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/framework/src/org/apache/cordova/CordovaChromeClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java
index f5cebb9..b915bc8 100755
--- a/framework/src/org/apache/cordova/CordovaChromeClient.java
+++ b/framework/src/org/apache/cordova/CordovaChromeClient.java
@@ -64,7 +64,10 @@ public class CordovaChromeClient extends WebChromeClient {
       appView = app;
     }
 
-    
+    public void setWebView(CordovaWebView view)
+    {
+      appView = view;
+    }
     
     /**
      * Tell the client to display a javascript alert dialog.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index ffc686d..1b139f3 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -270,6 +270,11 @@ public class CordovaWebView extends WebView {
       return false;
   }
   
+  /** 
+   * We override loadUrl so that we can track the back history
+   * @see android.webkit.WebView#loadUrl(java.lang.String)
+   */
+  
   @Override
   public void loadUrl(String url)
   {
@@ -283,25 +288,53 @@ public class CordovaWebView extends WebView {
           else {
               this.baseUrl = this.url + "/";
           }
-      }
-      
 
-      // Create callback server and plugin manager
-      if (callbackServer == null) {
-          callbackServer = new CallbackServer();
-          callbackServer.init(url);
-      }
-      else {
-          callbackServer.reinit(url);
+          // Create callback server and plugin manager
+          if (callbackServer == null) {
+            callbackServer = new CallbackServer();
+            callbackServer.init(url);
+          }
+          else {
+            callbackServer.reinit(url);
+          }
+          pluginManager.init();
+          
+          this.urls.push(url);
       }
-      pluginManager.init();
-      
-     this.urls.push(url);
     }
     
-    
     super.loadUrl(url);
   }
+  
+  
+  public void loadUrl(final String url, final int time)
+  {
+    // If not first page of app, then load immediately
+    if (this.urls.size() > 0) {
+        this.loadUrl(url);
+    }
+    
+    if (!url.startsWith("javascript:")) {
+        LOG.d(TAG, "DroidGap.loadUrl(%s, %d)", url, time);
+    }
+
+    final CordovaWebView me = this;
+    Runnable runnable = new Runnable() {
+        public void run() {
+            try {
+                synchronized(this) {
+                    this.wait(time);
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+              //I'm pretty sure this has to be on the UI thread
+              me.loadUrl(url);
+            }
+    };
+    Thread thread = new Thread(runnable);
+    thread.start();
+  }
 
   public void sendJavascript(String statement) {
     callbackServer.sendJavascript(statement);
@@ -330,4 +363,29 @@ public class CordovaWebView extends WebView {
   public void pushUrl(String url) {
       urls.push(url);
   }
+
+  /**
+   * Go to previous page in history.  (We manage our own history)
+   * 
+   * @return true if we went back, false if we are already at top
+   */
+  public boolean backHistory() {
+
+      // Check webview first to see if there is a history
+      // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
+      if (this.canGoBack()) {
+          this.goBack();  
+          return true;
+      }
+
+      // If our managed history has prev url
+      if (this.urls.size() > 1) {
+          this.urls.pop();                // Pop current url
+          String url = this.urls.pop();   // Pop prev url that we want to load, since it will be added back by loadUrl()
+          loadUrl(url);
+          return true;
+      }
+      
+      return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index 20dbcbc..7338ed2 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -61,6 +61,11 @@ public class CordovaWebViewClient extends WebViewClient {
       appView = view;
     }
     
+    public void setWebView(CordovaWebView view)
+    {
+      appView = view;
+    }
+    
     /**
      * Give the host application a chance to take over the control when a new url 
      * is about to be loaded in the current WebView.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index 85a217f..e523b00 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -531,30 +531,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         }
     }
     
-    /**
-     * Go to previous page in history.  (We manage our own history)
-     * 
-     * @return true if we went back, false if we are already at top
-     */
-    public boolean backHistory() {
-
-        // Check webview first to see if there is a history
-        // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
-        if (this.appView.canGoBack()) {
-            this.appView.goBack();  
-            return true;
-        }
-
-        // If our managed history has prev url
-        if (this.urls.size() > 1) {
-            this.urls.pop();                // Pop current url
-            String url = this.urls.pop();   // Pop prev url that we want to load, since it will be added back by loadUrl()
-            this.loadUrl(url);
-            return true;
-        }
-        
-        return false;
-    }
+    
 
     @Override
     /**
@@ -1208,4 +1185,8 @@ public class DroidGap extends Activity implements CordovaInterface {
       return this.bound;
     }
 
+    public boolean backHistory() {
+      return appView.backHistory();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/test/src/org/apache/cordova/test/PhoneGapSplash.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/PhoneGapSplash.java b/test/src/org/apache/cordova/test/PhoneGapSplash.java
index 104720d..bda34b3 100644
--- a/test/src/org/apache/cordova/test/PhoneGapSplash.java
+++ b/test/src/org/apache/cordova/test/PhoneGapSplash.java
@@ -14,7 +14,7 @@ public class PhoneGapSplash extends Activity {
         setContentView(R.layout.main);
         
         phoneGap = (CordovaWebView) findViewById(R.id.phoneGapView);
-        //phoneGap.loadUrl("file:///android_asset/index.html", 5000);
+        phoneGap.loadUrl("file:///android_asset/index.html", 5000);
     }
     
     public void onDestroy()

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/99b3693f/test/src/org/apache/cordova/test/WebDriverTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/WebDriverTest.java b/test/src/org/apache/cordova/test/WebDriverTest.java
index 5cf7dc4..31a3cca 100644
--- a/test/src/org/apache/cordova/test/WebDriverTest.java
+++ b/test/src/org/apache/cordova/test/WebDriverTest.java
@@ -34,6 +34,8 @@ public class WebDriverTest extends ActivityInstrumentationTestCase2<CordovaDrive
 		viewHandler = new CordovaWebViewClient(testActivity);
 		testDriver = new AndroidWebDriver(testActivity, viewFactory, viewHandler, appCode);
 		testView = (CordovaWebView) testDriver.getWebView();
+		viewHandler.setWebView(testView);
+		appCode.setWebView(testView);
 	}
 	
 	public void testPreconditions(){