Fixed state of embedded web view for creation of second and later accounts, and for...
authorDavid A. Velasco <dvelasco@solidgear.es>
Mon, 12 Aug 2013 10:55:01 +0000 (12:55 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Mon, 12 Aug 2013 10:55:01 +0000 (12:55 +0200)
src/com/owncloud/android/authentication/AuthenticatorActivity.java

index 50360c0..0e8ba48 100644 (file)
@@ -231,7 +231,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 mHostUrlInput.setText(mHostBaseUrl);\r
             }\r
             initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
-            mOAuth2Check.setChecked(mCurrentAuthTokenType == AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN);\r
             mJustCreated = true;\r
             \r
             if (mAction == ACTION_UPDATE_TOKEN || !mHostUrlInputEnabled) {\r
@@ -263,6 +262,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mCurrentAuthTokenType = savedInstanceState.getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
             if (mCurrentAuthTokenType == null) {\r
                 mCurrentAuthTokenType =  AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;\r
+                \r
+            } else if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
+                restoreWebView(savedInstanceState);\r
             }\r
 \r
             // check if server check was interrupted by a configuration change\r
@@ -293,7 +295,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         if (mServerIsChecked && !mServerIsValid && refreshButtonEnabled) showRefreshButton();\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
-        if (mCurrentAuthTokenType == AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE || \r
+        if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType) || \r
                 !AUTH_OPTIONAL.equals(getString(R.string.auth_method_oauth2))) {\r
             mOAuth2Check.setVisibility(View.GONE);\r
         }\r
@@ -337,7 +339,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
        private void initWebView() {\r
         CookieManager cookieManager = CookieManager.getInstance();\r
         cookieManager.setAcceptCookie(true);\r
-        //cookieManager.removeSessionCookie();        \r
+        cookieManager.removeAllCookie();\r
 \r
         mWebViewClient = new SsoWebViewClient(mHandler, this);\r
         mSsoWebView.setWebViewClient(mWebViewClient);\r
@@ -349,6 +351,25 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         webSettings.setUserAgentString(WebdavClient.USER_AGENT);\r
     }\r
 \r
+    @SuppressLint("SetJavaScriptEnabled")\r
+    private void restoreWebView(Bundle savedInstanceState) {\r
+        mSsoWebView.restoreState(savedInstanceState);\r
+        \r
+        CookieManager cookieManager = CookieManager.getInstance();\r
+        Log_OC.e(TAG, "Accept Cookie: " + cookieManager.acceptCookie());\r
+\r
+        mWebViewClient = new SsoWebViewClient(mHandler, this);\r
+        mSsoWebView.setWebViewClient(mWebViewClient);\r
+        mWebViewClient.setTargetUrl(mHostBaseUrl + AccountUtils.getWebdavPath(mDiscoveredVersion, mCurrentAuthTokenType));\r
+        \r
+        WebSettings webSettings = mSsoWebView.getSettings();\r
+        webSettings.setJavaScriptEnabled(true);     // at least this one is not being kept by WebView#restoreState\r
+        webSettings.setBuiltInZoomControls(true);\r
+        webSettings.setLoadWithOverviewMode(false);\r
+        webSettings.setSavePassword(false);\r
+        webSettings.setUserAgentString(WebdavClient.USER_AGENT);\r
+    }\r
+\r
     private void initAuthorizationMethod() {\r
         boolean oAuthRequired = false;\r
         boolean samlWebSsoRequired = false;\r
@@ -382,6 +403,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
             mUsernameInput.setText(userName);\r
         }\r
+        \r
+        if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
+            initWebView();\r
+        }\r
+        mOAuth2Check.setChecked(AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(mCurrentAuthTokenType));\r
+        \r
     }\r
 \r
     /**\r
@@ -418,6 +445,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
         }\r
         outState.putString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE, mCurrentAuthTokenType);\r
+        if (AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mCurrentAuthTokenType)) {\r
+            mSsoWebView.saveState(outState);\r
+        }\r
         \r
         // refresh button enabled\r
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
@@ -1418,7 +1448,6 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mPasswordInput.setVisibility(View.GONE);\r
             mAccountNameInput.setVisibility(View.VISIBLE);\r
             mSsoWebView.setVisibility(View.VISIBLE);\r
-            initWebView();\r
             \r
         } else {\r
             // basic HTTP authorization\r