1 /* 2 * Copyright (C) 2011 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.app.Activity; 20 import android.content.Context; 21 import android.graphics.Bitmap; 22 import android.net.Uri; 23 import android.net.http.SslError; 24 import android.os.Message; 25 import android.util.Log; 26 import android.view.KeyEvent; 27 import android.view.View; 28 import android.webkit.HttpAuthHandler; 29 import android.webkit.SslErrorHandler; 30 import android.webkit.ValueCallback; 31 import android.webkit.WebChromeClient.CustomViewCallback; 32 import android.webkit.WebView; 33 34 public class PreloadController implements WebViewController { 35 36 private static final boolean LOGD_ENABLED = false; 37 private static final String LOGTAG = "PreloadController"; 38 39 private Context mContext; 40 PreloadController(Context ctx)41 public PreloadController(Context ctx) { 42 mContext = ctx.getApplicationContext(); 43 44 } 45 46 @Override getContext()47 public Context getContext() { 48 return mContext; 49 } 50 51 @Override getActivity()52 public Activity getActivity() { 53 if (LOGD_ENABLED) Log.d(LOGTAG, "getActivity()"); 54 return null; 55 } 56 57 @Override getTabControl()58 public TabControl getTabControl() { 59 if (LOGD_ENABLED) Log.d(LOGTAG, "getTabControl()"); 60 return null; 61 } 62 63 @Override getWebViewFactory()64 public WebViewFactory getWebViewFactory() { 65 if (LOGD_ENABLED) Log.d(LOGTAG, "getWebViewFactory()"); 66 return null; 67 } 68 69 @Override onSetWebView(Tab tab, WebView view)70 public void onSetWebView(Tab tab, WebView view) { 71 if (LOGD_ENABLED) Log.d(LOGTAG, "onSetWebView()"); 72 } 73 74 @Override createSubWindow(Tab tab)75 public void createSubWindow(Tab tab) { 76 if (LOGD_ENABLED) Log.d(LOGTAG, "createSubWindow()"); 77 } 78 79 @Override onPageStarted(Tab tab, WebView view, Bitmap favicon)80 public void onPageStarted(Tab tab, WebView view, Bitmap favicon) { 81 if (LOGD_ENABLED) Log.d(LOGTAG, "onPageStarted()"); 82 if (view != null) { 83 // Clear history of all previously visited pages. When the 84 // user visits a preloaded tab, the only item in the history 85 // list should the currently viewed page. 86 view.clearHistory(); 87 } 88 } 89 90 @Override onPageFinished(Tab tab)91 public void onPageFinished(Tab tab) { 92 if (LOGD_ENABLED) Log.d(LOGTAG, "onPageFinished()"); 93 if (tab != null) { 94 final WebView view = tab.getWebView(); 95 if (view != null) { 96 // Clear history of all previously visited pages. When the 97 // user visits a preloaded tab. 98 view.clearHistory(); 99 } 100 } 101 } 102 103 @Override onProgressChanged(Tab tab)104 public void onProgressChanged(Tab tab) { 105 if (LOGD_ENABLED) Log.d(LOGTAG, "onProgressChanged()"); 106 } 107 108 @Override onReceivedTitle(Tab tab, String title)109 public void onReceivedTitle(Tab tab, String title) { 110 if (LOGD_ENABLED) Log.d(LOGTAG, "onReceivedTitle()"); 111 } 112 113 @Override onFavicon(Tab tab, WebView view, Bitmap icon)114 public void onFavicon(Tab tab, WebView view, Bitmap icon) { 115 if (LOGD_ENABLED) Log.d(LOGTAG, "onFavicon()"); 116 } 117 118 @Override shouldOverrideUrlLoading(Tab tab, WebView view, String url)119 public boolean shouldOverrideUrlLoading(Tab tab, WebView view, String url) { 120 if (LOGD_ENABLED) Log.d(LOGTAG, "shouldOverrideUrlLoading()"); 121 return false; 122 } 123 124 @Override shouldOverrideKeyEvent(KeyEvent event)125 public boolean shouldOverrideKeyEvent(KeyEvent event) { 126 if (LOGD_ENABLED) Log.d(LOGTAG, "shouldOverrideKeyEvent()"); 127 return false; 128 } 129 130 @Override onUnhandledKeyEvent(KeyEvent event)131 public boolean onUnhandledKeyEvent(KeyEvent event) { 132 if (LOGD_ENABLED) Log.d(LOGTAG, "onUnhandledKeyEvent()"); 133 return false; 134 } 135 136 @Override doUpdateVisitedHistory(Tab tab, boolean isReload)137 public void doUpdateVisitedHistory(Tab tab, boolean isReload) { 138 if (LOGD_ENABLED) Log.d(LOGTAG, "doUpdateVisitedHistory()"); 139 } 140 141 @Override getVisitedHistory(ValueCallback<String[]> callback)142 public void getVisitedHistory(ValueCallback<String[]> callback) { 143 if (LOGD_ENABLED) Log.d(LOGTAG, "getVisitedHistory()"); 144 } 145 146 @Override onReceivedHttpAuthRequest(Tab tab, WebView view, HttpAuthHandler handler, String host, String realm)147 public void onReceivedHttpAuthRequest(Tab tab, WebView view, 148 HttpAuthHandler handler, String host, 149 String realm) { 150 if (LOGD_ENABLED) Log.d(LOGTAG, "onReceivedHttpAuthRequest()"); 151 } 152 153 @Override onDownloadStart(Tab tab, String url, String useragent, String contentDisposition, String mimeType, String referer, long contentLength)154 public void onDownloadStart(Tab tab, String url, String useragent, 155 String contentDisposition, String mimeType, 156 String referer, long contentLength) { 157 if (LOGD_ENABLED) Log.d(LOGTAG, "onDownloadStart()"); 158 } 159 160 @Override showCustomView(Tab tab, View view, int requestedOrientation, CustomViewCallback callback)161 public void showCustomView(Tab tab, View view, int requestedOrientation, 162 CustomViewCallback callback) { 163 if (LOGD_ENABLED) Log.d(LOGTAG, "showCustomView()"); 164 } 165 166 @Override hideCustomView()167 public void hideCustomView() { 168 if (LOGD_ENABLED) Log.d(LOGTAG, "hideCustomView()"); 169 } 170 171 @Override getDefaultVideoPoster()172 public Bitmap getDefaultVideoPoster() { 173 if (LOGD_ENABLED) Log.d(LOGTAG, "getDefaultVideoPoster()"); 174 return null; 175 } 176 177 @Override getVideoLoadingProgressView()178 public View getVideoLoadingProgressView() { 179 if (LOGD_ENABLED) Log.d(LOGTAG, "getVideoLoadingProgressView()"); 180 return null; 181 } 182 183 @Override showSslCertificateOnError(WebView view, SslErrorHandler handler, SslError error)184 public void showSslCertificateOnError(WebView view, 185 SslErrorHandler handler, SslError error) { 186 if (LOGD_ENABLED) Log.d(LOGTAG, "showSslCertificateOnError()"); 187 } 188 189 @Override onUserCanceledSsl(Tab tab)190 public void onUserCanceledSsl(Tab tab) { 191 if (LOGD_ENABLED) Log.d(LOGTAG, "onUserCanceledSsl()"); 192 } 193 194 @Override shouldShowErrorConsole()195 public boolean shouldShowErrorConsole() { 196 if (LOGD_ENABLED) Log.d(LOGTAG, "shouldShowErrorConsole()"); 197 return false; 198 } 199 200 @Override onUpdatedSecurityState(Tab tab)201 public void onUpdatedSecurityState(Tab tab) { 202 if (LOGD_ENABLED) Log.d(LOGTAG, "onUpdatedSecurityState()"); 203 } 204 205 @Override openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture)206 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { 207 if (LOGD_ENABLED) Log.d(LOGTAG, "openFileChooser()"); 208 } 209 210 @Override endActionMode()211 public void endActionMode() { 212 if (LOGD_ENABLED) Log.d(LOGTAG, "endActionMode()"); 213 } 214 215 @Override attachSubWindow(Tab tab)216 public void attachSubWindow(Tab tab) { 217 if (LOGD_ENABLED) Log.d(LOGTAG, "attachSubWindow()"); 218 } 219 220 @Override dismissSubWindow(Tab tab)221 public void dismissSubWindow(Tab tab) { 222 if (LOGD_ENABLED) Log.d(LOGTAG, "dismissSubWindow()"); 223 } 224 225 @Override openTab(String url, boolean incognito, boolean setActive, boolean useCurrent)226 public Tab openTab(String url, boolean incognito, boolean setActive, boolean useCurrent) { 227 if (LOGD_ENABLED) Log.d(LOGTAG, "openTab()"); 228 return null; 229 } 230 231 @Override openTab(String url, Tab parent, boolean setActive, boolean useCurrent)232 public Tab openTab(String url, Tab parent, boolean setActive, boolean useCurrent) { 233 if (LOGD_ENABLED) Log.d(LOGTAG, "openTab()"); 234 return null; 235 } 236 237 @Override switchToTab(Tab tab)238 public boolean switchToTab(Tab tab) { 239 if (LOGD_ENABLED) Log.d(LOGTAG, "switchToTab()"); 240 return false; 241 } 242 243 @Override closeTab(Tab tab)244 public void closeTab(Tab tab) { 245 if (LOGD_ENABLED) Log.d(LOGTAG, "closeTab()"); 246 } 247 248 @Override setupAutoFill(Message message)249 public void setupAutoFill(Message message) { 250 if (LOGD_ENABLED) Log.d(LOGTAG, "setupAutoFill()"); 251 } 252 253 @Override bookmarkedStatusHasChanged(Tab tab)254 public void bookmarkedStatusHasChanged(Tab tab) { 255 if (LOGD_ENABLED) Log.d(LOGTAG, "bookmarkedStatusHasChanged()"); 256 } 257 258 @Override showAutoLogin(Tab tab)259 public void showAutoLogin(Tab tab) { 260 if (LOGD_ENABLED) Log.d(LOGTAG, "showAutoLogin()"); 261 } 262 263 @Override hideAutoLogin(Tab tab)264 public void hideAutoLogin(Tab tab) { 265 if (LOGD_ENABLED) Log.d(LOGTAG, "hideAutoLogin()"); 266 } 267 268 @Override shouldCaptureThumbnails()269 public boolean shouldCaptureThumbnails() { 270 return false; 271 } 272 273 } 274