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/03/26 19:22:58 UTC
android commit: Work on CB-369, Moving Authentication OUT of DroidGap
Updated Branches:
refs/heads/CordovaWebView 8ecfcb12c -> 6dabe4c01
Work on CB-369, Moving Authentication OUT of DroidGap
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/6dabe4c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/6dabe4c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/6dabe4c0
Branch: refs/heads/CordovaWebView
Commit: 6dabe4c0102e5474a887a3297a11abbaff50d9ae
Parents: 8ecfcb1
Author: Joe Bowser <bo...@apache.org>
Authored: Mon Mar 26 10:22:37 2012 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Mon Mar 26 10:22:37 2012 -0700
----------------------------------------------------------------------
.../src/org/apache/cordova/CordovaWebView.java | 90 ++++++++++++++-
.../org/apache/cordova/CordovaWebViewClient.java | 3 +-
framework/src/org/apache/cordova/DroidGap.java | 84 --------------
3 files changed, 90 insertions(+), 87 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/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 ff80992..526a183 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -1,11 +1,16 @@
package org.apache.cordova;
+import java.util.Hashtable;
+
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
public class CordovaWebView extends WebView {
-
+
+ /** The authorization tokens. */
+ private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
+
public CordovaWebView(Context context) {
super(context);
}
@@ -22,5 +27,86 @@ public class CordovaWebView extends WebView {
boolean privateBrowsing) {
super(context, attrs, defStyle, privateBrowsing);
}
-
+
+ /**
+ * Sets the authentication token.
+ *
+ * @param authenticationToken
+ * the authentication token
+ * @param host
+ * the host
+ * @param realm
+ * the realm
+ */
+ public void setAuthenticationToken(AuthenticationToken authenticationToken, String host, String realm) {
+
+ if(host == null) {
+ host = "";
+ }
+
+ if(realm == null) {
+ realm = "";
+ }
+
+ authenticationTokens.put(host.concat(realm), authenticationToken);
+ }
+
+ /**
+ * Removes the authentication token.
+ *
+ * @param host
+ * the host
+ * @param realm
+ * the realm
+ * @return the authentication token or null if did not exist
+ */
+ public AuthenticationToken removeAuthenticationToken(String host, String realm) {
+ return authenticationTokens.remove(host.concat(realm));
+ }
+
+ /**
+ * Gets the authentication token.
+ *
+ * In order it tries:
+ * 1- host + realm
+ * 2- host
+ * 3- realm
+ * 4- no host, no realm
+ *
+ * @param host
+ * the host
+ * @param realm
+ * the realm
+ * @return the authentication token
+ */
+ public AuthenticationToken getAuthenticationToken(String host, String realm) {
+ AuthenticationToken token = null;
+
+ token = authenticationTokens.get(host.concat(realm));
+
+ if(token == null) {
+ // try with just the host
+ token = authenticationTokens.get(host);
+
+ // Try the realm
+ if(token == null) {
+ token = authenticationTokens.get(realm);
+ }
+
+ // if no host found, just query for default
+ if(token == null) {
+ token = authenticationTokens.get("");
+ }
+ }
+
+ return token;
+ }
+
+ /**
+ * Clear all authentication tokens.
+ */
+ public void clearAuthenticationTokens() {
+ authenticationTokens.clear();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/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 5eb2406..2651687 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -173,7 +173,8 @@ public class CordovaWebViewClient extends WebViewClient {
String realm) {
// get the authentication token
- AuthenticationToken token = ctx.getAuthenticationToken(host,realm);
+ // Note: The WebView MUST be a CordoaWebView
+ AuthenticationToken token = ((CordovaWebView) view).getAuthenticationToken(host,realm);
if(token != null) {
handler.proceed(token.getUserName(), token.getPassword());
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6dabe4c0/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 39d5c31..f5e256e 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -191,9 +191,6 @@ public class DroidGap extends Activity implements CordovaInterface {
// (this is not the color for the webview, which is set in HTML)
private int backgroundColor = Color.BLACK;
- /** The authorization tokens. */
- private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
-
/*
* The variables below are used to cache some of the activity properties.
*/
@@ -212,87 +209,6 @@ public class DroidGap extends Activity implements CordovaInterface {
// preferences read from cordova.xml
protected PreferenceSet preferences;
-
- /**
- * Sets the authentication token.
- *
- * @param authenticationToken
- * the authentication token
- * @param host
- * the host
- * @param realm
- * the realm
- */
- public void setAuthenticationToken(AuthenticationToken authenticationToken, String host, String realm) {
-
- if(host == null) {
- host = "";
- }
-
- if(realm == null) {
- realm = "";
- }
-
- authenticationTokens.put(host.concat(realm), authenticationToken);
- }
-
- /**
- * Removes the authentication token.
- *
- * @param host
- * the host
- * @param realm
- * the realm
- * @return the authentication token or null if did not exist
- */
- public AuthenticationToken removeAuthenticationToken(String host, String realm) {
- return authenticationTokens.remove(host.concat(realm));
- }
-
- /**
- * Gets the authentication token.
- *
- * In order it tries:
- * 1- host + realm
- * 2- host
- * 3- realm
- * 4- no host, no realm
- *
- * @param host
- * the host
- * @param realm
- * the realm
- * @return the authentication token
- */
- public AuthenticationToken getAuthenticationToken(String host, String realm) {
- AuthenticationToken token = null;
-
- token = authenticationTokens.get(host.concat(realm));
-
- if(token == null) {
- // try with just the host
- token = authenticationTokens.get(host);
-
- // Try the realm
- if(token == null) {
- token = authenticationTokens.get(realm);
- }
-
- // if no host found, just query for default
- if(token == null) {
- token = authenticationTokens.get("");
- }
- }
-
- return token;
- }
-
- /**
- * Clear all authentication tokens.
- */
- public void clearAuthenticationTokens() {
- authenticationTokens.clear();
- }
/**