1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.authentication
;
20 import android
.content
.Context
;
21 import android
.graphics
.Bitmap
;
22 import android
.view
.View
;
23 import android
.webkit
.CookieManager
;
24 import android
.webkit
.WebView
;
25 import android
.webkit
.WebViewClient
;
26 import android
.widget
.Toast
;
28 import com
.owncloud
.android
.Log_OC
;
31 * Custom {@link WebViewClient} client aimed to catch the end of a single-sign-on process
32 * running in the {@link WebView} that is attached to.
34 * Assumes that the single-sign-on is kept thanks to a cookie set at the end of the
35 * authentication process.
37 * @author David A. Velasco
39 public class SsoWebViewClient
extends WebViewClient
{
41 private static final String TAG
= SsoWebViewClient
.class.getSimpleName();
43 private Context mContext
;
44 private String mTargetUrl
;
46 public SsoWebViewClient (Context context
) {
48 mTargetUrl
= "fake://url.to.be.set";
51 public String
getTargetUrl() {
55 public void setTargetUrl(String targetUrl
) {
56 mTargetUrl
= targetUrl
;
60 public void onPageStarted (WebView view
, String url
, Bitmap favicon
) {
61 //Log_OC.e(TAG, "onPageStarted : " + url);
62 if (url
.startsWith(mTargetUrl
)) {
63 view
.setVisibility(View
.GONE
);
64 CookieManager cookieManager
= CookieManager
.getInstance();
65 String cookies
= cookieManager
.getCookie(url
);
66 Toast
.makeText(mContext
, "got cookies: " + cookies
, Toast
.LENGTH_LONG
).show();
71 public boolean shouldOverrideUrlLoading(WebView view
, String url
) {
77 public void onReceivedError (WebView view
, int errorCode
, String description
, String failingUrl
) {
78 Log_OC
.e(TAG
, "onReceivedError : " + failingUrl
);
84 public void doUpdateVisitedHistory (WebView view, String url, boolean isReload) {
85 Log_OC.e(TAG, "doUpdateVisitedHistory : " + url);
89 public void onPageFinished (WebView view, String url) {
90 Log_OC.e(TAG, "onPageFinished : " + url);
94 public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
95 Log_OC.e(TAG, "onReceivedSslError : " + error);
99 public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm) {
100 Log_OC.e(TAG, "onReceivedHttpAuthRequest : " + host);
104 public WebResourceResponse shouldInterceptRequest (WebView view, String url) {
105 Log_OC.e(TAG, "shouldInterceptRequest : " + url);
110 public void onLoadResource (WebView view, String url) {
111 Log_OC.e(TAG, "onLoadResource : " + url);
115 public void onFormResubmission (WebView view, Message dontResend, Message resend) {
116 Log_OC.e(TAG, "onFormResubMission ");
117 super.onFormResubmission(view, dontResend, resend);
121 public void onReceivedLoginRequest (WebView view, String realm, String account, String args) {
122 Log_OC.e(TAG, "onReceivedLoginRequest : " + realm + ", " + account + ", " + args);
126 public void onScaleChanged (WebView view, float oldScale, float newScale) {
127 Log_OC.e(TAG, "onScaleChanged : " + oldScale + " -> " + newScale);
131 public void onUnhandledKeyEvent (WebView view, KeyEvent event) {
132 Log_OC.e(TAG, "onUnhandledKeyEvent : " + event);
136 public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event) {
137 Log_OC.e(TAG, "shouldOverrideKeyEvent : " + event);