incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject android commit: Partially moved the callback server into the WebView. The WebView MUST own the CordovaWebViewClient and the CordovaWebChromeClient
Date Wed, 28 Mar 2012 23:50:18 GMT
Updated Branches:
  refs/heads/CordovaWebView 59ff94fef -> b793fbfc2


Partially moved the callback server into the WebView.  The WebView MUST own the CordovaWebViewClient
and the CordovaWebChromeClient


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/b793fbfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/b793fbfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/b793fbfc

Branch: refs/heads/CordovaWebView
Commit: b793fbfc28cadc7d362c1fbc402d1f5201bb5bea
Parents: 59ff94f
Author: Joe Bowser <bowserj@apache.org>
Authored: Wed Mar 28 16:49:59 2012 -0700
Committer: Joe Bowser <bowserj@apache.org>
Committed: Wed Mar 28 16:49:59 2012 -0700

----------------------------------------------------------------------
 .../org/apache/cordova/CordovaChromeClient.java    |   10 +++-
 .../src/org/apache/cordova/CordovaWebView.java     |   18 ++++++-
 .../org/apache/cordova/CordovaWebViewClient.java   |   11 ++++-
 framework/src/org/apache/cordova/DroidGap.java     |   43 +++------------
 4 files changed, 42 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b793fbfc/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 e9f8f93..49ec1b5 100755
