• 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.Uri;
21 import android.os.Message;
22 import android.view.View;
23 import android.webkit.ConsoleMessage;
24 import android.webkit.GeolocationPermissions;
25 import android.webkit.JsPromptResult;
26 import android.webkit.JsResult;
27 import android.webkit.ValueCallback;
28 import android.webkit.WebChromeClient;
29 import android.webkit.WebStorage;
30 import android.webkit.WebView;
31 
32 /**
33  *
34  * WebChromeClient for browser tests.
35  * Wraps around existing client so that specific methods can be overridden if needed.
36  *
37  */
38 abstract class TestWebChromeClient extends WebChromeClient {
39 
40     private WebChromeClient mWrappedClient;
41 
TestWebChromeClient(WebChromeClient wrappedClient)42     protected TestWebChromeClient(WebChromeClient wrappedClient) {
43         mWrappedClient = wrappedClient;
44     }
45 
46     /** {@inheritDoc} */
47     @Override
onProgressChanged(WebView view, int newProgress)48     public void onProgressChanged(WebView view, int newProgress) {
49         mWrappedClient.onProgressChanged(view, newProgress);
50     }
51 
52     /** {@inheritDoc} */
53     @Override
onReceivedTitle(WebView view, String title)54     public void onReceivedTitle(WebView view, String title) {
55         mWrappedClient.onReceivedTitle(view, title);
56     }
57 
58     /** {@inheritDoc} */
59     @Override
onReceivedIcon(WebView view, Bitmap icon)60     public void onReceivedIcon(WebView view, Bitmap icon) {
61         mWrappedClient.onReceivedIcon(view, icon);
62     }
63 
64     /** {@inheritDoc} */
65     @Override
onReceivedTouchIconUrl(WebView view, String url, boolean precomposed)66     public void onReceivedTouchIconUrl(WebView view, String url,
67             boolean precomposed) {
68         mWrappedClient.onReceivedTouchIconUrl(view, url, precomposed);
69     }
70 
71     /** {@inheritDoc} */
72     @Override
onShowCustomView(View view, CustomViewCallback callback)73     public void onShowCustomView(View view, CustomViewCallback callback) {
74         mWrappedClient.onShowCustomView(view, callback);
75     }
76 
77     /** {@inheritDoc} */
78     @Override
onHideCustomView()79     public void onHideCustomView() {
80         mWrappedClient.onHideCustomView();
81     }
82 
83     /** {@inheritDoc} */
84     @Override
onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg)85     public boolean onCreateWindow(WebView view, boolean dialog,
86             boolean userGesture, Message resultMsg) {
87         // do not open any new pop-ups
88         resultMsg.sendToTarget();
89         return true;
90     }
91 
92     /** {@inheritDoc} */
93     @Override
onRequestFocus(WebView view)94     public void onRequestFocus(WebView view) {
95         mWrappedClient.onRequestFocus(view);
96     }
97 
98     /** {@inheritDoc} */
99     @Override
onCloseWindow(WebView window)100     public void onCloseWindow(WebView window) {
101         mWrappedClient.onCloseWindow(window);
102     }
103 
104     /** {@inheritDoc} */
105     @Override
onJsAlert(WebView view, String url, String message, JsResult result)106     public boolean onJsAlert(WebView view, String url, String message,
107             JsResult result) {
108         return mWrappedClient.onJsAlert(view, url, message, result);
109     }
110 
111     /** {@inheritDoc} */
112     @Override
onJsConfirm(WebView view, String url, String message, JsResult result)113     public boolean onJsConfirm(WebView view, String url, String message,
114             JsResult result) {
115         return mWrappedClient.onJsConfirm(view, url, message, result);
116     }
117 
118     /** {@inheritDoc} */
119     @Override
onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result)120     public boolean onJsPrompt(WebView view, String url, String message,
121             String defaultValue, JsPromptResult result) {
122         return mWrappedClient.onJsPrompt(view, url, message, defaultValue, result);
123     }
124 
125     /** {@inheritDoc} */
126     @Override
onJsBeforeUnload(WebView view, String url, String message, JsResult result)127     public boolean onJsBeforeUnload(WebView view, String url, String message,
128             JsResult result) {
129         return mWrappedClient.onJsBeforeUnload(view, url, message, result);
130     }
131 
132     /** {@inheritDoc} */
133     @Override
onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)134     public void onExceededDatabaseQuota(String url, String databaseIdentifier,
135             long currentQuota, long estimatedSize, long totalUsedQuota,
136             WebStorage.QuotaUpdater quotaUpdater) {
137         mWrappedClient.onExceededDatabaseQuota(url, databaseIdentifier, currentQuota,
138                 estimatedSize, totalUsedQuota, quotaUpdater);
139     }
140 
141     /** {@inheritDoc} */
142     @Override
onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)143     public void onReachedMaxAppCacheSize(long spaceNeeded, long totalUsedQuota,
144             WebStorage.QuotaUpdater quotaUpdater) {
145         mWrappedClient.onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota, quotaUpdater);
146     }
147 
148     /** {@inheritDoc} */
149     @Override
onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback)150     public void onGeolocationPermissionsShowPrompt(String origin,
151             GeolocationPermissions.Callback callback) {
152         mWrappedClient.onGeolocationPermissionsShowPrompt(origin, callback);
153     }
154 
155     /** {@inheritDoc} */
156     @Override
onGeolocationPermissionsHidePrompt()157     public void onGeolocationPermissionsHidePrompt() {
158         mWrappedClient.onGeolocationPermissionsHidePrompt();
159     }
160 
161     /** {@inheritDoc} */
162     @Override
onJsTimeout()163     public boolean onJsTimeout() {
164         return mWrappedClient.onJsTimeout();
165     }
166 
167     /** {@inheritDoc} */
168     @Override
169     @Deprecated
onConsoleMessage(String message, int lineNumber, String sourceID)170     public void onConsoleMessage(String message, int lineNumber, String sourceID) {
171         mWrappedClient.onConsoleMessage(message, lineNumber, sourceID);
172     }
173 
174     /** {@inheritDoc} */
175     @Override
onConsoleMessage(ConsoleMessage consoleMessage)176     public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
177         return mWrappedClient.onConsoleMessage(consoleMessage);
178     }
179 
180     /** {@inheritDoc} */
181     @Override
getDefaultVideoPoster()182     public Bitmap getDefaultVideoPoster() {
183         return mWrappedClient.getDefaultVideoPoster();
184     }
185 
186     /** {@inheritDoc} */
187     @Override
getVideoLoadingProgressView()188     public View getVideoLoadingProgressView() {
189         return mWrappedClient.getVideoLoadingProgressView();
190     }
191 
192     /** {@inheritDoc} */
193     @Override
getVisitedHistory(ValueCallback<String[]> callback)194     public void getVisitedHistory(ValueCallback<String[]> callback) {
195         mWrappedClient.getVisitedHistory(callback);
196     }
197 
198     /** {@inheritDoc} */
199     @Override
openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture)200     public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
201         mWrappedClient.openFileChooser(uploadFile, acceptType, capture);
202     }
203 }
204