X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/52bc433bb1180fd2b2105403fe9f817f330da61c..c3d88a0594e32043b2599a37789b7ada4a9ac85a:/src/com/owncloud/android/authentication/SsoWebViewClient.java diff --git a/src/com/owncloud/android/authentication/SsoWebViewClient.java b/src/com/owncloud/android/authentication/SsoWebViewClient.java index 475b88db..8d80e9b7 100644 --- a/src/com/owncloud/android/authentication/SsoWebViewClient.java +++ b/src/com/owncloud/android/authentication/SsoWebViewClient.java @@ -19,14 +19,17 @@ package com.owncloud.android.authentication; import java.lang.ref.WeakReference; +import com.owncloud.android.utils.Log_OC; + + import android.graphics.Bitmap; import android.os.Handler; +import android.os.Message; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebView; import android.webkit.WebViewClient; -import com.owncloud.android.Log_OC; /** * Custom {@link WebViewClient} client aimed to catch the end of a single-sign-on process @@ -48,11 +51,13 @@ public class SsoWebViewClient extends WebViewClient { private Handler mListenerHandler; private WeakReference mListenerRef; private String mTargetUrl; + private String mLastReloadedUrlAtError; public SsoWebViewClient (Handler listenerHandler, SsoWebViewClientListener listener) { mListenerHandler = listenerHandler; mListenerRef = new WeakReference(listener); mTargetUrl = "fake://url.to.be.set"; + mLastReloadedUrlAtError = null; } public String getTargetUrl() { @@ -65,13 +70,46 @@ public class SsoWebViewClient extends WebViewClient { @Override public void onPageStarted (WebView view, String url, Bitmap favicon) { - //Log_OC.e(TAG, "onPageStarted : " + url); + Log_OC.d(TAG, "onPageStarted : " + url); + super.onPageStarted(view, url, favicon); + } + + @Override + public void onFormResubmission (WebView view, Message dontResend, Message resend) { + Log_OC.d(TAG, "onFormResubMission "); + + // necessary to grant reload of last page when device orientation is changed after sending a form + resend.sendToTarget(); + } + + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + return false; + } + + @Override + public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) { + Log_OC.e(TAG, "onReceivedError : " + failingUrl + ", code " + errorCode + ", description: " + description); + if (!failingUrl.equals(mLastReloadedUrlAtError)) { + view.reload(); + mLastReloadedUrlAtError = failingUrl; + } else { + mLastReloadedUrlAtError = null; + super.onReceivedError(view, errorCode, description, failingUrl); + } + } + + @Override + public void onPageFinished (WebView view, String url) { + Log_OC.d(TAG, "onPageFinished : " + url); + mLastReloadedUrlAtError = null; if (url.startsWith(mTargetUrl)) { view.setVisibility(View.GONE); CookieManager cookieManager = CookieManager.getInstance(); final String cookies = cookieManager.getCookie(url); + //Log_OC.d(TAG, "Cookies: " + cookies); if (mListenerHandler != null && mListenerRef != null) { - // this is good idea because onPageStarted is not running in the UI thread + // this is good idea because onPageFinished is not running in the UI thread mListenerHandler.post(new Runnable() { @Override public void run() { @@ -83,78 +121,56 @@ public class SsoWebViewClient extends WebViewClient { }); } } + } - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - //view.loadUrl(url); - return false; - } - - @Override - public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) { - Log_OC.e(TAG, "onReceivedError : " + failingUrl); - } - /* - @Override public void doUpdateVisitedHistory (WebView view, String url, boolean isReload) { - Log_OC.e(TAG, "doUpdateVisitedHistory : " + url); + Log_OC.d(TAG, "doUpdateVisitedHistory : " + url); } @Override public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) { - Log_OC.e(TAG, "onReceivedSslError : " + error); + Log_OC.d(TAG, "onReceivedSslError : " + error); } @Override public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm) { - Log_OC.e(TAG, "onReceivedHttpAuthRequest : " + host); + Log_OC.d(TAG, "onReceivedHttpAuthRequest : " + host); } @Override - public void onPageFinished (WebView view, String url) { - Log_OC.e(TAG, "onPageFinished : " + url); - } - - @Override public WebResourceResponse shouldInterceptRequest (WebView view, String url) { - Log_OC.e(TAG, "shouldInterceptRequest : " + url); + Log_OC.d(TAG, "shouldInterceptRequest : " + url); return null; } @Override public void onLoadResource (WebView view, String url) { - Log_OC.e(TAG, "onLoadResource : " + url); - } - - @Override - public void onFormResubmission (WebView view, Message dontResend, Message resend) { - Log_OC.e(TAG, "onFormResubMission "); - super.onFormResubmission(view, dontResend, resend); + Log_OC.d(TAG, "onLoadResource : " + url); } @Override public void onReceivedLoginRequest (WebView view, String realm, String account, String args) { - Log_OC.e(TAG, "onReceivedLoginRequest : " + realm + ", " + account + ", " + args); + Log_OC.d(TAG, "onReceivedLoginRequest : " + realm + ", " + account + ", " + args); } @Override public void onScaleChanged (WebView view, float oldScale, float newScale) { - Log_OC.e(TAG, "onScaleChanged : " + oldScale + " -> " + newScale); + Log_OC.d(TAG, "onScaleChanged : " + oldScale + " -> " + newScale); + super.onScaleChanged(view, oldScale, newScale); } - + @Override public void onUnhandledKeyEvent (WebView view, KeyEvent event) { - Log_OC.e(TAG, "onUnhandledKeyEvent : " + event); + Log_OC.d(TAG, "onUnhandledKeyEvent : " + event); } @Override public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event) { - Log_OC.e(TAG, "shouldOverrideKeyEvent : " + event); + Log_OC.d(TAG, "shouldOverrideKeyEvent : " + event); return false; } - */ }