You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sg...@apache.org on 2015/11/20 18:00:29 UTC
cordova-plugin-inappbrowser git commit: CB-8534: Allow plugins to
respond to onReceivedHttpAuthRequest. This closes #82
Repository: cordova-plugin-inappbrowser
Updated Branches:
refs/heads/master 52cfd3216 -> 9b576f303
CB-8534: Allow plugins to respond to onReceivedHttpAuthRequest. This closes #82
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/9b576f30
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/9b576f30
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/9b576f30
Branch: refs/heads/master
Commit: 9b576f303b87f30b5054c47240c1e815415da374
Parents: 52cfd32
Author: Connor Pearson <cj...@gmail.com>
Authored: Tue Feb 24 13:48:14 2015 -0500
Committer: sgrebnov <v-...@microsoft.com>
Committed: Fri Nov 20 19:59:43 2015 +0300
----------------------------------------------------------------------
src/android/InAppBrowser.java | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/9b576f30/src/android/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 6043745..8487b64 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -41,6 +41,7 @@ import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager;
+import android.webkit.HttpAuthHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@@ -52,6 +53,7 @@ import android.widget.RelativeLayout;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.Config;
import org.apache.cordova.CordovaArgs;
+import org.apache.cordova.CordovaHttpAuthHandler;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
@@ -61,6 +63,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.StringTokenizer;
@@ -864,6 +867,39 @@ public class InAppBrowser extends CordovaPlugin {
Log.d(LOG_TAG, "Should never happen");
}
}
+
+ /**
+ * On received http auth request.
+ */
+ @Override
+ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
+
+ // Check if there is some plugin which can resolve this auth challenge
+ PluginManager pluginManager = null;
+ try {
+ Method gpm = webView.getClass().getMethod("getPluginManager");
+ pluginManager = (PluginManager)gpm.invoke(webView);
+ } catch (NoSuchMethodException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ }
+
+ if (pluginManager == null) {
+ try {
+ Field pmf = webView.getClass().getField("pluginManager");
+ pluginManager = (PluginManager)pmf.get(webView);
+ } catch (NoSuchFieldException e) {
+ } catch (IllegalAccessException e) {
+ }
+ }
+
+ if (pluginManager != null && pluginManager.onReceivedHttpAuthRequest(webView, new CordovaHttpAuthHandler(handler), host, realm)) {
+ return;
+ }
+
+ // By default handle 401 like we'd normally do!
+ super.onReceivedHttpAuthRequest(view, handler, host, realm);
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org