--- a/framework/src/org/apache/cordova/CordovaChromeClient.java
+++ b/framework/src/org/apache/cordova/CordovaChromeClient.java
@@ -45,6 +45,7 @@ public class CordovaChromeClient extends WebChromeClient {
     private String TAG = "CordovaLog";
     private long MAX_QUOTA = 100 * 1024 * 1024;
     private DroidGap ctx;
+    private CordovaWebView appView;
     
     /**
      * Constructor.
@@ -53,6 +54,13 @@ public class CordovaChromeClient extends WebChromeClient {
      */
     public CordovaChromeClient(Context ctx) {
         this.ctx = (DroidGap) ctx;
+        appView = this.ctx.appView;
+    }
+    
+    public CordovaChromeClient(Context ctx, CordovaWebView app)
+    {
+      this.ctx = (DroidGap) ctx;
+      appView = app;
     }
 
     /**
@@ -182,7 +190,7 @@ public class CordovaChromeClient extends WebChromeClient {
                 String action = array.getString(1);
                 String callbackId = array.getString(2);
                 boolean async = array.getBoolean(3);
-                String r = ctx.pluginManager.exec(service, action, callbackId, message, async);
+                String r = appView.pluginManager.exec(service, action, callbackId, message,
async);
                 result.confirm(r);
             } catch (JSONException e) {
                 e.printStackTrace();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b793fbfc/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 c55877f..aaa11ed 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -9,6 +9,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.cordova.api.LOG;
+import org.apache.cordova.api.PluginManager;
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.Context;
@@ -24,10 +25,16 @@ public class CordovaWebView extends WebView {
   
   /** The authorization tokens. */
   private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String,
AuthenticationToken>();
-  private Context mCtx;
+  
   /** The whitelist **/
   private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
   private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
+  protected PluginManager pluginManager;
+  
+  /** Actvities and other important classes **/
+  private Context mCtx;
+  private CordovaWebViewClient viewClient;
+  private CordovaChromeClient chromeClient;
 
   public CordovaWebView(Context context) {
     super(context);
@@ -73,12 +80,19 @@ public class CordovaWebView extends WebView {
     settings.setDatabaseEnabled(true);
     String databasePath = mCtx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();

     settings.setDatabasePath(databasePath);
-
+    
+    //Setup the WebChromeClient and WebViewClient
+    setWebViewClient(new CordovaWebViewClient(mCtx, this));
+    setWebChromeClient(new CordovaChromeClient(mCtx, this));
+    
     // Enable DOM storage
     settings.setDomStorageEnabled(true);
     
     // Enable built-in geolocation
     settings.setGeolocationEnabled(true);
+    
+    //Start up the plugin manager
+    this.pluginManager = new PluginManager(this, (DroidGap) mCtx);
   }
   
   /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b793fbfc/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 2651687..1daf759 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -20,6 +20,7 @@ package org.apache.cordova;
 
 import org.apache.cordova.api.LOG;
 
+import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager;
@@ -41,6 +42,7 @@ public class CordovaWebViewClient extends WebViewClient {
     
     private static final String TAG = "Cordova";
     DroidGap ctx;
+    CordovaWebView appView;
     private boolean doClearHistory = false;
 
     /**
@@ -50,6 +52,13 @@ public class CordovaWebViewClient extends WebViewClient {
      */
     public CordovaWebViewClient(DroidGap ctx) {
         this.ctx = ctx;
+        appView = ctx.appView;
+    }
+    
+    public CordovaWebViewClient(Context ctx, CordovaWebView view)
+    {
+      this.ctx = (DroidGap) ctx;
+      appView = view;
     }
     
     /**
@@ -64,7 +73,7 @@ public class CordovaWebViewClient extends WebViewClient {
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
         
         // First give any plugins the chance to handle the url themselves
-        if ((this.ctx.pluginManager != null) && this.ctx.pluginManager.onOverrideUrlLoading(url))
{
+        if ((appView.pluginManager != null) && appView.pluginManager.onOverrideUrlLoading(url))
{
         }
         
         // If dialing phone (tel:5551212)

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b793fbfc/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 f586419..5f9e3bd 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -156,7 +156,6 @@ public class DroidGap extends Activity implements CordovaInterface {
     protected LinearLayout root;
     public boolean bound = false;
     public CallbackServer callbackServer;
-    protected PluginManager pluginManager;
     protected boolean cancelLoadUrl = false;
     protected ProgressDialog spinnerDialog = null;
 
@@ -285,9 +284,6 @@ public class DroidGap extends Activity implements CordovaInterface {
                 ViewGroup.LayoutParams.FILL_PARENT, 
                 1.0F));
 
-       	this.appView.setWebChromeClient(webChromeClient);
-       	this.setWebViewClient(this.appView, webViewClient);
-
         // Add web view but make it invisible while loading URL
         this.appView.setVisibility(View.INVISIBLE);
         root.addView(this.appView);
@@ -296,22 +292,9 @@ public class DroidGap extends Activity implements CordovaInterface {
         // Clear cancel flag
         this.cancelLoadUrl = false;
         
-        // Create plugin manager
-        this.pluginManager = new PluginManager(this.appView, this);
     }
     
     /**
-     * Set the WebViewClient.
-     * 
-     * @param appView
-     * @param client
-     */
-    protected void setWebViewClient(WebView appView, WebViewClient client) {
-        this.webViewClient = client;
-        appView.setWebViewClient(client);
-    }
-
-    /**
      * Look at activity parameters and process them.
      * This must be called from the main UI thread.
      */
@@ -403,7 +386,7 @@ public class DroidGap extends Activity implements CordovaInterface {
                 else {
                     me.callbackServer.reinit(url);
                 }
-                me.pluginManager.init();
+                appView.pluginManager.init();
                 
                 // If loadingDialog property, then show the App loading dialog for first
page of app
                 String loading = null;
@@ -734,9 +717,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception
firing pause event from native');};");
 
         // Forward to plugins
-        if (this.pluginManager != null) {
-        	this.pluginManager.onPause(this.keepRunning);
-        }
+        appView.pluginManager.onPause(this.keepRunning);
         
         // If app doesn't want to run in background
         if (!this.keepRunning) {
@@ -754,9 +735,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         super.onNewIntent(intent);
 
         //Forward to plugins
-        if (this.pluginManager != null) {
-        	this.pluginManager.onNewIntent(intent);
-        }
+        appView.pluginManager.onNewIntent(intent);
     }
     
     @Override
@@ -779,9 +758,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception
firing resume event from native');};");
 
         // Forward to plugins
-        if (this.pluginManager != null) {
-        	this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
-        }
+        appView.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
         
         // If app doesn't want to run in background
         if (!this.keepRunning || this.activityResultKeepRunning) {
@@ -814,9 +791,7 @@ public class DroidGap extends Activity implements CordovaInterface {
             this.appView.loadUrl("about:blank");
 
             // Forward to plugins
-            if (this.pluginManager != null) {
-                this.pluginManager.onDestroy();
-            }
+            appView.pluginManager.onDestroy();
         }
         else {
             this.endActivity();
@@ -832,9 +807,7 @@ public class DroidGap extends Activity implements CordovaInterface {
     public void postMessage(String id, Object data) {
         
         // Forward to plugins
-        if (this.pluginManager != null) {
-            this.pluginManager.postMessage(id, data);
-        }
+        appView.pluginManager.postMessage(id, data);
     }
 
     /**
@@ -848,9 +821,7 @@ public class DroidGap extends Activity implements CordovaInterface {
      */
     @Deprecated
     public void addService(String serviceType, String className) {
-        if (this.pluginManager != null) {
-        	this.pluginManager.addService(serviceType, className);
-        }
+        appView.pluginManager.addService(serviceType, className);
     }
     
     /**


Mime
View raw message