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