• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.browser;
18 
19 import android.graphics.Bitmap;
20 import android.net.http.SslError;
21 import android.os.Message;
22 import android.view.KeyEvent;
23 import android.webkit.ClientCertRequestHandler;
24 import android.webkit.HttpAuthHandler;
25 import android.webkit.SslErrorHandler;
26 import android.webkit.WebView;
27 import android.webkit.WebViewClient;
28 import android.webkit.WebViewClientClassicExt;
29 
30 /**
31  *
32  *
33  * WebViewClient for browser tests.
34  * Wraps around existing client so that specific methods can be overridden if needed.
35  *
36  */
37 abstract class TestWebViewClient extends WebViewClientClassicExt {
38 
39   private WebViewClient mWrappedClient;
40 
TestWebViewClient(WebViewClient wrappedClient)41   protected TestWebViewClient(WebViewClient wrappedClient) {
42     mWrappedClient = wrappedClient;
43   }
44 
45   /** {@inheritDoc} */
46   @Override
shouldOverrideUrlLoading(WebView view, String url)47   public boolean shouldOverrideUrlLoading(WebView view, String url) {
48       return mWrappedClient.shouldOverrideUrlLoading(view, url);
49   }
50 
51   /** {@inheritDoc} */
52   @Override
onPageStarted(WebView view, String url, Bitmap favicon)53   public void onPageStarted(WebView view, String url, Bitmap favicon) {
54     mWrappedClient.onPageStarted(view, url, favicon);
55   }
56 
57   /** {@inheritDoc} */
58   @Override
onPageFinished(WebView view, String url)59   public void onPageFinished(WebView view, String url) {
60     mWrappedClient.onPageFinished(view, url);
61   }
62 
63   /** {@inheritDoc} */
64   @Override
onLoadResource(WebView view, String url)65   public void onLoadResource(WebView view, String url) {
66     mWrappedClient.onLoadResource(view, url);
67   }
68 
69   /** {@inheritDoc} */
70   @Deprecated
71   @Override
onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg)72   public void onTooManyRedirects(WebView view, Message cancelMsg,
73           Message continueMsg) {
74       mWrappedClient.onTooManyRedirects(view, cancelMsg, continueMsg);
75   }
76 
77   /** {@inheritDoc} */
78   @Override
onReceivedError(WebView view, int errorCode, String description, String failingUrl)79   public void onReceivedError(WebView view, int errorCode,
80           String description, String failingUrl) {
81     mWrappedClient.onReceivedError(view, errorCode, description, failingUrl);
82   }
83 
84   /** {@inheritDoc} */
85   @Override
onFormResubmission(WebView view, Message dontResend, Message resend)86   public void onFormResubmission(WebView view, Message dontResend,
87           Message resend) {
88     mWrappedClient.onFormResubmission(view, dontResend, resend);
89   }
90 
91   /** {@inheritDoc} */
92   @Override
doUpdateVisitedHistory(WebView view, String url, boolean isReload)93   public void doUpdateVisitedHistory(WebView view, String url,
94           boolean isReload) {
95     mWrappedClient.doUpdateVisitedHistory(view, url, isReload);
96   }
97 
98   /** {@inheritDoc} */
99   @Override
onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)100   public void onReceivedSslError(WebView view, SslErrorHandler handler,
101           SslError error) {
102       mWrappedClient.onReceivedSslError(view, handler, error);
103   }
104 
105   /** {@inheritDoc} */
106   @Override
onReceivedClientCertRequest(WebView view, ClientCertRequestHandler handler, String host_and_port)107   public void onReceivedClientCertRequest(WebView view, ClientCertRequestHandler handler,
108           String host_and_port) {
109     if (mWrappedClient instanceof WebViewClientClassicExt) {
110       ((WebViewClientClassicExt) mWrappedClient).onReceivedClientCertRequest(view, handler, host_and_port);
111     } else {
112       super.onReceivedClientCertRequest(view, handler, host_and_port);
113     }
114   }
115 
116   /** {@inheritDoc} */
117   @Override
onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm)118   public void onReceivedHttpAuthRequest(WebView view,
119           HttpAuthHandler handler, String host, String realm) {
120       mWrappedClient.onReceivedHttpAuthRequest(view, handler, host, realm);
121   }
122 
123   /** {@inheritDoc} */
124   @Override
shouldOverrideKeyEvent(WebView view, KeyEvent event)125   public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
126       return mWrappedClient.shouldOverrideKeyEvent(view, event);
127   }
128 
129   /** {@inheritDoc} */
130   @Override
onUnhandledKeyEvent(WebView view, KeyEvent event)131   public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
132     mWrappedClient.onUnhandledKeyEvent(view, event);
133   }
134 
135   /** {@inheritDoc} */
136   @Override
onScaleChanged(WebView view, float oldScale, float newScale)137   public void onScaleChanged(WebView view, float oldScale, float newScale) {
138     mWrappedClient.onScaleChanged(view, oldScale, newScale);
139   }
140 }
141