X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/9dacdbec0b54e2255700747c7f6076024f7b5717..55f2bd23e6e0464ec68f3bd6beb43ae72b30b717:/src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java diff --git a/src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java b/src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java index 2d0ac94a..17a1e13f 100644 --- a/src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java +++ b/src/com/owncloud/android/ui/dialog/SamlWebViewDialog.java @@ -1,6 +1,7 @@ package com.owncloud.android.ui.dialog; import android.annotation.SuppressLint; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; @@ -11,7 +12,6 @@ import android.webkit.WebSettings; import android.webkit.WebView; import com.owncloud.android.Log_OC; -import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.authentication.SsoWebViewClient; import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener; @@ -23,7 +23,7 @@ import eu.alefzero.webdav.WebdavClient; * @author Maria Asensio */ public class SamlWebViewDialog extends DialogFragment - implements SsoWebViewClientListener{ + { public final String SAML_DIALOG_TAG = "SamlWebViewDialog"; @@ -35,7 +35,9 @@ public class SamlWebViewDialog extends DialogFragment private static String mUrl; private static String mTargetUrl; - private static Handler mHandler; + private Handler mHandler; + + private SsoWebViewClientListener mSsoWebViewClientListener; /** @@ -46,9 +48,9 @@ public class SamlWebViewDialog extends DialogFragment * @param targetURL mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType) * @return New dialog instance, ready to show. */ - public static SamlWebViewDialog newInstance(Handler handler,String url, String targetUrl) { + public static SamlWebViewDialog newInstance(String url, String targetUrl) { SamlWebViewDialog fragment = new SamlWebViewDialog(); - mHandler = handler; + mUrl = url; mTargetUrl = targetUrl; return fragment; @@ -63,63 +65,69 @@ public class SamlWebViewDialog extends DialogFragment mSsoWebView.saveState(outState); } - - @Override + @SuppressLint("SetJavaScriptEnabled") + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Log_OC.d(TAG, "On Create Dialog"); - /// load the dialog - initWebView(savedInstanceState); - setRetainInstance(true); - /// build the dialog - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + mHandler = new Handler(); + + mSsoWebView = new WebView(getActivity()) { + @Override + public boolean onCheckIsTextEditor() { + return true; + } + }; + + + mWebViewClient = new SsoWebViewClient(mHandler, mSsoWebViewClientListener); + mSsoWebView.setWebViewClient(mWebViewClient); + mWebViewClient.setTargetUrl(mTargetUrl); + + mSsoWebView.setFocusable(true); + mSsoWebView.setFocusableInTouchMode(true); + mSsoWebView.setClickable(true); + + WebSettings webSettings = mSsoWebView.getSettings(); + webSettings.setJavaScriptEnabled(true); + webSettings.setBuiltInZoomControls(true); + webSettings.setLoadWithOverviewMode(false); + webSettings.setSavePassword(false); + webSettings.setUserAgentString(WebdavClient.USER_AGENT); + + // load the dialog + if (savedInstanceState == null) { + initWebView(); + } + else { + restoreWebView(savedInstanceState); + } + // build the dialog + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); Dialog dialog = builder.setView(mSsoWebView).create(); return dialog; } - @SuppressLint("SetJavaScriptEnabled") - private void initWebView(Bundle savedInstanceState) { + private void initWebView() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); - //cookieManager.removeSessionCookie(); + cookieManager.removeAllCookie(); - mWebViewClient = new SsoWebViewClient(mHandler, this); - mWebViewClient.setTargetUrl(mTargetUrl); - if (savedInstanceState == null) { - - Log_OC.d(TAG, "Saved Instance State NULL"); - mSsoWebView = new WebView(getActivity()) { - @Override - public boolean onCheckIsTextEditor() { - return true; - } - }; - - mSsoWebView.setWebViewClient(mWebViewClient); - mSsoWebView.setFocusable(true); - mSsoWebView.setFocusableInTouchMode(true); - mSsoWebView.setClickable(true); - - WebSettings webSettings = mSsoWebView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setBuiltInZoomControls(true); - webSettings.setLoadWithOverviewMode(false); - webSettings.setSavePassword(false); - webSettings.setUserAgentString(WebdavClient.USER_AGENT); - - mSsoWebView.loadUrl(mUrl); - } - else { - Log_OC.d(TAG, "Saved Instance State NOT NULL"); - - mSsoWebView.restoreState(savedInstanceState); - } - + mSsoWebView.loadUrl(mUrl); } + @SuppressLint("SetJavaScriptEnabled") + private void restoreWebView(Bundle savedInstanceState) { + mSsoWebView.restoreState(savedInstanceState); + + CookieManager cookieManager = CookieManager.getInstance(); + Log_OC.e(TAG, "Accept Cookie: " + cookieManager.acceptCookie()); + } + + @Override public void onDestroyView() { Dialog dialog = getDialog(); @@ -133,18 +141,13 @@ public class SamlWebViewDialog extends DialogFragment @Override - public void onSsoFinished(String sessionCookie) { - //Toast.makeText(this, "got cookies: " + sessionCookie, Toast.LENGTH_LONG).show(); - - if (sessionCookie != null && sessionCookie.length() > 0) { - Log_OC.d(TAG, "Successful SSO - time to save the account"); - ((AuthenticatorActivity) getActivity()).onSamlDialogSuccess(sessionCookie); - dismiss(); - - } else { - // TODO - show fail - Log_OC.d(TAG, "SSO failed"); + public void onAttach(Activity activity) { + super.onAttach(activity); + Log_OC.e(TAG, "onAttach"); + try { + mSsoWebViewClientListener = (SsoWebViewClientListener) activity; + } catch (ClassCastException e) { + throw new ClassCastException(activity.toString() + " must implement " + SsoWebViewClientListener.class.getSimpleName()); } } - } \ No newline at end of file