The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 com.google.android.googleapps.IGoogleLoginService; |
| 20 | import com.google.android.googlelogin.GoogleLoginServiceConstants; |
| 21 | |
| 22 | import android.app.Activity; |
| 23 | import android.app.ActivityManager; |
| 24 | import android.app.AlertDialog; |
| 25 | import android.app.ProgressDialog; |
| 26 | import android.app.SearchManager; |
| 27 | import android.content.ActivityNotFoundException; |
| 28 | import android.content.BroadcastReceiver; |
| 29 | import android.content.ComponentName; |
| 30 | import android.content.ContentResolver; |
Leon Scroggins | b6b7f9e | 2009-06-18 12:05:28 -0400 | [diff] [blame] | 31 | import android.content.ContentUris; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 32 | import android.content.ContentValues; |
| 33 | import android.content.Context; |
| 34 | import android.content.DialogInterface; |
| 35 | import android.content.Intent; |
| 36 | import android.content.IntentFilter; |
| 37 | import android.content.ServiceConnection; |
| 38 | import android.content.DialogInterface.OnCancelListener; |
Grace Kloba | b4da0ad | 2009-05-14 14:45:40 -0700 | [diff] [blame] | 39 | import android.content.pm.PackageInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
| 41 | import android.content.pm.ResolveInfo; |
| 42 | import android.content.res.AssetManager; |
| 43 | import android.content.res.Configuration; |
| 44 | import android.content.res.Resources; |
| 45 | import android.database.Cursor; |
| 46 | import android.database.sqlite.SQLiteDatabase; |
| 47 | import android.database.sqlite.SQLiteException; |
| 48 | import android.graphics.Bitmap; |
| 49 | import android.graphics.Canvas; |
| 50 | import android.graphics.Color; |
| 51 | import android.graphics.DrawFilter; |
| 52 | import android.graphics.Paint; |
| 53 | import android.graphics.PaintFlagsDrawFilter; |
| 54 | import android.graphics.Picture; |
| 55 | import android.graphics.drawable.BitmapDrawable; |
| 56 | import android.graphics.drawable.Drawable; |
| 57 | import android.graphics.drawable.LayerDrawable; |
| 58 | import android.graphics.drawable.PaintDrawable; |
| 59 | import android.hardware.SensorListener; |
| 60 | import android.hardware.SensorManager; |
| 61 | import android.net.ConnectivityManager; |
| 62 | import android.net.Uri; |
| 63 | import android.net.WebAddress; |
| 64 | import android.net.http.EventHandler; |
| 65 | import android.net.http.SslCertificate; |
| 66 | import android.net.http.SslError; |
| 67 | import android.os.AsyncTask; |
| 68 | import android.os.Bundle; |
| 69 | import android.os.Debug; |
| 70 | import android.os.Environment; |
| 71 | import android.os.Handler; |
| 72 | import android.os.IBinder; |
| 73 | import android.os.Message; |
| 74 | import android.os.PowerManager; |
| 75 | import android.os.Process; |
| 76 | import android.os.RemoteException; |
| 77 | import android.os.ServiceManager; |
| 78 | import android.os.SystemClock; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 79 | import android.provider.Browser; |
| 80 | import android.provider.Contacts; |
| 81 | import android.provider.Downloads; |
| 82 | import android.provider.MediaStore; |
| 83 | import android.provider.Contacts.Intents.Insert; |
| 84 | import android.text.IClipboard; |
| 85 | import android.text.TextUtils; |
| 86 | import android.text.format.DateFormat; |
| 87 | import android.text.util.Regex; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 88 | import android.util.Log; |
| 89 | import android.view.ContextMenu; |
| 90 | import android.view.Gravity; |
| 91 | import android.view.KeyEvent; |
| 92 | import android.view.LayoutInflater; |
| 93 | import android.view.Menu; |
| 94 | import android.view.MenuInflater; |
| 95 | import android.view.MenuItem; |
| 96 | import android.view.View; |
| 97 | import android.view.ViewGroup; |
| 98 | import android.view.Window; |
| 99 | import android.view.WindowManager; |
| 100 | import android.view.ContextMenu.ContextMenuInfo; |
| 101 | import android.view.MenuItem.OnMenuItemClickListener; |
| 102 | import android.view.animation.AlphaAnimation; |
| 103 | import android.view.animation.Animation; |
| 104 | import android.view.animation.AnimationSet; |
| 105 | import android.view.animation.DecelerateInterpolator; |
| 106 | import android.view.animation.ScaleAnimation; |
| 107 | import android.view.animation.TranslateAnimation; |
| 108 | import android.webkit.CookieManager; |
| 109 | import android.webkit.CookieSyncManager; |
| 110 | import android.webkit.DownloadListener; |
| 111 | import android.webkit.HttpAuthHandler; |
Grace Kloba | b4da0ad | 2009-05-14 14:45:40 -0700 | [diff] [blame] | 112 | import android.webkit.PluginManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 113 | import android.webkit.SslErrorHandler; |
| 114 | import android.webkit.URLUtil; |
| 115 | import android.webkit.WebChromeClient; |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 116 | import android.webkit.WebChromeClient.CustomViewCallback; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 117 | import android.webkit.WebHistoryItem; |
| 118 | import android.webkit.WebIconDatabase; |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 119 | import android.webkit.WebStorage; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 120 | import android.webkit.WebView; |
| 121 | import android.webkit.WebViewClient; |
| 122 | import android.widget.EditText; |
| 123 | import android.widget.FrameLayout; |
| 124 | import android.widget.LinearLayout; |
| 125 | import android.widget.TextView; |
| 126 | import android.widget.Toast; |
| 127 | |
| 128 | import java.io.BufferedOutputStream; |
Leon Scroggins | b6b7f9e | 2009-06-18 12:05:28 -0400 | [diff] [blame] | 129 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 130 | import java.io.File; |
| 131 | import java.io.FileInputStream; |
| 132 | import java.io.FileOutputStream; |
| 133 | import java.io.IOException; |
| 134 | import java.io.InputStream; |
| 135 | import java.net.MalformedURLException; |
| 136 | import java.net.URI; |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 137 | import java.net.URISyntaxException; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 138 | import java.net.URL; |
| 139 | import java.net.URLEncoder; |
| 140 | import java.text.ParseException; |
| 141 | import java.util.Date; |
| 142 | import java.util.Enumeration; |
| 143 | import java.util.HashMap; |
Patrick Scott | 37911c7 | 2009-03-24 18:02:58 -0700 | [diff] [blame] | 144 | import java.util.LinkedList; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 145 | import java.util.Vector; |
| 146 | import java.util.regex.Matcher; |
| 147 | import java.util.regex.Pattern; |
| 148 | import java.util.zip.ZipEntry; |
| 149 | import java.util.zip.ZipFile; |
| 150 | |
| 151 | public class BrowserActivity extends Activity |
| 152 | implements KeyTracker.OnKeyTracker, |
| 153 | View.OnCreateContextMenuListener, |
| 154 | DownloadListener { |
| 155 | |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 156 | /* Define some aliases to make these debugging flags easier to refer to. |
| 157 | * This file imports android.provider.Browser, so we can't just refer to "Browser.DEBUG". |
| 158 | */ |
| 159 | private final static boolean DEBUG = com.android.browser.Browser.DEBUG; |
| 160 | private final static boolean LOGV_ENABLED = com.android.browser.Browser.LOGV_ENABLED; |
| 161 | private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; |
| 162 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 163 | private IGoogleLoginService mGls = null; |
| 164 | private ServiceConnection mGlsConnection = null; |
| 165 | |
| 166 | private SensorManager mSensorManager = null; |
| 167 | |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 168 | // These are single-character shortcuts for searching popular sources. |
| 169 | private static final int SHORTCUT_INVALID = 0; |
| 170 | private static final int SHORTCUT_GOOGLE_SEARCH = 1; |
| 171 | private static final int SHORTCUT_WIKIPEDIA_SEARCH = 2; |
| 172 | private static final int SHORTCUT_DICTIONARY_SEARCH = 3; |
| 173 | private static final int SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH = 4; |
| 174 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 175 | /* Whitelisted webpages |
| 176 | private static HashSet<String> sWhiteList; |
| 177 | |
| 178 | static { |
| 179 | sWhiteList = new HashSet<String>(); |
| 180 | sWhiteList.add("cnn.com/"); |
| 181 | sWhiteList.add("espn.go.com/"); |
| 182 | sWhiteList.add("nytimes.com/"); |
| 183 | sWhiteList.add("engadget.com/"); |
| 184 | sWhiteList.add("yahoo.com/"); |
| 185 | sWhiteList.add("msn.com/"); |
| 186 | sWhiteList.add("amazon.com/"); |
| 187 | sWhiteList.add("consumerist.com/"); |
| 188 | sWhiteList.add("google.com/m/news"); |
| 189 | } |
| 190 | */ |
| 191 | |
| 192 | private void setupHomePage() { |
| 193 | final Runnable getAccount = new Runnable() { |
| 194 | public void run() { |
| 195 | // Lower priority |
| 196 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 197 | // get the default home page |
| 198 | String homepage = mSettings.getHomePage(); |
| 199 | |
| 200 | try { |
| 201 | if (mGls == null) return; |
| 202 | |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 203 | if (!homepage.startsWith("http://www.google.")) return; |
| 204 | if (homepage.indexOf('?') == -1) return; |
| 205 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 206 | String hostedUser = mGls.getAccount(GoogleLoginServiceConstants.PREFER_HOSTED); |
| 207 | String googleUser = mGls.getAccount(GoogleLoginServiceConstants.REQUIRE_GOOGLE); |
| 208 | |
| 209 | // three cases: |
| 210 | // |
| 211 | // hostedUser == googleUser |
| 212 | // The device has only a google account |
| 213 | // |
| 214 | // hostedUser != googleUser |
| 215 | // The device has a hosted account and a google account |
| 216 | // |
| 217 | // hostedUser != null, googleUser == null |
| 218 | // The device has only a hosted account (so far) |
| 219 | |
| 220 | // developers might have no accounts at all |
| 221 | if (hostedUser == null) return; |
| 222 | |
| 223 | if (googleUser == null || !hostedUser.equals(googleUser)) { |
| 224 | String domain = hostedUser.substring(hostedUser.lastIndexOf('@')+1); |
Grace Kloba | f2c5c1b | 2009-05-26 10:48:31 -0700 | [diff] [blame] | 225 | homepage = homepage.replace("?", "/a/" + domain + "?"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 226 | } |
| 227 | } catch (RemoteException ignore) { |
| 228 | // Login service died; carry on |
| 229 | } catch (RuntimeException ignore) { |
| 230 | // Login service died; carry on |
| 231 | } finally { |
| 232 | finish(homepage); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | private void finish(final String homepage) { |
| 237 | mHandler.post(new Runnable() { |
| 238 | public void run() { |
| 239 | mSettings.setHomePage(BrowserActivity.this, homepage); |
| 240 | resumeAfterCredentials(); |
| 241 | |
| 242 | // as this is running in a separate thread, |
| 243 | // BrowserActivity's onDestroy() may have been called, |
| 244 | // which also calls unbindService(). |
| 245 | if (mGlsConnection != null) { |
| 246 | // we no longer need to keep GLS open |
| 247 | unbindService(mGlsConnection); |
| 248 | mGlsConnection = null; |
| 249 | } |
| 250 | } }); |
| 251 | } }; |
| 252 | |
| 253 | final boolean[] done = { false }; |
| 254 | |
| 255 | // Open a connection to the Google Login Service. The first |
| 256 | // time the connection is established, set up the homepage depending on |
| 257 | // the account in a background thread. |
| 258 | mGlsConnection = new ServiceConnection() { |
| 259 | public void onServiceConnected(ComponentName className, IBinder service) { |
| 260 | mGls = IGoogleLoginService.Stub.asInterface(service); |
| 261 | if (done[0] == false) { |
| 262 | done[0] = true; |
| 263 | Thread account = new Thread(getAccount); |
| 264 | account.setName("GLSAccount"); |
| 265 | account.start(); |
| 266 | } |
| 267 | } |
| 268 | public void onServiceDisconnected(ComponentName className) { |
| 269 | mGls = null; |
| 270 | } |
| 271 | }; |
| 272 | |
| 273 | bindService(GoogleLoginServiceConstants.SERVICE_INTENT, |
| 274 | mGlsConnection, Context.BIND_AUTO_CREATE); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * This class is in charge of installing pre-packaged plugins |
| 279 | * from the Browser assets directory to the user's data partition. |
| 280 | * Plugins are loaded from the "plugins" directory in the assets; |
| 281 | * Anything that is in this directory will be copied over to the |
| 282 | * user data partition in app_plugins. |
| 283 | */ |
| 284 | private class CopyPlugins implements Runnable { |
| 285 | final static String TAG = "PluginsInstaller"; |
| 286 | final static String ZIP_FILTER = "assets/plugins/"; |
| 287 | final static String APK_PATH = "/system/app/Browser.apk"; |
| 288 | final static String PLUGIN_EXTENSION = ".so"; |
| 289 | final static String TEMPORARY_EXTENSION = "_temp"; |
| 290 | final static String BUILD_INFOS_FILE = "build.prop"; |
| 291 | final static String SYSTEM_BUILD_INFOS_FILE = "/system/" |
| 292 | + BUILD_INFOS_FILE; |
| 293 | final int BUFSIZE = 4096; |
| 294 | boolean mDoOverwrite = false; |
| 295 | String pluginsPath; |
| 296 | Context mContext; |
| 297 | File pluginsDir; |
| 298 | AssetManager manager; |
| 299 | |
| 300 | public CopyPlugins (boolean overwrite, Context context) { |
| 301 | mDoOverwrite = overwrite; |
| 302 | mContext = context; |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Returned a filtered list of ZipEntry. |
| 307 | * We list all the files contained in the zip and |
| 308 | * only returns the ones starting with the ZIP_FILTER |
| 309 | * path. |
| 310 | * |
| 311 | * @param zip the zip file used. |
| 312 | */ |
| 313 | public Vector<ZipEntry> pluginsFilesFromZip(ZipFile zip) { |
| 314 | Vector<ZipEntry> list = new Vector<ZipEntry>(); |
| 315 | Enumeration entries = zip.entries(); |
| 316 | while (entries.hasMoreElements()) { |
| 317 | ZipEntry entry = (ZipEntry) entries.nextElement(); |
| 318 | if (entry.getName().startsWith(ZIP_FILTER)) { |
| 319 | list.add(entry); |
| 320 | } |
| 321 | } |
| 322 | return list; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Utility method to copy the content from an inputstream |
| 327 | * to a file output stream. |
| 328 | */ |
| 329 | public void copyStreams(InputStream is, FileOutputStream fos) { |
| 330 | BufferedOutputStream os = null; |
| 331 | try { |
| 332 | byte data[] = new byte[BUFSIZE]; |
| 333 | int count; |
| 334 | os = new BufferedOutputStream(fos, BUFSIZE); |
| 335 | while ((count = is.read(data, 0, BUFSIZE)) != -1) { |
| 336 | os.write(data, 0, count); |
| 337 | } |
| 338 | os.flush(); |
| 339 | } catch (IOException e) { |
| 340 | Log.e(TAG, "Exception while copying: " + e); |
| 341 | } finally { |
| 342 | try { |
| 343 | if (os != null) { |
| 344 | os.close(); |
| 345 | } |
| 346 | } catch (IOException e2) { |
| 347 | Log.e(TAG, "Exception while closing the stream: " + e2); |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Returns a string containing the contents of a file |
| 354 | * |
| 355 | * @param file the target file |
| 356 | */ |
| 357 | private String contentsOfFile(File file) { |
| 358 | String ret = null; |
| 359 | FileInputStream is = null; |
| 360 | try { |
| 361 | byte[] buffer = new byte[BUFSIZE]; |
| 362 | int count; |
| 363 | is = new FileInputStream(file); |
| 364 | StringBuffer out = new StringBuffer(); |
| 365 | |
| 366 | while ((count = is.read(buffer, 0, BUFSIZE)) != -1) { |
| 367 | out.append(new String(buffer, 0, count)); |
| 368 | } |
| 369 | ret = out.toString(); |
| 370 | } catch (IOException e) { |
| 371 | Log.e(TAG, "Exception getting contents of file " + e); |
| 372 | } finally { |
| 373 | if (is != null) { |
| 374 | try { |
| 375 | is.close(); |
| 376 | } catch (IOException e2) { |
| 377 | Log.e(TAG, "Exception while closing the file: " + e2); |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Utility method to initialize the user data plugins path. |
| 386 | */ |
| 387 | public void initPluginsPath() { |
| 388 | BrowserSettings s = BrowserSettings.getInstance(); |
| 389 | pluginsPath = s.getPluginsPath(); |
| 390 | if (pluginsPath == null) { |
| 391 | s.loadFromDb(mContext); |
| 392 | pluginsPath = s.getPluginsPath(); |
| 393 | } |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 394 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 395 | Log.v(TAG, "Plugin path: " + pluginsPath); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Utility method to delete a file or a directory |
| 401 | * |
| 402 | * @param file the File to delete |
| 403 | */ |
| 404 | public void deleteFile(File file) { |
| 405 | File[] files = file.listFiles(); |
| 406 | if ((files != null) && files.length > 0) { |
| 407 | for (int i=0; i< files.length; i++) { |
| 408 | deleteFile(files[i]); |
| 409 | } |
| 410 | } |
| 411 | if (!file.delete()) { |
| 412 | Log.e(TAG, file.getPath() + " could not get deleted"); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Clean the content of the plugins directory. |
| 418 | * We delete the directory, then recreate it. |
| 419 | */ |
| 420 | public void cleanPluginsDirectory() { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 421 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 422 | Log.v(TAG, "delete plugins directory: " + pluginsPath); |
| 423 | } |
| 424 | File pluginsDirectory = new File(pluginsPath); |
| 425 | deleteFile(pluginsDirectory); |
| 426 | pluginsDirectory.mkdir(); |
| 427 | } |
| 428 | |
| 429 | |
| 430 | /** |
| 431 | * Copy the SYSTEM_BUILD_INFOS_FILE file containing the |
| 432 | * informations about the system build to the |
| 433 | * BUILD_INFOS_FILE in the plugins directory. |
| 434 | */ |
| 435 | public void copyBuildInfos() { |
| 436 | try { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 437 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 438 | Log.v(TAG, "Copy build infos to the plugins directory"); |
| 439 | } |
| 440 | File buildInfoFile = new File(SYSTEM_BUILD_INFOS_FILE); |
| 441 | File buildInfoPlugins = new File(pluginsPath, BUILD_INFOS_FILE); |
| 442 | copyStreams(new FileInputStream(buildInfoFile), |
| 443 | new FileOutputStream(buildInfoPlugins)); |
| 444 | } catch (IOException e) { |
| 445 | Log.e(TAG, "Exception while copying the build infos: " + e); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Returns true if the current system is newer than the |
| 451 | * system that installed the plugins. |
| 452 | * We determinate this by checking the build number of the system. |
| 453 | * |
| 454 | * At the end of the plugins copy operation, we copy the |
| 455 | * SYSTEM_BUILD_INFOS_FILE to the BUILD_INFOS_FILE. |
| 456 | * We then just have to load both and compare them -- if they |
| 457 | * are different the current system is newer. |
| 458 | * |
| 459 | * Loading and comparing the strings should be faster than |
| 460 | * creating a hash, the files being rather small. Extracting the |
| 461 | * version number would require some parsing which may be more |
| 462 | * brittle. |
| 463 | */ |
| 464 | public boolean newSystemImage() { |
| 465 | try { |
| 466 | File buildInfoFile = new File(SYSTEM_BUILD_INFOS_FILE); |
| 467 | File buildInfoPlugins = new File(pluginsPath, BUILD_INFOS_FILE); |
| 468 | if (!buildInfoPlugins.exists()) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 469 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 470 | Log.v(TAG, "build.prop in plugins directory " + pluginsPath |
| 471 | + " does not exist, therefore it's a new system image"); |
| 472 | } |
| 473 | return true; |
| 474 | } else { |
| 475 | String buildInfo = contentsOfFile(buildInfoFile); |
| 476 | String buildInfoPlugin = contentsOfFile(buildInfoPlugins); |
| 477 | if (buildInfo == null || buildInfoPlugin == null |
| 478 | || buildInfo.compareTo(buildInfoPlugin) != 0) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 479 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 480 | Log.v(TAG, "build.prop are different, " |
| 481 | + " therefore it's a new system image"); |
| 482 | } |
| 483 | return true; |
| 484 | } |
| 485 | } |
| 486 | } catch (Exception e) { |
| 487 | Log.e(TAG, "Exc in newSystemImage(): " + e); |
| 488 | } |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Check if the version of the plugins contained in the |
| 494 | * Browser assets is the same as the version of the plugins |
| 495 | * in the plugins directory. |
| 496 | * We simply iterate on every file in the assets/plugins |
| 497 | * and return false if a file listed in the assets does |
| 498 | * not exist in the plugins directory. |
| 499 | */ |
| 500 | private boolean checkIsDifferentVersions() { |
| 501 | try { |
| 502 | ZipFile zip = new ZipFile(APK_PATH); |
| 503 | Vector<ZipEntry> files = pluginsFilesFromZip(zip); |
| 504 | int zipFilterLength = ZIP_FILTER.length(); |
| 505 | |
| 506 | Enumeration entries = files.elements(); |
| 507 | while (entries.hasMoreElements()) { |
| 508 | ZipEntry entry = (ZipEntry) entries.nextElement(); |
| 509 | String path = entry.getName().substring(zipFilterLength); |
| 510 | File outputFile = new File(pluginsPath, path); |
| 511 | if (!outputFile.exists()) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 512 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 513 | Log.v(TAG, "checkIsDifferentVersions(): extracted file " |
| 514 | + path + " does not exist, we have a different version"); |
| 515 | } |
| 516 | return true; |
| 517 | } |
| 518 | } |
| 519 | } catch (IOException e) { |
| 520 | Log.e(TAG, "Exception in checkDifferentVersions(): " + e); |
| 521 | } |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Copy every files from the assets/plugins directory |
| 527 | * to the app_plugins directory in the data partition. |
| 528 | * Once copied, we copy over the SYSTEM_BUILD_INFOS file |
| 529 | * in the plugins directory. |
| 530 | * |
| 531 | * NOTE: we directly access the content from the Browser |
| 532 | * package (it's a zip file) and do not use AssetManager |
| 533 | * as there is a limit of 1Mb (see Asset.h) |
| 534 | */ |
| 535 | public void run() { |
| 536 | // Lower the priority |
| 537 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 538 | try { |
| 539 | if (pluginsPath == null) { |
| 540 | Log.e(TAG, "No plugins path found!"); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | ZipFile zip = new ZipFile(APK_PATH); |
| 545 | Vector<ZipEntry> files = pluginsFilesFromZip(zip); |
| 546 | Vector<File> plugins = new Vector<File>(); |
| 547 | int zipFilterLength = ZIP_FILTER.length(); |
| 548 | |
| 549 | Enumeration entries = files.elements(); |
| 550 | while (entries.hasMoreElements()) { |
| 551 | ZipEntry entry = (ZipEntry) entries.nextElement(); |
| 552 | String path = entry.getName().substring(zipFilterLength); |
| 553 | File outputFile = new File(pluginsPath, path); |
| 554 | outputFile.getParentFile().mkdirs(); |
| 555 | |
| 556 | if (outputFile.exists() && !mDoOverwrite) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 557 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 558 | Log.v(TAG, path + " already extracted."); |
| 559 | } |
| 560 | } else { |
| 561 | if (path.endsWith(PLUGIN_EXTENSION)) { |
| 562 | // We rename plugins to be sure a half-copied |
| 563 | // plugin is not loaded by the browser. |
| 564 | plugins.add(outputFile); |
| 565 | outputFile = new File(pluginsPath, |
| 566 | path + TEMPORARY_EXTENSION); |
| 567 | } |
| 568 | FileOutputStream fos = new FileOutputStream(outputFile); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 569 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 570 | Log.v(TAG, "copy " + entry + " to " |
| 571 | + pluginsPath + "/" + path); |
| 572 | } |
| 573 | copyStreams(zip.getInputStream(entry), fos); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | // We now rename the .so we copied, once all their resources |
| 578 | // are safely copied over to the user data partition. |
| 579 | Enumeration elems = plugins.elements(); |
| 580 | while (elems.hasMoreElements()) { |
| 581 | File renamedFile = (File) elems.nextElement(); |
| 582 | File sourceFile = new File(renamedFile.getPath() |
| 583 | + TEMPORARY_EXTENSION); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 584 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 585 | Log.v(TAG, "rename " + sourceFile.getPath() |
| 586 | + " to " + renamedFile.getPath()); |
| 587 | } |
| 588 | sourceFile.renameTo(renamedFile); |
| 589 | } |
| 590 | |
| 591 | copyBuildInfos(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 592 | } catch (IOException e) { |
| 593 | Log.e(TAG, "IO Exception: " + e); |
| 594 | } |
| 595 | } |
| 596 | }; |
| 597 | |
| 598 | /** |
| 599 | * Copy the content of assets/plugins/ to the app_plugins directory |
| 600 | * in the data partition. |
| 601 | * |
| 602 | * This function is called every time the browser is started. |
| 603 | * We first check if the system image is newer than the one that |
| 604 | * copied the plugins (if there's plugins in the data partition). |
| 605 | * If this is the case, we then check if the versions are different. |
| 606 | * If they are different, we clean the plugins directory in the |
| 607 | * data partition, then start a thread to copy the plugins while |
| 608 | * the browser continue to load. |
| 609 | * |
| 610 | * @param overwrite if true overwrite the files even if they are |
| 611 | * already present (to let the user "reset" the plugins if needed). |
| 612 | */ |
| 613 | private void copyPlugins(boolean overwrite) { |
| 614 | CopyPlugins copyPluginsFromAssets = new CopyPlugins(overwrite, this); |
| 615 | copyPluginsFromAssets.initPluginsPath(); |
| 616 | if (copyPluginsFromAssets.newSystemImage()) { |
| 617 | if (copyPluginsFromAssets.checkIsDifferentVersions()) { |
| 618 | copyPluginsFromAssets.cleanPluginsDirectory(); |
| 619 | Thread copyplugins = new Thread(copyPluginsFromAssets); |
| 620 | copyplugins.setName("CopyPlugins"); |
| 621 | copyplugins.start(); |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | private class ClearThumbnails extends AsyncTask<File, Void, Void> { |
| 627 | @Override |
| 628 | public Void doInBackground(File... files) { |
| 629 | if (files != null) { |
| 630 | for (File f : files) { |
| 631 | f.delete(); |
| 632 | } |
| 633 | } |
| 634 | return null; |
| 635 | } |
| 636 | } |
| 637 | |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 638 | // Flag to enable the touchable browser bar with buttons |
| 639 | private final boolean CUSTOM_BROWSER_BAR = true; |
| 640 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 641 | @Override public void onCreate(Bundle icicle) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 642 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 643 | Log.v(LOGTAG, this + " onStart"); |
| 644 | } |
| 645 | super.onCreate(icicle); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 646 | if (CUSTOM_BROWSER_BAR) { |
| 647 | this.requestWindowFeature(Window.FEATURE_NO_TITLE); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 648 | } else { |
| 649 | this.requestWindowFeature(Window.FEATURE_LEFT_ICON); |
| 650 | this.requestWindowFeature(Window.FEATURE_RIGHT_ICON); |
| 651 | this.requestWindowFeature(Window.FEATURE_PROGRESS); |
| 652 | this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); |
| 653 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 654 | // test the browser in OpenGL |
| 655 | // requestWindowFeature(Window.FEATURE_OPENGL); |
| 656 | |
| 657 | setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); |
| 658 | |
| 659 | mResolver = getContentResolver(); |
| 660 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 661 | // |
| 662 | // start MASF proxy service |
| 663 | // |
| 664 | //Intent proxyServiceIntent = new Intent(); |
| 665 | //proxyServiceIntent.setComponent |
| 666 | // (new ComponentName( |
| 667 | // "com.android.masfproxyservice", |
| 668 | // "com.android.masfproxyservice.MasfProxyService")); |
| 669 | //startService(proxyServiceIntent, null); |
| 670 | |
| 671 | mSecLockIcon = Resources.getSystem().getDrawable( |
| 672 | android.R.drawable.ic_secure); |
| 673 | mMixLockIcon = Resources.getSystem().getDrawable( |
| 674 | android.R.drawable.ic_partial_secure); |
| 675 | mGenericFavicon = getResources().getDrawable( |
| 676 | R.drawable.app_web_browser_sm); |
| 677 | |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 678 | FrameLayout frameLayout = (FrameLayout) getWindow().getDecorView() |
| 679 | .findViewById(com.android.internal.R.id.content); |
| 680 | if (CUSTOM_BROWSER_BAR) { |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 681 | // This FrameLayout will hold the custom FrameLayout and a LinearLayout |
| 682 | // that contains the title bar and a FrameLayout, which |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 683 | // holds everything else. |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 684 | FrameLayout browserFrameLayout = (FrameLayout) LayoutInflater.from(this) |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 685 | .inflate(R.layout.custom_screen, null); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 686 | mTitleBar = (TitleBar) browserFrameLayout.findViewById(R.id.title_bar); |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 687 | mTitleBar.setBrowserActivity(this); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 688 | mContentView = (FrameLayout) browserFrameLayout.findViewById( |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 689 | R.id.main_content); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 690 | mErrorConsoleContainer = (LinearLayout) browserFrameLayout.findViewById( |
| 691 | R.id.error_console); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 692 | mCustomViewContainer = (FrameLayout) browserFrameLayout |
| 693 | .findViewById(R.id.fullscreen_custom_content); |
| 694 | frameLayout.addView(browserFrameLayout, COVER_SCREEN_PARAMS); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 695 | } else { |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 696 | mCustomViewContainer = new FrameLayout(this); |
Andrei Popescu | 78f7570 | 2009-06-26 16:50:04 +0100 | [diff] [blame] | 697 | mCustomViewContainer.setBackgroundColor(Color.BLACK); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 698 | mContentView = new FrameLayout(this); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 699 | |
| 700 | LinearLayout linearLayout = new LinearLayout(this); |
| 701 | linearLayout.setOrientation(LinearLayout.VERTICAL); |
| 702 | mErrorConsoleContainer = new LinearLayout(this); |
| 703 | linearLayout.addView(mErrorConsoleContainer, new LinearLayout.LayoutParams( |
| 704 | ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 705 | linearLayout.addView(mContentView, COVER_SCREEN_PARAMS); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 706 | frameLayout.addView(mCustomViewContainer, COVER_SCREEN_PARAMS); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 707 | frameLayout.addView(linearLayout, COVER_SCREEN_PARAMS); |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 708 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 709 | |
| 710 | // Create the tab control and our initial tab |
| 711 | mTabControl = new TabControl(this); |
| 712 | |
| 713 | // Open the icon database and retain all the bookmark urls for favicons |
| 714 | retainIconsOnStartup(); |
| 715 | |
| 716 | // Keep a settings instance handy. |
| 717 | mSettings = BrowserSettings.getInstance(); |
| 718 | mSettings.setTabControl(mTabControl); |
| 719 | mSettings.loadFromDb(this); |
| 720 | |
| 721 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 722 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser"); |
| 723 | |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 724 | // If this was a web search request, pass it on to the default web search provider. |
| 725 | if (handleWebSearchIntent(getIntent())) { |
| 726 | moveTaskToBack(true); |
| 727 | return; |
| 728 | } |
| 729 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 730 | if (!mTabControl.restoreState(icicle)) { |
| 731 | // clear up the thumbnail directory if we can't restore the state as |
| 732 | // none of the files in the directory are referenced any more. |
| 733 | new ClearThumbnails().execute( |
| 734 | mTabControl.getThumbnailDir().listFiles()); |
Grace Kloba | aab3f09 | 2009-07-30 12:29:51 -0700 | [diff] [blame^] | 735 | // there is no quit on Android. But if we can't restore the state, |
| 736 | // we can treat it as a new Browser, remove the old session cookies. |
| 737 | CookieManager.getInstance().removeSessionCookie(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 738 | final Intent intent = getIntent(); |
| 739 | final Bundle extra = intent.getExtras(); |
| 740 | // Create an initial tab. |
| 741 | // If the intent is ACTION_VIEW and data is not null, the Browser is |
| 742 | // invoked to view the content by another application. In this case, |
| 743 | // the tab will be close when exit. |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 744 | UrlData urlData = getUrlDataFromIntent(intent); |
| 745 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 746 | final TabControl.Tab t = mTabControl.createNewTab( |
| 747 | Intent.ACTION_VIEW.equals(intent.getAction()) && |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 748 | intent.getData() != null, |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 749 | intent.getStringExtra(Browser.EXTRA_APPLICATION_ID), urlData.mUrl); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 750 | mTabControl.setCurrentTab(t); |
| 751 | // This is one of the only places we call attachTabToContentView |
| 752 | // without animating from the tab picker. |
| 753 | attachTabToContentView(t); |
| 754 | WebView webView = t.getWebView(); |
| 755 | if (extra != null) { |
| 756 | int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0); |
| 757 | if (scale > 0 && scale <= 1000) { |
| 758 | webView.setInitialScale(scale); |
| 759 | } |
| 760 | } |
| 761 | // If we are not restoring from an icicle, then there is a high |
| 762 | // likely hood this is the first run. So, check to see if the |
| 763 | // homepage needs to be configured and copy any plugins from our |
| 764 | // asset directory to the data partition. |
| 765 | if ((extra == null || !extra.getBoolean("testing")) |
| 766 | && !mSettings.isLoginInitialized()) { |
| 767 | setupHomePage(); |
| 768 | } |
| 769 | copyPlugins(true); |
| 770 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 771 | if (urlData.isEmpty()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 772 | if (mSettings.isLoginInitialized()) { |
| 773 | webView.loadUrl(mSettings.getHomePage()); |
| 774 | } else { |
| 775 | waitForCredentials(); |
| 776 | } |
| 777 | } else { |
Grace Kloba | 81678d9 | 2009-06-30 07:09:56 -0700 | [diff] [blame] | 778 | if (extra != null) { |
| 779 | urlData.setPostData(extra |
| 780 | .getByteArray(Browser.EXTRA_POST_DATA)); |
| 781 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 782 | urlData.loadIn(webView); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 783 | } |
| 784 | } else { |
| 785 | // TabControl.restoreState() will create a new tab even if |
| 786 | // restoring the state fails. Attach it to the view here since we |
| 787 | // are not animating from the tab picker. |
| 788 | attachTabToContentView(mTabControl.getCurrentTab()); |
| 789 | } |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 790 | // Read JavaScript flags if it exists. |
| 791 | String jsFlags = mSettings.getJsFlags(); |
| 792 | if (jsFlags.trim().length() != 0) { |
| 793 | mTabControl.getCurrentWebView().setJsFlags(jsFlags); |
| 794 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 795 | |
| 796 | /* enables registration for changes in network status from |
| 797 | http stack */ |
| 798 | mNetworkStateChangedFilter = new IntentFilter(); |
| 799 | mNetworkStateChangedFilter.addAction( |
| 800 | ConnectivityManager.CONNECTIVITY_ACTION); |
| 801 | mNetworkStateIntentReceiver = new BroadcastReceiver() { |
| 802 | @Override |
| 803 | public void onReceive(Context context, Intent intent) { |
| 804 | if (intent.getAction().equals( |
| 805 | ConnectivityManager.CONNECTIVITY_ACTION)) { |
| 806 | boolean down = intent.getBooleanExtra( |
| 807 | ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); |
| 808 | onNetworkToggle(!down); |
| 809 | } |
| 810 | } |
| 811 | }; |
Grace Kloba | b4da0ad | 2009-05-14 14:45:40 -0700 | [diff] [blame] | 812 | |
| 813 | IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); |
| 814 | filter.addAction(Intent.ACTION_PACKAGE_REMOVED); |
| 815 | filter.addDataScheme("package"); |
| 816 | mPackageInstallationReceiver = new BroadcastReceiver() { |
| 817 | @Override |
| 818 | public void onReceive(Context context, Intent intent) { |
| 819 | final String action = intent.getAction(); |
| 820 | final String packageName = intent.getData() |
| 821 | .getSchemeSpecificPart(); |
| 822 | final boolean replacing = intent.getBooleanExtra( |
| 823 | Intent.EXTRA_REPLACING, false); |
| 824 | if (Intent.ACTION_PACKAGE_REMOVED.equals(action) && replacing) { |
| 825 | // if it is replacing, refreshPlugins() when adding |
| 826 | return; |
| 827 | } |
| 828 | PackageManager pm = BrowserActivity.this.getPackageManager(); |
| 829 | PackageInfo pkgInfo = null; |
| 830 | try { |
| 831 | pkgInfo = pm.getPackageInfo(packageName, |
| 832 | PackageManager.GET_PERMISSIONS); |
| 833 | } catch (PackageManager.NameNotFoundException e) { |
| 834 | return; |
| 835 | } |
| 836 | if (pkgInfo != null) { |
| 837 | String permissions[] = pkgInfo.requestedPermissions; |
| 838 | if (permissions == null) { |
| 839 | return; |
| 840 | } |
| 841 | boolean permissionOk = false; |
| 842 | for (String permit : permissions) { |
| 843 | if (PluginManager.PLUGIN_PERMISSION.equals(permit)) { |
| 844 | permissionOk = true; |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | if (permissionOk) { |
| 849 | PluginManager.getInstance(BrowserActivity.this) |
| 850 | .refreshPlugins( |
| 851 | Intent.ACTION_PACKAGE_ADDED |
| 852 | .equals(action)); |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | }; |
| 857 | registerReceiver(mPackageInstallationReceiver, filter); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | @Override |
| 861 | protected void onNewIntent(Intent intent) { |
| 862 | TabControl.Tab current = mTabControl.getCurrentTab(); |
| 863 | // When a tab is closed on exit, the current tab index is set to -1. |
| 864 | // Reset before proceed as Browser requires the current tab to be set. |
| 865 | if (current == null) { |
| 866 | // Try to reset the tab in case the index was incorrect. |
| 867 | current = mTabControl.getTab(0); |
| 868 | if (current == null) { |
| 869 | // No tabs at all so just ignore this intent. |
| 870 | return; |
| 871 | } |
| 872 | mTabControl.setCurrentTab(current); |
| 873 | attachTabToContentView(current); |
| 874 | resetTitleAndIcon(current.getWebView()); |
| 875 | } |
| 876 | final String action = intent.getAction(); |
| 877 | final int flags = intent.getFlags(); |
| 878 | if (Intent.ACTION_MAIN.equals(action) || |
| 879 | (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 880 | // just resume the browser |
| 881 | return; |
| 882 | } |
| 883 | if (Intent.ACTION_VIEW.equals(action) |
| 884 | || Intent.ACTION_SEARCH.equals(action) |
| 885 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
| 886 | || Intent.ACTION_WEB_SEARCH.equals(action)) { |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 887 | // If this was a search request (e.g. search query directly typed into the address bar), |
| 888 | // pass it on to the default web search provider. |
| 889 | if (handleWebSearchIntent(intent)) { |
| 890 | return; |
| 891 | } |
| 892 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 893 | UrlData urlData = getUrlDataFromIntent(intent); |
| 894 | if (urlData.isEmpty()) { |
| 895 | urlData = new UrlData(mSettings.getHomePage()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 896 | } |
Grace Kloba | 81678d9 | 2009-06-30 07:09:56 -0700 | [diff] [blame] | 897 | urlData.setPostData(intent |
| 898 | .getByteArrayExtra(Browser.EXTRA_POST_DATA)); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 899 | |
Grace Kloba | cc63403 | 2009-07-28 15:58:19 -0700 | [diff] [blame] | 900 | final String appId = intent |
| 901 | .getStringExtra(Browser.EXTRA_APPLICATION_ID); |
| 902 | if (Intent.ACTION_VIEW.equals(action) |
| 903 | && !getPackageName().equals(appId) |
| 904 | && (flags & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 905 | TabControl.Tab appTab = mTabControl.getTabFromId(appId); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 906 | if (appTab != null) { |
| 907 | Log.i(LOGTAG, "Reusing tab for " + appId); |
| 908 | // Dismiss the subwindow if applicable. |
| 909 | dismissSubWindow(appTab); |
| 910 | // Since we might kill the WebView, remove it from the |
| 911 | // content view first. |
| 912 | removeTabFromContentView(appTab); |
| 913 | // Recreate the main WebView after destroying the old one. |
| 914 | // If the WebView has the same original url and is on that |
| 915 | // page, it can be reused. |
| 916 | boolean needsLoad = |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 917 | mTabControl.recreateWebView(appTab, urlData.mUrl); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 918 | |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 919 | if (current != appTab) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 920 | showTab(appTab, needsLoad ? urlData : EMPTY_URL_DATA); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 921 | } else { |
| 922 | if (mTabOverview != null && mAnimationCount == 0) { |
| 923 | sendAnimateFromOverview(appTab, false, |
Grace Kloba | ec7eb37 | 2009-06-16 13:45:56 -0700 | [diff] [blame] | 924 | needsLoad ? urlData : EMPTY_URL_DATA, |
Grace Kloba | 8ca2c79 | 2009-05-26 15:41:51 -0700 | [diff] [blame] | 925 | TAB_OVERVIEW_DELAY, null); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 926 | } else { |
| 927 | // If the tab was the current tab, we have to attach |
| 928 | // it to the view system again. |
| 929 | attachTabToContentView(appTab); |
| 930 | if (needsLoad) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 931 | urlData.loadIn(appTab.getWebView()); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | } |
| 935 | return; |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 936 | } else { |
| 937 | // No matching application tab, try to find a regular tab |
| 938 | // with a matching url. |
| 939 | appTab = mTabControl.findUnusedTabWithUrl(urlData.mUrl); |
| 940 | if (appTab != null) { |
| 941 | if (current != appTab) { |
| 942 | // Use EMPTY_URL_DATA so we do not reload the page |
| 943 | showTab(appTab, EMPTY_URL_DATA); |
| 944 | } else { |
| 945 | if (mTabOverview != null && mAnimationCount == 0) { |
| 946 | sendAnimateFromOverview(appTab, false, |
| 947 | EMPTY_URL_DATA, TAB_OVERVIEW_DELAY, |
| 948 | null); |
| 949 | } |
| 950 | // Don't do anything here since we are on the |
| 951 | // correct page. |
| 952 | } |
| 953 | } else { |
| 954 | // if FLAG_ACTIVITY_BROUGHT_TO_FRONT flag is on, the url |
| 955 | // will be opened in a new tab unless we have reached |
| 956 | // MAX_TABS. Then the url will be opened in the current |
| 957 | // tab. If a new tab is created, it will have "true" for |
| 958 | // exit on close. |
| 959 | openTabAndShow(urlData, null, true, appId); |
| 960 | } |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 961 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 962 | } else { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 963 | if ("about:debug".equals(urlData.mUrl)) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 964 | mSettings.toggleDebugSettings(); |
| 965 | return; |
| 966 | } |
| 967 | // If the Window overview is up and we are not in the midst of |
| 968 | // an animation, animate away from the Window overview. |
| 969 | if (mTabOverview != null && mAnimationCount == 0) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 970 | sendAnimateFromOverview(current, false, urlData, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 971 | TAB_OVERVIEW_DELAY, null); |
| 972 | } else { |
| 973 | // Get rid of the subwindow if it exists |
| 974 | dismissSubWindow(current); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 975 | urlData.loadIn(current.getWebView()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | } |
| 979 | } |
| 980 | |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 981 | private int parseUrlShortcut(String url) { |
| 982 | if (url == null) return SHORTCUT_INVALID; |
| 983 | |
| 984 | // FIXME: quick search, need to be customized by setting |
| 985 | if (url.length() > 2 && url.charAt(1) == ' ') { |
| 986 | switch (url.charAt(0)) { |
| 987 | case 'g': return SHORTCUT_GOOGLE_SEARCH; |
| 988 | case 'w': return SHORTCUT_WIKIPEDIA_SEARCH; |
| 989 | case 'd': return SHORTCUT_DICTIONARY_SEARCH; |
| 990 | case 'l': return SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH; |
| 991 | } |
| 992 | } |
| 993 | return SHORTCUT_INVALID; |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * Launches the default web search activity with the query parameters if the given intent's data |
| 998 | * are identified as plain search terms and not URLs/shortcuts. |
| 999 | * @return true if the intent was handled and web search activity was launched, false if not. |
| 1000 | */ |
| 1001 | private boolean handleWebSearchIntent(Intent intent) { |
| 1002 | if (intent == null) return false; |
| 1003 | |
| 1004 | String url = null; |
| 1005 | final String action = intent.getAction(); |
| 1006 | if (Intent.ACTION_VIEW.equals(action)) { |
| 1007 | url = intent.getData().toString(); |
| 1008 | } else if (Intent.ACTION_SEARCH.equals(action) |
| 1009 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
| 1010 | || Intent.ACTION_WEB_SEARCH.equals(action)) { |
| 1011 | url = intent.getStringExtra(SearchManager.QUERY); |
| 1012 | } |
Satish Sampath | 15e9f2d | 2009-06-23 22:29:49 +0100 | [diff] [blame] | 1013 | return handleWebSearchRequest(url, intent.getBundleExtra(SearchManager.APP_DATA)); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | /** |
| 1017 | * Launches the default web search activity with the query parameters if the given url string |
| 1018 | * was identified as plain search terms and not URL/shortcut. |
| 1019 | * @return true if the request was handled and web search activity was launched, false if not. |
| 1020 | */ |
Satish Sampath | 15e9f2d | 2009-06-23 22:29:49 +0100 | [diff] [blame] | 1021 | private boolean handleWebSearchRequest(String inUrl, Bundle appData) { |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 1022 | if (inUrl == null) return false; |
| 1023 | |
| 1024 | // In general, we shouldn't modify URL from Intent. |
| 1025 | // But currently, we get the user-typed URL from search box as well. |
| 1026 | String url = fixUrl(inUrl).trim(); |
| 1027 | |
| 1028 | // URLs and site specific search shortcuts are handled by the regular flow of control, so |
| 1029 | // return early. |
| 1030 | if (Regex.WEB_URL_PATTERN.matcher(url).matches() |
Satish Sampath | bc5b9f3 | 2009-06-04 18:21:40 +0100 | [diff] [blame] | 1031 | || ACCEPTED_URI_SCHEMA.matcher(url).matches() |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 1032 | || parseUrlShortcut(url) != SHORTCUT_INVALID) { |
| 1033 | return false; |
| 1034 | } |
| 1035 | |
| 1036 | Browser.updateVisitedHistory(mResolver, url, false); |
| 1037 | Browser.addSearchUrl(mResolver, url); |
| 1038 | |
| 1039 | Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); |
| 1040 | intent.addCategory(Intent.CATEGORY_DEFAULT); |
| 1041 | intent.putExtra(SearchManager.QUERY, url); |
Satish Sampath | 15e9f2d | 2009-06-23 22:29:49 +0100 | [diff] [blame] | 1042 | if (appData != null) { |
| 1043 | intent.putExtra(SearchManager.APP_DATA, appData); |
| 1044 | } |
Grace Kloba | cc63403 | 2009-07-28 15:58:19 -0700 | [diff] [blame] | 1045 | intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName()); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 1046 | startActivity(intent); |
| 1047 | |
| 1048 | return true; |
| 1049 | } |
| 1050 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 1051 | private UrlData getUrlDataFromIntent(Intent intent) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1052 | String url = null; |
| 1053 | if (intent != null) { |
| 1054 | final String action = intent.getAction(); |
| 1055 | if (Intent.ACTION_VIEW.equals(action)) { |
| 1056 | url = smartUrlFilter(intent.getData()); |
| 1057 | if (url != null && url.startsWith("content:")) { |
| 1058 | /* Append mimetype so webview knows how to display */ |
| 1059 | String mimeType = intent.resolveType(getContentResolver()); |
| 1060 | if (mimeType != null) { |
| 1061 | url += "?" + mimeType; |
| 1062 | } |
| 1063 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 1064 | if ("inline:".equals(url)) { |
| 1065 | return new InlinedUrlData( |
| 1066 | intent.getStringExtra(Browser.EXTRA_INLINE_CONTENT), |
| 1067 | intent.getType(), |
| 1068 | intent.getStringExtra(Browser.EXTRA_INLINE_ENCODING), |
| 1069 | intent.getStringExtra(Browser.EXTRA_INLINE_FAILURL)); |
| 1070 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1071 | } else if (Intent.ACTION_SEARCH.equals(action) |
| 1072 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
| 1073 | || Intent.ACTION_WEB_SEARCH.equals(action)) { |
| 1074 | url = intent.getStringExtra(SearchManager.QUERY); |
| 1075 | if (url != null) { |
| 1076 | mLastEnteredUrl = url; |
| 1077 | // Don't add Urls, just search terms. |
| 1078 | // Urls will get added when the page is loaded. |
| 1079 | if (!Regex.WEB_URL_PATTERN.matcher(url).matches()) { |
| 1080 | Browser.updateVisitedHistory(mResolver, url, false); |
| 1081 | } |
| 1082 | // In general, we shouldn't modify URL from Intent. |
| 1083 | // But currently, we get the user-typed URL from search box as well. |
| 1084 | url = fixUrl(url); |
| 1085 | url = smartUrlFilter(url); |
| 1086 | String searchSource = "&source=android-" + GOOGLE_SEARCH_SOURCE_SUGGEST + "&"; |
| 1087 | if (url.contains(searchSource)) { |
| 1088 | String source = null; |
| 1089 | final Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA); |
| 1090 | if (appData != null) { |
| 1091 | source = appData.getString(SearchManager.SOURCE); |
| 1092 | } |
| 1093 | if (TextUtils.isEmpty(source)) { |
| 1094 | source = GOOGLE_SEARCH_SOURCE_UNKNOWN; |
| 1095 | } |
| 1096 | url = url.replace(searchSource, "&source=android-"+source+"&"); |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 1101 | return new UrlData(url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | /* package */ static String fixUrl(String inUrl) { |
| 1105 | if (inUrl.startsWith("http://") || inUrl.startsWith("https://")) |
| 1106 | return inUrl; |
| 1107 | if (inUrl.startsWith("http:") || |
| 1108 | inUrl.startsWith("https:")) { |
| 1109 | if (inUrl.startsWith("http:/") || inUrl.startsWith("https:/")) { |
| 1110 | inUrl = inUrl.replaceFirst("/", "//"); |
| 1111 | } else inUrl = inUrl.replaceFirst(":", "://"); |
| 1112 | } |
| 1113 | return inUrl; |
| 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * Looking for the pattern like this |
| 1118 | * |
| 1119 | * * |
| 1120 | * * * |
| 1121 | * *** * ******* |
| 1122 | * * * |
| 1123 | * * * |
| 1124 | * * |
| 1125 | */ |
| 1126 | private final SensorListener mSensorListener = new SensorListener() { |
| 1127 | private long mLastGestureTime; |
| 1128 | private float[] mPrev = new float[3]; |
| 1129 | private float[] mPrevDiff = new float[3]; |
| 1130 | private float[] mDiff = new float[3]; |
| 1131 | private float[] mRevertDiff = new float[3]; |
| 1132 | |
| 1133 | public void onSensorChanged(int sensor, float[] values) { |
| 1134 | boolean show = false; |
| 1135 | float[] diff = new float[3]; |
| 1136 | |
| 1137 | for (int i = 0; i < 3; i++) { |
| 1138 | diff[i] = values[i] - mPrev[i]; |
| 1139 | if (Math.abs(diff[i]) > 1) { |
| 1140 | show = true; |
| 1141 | } |
| 1142 | if ((diff[i] > 1.0 && mDiff[i] < 0.2) |
| 1143 | || (diff[i] < -1.0 && mDiff[i] > -0.2)) { |
| 1144 | // start track when there is a big move, or revert |
| 1145 | mRevertDiff[i] = mDiff[i]; |
| 1146 | mDiff[i] = 0; |
| 1147 | } else if (diff[i] > -0.2 && diff[i] < 0.2) { |
| 1148 | // reset when it is flat |
| 1149 | mDiff[i] = mRevertDiff[i] = 0; |
| 1150 | } |
| 1151 | mDiff[i] += diff[i]; |
| 1152 | mPrevDiff[i] = diff[i]; |
| 1153 | mPrev[i] = values[i]; |
| 1154 | } |
| 1155 | |
| 1156 | if (false) { |
| 1157 | // only shows if we think the delta is big enough, in an attempt |
| 1158 | // to detect "serious" moves left/right or up/down |
| 1159 | Log.d("BrowserSensorHack", "sensorChanged " + sensor + " (" |
| 1160 | + values[0] + ", " + values[1] + ", " + values[2] + ")" |
| 1161 | + " diff(" + diff[0] + " " + diff[1] + " " + diff[2] |
| 1162 | + ")"); |
| 1163 | Log.d("BrowserSensorHack", " mDiff(" + mDiff[0] + " " |
| 1164 | + mDiff[1] + " " + mDiff[2] + ")" + " mRevertDiff(" |
| 1165 | + mRevertDiff[0] + " " + mRevertDiff[1] + " " |
| 1166 | + mRevertDiff[2] + ")"); |
| 1167 | } |
| 1168 | |
| 1169 | long now = android.os.SystemClock.uptimeMillis(); |
| 1170 | if (now - mLastGestureTime > 1000) { |
| 1171 | mLastGestureTime = 0; |
| 1172 | |
| 1173 | float y = mDiff[1]; |
| 1174 | float z = mDiff[2]; |
| 1175 | float ay = Math.abs(y); |
| 1176 | float az = Math.abs(z); |
| 1177 | float ry = mRevertDiff[1]; |
| 1178 | float rz = mRevertDiff[2]; |
| 1179 | float ary = Math.abs(ry); |
| 1180 | float arz = Math.abs(rz); |
| 1181 | boolean gestY = ay > 2.5f && ary > 1.0f && ay > ary; |
| 1182 | boolean gestZ = az > 3.5f && arz > 1.0f && az > arz; |
| 1183 | |
| 1184 | if ((gestY || gestZ) && !(gestY && gestZ)) { |
| 1185 | WebView view = mTabControl.getCurrentWebView(); |
| 1186 | |
| 1187 | if (view != null) { |
| 1188 | if (gestZ) { |
| 1189 | if (z < 0) { |
| 1190 | view.zoomOut(); |
| 1191 | } else { |
| 1192 | view.zoomIn(); |
| 1193 | } |
| 1194 | } else { |
| 1195 | view.flingScroll(0, Math.round(y * 100)); |
| 1196 | } |
| 1197 | } |
| 1198 | mLastGestureTime = now; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | public void onAccuracyChanged(int sensor, int accuracy) { |
| 1204 | // TODO Auto-generated method stub |
| 1205 | |
| 1206 | } |
| 1207 | }; |
| 1208 | |
| 1209 | @Override protected void onResume() { |
| 1210 | super.onResume(); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 1211 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1212 | Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this); |
| 1213 | } |
| 1214 | |
| 1215 | if (!mActivityInPause) { |
| 1216 | Log.e(LOGTAG, "BrowserActivity is already resumed."); |
| 1217 | return; |
| 1218 | } |
| 1219 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1220 | mTabControl.resumeCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1221 | mActivityInPause = false; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1222 | resumeWebViewTimers(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1223 | |
| 1224 | if (mWakeLock.isHeld()) { |
| 1225 | mHandler.removeMessages(RELEASE_WAKELOCK); |
| 1226 | mWakeLock.release(); |
| 1227 | } |
| 1228 | |
| 1229 | if (mCredsDlg != null) { |
| 1230 | if (!mHandler.hasMessages(CANCEL_CREDS_REQUEST)) { |
| 1231 | // In case credential request never comes back |
| 1232 | mHandler.sendEmptyMessageDelayed(CANCEL_CREDS_REQUEST, 6000); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | registerReceiver(mNetworkStateIntentReceiver, |
| 1237 | mNetworkStateChangedFilter); |
| 1238 | WebView.enablePlatformNotifications(); |
| 1239 | |
| 1240 | if (mSettings.doFlick()) { |
| 1241 | if (mSensorManager == null) { |
| 1242 | mSensorManager = (SensorManager) getSystemService( |
| 1243 | Context.SENSOR_SERVICE); |
| 1244 | } |
| 1245 | mSensorManager.registerListener(mSensorListener, |
| 1246 | SensorManager.SENSOR_ACCELEROMETER, |
| 1247 | SensorManager.SENSOR_DELAY_FASTEST); |
| 1248 | } else { |
| 1249 | mSensorManager = null; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * onSaveInstanceState(Bundle map) |
| 1255 | * onSaveInstanceState is called right before onStop(). The map contains |
| 1256 | * the saved state. |
| 1257 | */ |
| 1258 | @Override protected void onSaveInstanceState(Bundle outState) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 1259 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1260 | Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this); |
| 1261 | } |
| 1262 | // the default implementation requires each view to have an id. As the |
| 1263 | // browser handles the state itself and it doesn't use id for the views, |
| 1264 | // don't call the default implementation. Otherwise it will trigger the |
| 1265 | // warning like this, "couldn't save which view has focus because the |
| 1266 | // focused view XXX has no id". |
| 1267 | |
| 1268 | // Save all the tabs |
| 1269 | mTabControl.saveState(outState); |
| 1270 | } |
| 1271 | |
| 1272 | @Override protected void onPause() { |
| 1273 | super.onPause(); |
| 1274 | |
| 1275 | if (mActivityInPause) { |
| 1276 | Log.e(LOGTAG, "BrowserActivity is already paused."); |
| 1277 | return; |
| 1278 | } |
| 1279 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1280 | mTabControl.pauseCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1281 | mActivityInPause = true; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1282 | if (mTabControl.getCurrentIndex() >= 0 && !pauseWebViewTimers()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1283 | mWakeLock.acquire(); |
| 1284 | mHandler.sendMessageDelayed(mHandler |
| 1285 | .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT); |
| 1286 | } |
| 1287 | |
| 1288 | // Clear the credentials toast if it is up |
| 1289 | if (mCredsDlg != null && mCredsDlg.isShowing()) { |
| 1290 | mCredsDlg.dismiss(); |
| 1291 | } |
| 1292 | mCredsDlg = null; |
| 1293 | |
| 1294 | cancelStopToast(); |
| 1295 | |
| 1296 | // unregister network state listener |
| 1297 | unregisterReceiver(mNetworkStateIntentReceiver); |
| 1298 | WebView.disablePlatformNotifications(); |
| 1299 | |
| 1300 | if (mSensorManager != null) { |
| 1301 | mSensorManager.unregisterListener(mSensorListener); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | @Override protected void onDestroy() { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 1306 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1307 | Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this); |
| 1308 | } |
| 1309 | super.onDestroy(); |
| 1310 | // Remove the current tab and sub window |
| 1311 | TabControl.Tab t = mTabControl.getCurrentTab(); |
Patrick Scott | fb5e77f | 2009-04-08 19:17:37 -0700 | [diff] [blame] | 1312 | if (t != null) { |
| 1313 | dismissSubWindow(t); |
| 1314 | removeTabFromContentView(t); |
| 1315 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1316 | // Destroy all the tabs |
| 1317 | mTabControl.destroy(); |
| 1318 | WebIconDatabase.getInstance().close(); |
| 1319 | if (mGlsConnection != null) { |
| 1320 | unbindService(mGlsConnection); |
| 1321 | mGlsConnection = null; |
| 1322 | } |
| 1323 | |
| 1324 | // |
| 1325 | // stop MASF proxy service |
| 1326 | // |
| 1327 | //Intent proxyServiceIntent = new Intent(); |
| 1328 | //proxyServiceIntent.setComponent |
| 1329 | // (new ComponentName( |
| 1330 | // "com.android.masfproxyservice", |
| 1331 | // "com.android.masfproxyservice.MasfProxyService")); |
| 1332 | //stopService(proxyServiceIntent); |
Grace Kloba | b4da0ad | 2009-05-14 14:45:40 -0700 | [diff] [blame] | 1333 | |
| 1334 | unregisterReceiver(mPackageInstallationReceiver); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | @Override |
| 1338 | public void onConfigurationChanged(Configuration newConfig) { |
| 1339 | super.onConfigurationChanged(newConfig); |
| 1340 | |
| 1341 | if (mPageInfoDialog != null) { |
| 1342 | mPageInfoDialog.dismiss(); |
| 1343 | showPageInfo( |
| 1344 | mPageInfoView, |
| 1345 | mPageInfoFromShowSSLCertificateOnError.booleanValue()); |
| 1346 | } |
| 1347 | if (mSSLCertificateDialog != null) { |
| 1348 | mSSLCertificateDialog.dismiss(); |
| 1349 | showSSLCertificate( |
| 1350 | mSSLCertificateView); |
| 1351 | } |
| 1352 | if (mSSLCertificateOnErrorDialog != null) { |
| 1353 | mSSLCertificateOnErrorDialog.dismiss(); |
| 1354 | showSSLCertificateOnError( |
| 1355 | mSSLCertificateOnErrorView, |
| 1356 | mSSLCertificateOnErrorHandler, |
| 1357 | mSSLCertificateOnErrorError); |
| 1358 | } |
| 1359 | if (mHttpAuthenticationDialog != null) { |
| 1360 | String title = ((TextView) mHttpAuthenticationDialog |
| 1361 | .findViewById(com.android.internal.R.id.alertTitle)).getText() |
| 1362 | .toString(); |
| 1363 | String name = ((TextView) mHttpAuthenticationDialog |
| 1364 | .findViewById(R.id.username_edit)).getText().toString(); |
| 1365 | String password = ((TextView) mHttpAuthenticationDialog |
| 1366 | .findViewById(R.id.password_edit)).getText().toString(); |
| 1367 | int focusId = mHttpAuthenticationDialog.getCurrentFocus() |
| 1368 | .getId(); |
| 1369 | mHttpAuthenticationDialog.dismiss(); |
| 1370 | showHttpAuthentication(mHttpAuthHandler, null, null, title, |
| 1371 | name, password, focusId); |
| 1372 | } |
| 1373 | if (mFindDialog != null && mFindDialog.isShowing()) { |
| 1374 | mFindDialog.onConfigurationChanged(newConfig); |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | @Override public void onLowMemory() { |
| 1379 | super.onLowMemory(); |
| 1380 | mTabControl.freeMemory(); |
| 1381 | } |
| 1382 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1383 | private boolean resumeWebViewTimers() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1384 | if ((!mActivityInPause && !mPageStarted) || |
| 1385 | (mActivityInPause && mPageStarted)) { |
| 1386 | CookieSyncManager.getInstance().startSync(); |
| 1387 | WebView w = mTabControl.getCurrentWebView(); |
| 1388 | if (w != null) { |
| 1389 | w.resumeTimers(); |
| 1390 | } |
| 1391 | return true; |
| 1392 | } else { |
| 1393 | return false; |
| 1394 | } |
| 1395 | } |
| 1396 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1397 | private boolean pauseWebViewTimers() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1398 | if (mActivityInPause && !mPageStarted) { |
| 1399 | CookieSyncManager.getInstance().stopSync(); |
| 1400 | WebView w = mTabControl.getCurrentWebView(); |
| 1401 | if (w != null) { |
| 1402 | w.pauseTimers(); |
| 1403 | } |
| 1404 | return true; |
| 1405 | } else { |
| 1406 | return false; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | /* |
| 1411 | * This function is called when we are launching for the first time. We |
| 1412 | * are waiting for the login credentials before loading Google home |
| 1413 | * pages. This way the user will be logged in straight away. |
| 1414 | */ |
| 1415 | private void waitForCredentials() { |
| 1416 | // Show a toast |
| 1417 | mCredsDlg = new ProgressDialog(this); |
| 1418 | mCredsDlg.setIndeterminate(true); |
| 1419 | mCredsDlg.setMessage(getText(R.string.retrieving_creds_dlg_msg)); |
| 1420 | // If the user cancels the operation, then cancel the Google |
| 1421 | // Credentials request. |
| 1422 | mCredsDlg.setCancelMessage(mHandler.obtainMessage(CANCEL_CREDS_REQUEST)); |
| 1423 | mCredsDlg.show(); |
| 1424 | |
| 1425 | // We set a timeout for the retrieval of credentials in onResume() |
| 1426 | // as that is when we have freed up some CPU time to get |
| 1427 | // the login credentials. |
| 1428 | } |
| 1429 | |
| 1430 | /* |
| 1431 | * If we have received the credentials or we have timed out and we are |
| 1432 | * showing the credentials dialog, then it is time to move on. |
| 1433 | */ |
| 1434 | private void resumeAfterCredentials() { |
| 1435 | if (mCredsDlg == null) { |
| 1436 | return; |
| 1437 | } |
| 1438 | |
| 1439 | // Clear the toast |
| 1440 | if (mCredsDlg.isShowing()) { |
| 1441 | mCredsDlg.dismiss(); |
| 1442 | } |
| 1443 | mCredsDlg = null; |
| 1444 | |
| 1445 | // Clear any pending timeout |
| 1446 | mHandler.removeMessages(CANCEL_CREDS_REQUEST); |
| 1447 | |
| 1448 | // Load the page |
| 1449 | WebView w = mTabControl.getCurrentWebView(); |
| 1450 | if (w != null) { |
| 1451 | w.loadUrl(mSettings.getHomePage()); |
| 1452 | } |
| 1453 | |
| 1454 | // Update the settings, need to do this last as it can take a moment |
| 1455 | // to persist the settings. In the mean time we could be loading |
| 1456 | // content. |
| 1457 | mSettings.setLoginInitialized(this); |
| 1458 | } |
| 1459 | |
| 1460 | // Open the icon database and retain all the icons for visited sites. |
| 1461 | private void retainIconsOnStartup() { |
| 1462 | final WebIconDatabase db = WebIconDatabase.getInstance(); |
| 1463 | db.open(getDir("icons", 0).getPath()); |
| 1464 | try { |
| 1465 | Cursor c = Browser.getAllBookmarks(mResolver); |
| 1466 | if (!c.moveToFirst()) { |
| 1467 | c.deactivate(); |
| 1468 | return; |
| 1469 | } |
| 1470 | int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); |
| 1471 | do { |
| 1472 | String url = c.getString(urlIndex); |
| 1473 | db.retainIconForPageUrl(url); |
| 1474 | } while (c.moveToNext()); |
| 1475 | c.deactivate(); |
| 1476 | } catch (IllegalStateException e) { |
| 1477 | Log.e(LOGTAG, "retainIconsOnStartup", e); |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | // Helper method for getting the top window. |
| 1482 | WebView getTopWindow() { |
| 1483 | return mTabControl.getCurrentTopWebView(); |
| 1484 | } |
| 1485 | |
| 1486 | @Override |
| 1487 | public boolean onCreateOptionsMenu(Menu menu) { |
| 1488 | super.onCreateOptionsMenu(menu); |
| 1489 | |
| 1490 | MenuInflater inflater = getMenuInflater(); |
| 1491 | inflater.inflate(R.menu.browser, menu); |
| 1492 | mMenu = menu; |
| 1493 | updateInLoadMenuItems(); |
| 1494 | return true; |
| 1495 | } |
| 1496 | |
| 1497 | /** |
| 1498 | * As the menu can be open when loading state changes |
| 1499 | * we must manually update the state of the stop/reload menu |
| 1500 | * item |
| 1501 | */ |
| 1502 | private void updateInLoadMenuItems() { |
| 1503 | if (mMenu == null) { |
| 1504 | return; |
| 1505 | } |
| 1506 | MenuItem src = mInLoad ? |
| 1507 | mMenu.findItem(R.id.stop_menu_id): |
| 1508 | mMenu.findItem(R.id.reload_menu_id); |
| 1509 | MenuItem dest = mMenu.findItem(R.id.stop_reload_menu_id); |
| 1510 | dest.setIcon(src.getIcon()); |
| 1511 | dest.setTitle(src.getTitle()); |
| 1512 | } |
| 1513 | |
| 1514 | @Override |
| 1515 | public boolean onContextItemSelected(MenuItem item) { |
| 1516 | // chording is not an issue with context menus, but we use the same |
| 1517 | // options selector, so set mCanChord to true so we can access them. |
| 1518 | mCanChord = true; |
| 1519 | int id = item.getItemId(); |
| 1520 | final WebView webView = getTopWindow(); |
Leon Scroggins | 0d7ae0e | 2009-06-05 11:04:45 -0400 | [diff] [blame] | 1521 | if (null == webView) { |
| 1522 | return false; |
| 1523 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1524 | final HashMap hrefMap = new HashMap(); |
| 1525 | hrefMap.put("webview", webView); |
| 1526 | final Message msg = mHandler.obtainMessage( |
| 1527 | FOCUS_NODE_HREF, id, 0, hrefMap); |
| 1528 | switch (id) { |
| 1529 | // -- Browser context menu |
| 1530 | case R.id.open_context_menu_id: |
| 1531 | case R.id.open_newtab_context_menu_id: |
| 1532 | case R.id.bookmark_context_menu_id: |
| 1533 | case R.id.save_link_context_menu_id: |
| 1534 | case R.id.share_link_context_menu_id: |
| 1535 | case R.id.copy_link_context_menu_id: |
| 1536 | webView.requestFocusNodeHref(msg); |
| 1537 | break; |
| 1538 | |
| 1539 | default: |
| 1540 | // For other context menus |
| 1541 | return onOptionsItemSelected(item); |
| 1542 | } |
| 1543 | mCanChord = false; |
| 1544 | return true; |
| 1545 | } |
| 1546 | |
| 1547 | private Bundle createGoogleSearchSourceBundle(String source) { |
| 1548 | Bundle bundle = new Bundle(); |
| 1549 | bundle.putString(SearchManager.SOURCE, source); |
| 1550 | return bundle; |
| 1551 | } |
| 1552 | |
| 1553 | /** |
The Android Open Source Project | 4e5f587 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1554 | * Overriding this to insert a local information bundle |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1555 | */ |
| 1556 | @Override |
| 1557 | public boolean onSearchRequested() { |
Grace Kloba | cf84995 | 2009-07-09 18:57:55 -0700 | [diff] [blame] | 1558 | String url = getTopWindow().getUrl(); |
Grace Kloba | 83f4734 | 2009-07-20 10:44:31 -0700 | [diff] [blame] | 1559 | startSearch(mSettings.getHomePage().equals(url) ? null : url, true, |
The Android Open Source Project | 4e5f587 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1560 | createGoogleSearchSourceBundle(GOOGLE_SEARCH_SOURCE_SEARCHKEY), false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1561 | return true; |
| 1562 | } |
| 1563 | |
| 1564 | @Override |
| 1565 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
| 1566 | Bundle appSearchData, boolean globalSearch) { |
| 1567 | if (appSearchData == null) { |
| 1568 | appSearchData = createGoogleSearchSourceBundle(GOOGLE_SEARCH_SOURCE_TYPE); |
| 1569 | } |
| 1570 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 1571 | } |
| 1572 | |
| 1573 | @Override |
| 1574 | public boolean onOptionsItemSelected(MenuItem item) { |
| 1575 | if (!mCanChord) { |
| 1576 | // The user has already fired a shortcut with this hold down of the |
| 1577 | // menu key. |
| 1578 | return false; |
| 1579 | } |
Leon Scroggins | 0d7ae0e | 2009-06-05 11:04:45 -0400 | [diff] [blame] | 1580 | if (null == mTabOverview && null == getTopWindow()) { |
| 1581 | return false; |
| 1582 | } |
Grace Kloba | 6ee9c49 | 2009-07-13 10:04:34 -0700 | [diff] [blame] | 1583 | if (mMenuIsDown) { |
| 1584 | // The shortcut action consumes the MENU. Even if it is still down, |
| 1585 | // it won't trigger the next shortcut action. In the case of the |
| 1586 | // shortcut action triggering a new activity, like Bookmarks, we |
| 1587 | // won't get onKeyUp for MENU. So it is important to reset it here. |
| 1588 | mMenuIsDown = false; |
| 1589 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1590 | switch (item.getItemId()) { |
| 1591 | // -- Main menu |
| 1592 | case R.id.goto_menu_id: { |
| 1593 | String url = getTopWindow().getUrl(); |
| 1594 | startSearch(mSettings.getHomePage().equals(url) ? null : url, true, |
| 1595 | createGoogleSearchSourceBundle(GOOGLE_SEARCH_SOURCE_GOTO), false); |
| 1596 | } |
| 1597 | break; |
| 1598 | |
| 1599 | case R.id.bookmarks_menu_id: |
| 1600 | bookmarksOrHistoryPicker(false); |
| 1601 | break; |
| 1602 | |
| 1603 | case R.id.windows_menu_id: |
| 1604 | if (mTabControl.getTabCount() == 1) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 1605 | openTabAndShow(mSettings.getHomePage(), null, false, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1606 | } else { |
| 1607 | tabPicker(true, mTabControl.getCurrentIndex(), false); |
| 1608 | } |
| 1609 | break; |
| 1610 | |
| 1611 | case R.id.stop_reload_menu_id: |
| 1612 | if (mInLoad) { |
| 1613 | stopLoading(); |
| 1614 | } else { |
| 1615 | getTopWindow().reload(); |
| 1616 | } |
| 1617 | break; |
| 1618 | |
| 1619 | case R.id.back_menu_id: |
| 1620 | getTopWindow().goBack(); |
| 1621 | break; |
| 1622 | |
| 1623 | case R.id.forward_menu_id: |
| 1624 | getTopWindow().goForward(); |
| 1625 | break; |
| 1626 | |
| 1627 | case R.id.close_menu_id: |
| 1628 | // Close the subwindow if it exists. |
| 1629 | if (mTabControl.getCurrentSubWindow() != null) { |
| 1630 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 1631 | break; |
| 1632 | } |
| 1633 | final int currentIndex = mTabControl.getCurrentIndex(); |
| 1634 | final TabControl.Tab parent = |
| 1635 | mTabControl.getCurrentTab().getParentTab(); |
| 1636 | int indexToShow = -1; |
| 1637 | if (parent != null) { |
| 1638 | indexToShow = mTabControl.getTabIndex(parent); |
| 1639 | } else { |
| 1640 | // Get the last tab in the list. If it is the current tab, |
| 1641 | // subtract 1 more. |
| 1642 | indexToShow = mTabControl.getTabCount() - 1; |
| 1643 | if (currentIndex == indexToShow) { |
| 1644 | indexToShow--; |
| 1645 | } |
| 1646 | } |
| 1647 | switchTabs(currentIndex, indexToShow, true); |
| 1648 | break; |
| 1649 | |
| 1650 | case R.id.homepage_menu_id: |
| 1651 | TabControl.Tab current = mTabControl.getCurrentTab(); |
| 1652 | if (current != null) { |
| 1653 | dismissSubWindow(current); |
| 1654 | current.getWebView().loadUrl(mSettings.getHomePage()); |
| 1655 | } |
| 1656 | break; |
| 1657 | |
| 1658 | case R.id.preferences_menu_id: |
| 1659 | Intent intent = new Intent(this, |
| 1660 | BrowserPreferencesPage.class); |
| 1661 | startActivityForResult(intent, PREFERENCES_PAGE); |
| 1662 | break; |
| 1663 | |
| 1664 | case R.id.find_menu_id: |
| 1665 | if (null == mFindDialog) { |
| 1666 | mFindDialog = new FindDialog(this); |
| 1667 | } |
| 1668 | mFindDialog.setWebView(getTopWindow()); |
| 1669 | mFindDialog.show(); |
| 1670 | mMenuState = EMPTY_MENU; |
| 1671 | break; |
| 1672 | |
| 1673 | case R.id.select_text_id: |
| 1674 | getTopWindow().emulateShiftHeld(); |
| 1675 | break; |
| 1676 | case R.id.page_info_menu_id: |
| 1677 | showPageInfo(mTabControl.getCurrentTab(), false); |
| 1678 | break; |
| 1679 | |
| 1680 | case R.id.classic_history_menu_id: |
| 1681 | bookmarksOrHistoryPicker(true); |
| 1682 | break; |
| 1683 | |
| 1684 | case R.id.share_page_menu_id: |
| 1685 | Browser.sendString(this, getTopWindow().getUrl()); |
| 1686 | break; |
| 1687 | |
| 1688 | case R.id.dump_nav_menu_id: |
| 1689 | getTopWindow().debugDump(); |
| 1690 | break; |
| 1691 | |
| 1692 | case R.id.zoom_in_menu_id: |
| 1693 | getTopWindow().zoomIn(); |
| 1694 | break; |
| 1695 | |
| 1696 | case R.id.zoom_out_menu_id: |
| 1697 | getTopWindow().zoomOut(); |
| 1698 | break; |
| 1699 | |
| 1700 | case R.id.view_downloads_menu_id: |
| 1701 | viewDownloads(null); |
| 1702 | break; |
| 1703 | |
| 1704 | // -- Tab menu |
| 1705 | case R.id.view_tab_menu_id: |
| 1706 | if (mTabListener != null && mTabOverview != null) { |
| 1707 | int pos = mTabOverview.getContextMenuPosition(item); |
| 1708 | mTabOverview.setCurrentIndex(pos); |
| 1709 | mTabListener.onClick(pos); |
| 1710 | } |
| 1711 | break; |
| 1712 | |
| 1713 | case R.id.remove_tab_menu_id: |
| 1714 | if (mTabListener != null && mTabOverview != null) { |
| 1715 | int pos = mTabOverview.getContextMenuPosition(item); |
| 1716 | mTabListener.remove(pos); |
| 1717 | } |
| 1718 | break; |
| 1719 | |
| 1720 | case R.id.new_tab_menu_id: |
| 1721 | // No need to check for mTabOverview here since we are not |
| 1722 | // dependent on it for a position. |
| 1723 | if (mTabListener != null) { |
| 1724 | // If the overview happens to be non-null, make the "New |
| 1725 | // Tab" cell visible. |
| 1726 | if (mTabOverview != null) { |
| 1727 | mTabOverview.setCurrentIndex(ImageGrid.NEW_TAB); |
| 1728 | } |
| 1729 | mTabListener.onClick(ImageGrid.NEW_TAB); |
| 1730 | } |
| 1731 | break; |
| 1732 | |
| 1733 | case R.id.bookmark_tab_menu_id: |
| 1734 | if (mTabListener != null && mTabOverview != null) { |
| 1735 | int pos = mTabOverview.getContextMenuPosition(item); |
| 1736 | TabControl.Tab t = mTabControl.getTab(pos); |
| 1737 | // Since we called populatePickerData for all of the |
| 1738 | // tabs, getTitle and getUrl will return appropriate |
| 1739 | // values. |
| 1740 | Browser.saveBookmark(BrowserActivity.this, t.getTitle(), |
| 1741 | t.getUrl()); |
| 1742 | } |
| 1743 | break; |
| 1744 | |
| 1745 | case R.id.history_tab_menu_id: |
| 1746 | bookmarksOrHistoryPicker(true); |
| 1747 | break; |
| 1748 | |
| 1749 | case R.id.bookmarks_tab_menu_id: |
| 1750 | bookmarksOrHistoryPicker(false); |
| 1751 | break; |
| 1752 | |
| 1753 | case R.id.properties_tab_menu_id: |
| 1754 | if (mTabListener != null && mTabOverview != null) { |
| 1755 | int pos = mTabOverview.getContextMenuPosition(item); |
| 1756 | showPageInfo(mTabControl.getTab(pos), false); |
| 1757 | } |
| 1758 | break; |
| 1759 | |
| 1760 | case R.id.window_one_menu_id: |
| 1761 | case R.id.window_two_menu_id: |
| 1762 | case R.id.window_three_menu_id: |
| 1763 | case R.id.window_four_menu_id: |
| 1764 | case R.id.window_five_menu_id: |
| 1765 | case R.id.window_six_menu_id: |
| 1766 | case R.id.window_seven_menu_id: |
| 1767 | case R.id.window_eight_menu_id: |
| 1768 | { |
| 1769 | int menuid = item.getItemId(); |
| 1770 | for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) { |
| 1771 | if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) { |
| 1772 | TabControl.Tab desiredTab = mTabControl.getTab(id); |
| 1773 | if (desiredTab != null && |
| 1774 | desiredTab != mTabControl.getCurrentTab()) { |
| 1775 | switchTabs(mTabControl.getCurrentIndex(), id, false); |
| 1776 | } |
| 1777 | break; |
| 1778 | } |
| 1779 | } |
| 1780 | } |
| 1781 | break; |
| 1782 | |
| 1783 | default: |
| 1784 | if (!super.onOptionsItemSelected(item)) { |
| 1785 | return false; |
| 1786 | } |
| 1787 | // Otherwise fall through. |
| 1788 | } |
| 1789 | mCanChord = false; |
| 1790 | return true; |
| 1791 | } |
| 1792 | |
| 1793 | public void closeFind() { |
| 1794 | mMenuState = R.id.MAIN_MENU; |
| 1795 | } |
| 1796 | |
| 1797 | @Override public boolean onPrepareOptionsMenu(Menu menu) |
| 1798 | { |
| 1799 | // This happens when the user begins to hold down the menu key, so |
| 1800 | // allow them to chord to get a shortcut. |
| 1801 | mCanChord = true; |
| 1802 | // Note: setVisible will decide whether an item is visible; while |
| 1803 | // setEnabled() will decide whether an item is enabled, which also means |
| 1804 | // whether the matching shortcut key will function. |
| 1805 | super.onPrepareOptionsMenu(menu); |
| 1806 | switch (mMenuState) { |
| 1807 | case R.id.TAB_MENU: |
| 1808 | if (mCurrentMenuState != mMenuState) { |
| 1809 | menu.setGroupVisible(R.id.MAIN_MENU, false); |
| 1810 | menu.setGroupEnabled(R.id.MAIN_MENU, false); |
| 1811 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false); |
| 1812 | menu.setGroupVisible(R.id.TAB_MENU, true); |
| 1813 | menu.setGroupEnabled(R.id.TAB_MENU, true); |
| 1814 | } |
| 1815 | boolean newT = mTabControl.getTabCount() < TabControl.MAX_TABS; |
| 1816 | final MenuItem tab = menu.findItem(R.id.new_tab_menu_id); |
| 1817 | tab.setVisible(newT); |
| 1818 | tab.setEnabled(newT); |
| 1819 | break; |
| 1820 | case EMPTY_MENU: |
| 1821 | if (mCurrentMenuState != mMenuState) { |
| 1822 | menu.setGroupVisible(R.id.MAIN_MENU, false); |
| 1823 | menu.setGroupEnabled(R.id.MAIN_MENU, false); |
| 1824 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false); |
| 1825 | menu.setGroupVisible(R.id.TAB_MENU, false); |
| 1826 | menu.setGroupEnabled(R.id.TAB_MENU, false); |
| 1827 | } |
| 1828 | break; |
| 1829 | default: |
| 1830 | if (mCurrentMenuState != mMenuState) { |
| 1831 | menu.setGroupVisible(R.id.MAIN_MENU, true); |
| 1832 | menu.setGroupEnabled(R.id.MAIN_MENU, true); |
| 1833 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true); |
| 1834 | menu.setGroupVisible(R.id.TAB_MENU, false); |
| 1835 | menu.setGroupEnabled(R.id.TAB_MENU, false); |
| 1836 | } |
| 1837 | final WebView w = getTopWindow(); |
| 1838 | boolean canGoBack = false; |
| 1839 | boolean canGoForward = false; |
| 1840 | boolean isHome = false; |
| 1841 | if (w != null) { |
| 1842 | canGoBack = w.canGoBack(); |
| 1843 | canGoForward = w.canGoForward(); |
| 1844 | isHome = mSettings.getHomePage().equals(w.getUrl()); |
| 1845 | } |
| 1846 | final MenuItem back = menu.findItem(R.id.back_menu_id); |
| 1847 | back.setEnabled(canGoBack); |
| 1848 | |
| 1849 | final MenuItem home = menu.findItem(R.id.homepage_menu_id); |
| 1850 | home.setEnabled(!isHome); |
| 1851 | |
| 1852 | menu.findItem(R.id.forward_menu_id) |
| 1853 | .setEnabled(canGoForward); |
| 1854 | |
| 1855 | // decide whether to show the share link option |
| 1856 | PackageManager pm = getPackageManager(); |
| 1857 | Intent send = new Intent(Intent.ACTION_SEND); |
| 1858 | send.setType("text/plain"); |
| 1859 | ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY); |
| 1860 | menu.findItem(R.id.share_page_menu_id).setVisible(ri != null); |
| 1861 | |
| 1862 | // If there is only 1 window, the text will be "New window" |
| 1863 | final MenuItem windows = menu.findItem(R.id.windows_menu_id); |
| 1864 | windows.setTitleCondensed(mTabControl.getTabCount() > 1 ? |
| 1865 | getString(R.string.view_tabs_condensed) : |
| 1866 | getString(R.string.tab_picker_new_tab)); |
| 1867 | |
| 1868 | boolean isNavDump = mSettings.isNavDump(); |
| 1869 | final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id); |
| 1870 | nav.setVisible(isNavDump); |
| 1871 | nav.setEnabled(isNavDump); |
| 1872 | break; |
| 1873 | } |
| 1874 | mCurrentMenuState = mMenuState; |
| 1875 | return true; |
| 1876 | } |
| 1877 | |
| 1878 | @Override |
| 1879 | public void onCreateContextMenu(ContextMenu menu, View v, |
| 1880 | ContextMenuInfo menuInfo) { |
| 1881 | WebView webview = (WebView) v; |
| 1882 | WebView.HitTestResult result = webview.getHitTestResult(); |
| 1883 | if (result == null) { |
| 1884 | return; |
| 1885 | } |
| 1886 | |
| 1887 | int type = result.getType(); |
| 1888 | if (type == WebView.HitTestResult.UNKNOWN_TYPE) { |
| 1889 | Log.w(LOGTAG, |
| 1890 | "We should not show context menu when nothing is touched"); |
| 1891 | return; |
| 1892 | } |
| 1893 | if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) { |
| 1894 | // let TextView handles context menu |
| 1895 | return; |
| 1896 | } |
| 1897 | |
| 1898 | // Note, http://b/issue?id=1106666 is requesting that |
| 1899 | // an inflated menu can be used again. This is not available |
| 1900 | // yet, so inflate each time (yuk!) |
| 1901 | MenuInflater inflater = getMenuInflater(); |
| 1902 | inflater.inflate(R.menu.browsercontext, menu); |
| 1903 | |
| 1904 | // Show the correct menu group |
| 1905 | String extra = result.getExtra(); |
| 1906 | menu.setGroupVisible(R.id.PHONE_MENU, |
| 1907 | type == WebView.HitTestResult.PHONE_TYPE); |
| 1908 | menu.setGroupVisible(R.id.EMAIL_MENU, |
| 1909 | type == WebView.HitTestResult.EMAIL_TYPE); |
| 1910 | menu.setGroupVisible(R.id.GEO_MENU, |
| 1911 | type == WebView.HitTestResult.GEO_TYPE); |
| 1912 | menu.setGroupVisible(R.id.IMAGE_MENU, |
| 1913 | type == WebView.HitTestResult.IMAGE_TYPE |
| 1914 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
| 1915 | menu.setGroupVisible(R.id.ANCHOR_MENU, |
| 1916 | type == WebView.HitTestResult.SRC_ANCHOR_TYPE |
| 1917 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
| 1918 | |
| 1919 | // Setup custom handling depending on the type |
| 1920 | switch (type) { |
| 1921 | case WebView.HitTestResult.PHONE_TYPE: |
| 1922 | menu.setHeaderTitle(Uri.decode(extra)); |
| 1923 | menu.findItem(R.id.dial_context_menu_id).setIntent( |
| 1924 | new Intent(Intent.ACTION_VIEW, Uri |
| 1925 | .parse(WebView.SCHEME_TEL + extra))); |
| 1926 | Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 1927 | addIntent.putExtra(Insert.PHONE, Uri.decode(extra)); |
| 1928 | addIntent.setType(Contacts.People.CONTENT_ITEM_TYPE); |
| 1929 | menu.findItem(R.id.add_contact_context_menu_id).setIntent( |
| 1930 | addIntent); |
| 1931 | menu.findItem(R.id.copy_phone_context_menu_id).setOnMenuItemClickListener( |
| 1932 | new Copy(extra)); |
| 1933 | break; |
| 1934 | |
| 1935 | case WebView.HitTestResult.EMAIL_TYPE: |
| 1936 | menu.setHeaderTitle(extra); |
| 1937 | menu.findItem(R.id.email_context_menu_id).setIntent( |
| 1938 | new Intent(Intent.ACTION_VIEW, Uri |
| 1939 | .parse(WebView.SCHEME_MAILTO + extra))); |
| 1940 | menu.findItem(R.id.copy_mail_context_menu_id).setOnMenuItemClickListener( |
| 1941 | new Copy(extra)); |
| 1942 | break; |
| 1943 | |
| 1944 | case WebView.HitTestResult.GEO_TYPE: |
| 1945 | menu.setHeaderTitle(extra); |
| 1946 | menu.findItem(R.id.map_context_menu_id).setIntent( |
| 1947 | new Intent(Intent.ACTION_VIEW, Uri |
| 1948 | .parse(WebView.SCHEME_GEO |
| 1949 | + URLEncoder.encode(extra)))); |
| 1950 | menu.findItem(R.id.copy_geo_context_menu_id).setOnMenuItemClickListener( |
| 1951 | new Copy(extra)); |
| 1952 | break; |
| 1953 | |
| 1954 | case WebView.HitTestResult.SRC_ANCHOR_TYPE: |
| 1955 | case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE: |
| 1956 | TextView titleView = (TextView) LayoutInflater.from(this) |
| 1957 | .inflate(android.R.layout.browser_link_context_header, |
| 1958 | null); |
| 1959 | titleView.setText(extra); |
| 1960 | menu.setHeaderView(titleView); |
| 1961 | // decide whether to show the open link in new tab option |
| 1962 | menu.findItem(R.id.open_newtab_context_menu_id).setVisible( |
| 1963 | mTabControl.getTabCount() < TabControl.MAX_TABS); |
| 1964 | PackageManager pm = getPackageManager(); |
| 1965 | Intent send = new Intent(Intent.ACTION_SEND); |
| 1966 | send.setType("text/plain"); |
| 1967 | ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY); |
| 1968 | menu.findItem(R.id.share_link_context_menu_id).setVisible(ri != null); |
| 1969 | if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) { |
| 1970 | break; |
| 1971 | } |
| 1972 | // otherwise fall through to handle image part |
| 1973 | case WebView.HitTestResult.IMAGE_TYPE: |
| 1974 | if (type == WebView.HitTestResult.IMAGE_TYPE) { |
| 1975 | menu.setHeaderTitle(extra); |
| 1976 | } |
| 1977 | menu.findItem(R.id.view_image_context_menu_id).setIntent( |
| 1978 | new Intent(Intent.ACTION_VIEW, Uri.parse(extra))); |
| 1979 | menu.findItem(R.id.download_context_menu_id). |
| 1980 | setOnMenuItemClickListener(new Download(extra)); |
| 1981 | break; |
| 1982 | |
| 1983 | default: |
| 1984 | Log.w(LOGTAG, "We should not get here."); |
| 1985 | break; |
| 1986 | } |
| 1987 | } |
| 1988 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1989 | // Attach the given tab to the content view. |
| 1990 | private void attachTabToContentView(TabControl.Tab t) { |
| 1991 | final WebView main = t.getWebView(); |
| 1992 | // Attach the main WebView. |
| 1993 | mContentView.addView(main, COVER_SCREEN_PARAMS); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1994 | |
| 1995 | if (mShouldShowErrorConsole) { |
| 1996 | ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(true); |
| 1997 | if (errorConsole.numberOfErrors() == 0) { |
| 1998 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 1999 | } else { |
| 2000 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 2001 | } |
| 2002 | |
| 2003 | mErrorConsoleContainer.addView(errorConsole, |
| 2004 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, |
| 2005 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 2006 | } |
| 2007 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2008 | // Attach the sub window if necessary |
| 2009 | attachSubWindow(t); |
| 2010 | // Request focus on the top window. |
| 2011 | t.getTopWindow().requestFocus(); |
| 2012 | } |
| 2013 | |
| 2014 | // Attach a sub window to the main WebView of the given tab. |
| 2015 | private void attachSubWindow(TabControl.Tab t) { |
| 2016 | // If a sub window exists, attach it to the content view. |
| 2017 | final WebView subView = t.getSubWebView(); |
| 2018 | if (subView != null) { |
| 2019 | final View container = t.getSubWebViewContainer(); |
| 2020 | mContentView.addView(container, COVER_SCREEN_PARAMS); |
| 2021 | subView.requestFocus(); |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | // Remove the given tab from the content view. |
| 2026 | private void removeTabFromContentView(TabControl.Tab t) { |
The Android Open Source Project | cb9a0bb | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2027 | // Remove the main WebView. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2028 | mContentView.removeView(t.getWebView()); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 2029 | |
| 2030 | if (mTabControl.getCurrentErrorConsole(false) != null) { |
| 2031 | mErrorConsoleContainer.removeView(mTabControl.getCurrentErrorConsole(false)); |
| 2032 | } |
| 2033 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2034 | // Remove the sub window if it exists. |
| 2035 | if (t.getSubWebView() != null) { |
| 2036 | mContentView.removeView(t.getSubWebViewContainer()); |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | // Remove the sub window if it exists. Also called by TabControl when the |
| 2041 | // user clicks the 'X' to dismiss a sub window. |
| 2042 | /* package */ void dismissSubWindow(TabControl.Tab t) { |
| 2043 | final WebView mainView = t.getWebView(); |
| 2044 | if (t.getSubWebView() != null) { |
| 2045 | // Remove the container view and request focus on the main WebView. |
| 2046 | mContentView.removeView(t.getSubWebViewContainer()); |
| 2047 | mainView.requestFocus(); |
| 2048 | // Tell the TabControl to dismiss the subwindow. This will destroy |
| 2049 | // the WebView. |
| 2050 | mTabControl.dismissSubWindow(t); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | // Send the ANIMTE_FROM_OVERVIEW message after changing the current tab. |
| 2055 | private void sendAnimateFromOverview(final TabControl.Tab tab, |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2056 | final boolean newTab, final UrlData urlData, final int delay, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2057 | final Message msg) { |
| 2058 | // Set the current tab. |
| 2059 | mTabControl.setCurrentTab(tab); |
| 2060 | // Attach the WebView so it will layout. |
| 2061 | attachTabToContentView(tab); |
| 2062 | // Set the view to invisibile for now. |
| 2063 | tab.getWebView().setVisibility(View.INVISIBLE); |
| 2064 | // If there is a sub window, make it invisible too. |
| 2065 | if (tab.getSubWebView() != null) { |
| 2066 | tab.getSubWebViewContainer().setVisibility(View.INVISIBLE); |
| 2067 | } |
| 2068 | // Create our fake animating view. |
| 2069 | final AnimatingView view = new AnimatingView(this, tab); |
| 2070 | // Attach it to the view system and make in invisible so it will |
| 2071 | // layout but not flash white on the screen. |
| 2072 | mContentView.addView(view, COVER_SCREEN_PARAMS); |
| 2073 | view.setVisibility(View.INVISIBLE); |
| 2074 | // Send the animate message. |
| 2075 | final HashMap map = new HashMap(); |
| 2076 | map.put("view", view); |
| 2077 | // Load the url after the AnimatingView has captured the picture. This |
| 2078 | // prevents any bad layout or bad scale from being used during |
| 2079 | // animation. |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2080 | if (!urlData.isEmpty()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2081 | dismissSubWindow(tab); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2082 | urlData.loadIn(tab.getWebView()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2083 | } |
| 2084 | map.put("msg", msg); |
| 2085 | mHandler.sendMessageDelayed(mHandler.obtainMessage( |
| 2086 | ANIMATE_FROM_OVERVIEW, newTab ? 1 : 0, 0, map), delay); |
| 2087 | // Increment the count to indicate that we are in an animation. |
| 2088 | mAnimationCount++; |
| 2089 | // Remove the listener so we don't get any more tab changes. |
| 2090 | mTabOverview.setListener(null); |
| 2091 | mTabListener = null; |
| 2092 | // Make the menu empty until the animation completes. |
| 2093 | mMenuState = EMPTY_MENU; |
| 2094 | |
| 2095 | } |
| 2096 | |
| 2097 | // 500ms animation with 800ms delay |
Patrick Scott | 95d601f | 2009-06-11 10:06:46 -0400 | [diff] [blame] | 2098 | private static final int TAB_ANIMATION_DURATION = 200; |
| 2099 | private static final int TAB_OVERVIEW_DELAY = 500; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2100 | |
| 2101 | // Called by TabControl when a tab is requesting focus |
| 2102 | /* package */ void showTab(TabControl.Tab t) { |
Patrick Scott | 95d601f | 2009-06-11 10:06:46 -0400 | [diff] [blame] | 2103 | showTab(t, EMPTY_URL_DATA); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2104 | } |
| 2105 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2106 | private void showTab(TabControl.Tab t, UrlData urlData) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2107 | // Disallow focus change during a tab animation. |
| 2108 | if (mAnimationCount > 0) { |
| 2109 | return; |
| 2110 | } |
| 2111 | int delay = 0; |
| 2112 | if (mTabOverview == null) { |
| 2113 | // Add a delay so the tab overview can be shown before the second |
| 2114 | // animation begins. |
| 2115 | delay = TAB_ANIMATION_DURATION + TAB_OVERVIEW_DELAY; |
| 2116 | tabPicker(false, mTabControl.getTabIndex(t), false); |
| 2117 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2118 | sendAnimateFromOverview(t, false, urlData, delay, null); |
| 2119 | } |
| 2120 | |
| 2121 | // A wrapper function of {@link #openTabAndShow(UrlData, Message, boolean, String)} |
| 2122 | // that accepts url as string. |
Mitsuru Oshima | f26aeab | 2009-06-11 02:53:57 -0700 | [diff] [blame] | 2123 | private TabControl.Tab openTabAndShow(String url, final Message msg, |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2124 | boolean closeOnExit, String appId) { |
Mitsuru Oshima | f26aeab | 2009-06-11 02:53:57 -0700 | [diff] [blame] | 2125 | return openTabAndShow(new UrlData(url), msg, closeOnExit, appId); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | // This method does a ton of stuff. It will attempt to create a new tab |
| 2129 | // if we haven't reached MAX_TABS. Otherwise it uses the current tab. If |
| 2130 | // url isn't null, it will load the given url. If the tab overview is not |
| 2131 | // showing, it will animate to the tab overview, create a new tab and |
| 2132 | // animate away from it. After the animation completes, it will dispatch |
| 2133 | // the given Message. If the tab overview is already showing (i.e. this |
| 2134 | // method is called from TabListener.onClick(), the method will animate |
| 2135 | // away from the tab overview. |
Mitsuru Oshima | f26aeab | 2009-06-11 02:53:57 -0700 | [diff] [blame] | 2136 | private TabControl.Tab openTabAndShow(UrlData urlData, final Message msg, |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2137 | boolean closeOnExit, String appId) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2138 | final boolean newTab = mTabControl.getTabCount() != TabControl.MAX_TABS; |
| 2139 | final TabControl.Tab currentTab = mTabControl.getCurrentTab(); |
| 2140 | if (newTab) { |
| 2141 | int delay = 0; |
| 2142 | // If the tab overview is up and there are animations, just load |
| 2143 | // the url. |
| 2144 | if (mTabOverview != null && mAnimationCount > 0) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2145 | if (!urlData.isEmpty()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2146 | // We should not have a msg here since onCreateWindow |
| 2147 | // checks the animation count and every other caller passes |
| 2148 | // null. |
| 2149 | assert msg == null; |
| 2150 | // just dismiss the subwindow and load the given url. |
| 2151 | dismissSubWindow(currentTab); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2152 | urlData.loadIn(currentTab.getWebView()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2153 | } |
| 2154 | } else { |
| 2155 | // show mTabOverview if it is not there. |
| 2156 | if (mTabOverview == null) { |
| 2157 | // We have to delay the animation from the tab picker by the |
| 2158 | // length of the tab animation. Add a delay so the tab |
| 2159 | // overview can be shown before the second animation begins. |
| 2160 | delay = TAB_ANIMATION_DURATION + TAB_OVERVIEW_DELAY; |
| 2161 | tabPicker(false, ImageGrid.NEW_TAB, false); |
| 2162 | } |
| 2163 | // Animate from the Tab overview after any animations have |
| 2164 | // finished. |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2165 | final TabControl.Tab tab = mTabControl.createNewTab( |
Mitsuru Oshima | f26aeab | 2009-06-11 02:53:57 -0700 | [diff] [blame] | 2166 | closeOnExit, appId, urlData.mUrl); |
Grace Kloba | ec7eb37 | 2009-06-16 13:45:56 -0700 | [diff] [blame] | 2167 | sendAnimateFromOverview(tab, true, urlData, delay, msg); |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2168 | return tab; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2169 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2170 | } else if (!urlData.isEmpty()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2171 | // We should not have a msg here. |
| 2172 | assert msg == null; |
| 2173 | if (mTabOverview != null && mAnimationCount == 0) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2174 | sendAnimateFromOverview(currentTab, false, urlData, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2175 | TAB_OVERVIEW_DELAY, null); |
| 2176 | } else { |
| 2177 | // Get rid of the subwindow if it exists |
| 2178 | dismissSubWindow(currentTab); |
| 2179 | // Load the given url. |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 2180 | urlData.loadIn(currentTab.getWebView()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2181 | } |
| 2182 | } |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2183 | return currentTab; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | private Animation createTabAnimation(final AnimatingView view, |
| 2187 | final View cell, boolean scaleDown) { |
| 2188 | final AnimationSet set = new AnimationSet(true); |
| 2189 | final float scaleX = (float) cell.getWidth() / view.getWidth(); |
| 2190 | final float scaleY = (float) cell.getHeight() / view.getHeight(); |
| 2191 | if (scaleDown) { |
| 2192 | set.addAnimation(new ScaleAnimation(1.0f, scaleX, 1.0f, scaleY)); |
| 2193 | set.addAnimation(new TranslateAnimation(0, cell.getLeft(), 0, |
| 2194 | cell.getTop())); |
| 2195 | } else { |
| 2196 | set.addAnimation(new ScaleAnimation(scaleX, 1.0f, scaleY, 1.0f)); |
| 2197 | set.addAnimation(new TranslateAnimation(cell.getLeft(), 0, |
| 2198 | cell.getTop(), 0)); |
| 2199 | } |
| 2200 | set.setDuration(TAB_ANIMATION_DURATION); |
| 2201 | set.setInterpolator(new DecelerateInterpolator()); |
| 2202 | return set; |
| 2203 | } |
| 2204 | |
| 2205 | // Animate to the tab overview. currentIndex tells us which position to |
| 2206 | // animate to and newIndex is the position that should be selected after |
| 2207 | // the animation completes. |
| 2208 | // If remove is true, after the animation stops, a confirmation dialog will |
| 2209 | // be displayed to the user. |
| 2210 | private void animateToTabOverview(final int newIndex, final boolean remove, |
| 2211 | final AnimatingView view) { |
| 2212 | // Find the view in the ImageGrid allowing for the "New Tab" cell. |
| 2213 | int position = mTabControl.getTabIndex(view.mTab); |
| 2214 | if (!((ImageAdapter) mTabOverview.getAdapter()).maxedOut()) { |
| 2215 | position++; |
| 2216 | } |
| 2217 | |
| 2218 | // Offset the tab position with the first visible position to get a |
| 2219 | // number between 0 and 3. |
| 2220 | position -= mTabOverview.getFirstVisiblePosition(); |
| 2221 | |
| 2222 | // Grab the view that we are going to animate to. |
| 2223 | final View v = mTabOverview.getChildAt(position); |
| 2224 | |
| 2225 | final Animation.AnimationListener l = |
| 2226 | new Animation.AnimationListener() { |
| 2227 | public void onAnimationStart(Animation a) { |
Patrick Scott | d068f80 | 2009-06-22 11:46:06 -0400 | [diff] [blame] | 2228 | if (mTabOverview != null) { |
| 2229 | mTabOverview.requestFocus(); |
| 2230 | // Clear the listener so we don't trigger a tab |
| 2231 | // selection. |
| 2232 | mTabOverview.setListener(null); |
| 2233 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2234 | } |
| 2235 | public void onAnimationRepeat(Animation a) {} |
| 2236 | public void onAnimationEnd(Animation a) { |
| 2237 | // We are no longer animating so decrement the count. |
| 2238 | mAnimationCount--; |
| 2239 | // Make the view GONE so that it will not draw between |
| 2240 | // now and when the Runnable is handled. |
| 2241 | view.setVisibility(View.GONE); |
| 2242 | // Post a runnable since we can't modify the view |
| 2243 | // hierarchy during this callback. |
| 2244 | mHandler.post(new Runnable() { |
| 2245 | public void run() { |
| 2246 | // Remove the AnimatingView. |
| 2247 | mContentView.removeView(view); |
| 2248 | if (mTabOverview != null) { |
| 2249 | // Make newIndex visible. |
| 2250 | mTabOverview.setCurrentIndex(newIndex); |
| 2251 | // Restore the listener. |
| 2252 | mTabOverview.setListener(mTabListener); |
| 2253 | // Change the menu to TAB_MENU if the |
| 2254 | // ImageGrid is interactive. |
| 2255 | if (mTabOverview.isLive()) { |
| 2256 | mMenuState = R.id.TAB_MENU; |
| 2257 | mTabOverview.requestFocus(); |
| 2258 | } |
| 2259 | } |
| 2260 | // If a remove was requested, remove the tab. |
| 2261 | if (remove) { |
| 2262 | // During a remove, the current tab has |
| 2263 | // already changed. Remember the current one |
| 2264 | // here. |
| 2265 | final TabControl.Tab currentTab = |
| 2266 | mTabControl.getCurrentTab(); |
| 2267 | // Remove the tab at newIndex from |
| 2268 | // TabControl and the tab overview. |
| 2269 | final TabControl.Tab tab = |
| 2270 | mTabControl.getTab(newIndex); |
| 2271 | mTabControl.removeTab(tab); |
| 2272 | // Restore the current tab. |
| 2273 | if (currentTab != tab) { |
| 2274 | mTabControl.setCurrentTab(currentTab); |
| 2275 | } |
| 2276 | if (mTabOverview != null) { |
| 2277 | mTabOverview.remove(newIndex); |
| 2278 | // Make the current tab visible. |
| 2279 | mTabOverview.setCurrentIndex( |
| 2280 | mTabControl.getCurrentIndex()); |
| 2281 | } |
| 2282 | } |
| 2283 | } |
| 2284 | }); |
| 2285 | } |
| 2286 | }; |
| 2287 | |
| 2288 | // Do an animation if there is a view to animate to. |
| 2289 | if (v != null) { |
| 2290 | // Create our animation |
| 2291 | final Animation anim = createTabAnimation(view, v, true); |
| 2292 | anim.setAnimationListener(l); |
| 2293 | // Start animating |
| 2294 | view.startAnimation(anim); |
| 2295 | } else { |
| 2296 | // If something goes wrong and we didn't find a view to animate to, |
| 2297 | // just do everything here. |
| 2298 | l.onAnimationStart(null); |
| 2299 | l.onAnimationEnd(null); |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | // Animate from the tab picker. The index supplied is the index to animate |
| 2304 | // from. |
| 2305 | private void animateFromTabOverview(final AnimatingView view, |
| 2306 | final boolean newTab, final Message msg) { |
| 2307 | // firstVisible is the first visible tab on the screen. This helps |
| 2308 | // to know which corner of the screen the selected tab is. |
| 2309 | int firstVisible = mTabOverview.getFirstVisiblePosition(); |
| 2310 | // tabPosition is the 0-based index of of the tab being opened |
| 2311 | int tabPosition = mTabControl.getTabIndex(view.mTab); |
| 2312 | if (!((ImageAdapter) mTabOverview.getAdapter()).maxedOut()) { |
| 2313 | // Add one to make room for the "New Tab" cell. |
| 2314 | tabPosition++; |
| 2315 | } |
| 2316 | // If this is a new tab, animate from the "New Tab" cell. |
| 2317 | if (newTab) { |
| 2318 | tabPosition = 0; |
| 2319 | } |
| 2320 | // Location corresponds to the four corners of the screen. |
| 2321 | // A new tab or 0 is upper left, 0 for an old tab is upper |
| 2322 | // right, 1 is lower left, and 2 is lower right |
| 2323 | int location = tabPosition - firstVisible; |
| 2324 | |
| 2325 | // Find the view at this location. |
| 2326 | final View v = mTabOverview.getChildAt(location); |
| 2327 | |
| 2328 | // Wait until the animation completes to replace the AnimatingView. |
| 2329 | final Animation.AnimationListener l = |
| 2330 | new Animation.AnimationListener() { |
| 2331 | public void onAnimationStart(Animation a) {} |
| 2332 | public void onAnimationRepeat(Animation a) {} |
| 2333 | public void onAnimationEnd(Animation a) { |
| 2334 | mHandler.post(new Runnable() { |
| 2335 | public void run() { |
| 2336 | mContentView.removeView(view); |
| 2337 | // Dismiss the tab overview. If the cell at the |
| 2338 | // given location is null, set the fade |
| 2339 | // parameter to true. |
| 2340 | dismissTabOverview(v == null); |
| 2341 | TabControl.Tab t = |
| 2342 | mTabControl.getCurrentTab(); |
| 2343 | mMenuState = R.id.MAIN_MENU; |
| 2344 | // Resume regular updates. |
| 2345 | t.getWebView().resumeTimers(); |
| 2346 | // Dispatch the message after the animation |
| 2347 | // completes. |
| 2348 | if (msg != null) { |
| 2349 | msg.sendToTarget(); |
| 2350 | } |
| 2351 | // The animation is done and the tab overview is |
| 2352 | // gone so allow key events and other animations |
| 2353 | // to begin. |
| 2354 | mAnimationCount--; |
| 2355 | // Reset all the title bar info. |
| 2356 | resetTitle(); |
| 2357 | } |
| 2358 | }); |
| 2359 | } |
| 2360 | }; |
| 2361 | |
| 2362 | if (v != null) { |
| 2363 | final Animation anim = createTabAnimation(view, v, false); |
| 2364 | // Set the listener and start animating |
| 2365 | anim.setAnimationListener(l); |
| 2366 | view.startAnimation(anim); |
| 2367 | // Make the view VISIBLE during the animation. |
| 2368 | view.setVisibility(View.VISIBLE); |
| 2369 | } else { |
| 2370 | // Go ahead and do all the cleanup. |
| 2371 | l.onAnimationEnd(null); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | // Dismiss the tab overview applying a fade if needed. |
| 2376 | private void dismissTabOverview(final boolean fade) { |
| 2377 | if (fade) { |
| 2378 | AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f); |
| 2379 | anim.setDuration(500); |
| 2380 | anim.startNow(); |
| 2381 | mTabOverview.startAnimation(anim); |
| 2382 | } |
| 2383 | // Just in case there was a problem with animating away from the tab |
| 2384 | // overview |
| 2385 | WebView current = mTabControl.getCurrentWebView(); |
| 2386 | if (current != null) { |
| 2387 | current.setVisibility(View.VISIBLE); |
| 2388 | } else { |
| 2389 | Log.e(LOGTAG, "No current WebView in dismissTabOverview"); |
| 2390 | } |
| 2391 | // Make the sub window container visible. |
| 2392 | if (mTabControl.getCurrentSubWindow() != null) { |
| 2393 | mTabControl.getCurrentTab().getSubWebViewContainer() |
| 2394 | .setVisibility(View.VISIBLE); |
| 2395 | } |
| 2396 | mContentView.removeView(mTabOverview); |
Patrick Scott | 2ed6edb | 2009-04-22 10:07:45 -0400 | [diff] [blame] | 2397 | // Clear all the data for tab picker so next time it will be |
| 2398 | // recreated. |
| 2399 | mTabControl.wipeAllPickerData(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2400 | mTabOverview.clear(); |
| 2401 | mTabOverview = null; |
| 2402 | mTabListener = null; |
| 2403 | } |
| 2404 | |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2405 | private TabControl.Tab openTab(String url) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2406 | if (mSettings.openInBackground()) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2407 | TabControl.Tab t = mTabControl.createNewTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2408 | if (t != null) { |
| 2409 | t.getWebView().loadUrl(url); |
| 2410 | } |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2411 | return t; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2412 | } else { |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2413 | return openTabAndShow(url, null, false, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | private class Copy implements OnMenuItemClickListener { |
| 2418 | private CharSequence mText; |
| 2419 | |
| 2420 | public boolean onMenuItemClick(MenuItem item) { |
| 2421 | copy(mText); |
| 2422 | return true; |
| 2423 | } |
| 2424 | |
| 2425 | public Copy(CharSequence toCopy) { |
| 2426 | mText = toCopy; |
| 2427 | } |
| 2428 | } |
| 2429 | |
| 2430 | private class Download implements OnMenuItemClickListener { |
| 2431 | private String mText; |
| 2432 | |
| 2433 | public boolean onMenuItemClick(MenuItem item) { |
| 2434 | onDownloadStartNoStream(mText, null, null, null, -1); |
| 2435 | return true; |
| 2436 | } |
| 2437 | |
| 2438 | public Download(String toDownload) { |
| 2439 | mText = toDownload; |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | private void copy(CharSequence text) { |
| 2444 | try { |
| 2445 | IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard")); |
| 2446 | if (clip != null) { |
| 2447 | clip.setClipboardText(text); |
| 2448 | } |
| 2449 | } catch (android.os.RemoteException e) { |
| 2450 | Log.e(LOGTAG, "Copy failed", e); |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | /** |
| 2455 | * Resets the browser title-view to whatever it must be (for example, if we |
| 2456 | * load a page from history). |
| 2457 | */ |
| 2458 | private void resetTitle() { |
| 2459 | resetLockIcon(); |
| 2460 | resetTitleIconAndProgress(); |
| 2461 | } |
| 2462 | |
| 2463 | /** |
| 2464 | * Resets the browser title-view to whatever it must be |
| 2465 | * (for example, if we had a loading error) |
| 2466 | * When we have a new page, we call resetTitle, when we |
| 2467 | * have to reset the titlebar to whatever it used to be |
| 2468 | * (for example, if the user chose to stop loading), we |
| 2469 | * call resetTitleAndRevertLockIcon. |
| 2470 | */ |
| 2471 | /* package */ void resetTitleAndRevertLockIcon() { |
| 2472 | revertLockIcon(); |
| 2473 | resetTitleIconAndProgress(); |
| 2474 | } |
| 2475 | |
| 2476 | /** |
| 2477 | * Reset the title, favicon, and progress. |
| 2478 | */ |
| 2479 | private void resetTitleIconAndProgress() { |
| 2480 | WebView current = mTabControl.getCurrentWebView(); |
| 2481 | if (current == null) { |
| 2482 | return; |
| 2483 | } |
| 2484 | resetTitleAndIcon(current); |
| 2485 | int progress = current.getProgress(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2486 | mWebChromeClient.onProgressChanged(current, progress); |
| 2487 | } |
| 2488 | |
| 2489 | // Reset the title and the icon based on the given item. |
| 2490 | private void resetTitleAndIcon(WebView view) { |
| 2491 | WebHistoryItem item = view.copyBackForwardList().getCurrentItem(); |
| 2492 | if (item != null) { |
| 2493 | setUrlTitle(item.getUrl(), item.getTitle()); |
| 2494 | setFavicon(item.getFavicon()); |
| 2495 | } else { |
| 2496 | setUrlTitle(null, null); |
| 2497 | setFavicon(null); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * Sets a title composed of the URL and the title string. |
| 2503 | * @param url The URL of the site being loaded. |
| 2504 | * @param title The title of the site being loaded. |
| 2505 | */ |
| 2506 | private void setUrlTitle(String url, String title) { |
| 2507 | mUrl = url; |
| 2508 | mTitle = title; |
| 2509 | |
| 2510 | // While the tab overview is animating or being shown, block changes |
| 2511 | // to the title. |
| 2512 | if (mAnimationCount == 0 && mTabOverview == null) { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 2513 | if (CUSTOM_BROWSER_BAR) { |
| 2514 | mTitleBar.setTitleAndUrl(title, url); |
| 2515 | } else { |
| 2516 | setTitle(buildUrlTitle(url, title)); |
| 2517 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | |
| 2521 | /** |
| 2522 | * Builds and returns the page title, which is some |
| 2523 | * combination of the page URL and title. |
| 2524 | * @param url The URL of the site being loaded. |
| 2525 | * @param title The title of the site being loaded. |
| 2526 | * @return The page title. |
| 2527 | */ |
| 2528 | private String buildUrlTitle(String url, String title) { |
| 2529 | String urlTitle = ""; |
| 2530 | |
| 2531 | if (url != null) { |
| 2532 | String titleUrl = buildTitleUrl(url); |
| 2533 | |
| 2534 | if (title != null && 0 < title.length()) { |
| 2535 | if (titleUrl != null && 0 < titleUrl.length()) { |
| 2536 | urlTitle = titleUrl + ": " + title; |
| 2537 | } else { |
| 2538 | urlTitle = title; |
| 2539 | } |
| 2540 | } else { |
| 2541 | if (titleUrl != null) { |
| 2542 | urlTitle = titleUrl; |
| 2543 | } |
| 2544 | } |
| 2545 | } |
| 2546 | |
| 2547 | return urlTitle; |
| 2548 | } |
| 2549 | |
| 2550 | /** |
| 2551 | * @param url The URL to build a title version of the URL from. |
| 2552 | * @return The title version of the URL or null if fails. |
| 2553 | * The title version of the URL can be either the URL hostname, |
| 2554 | * or the hostname with an "https://" prefix (for secure URLs), |
| 2555 | * or an empty string if, for example, the URL in question is a |
| 2556 | * file:// URL with no hostname. |
| 2557 | */ |
Leon Scroggins | 32e14a6 | 2009-06-11 10:26:34 -0400 | [diff] [blame] | 2558 | /* package */ static String buildTitleUrl(String url) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2559 | String titleUrl = null; |
| 2560 | |
| 2561 | if (url != null) { |
| 2562 | try { |
| 2563 | // parse the url string |
| 2564 | URL urlObj = new URL(url); |
| 2565 | if (urlObj != null) { |
| 2566 | titleUrl = ""; |
| 2567 | |
| 2568 | String protocol = urlObj.getProtocol(); |
| 2569 | String host = urlObj.getHost(); |
| 2570 | |
| 2571 | if (host != null && 0 < host.length()) { |
| 2572 | titleUrl = host; |
| 2573 | if (protocol != null) { |
| 2574 | // if a secure site, add an "https://" prefix! |
| 2575 | if (protocol.equalsIgnoreCase("https")) { |
| 2576 | titleUrl = protocol + "://" + host; |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | } |
| 2581 | } catch (MalformedURLException e) {} |
| 2582 | } |
| 2583 | |
| 2584 | return titleUrl; |
| 2585 | } |
| 2586 | |
| 2587 | // Set the favicon in the title bar. |
| 2588 | private void setFavicon(Bitmap icon) { |
| 2589 | // While the tab overview is animating or being shown, block changes to |
| 2590 | // the favicon. |
| 2591 | if (mAnimationCount > 0 || mTabOverview != null) { |
| 2592 | return; |
| 2593 | } |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 2594 | if (CUSTOM_BROWSER_BAR) { |
| 2595 | Drawable[] array = new Drawable[3]; |
| 2596 | array[0] = new PaintDrawable(Color.BLACK); |
| 2597 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 2598 | array[1] = p; |
| 2599 | if (icon == null) { |
| 2600 | array[2] = mGenericFavicon; |
| 2601 | } else { |
| 2602 | array[2] = new BitmapDrawable(icon); |
| 2603 | } |
| 2604 | LayerDrawable d = new LayerDrawable(array); |
| 2605 | d.setLayerInset(1, 1, 1, 1, 1); |
| 2606 | d.setLayerInset(2, 2, 2, 2, 2); |
| 2607 | mTitleBar.setFavicon(d); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2608 | } else { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 2609 | Drawable[] array = new Drawable[2]; |
| 2610 | PaintDrawable p = new PaintDrawable(Color.WHITE); |
| 2611 | p.setCornerRadius(3f); |
| 2612 | array[0] = p; |
| 2613 | if (icon == null) { |
| 2614 | array[1] = mGenericFavicon; |
| 2615 | } else { |
| 2616 | array[1] = new BitmapDrawable(icon); |
| 2617 | } |
| 2618 | LayerDrawable d = new LayerDrawable(array); |
| 2619 | d.setLayerInset(1, 2, 2, 2, 2); |
| 2620 | getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, d); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2621 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /** |
| 2625 | * Saves the current lock-icon state before resetting |
| 2626 | * the lock icon. If we have an error, we may need to |
| 2627 | * roll back to the previous state. |
| 2628 | */ |
| 2629 | private void saveLockIcon() { |
| 2630 | mPrevLockType = mLockIconType; |
| 2631 | } |
| 2632 | |
| 2633 | /** |
| 2634 | * Reverts the lock-icon state to the last saved state, |
| 2635 | * for example, if we had an error, and need to cancel |
| 2636 | * the load. |
| 2637 | */ |
| 2638 | private void revertLockIcon() { |
| 2639 | mLockIconType = mPrevLockType; |
| 2640 | |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 2641 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2642 | Log.v(LOGTAG, "BrowserActivity.revertLockIcon:" + |
| 2643 | " revert lock icon to " + mLockIconType); |
| 2644 | } |
| 2645 | |
| 2646 | updateLockIconImage(mLockIconType); |
| 2647 | } |
| 2648 | |
| 2649 | private void switchTabs(int indexFrom, int indexToShow, boolean remove) { |
| 2650 | int delay = TAB_ANIMATION_DURATION + TAB_OVERVIEW_DELAY; |
| 2651 | // Animate to the tab picker, remove the current tab, then |
| 2652 | // animate away from the tab picker to the parent WebView. |
| 2653 | tabPicker(false, indexFrom, remove); |
| 2654 | // Change to the parent tab |
| 2655 | final TabControl.Tab tab = mTabControl.getTab(indexToShow); |
| 2656 | if (tab != null) { |
Patrick Scott | 95d601f | 2009-06-11 10:06:46 -0400 | [diff] [blame] | 2657 | sendAnimateFromOverview(tab, false, EMPTY_URL_DATA, delay, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2658 | } else { |
| 2659 | // Increment this here so that no other animations can happen in |
| 2660 | // between the end of the tab picker transition and the beginning |
| 2661 | // of openTabAndShow. This has a matching decrement in the handler |
| 2662 | // of OPEN_TAB_AND_SHOW. |
| 2663 | mAnimationCount++; |
| 2664 | // Send a message to open a new tab. |
| 2665 | mHandler.sendMessageDelayed( |
| 2666 | mHandler.obtainMessage(OPEN_TAB_AND_SHOW, |
| 2667 | mSettings.getHomePage()), delay); |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | private void goBackOnePageOrQuit() { |
| 2672 | TabControl.Tab current = mTabControl.getCurrentTab(); |
| 2673 | if (current == null) { |
| 2674 | /* |
| 2675 | * Instead of finishing the activity, simply push this to the back |
| 2676 | * of the stack and let ActivityManager to choose the foreground |
| 2677 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2678 | * root of the task. So we can use either true or false for |
| 2679 | * moveTaskToBack(). |
| 2680 | */ |
| 2681 | moveTaskToBack(true); |
| 2682 | } |
| 2683 | WebView w = current.getWebView(); |
| 2684 | if (w.canGoBack()) { |
| 2685 | w.goBack(); |
| 2686 | } else { |
| 2687 | // Check to see if we are closing a window that was created by |
| 2688 | // another window. If so, we switch back to that window. |
| 2689 | TabControl.Tab parent = current.getParentTab(); |
| 2690 | if (parent != null) { |
| 2691 | switchTabs(mTabControl.getCurrentIndex(), |
| 2692 | mTabControl.getTabIndex(parent), true); |
| 2693 | } else { |
| 2694 | if (current.closeOnExit()) { |
| 2695 | if (mTabControl.getTabCount() == 1) { |
| 2696 | finish(); |
| 2697 | return; |
| 2698 | } |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 2699 | // call pauseWebViewTimers() now, we won't be able to call |
| 2700 | // it in onPause() as the WebView won't be valid. |
| 2701 | pauseWebViewTimers(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2702 | removeTabFromContentView(current); |
| 2703 | mTabControl.removeTab(current); |
| 2704 | } |
| 2705 | /* |
| 2706 | * Instead of finishing the activity, simply push this to the back |
| 2707 | * of the stack and let ActivityManager to choose the foreground |
| 2708 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2709 | * root of the task. So we can use either true or false for |
| 2710 | * moveTaskToBack(). |
| 2711 | */ |
| 2712 | moveTaskToBack(true); |
| 2713 | } |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | public KeyTracker.State onKeyTracker(int keyCode, |
| 2718 | KeyEvent event, |
| 2719 | KeyTracker.Stage stage, |
| 2720 | int duration) { |
| 2721 | // if onKeyTracker() is called after activity onStop() |
| 2722 | // because of accumulated key events, |
| 2723 | // we should ignore it as browser is not active any more. |
| 2724 | WebView topWindow = getTopWindow(); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 2725 | if (topWindow == null && mCustomView == null) |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2726 | return KeyTracker.State.NOT_TRACKING; |
| 2727 | |
| 2728 | if (keyCode == KeyEvent.KEYCODE_BACK) { |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 2729 | // Check if a custom view is currently showing and, if it is, hide it. |
| 2730 | if (mCustomView != null) { |
| 2731 | mWebChromeClient.onHideCustomView(); |
| 2732 | return KeyTracker.State.DONE_TRACKING; |
| 2733 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2734 | // During animations, block the back key so that other animations |
| 2735 | // are not triggered and so that we don't end up destroying all the |
| 2736 | // WebViews before finishing the animation. |
| 2737 | if (mAnimationCount > 0) { |
| 2738 | return KeyTracker.State.DONE_TRACKING; |
| 2739 | } |
| 2740 | if (stage == KeyTracker.Stage.LONG_REPEAT) { |
| 2741 | bookmarksOrHistoryPicker(true); |
| 2742 | return KeyTracker.State.DONE_TRACKING; |
| 2743 | } else if (stage == KeyTracker.Stage.UP) { |
| 2744 | // FIXME: Currently, we do not have a notion of the |
| 2745 | // history picker for the subwindow, but maybe we |
| 2746 | // should? |
| 2747 | WebView subwindow = mTabControl.getCurrentSubWindow(); |
| 2748 | if (subwindow != null) { |
| 2749 | if (subwindow.canGoBack()) { |
| 2750 | subwindow.goBack(); |
| 2751 | } else { |
| 2752 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 2753 | } |
| 2754 | } else { |
| 2755 | goBackOnePageOrQuit(); |
| 2756 | } |
| 2757 | return KeyTracker.State.DONE_TRACKING; |
| 2758 | } |
| 2759 | return KeyTracker.State.KEEP_TRACKING; |
| 2760 | } |
| 2761 | return KeyTracker.State.NOT_TRACKING; |
| 2762 | } |
| 2763 | |
| 2764 | @Override public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 2765 | if (keyCode == KeyEvent.KEYCODE_MENU) { |
| 2766 | mMenuIsDown = true; |
Grace Kloba | 6ee9c49 | 2009-07-13 10:04:34 -0700 | [diff] [blame] | 2767 | } else if (mMenuIsDown) { |
| 2768 | // The default key mode is DEFAULT_KEYS_SEARCH_LOCAL. As the MENU is |
| 2769 | // still down, we don't want to trigger the search. Pretend to |
| 2770 | // consume the key and do nothing. |
| 2771 | return true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2772 | } |
| 2773 | boolean handled = mKeyTracker.doKeyDown(keyCode, event); |
| 2774 | if (!handled) { |
| 2775 | switch (keyCode) { |
| 2776 | case KeyEvent.KEYCODE_SPACE: |
| 2777 | if (event.isShiftPressed()) { |
| 2778 | getTopWindow().pageUp(false); |
| 2779 | } else { |
| 2780 | getTopWindow().pageDown(false); |
| 2781 | } |
| 2782 | handled = true; |
| 2783 | break; |
| 2784 | |
| 2785 | default: |
| 2786 | break; |
| 2787 | } |
| 2788 | } |
| 2789 | return handled || super.onKeyDown(keyCode, event); |
| 2790 | } |
| 2791 | |
| 2792 | @Override public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 2793 | if (keyCode == KeyEvent.KEYCODE_MENU) { |
| 2794 | mMenuIsDown = false; |
| 2795 | } |
| 2796 | return mKeyTracker.doKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); |
| 2797 | } |
| 2798 | |
| 2799 | private void stopLoading() { |
| 2800 | resetTitleAndRevertLockIcon(); |
| 2801 | WebView w = getTopWindow(); |
| 2802 | w.stopLoading(); |
| 2803 | mWebViewClient.onPageFinished(w, w.getUrl()); |
| 2804 | |
| 2805 | cancelStopToast(); |
| 2806 | mStopToast = Toast |
| 2807 | .makeText(this, R.string.stopping, Toast.LENGTH_SHORT); |
| 2808 | mStopToast.show(); |
| 2809 | } |
| 2810 | |
| 2811 | private void cancelStopToast() { |
| 2812 | if (mStopToast != null) { |
| 2813 | mStopToast.cancel(); |
| 2814 | mStopToast = null; |
| 2815 | } |
| 2816 | } |
| 2817 | |
| 2818 | // called by a non-UI thread to post the message |
| 2819 | public void postMessage(int what, int arg1, int arg2, Object obj) { |
| 2820 | mHandler.sendMessage(mHandler.obtainMessage(what, arg1, arg2, obj)); |
| 2821 | } |
| 2822 | |
| 2823 | // public message ids |
| 2824 | public final static int LOAD_URL = 1001; |
| 2825 | public final static int STOP_LOAD = 1002; |
| 2826 | |
| 2827 | // Message Ids |
| 2828 | private static final int FOCUS_NODE_HREF = 102; |
| 2829 | private static final int CANCEL_CREDS_REQUEST = 103; |
| 2830 | private static final int ANIMATE_FROM_OVERVIEW = 104; |
| 2831 | private static final int ANIMATE_TO_OVERVIEW = 105; |
| 2832 | private static final int OPEN_TAB_AND_SHOW = 106; |
| 2833 | private static final int CHECK_MEMORY = 107; |
| 2834 | private static final int RELEASE_WAKELOCK = 108; |
| 2835 | |
| 2836 | // Private handler for handling javascript and saving passwords |
| 2837 | private Handler mHandler = new Handler() { |
| 2838 | |
| 2839 | public void handleMessage(Message msg) { |
| 2840 | switch (msg.what) { |
| 2841 | case ANIMATE_FROM_OVERVIEW: |
| 2842 | final HashMap map = (HashMap) msg.obj; |
| 2843 | animateFromTabOverview((AnimatingView) map.get("view"), |
| 2844 | msg.arg1 == 1, (Message) map.get("msg")); |
| 2845 | break; |
| 2846 | |
| 2847 | case ANIMATE_TO_OVERVIEW: |
| 2848 | animateToTabOverview(msg.arg1, msg.arg2 == 1, |
| 2849 | (AnimatingView) msg.obj); |
| 2850 | break; |
| 2851 | |
| 2852 | case OPEN_TAB_AND_SHOW: |
| 2853 | // Decrement mAnimationCount before openTabAndShow because |
| 2854 | // the method relies on the value being 0 to start the next |
| 2855 | // animation. |
| 2856 | mAnimationCount--; |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 2857 | openTabAndShow((String) msg.obj, null, false, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2858 | break; |
| 2859 | |
| 2860 | case FOCUS_NODE_HREF: |
| 2861 | String url = (String) msg.getData().get("url"); |
| 2862 | if (url == null || url.length() == 0) { |
| 2863 | break; |
| 2864 | } |
| 2865 | HashMap focusNodeMap = (HashMap) msg.obj; |
| 2866 | WebView view = (WebView) focusNodeMap.get("webview"); |
| 2867 | // Only apply the action if the top window did not change. |
| 2868 | if (getTopWindow() != view) { |
| 2869 | break; |
| 2870 | } |
| 2871 | switch (msg.arg1) { |
| 2872 | case R.id.open_context_menu_id: |
| 2873 | case R.id.view_image_context_menu_id: |
| 2874 | loadURL(getTopWindow(), url); |
| 2875 | break; |
| 2876 | case R.id.open_newtab_context_menu_id: |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 2877 | final TabControl.Tab parent = mTabControl |
| 2878 | .getCurrentTab(); |
| 2879 | final TabControl.Tab newTab = openTab(url); |
| 2880 | if (newTab != parent) { |
| 2881 | parent.addChildTab(newTab); |
| 2882 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2883 | break; |
| 2884 | case R.id.bookmark_context_menu_id: |
| 2885 | Intent intent = new Intent(BrowserActivity.this, |
| 2886 | AddBookmarkPage.class); |
| 2887 | intent.putExtra("url", url); |
| 2888 | startActivity(intent); |
| 2889 | break; |
| 2890 | case R.id.share_link_context_menu_id: |
| 2891 | Browser.sendString(BrowserActivity.this, url); |
| 2892 | break; |
| 2893 | case R.id.copy_link_context_menu_id: |
| 2894 | copy(url); |
| 2895 | break; |
| 2896 | case R.id.save_link_context_menu_id: |
| 2897 | case R.id.download_context_menu_id: |
| 2898 | onDownloadStartNoStream(url, null, null, null, -1); |
| 2899 | break; |
| 2900 | } |
| 2901 | break; |
| 2902 | |
| 2903 | case LOAD_URL: |
| 2904 | loadURL(getTopWindow(), (String) msg.obj); |
| 2905 | break; |
| 2906 | |
| 2907 | case STOP_LOAD: |
| 2908 | stopLoading(); |
| 2909 | break; |
| 2910 | |
| 2911 | case CANCEL_CREDS_REQUEST: |
| 2912 | resumeAfterCredentials(); |
| 2913 | break; |
| 2914 | |
| 2915 | case CHECK_MEMORY: |
| 2916 | // reschedule to check memory condition |
| 2917 | mHandler.removeMessages(CHECK_MEMORY); |
| 2918 | mHandler.sendMessageDelayed(mHandler.obtainMessage |
| 2919 | (CHECK_MEMORY), CHECK_MEMORY_INTERVAL); |
| 2920 | checkMemory(); |
| 2921 | break; |
| 2922 | |
| 2923 | case RELEASE_WAKELOCK: |
| 2924 | if (mWakeLock.isHeld()) { |
| 2925 | mWakeLock.release(); |
| 2926 | } |
| 2927 | break; |
| 2928 | } |
| 2929 | } |
| 2930 | }; |
| 2931 | |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 2932 | private void updateScreenshot(WebView view) { |
| 2933 | // If this is a bookmarked site, add a screenshot to the database. |
| 2934 | // FIXME: When should we update? Every time? |
| 2935 | // FIXME: Would like to make sure there is actually something to |
| 2936 | // draw, but the API for that (WebViewCore.pictureReady()) is not |
| 2937 | // currently accessible here. |
| 2938 | String original = view.getOriginalUrl(); |
| 2939 | if (original != null) { |
| 2940 | // copied from BrowserBookmarksAdapter |
| 2941 | int query = original.indexOf('?'); |
| 2942 | String noQuery = original; |
| 2943 | if (query != -1) { |
| 2944 | noQuery = original.substring(0, query); |
| 2945 | } |
| 2946 | String URL = noQuery + '?'; |
| 2947 | String[] selArgs = new String[] { noQuery, URL }; |
| 2948 | final String where |
| 2949 | = "(url == ? OR url GLOB ? || '*') AND bookmark == 1"; |
| 2950 | final String[] projection |
| 2951 | = new String[] { Browser.BookmarkColumns._ID }; |
| 2952 | ContentResolver cr = getContentResolver(); |
| 2953 | final Cursor c = cr.query(Browser.BOOKMARKS_URI, projection, |
| 2954 | where, selArgs, null); |
| 2955 | boolean succeed = c.moveToFirst(); |
| 2956 | ContentValues values = null; |
| 2957 | while (succeed) { |
| 2958 | if (values == null) { |
| 2959 | final ByteArrayOutputStream os |
| 2960 | = new ByteArrayOutputStream(); |
| 2961 | Picture thumbnail = view.capturePicture(); |
| 2962 | // Keep width and height in sync with BrowserBookmarksPage |
| 2963 | // and bookmark_thumb |
| 2964 | Bitmap bm = Bitmap.createBitmap(100, 80, |
| 2965 | Bitmap.Config.ARGB_4444); |
| 2966 | Canvas canvas = new Canvas(bm); |
| 2967 | // May need to tweak these values to determine what is the |
| 2968 | // best scale factor |
| 2969 | canvas.scale(.5f, .5f); |
| 2970 | thumbnail.draw(canvas); |
| 2971 | bm.compress(Bitmap.CompressFormat.PNG, 100, os); |
| 2972 | values = new ContentValues(); |
| 2973 | values.put(Browser.BookmarkColumns.THUMBNAIL, |
| 2974 | os.toByteArray()); |
| 2975 | } |
| 2976 | cr.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, |
| 2977 | c.getInt(0)), values, null, null); |
| 2978 | succeed = c.moveToNext(); |
| 2979 | } |
| 2980 | c.close(); |
| 2981 | } |
| 2982 | } |
| 2983 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2984 | // ------------------------------------------------------------------------- |
| 2985 | // WebViewClient implementation. |
| 2986 | //------------------------------------------------------------------------- |
| 2987 | |
| 2988 | // Use in overrideUrlLoading |
| 2989 | /* package */ final static String SCHEME_WTAI = "wtai://wp/"; |
| 2990 | /* package */ final static String SCHEME_WTAI_MC = "wtai://wp/mc;"; |
| 2991 | /* package */ final static String SCHEME_WTAI_SD = "wtai://wp/sd;"; |
| 2992 | /* package */ final static String SCHEME_WTAI_AP = "wtai://wp/ap;"; |
| 2993 | |
| 2994 | /* package */ WebViewClient getWebViewClient() { |
| 2995 | return mWebViewClient; |
| 2996 | } |
| 2997 | |
| 2998 | private void updateIcon(String url, Bitmap icon) { |
| 2999 | if (icon != null) { |
| 3000 | BrowserBookmarksAdapter.updateBookmarkFavicon(mResolver, |
| 3001 | url, icon); |
| 3002 | } |
| 3003 | setFavicon(icon); |
| 3004 | } |
| 3005 | |
| 3006 | private final WebViewClient mWebViewClient = new WebViewClient() { |
| 3007 | @Override |
| 3008 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 3009 | resetLockIcon(url); |
| 3010 | setUrlTitle(url, null); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3011 | |
| 3012 | ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(false); |
| 3013 | if (errorConsole != null) { |
| 3014 | errorConsole.clearErrorMessages(); |
| 3015 | if (mShouldShowErrorConsole) { |
| 3016 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 3017 | } |
| 3018 | } |
| 3019 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3020 | // Call updateIcon instead of setFavicon so the bookmark |
| 3021 | // database can be updated. |
| 3022 | updateIcon(url, favicon); |
| 3023 | |
| 3024 | if (mSettings.isTracing() == true) { |
| 3025 | // FIXME: we should save the trace file somewhere other than data. |
| 3026 | // I can't use "/tmp" as it competes for system memory. |
| 3027 | File file = getDir("browserTrace", 0); |
| 3028 | String baseDir = file.getPath(); |
| 3029 | if (!baseDir.endsWith(File.separator)) baseDir += File.separator; |
| 3030 | String host; |
| 3031 | try { |
| 3032 | WebAddress uri = new WebAddress(url); |
| 3033 | host = uri.mHost; |
| 3034 | } catch (android.net.ParseException ex) { |
| 3035 | host = "unknown_host"; |
| 3036 | } |
| 3037 | host = host.replace('.', '_'); |
| 3038 | baseDir = baseDir + host; |
| 3039 | file = new File(baseDir+".data"); |
| 3040 | if (file.exists() == true) { |
| 3041 | file.delete(); |
| 3042 | } |
| 3043 | file = new File(baseDir+".key"); |
| 3044 | if (file.exists() == true) { |
| 3045 | file.delete(); |
| 3046 | } |
| 3047 | mInTrace = true; |
| 3048 | Debug.startMethodTracing(baseDir, 8 * 1024 * 1024); |
| 3049 | } |
| 3050 | |
| 3051 | // Performance probe |
| 3052 | if (false) { |
| 3053 | mStart = SystemClock.uptimeMillis(); |
| 3054 | mProcessStart = Process.getElapsedCpuTime(); |
| 3055 | long[] sysCpu = new long[7]; |
| 3056 | if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null, |
| 3057 | sysCpu, null)) { |
| 3058 | mUserStart = sysCpu[0] + sysCpu[1]; |
| 3059 | mSystemStart = sysCpu[2]; |
| 3060 | mIdleStart = sysCpu[3]; |
| 3061 | mIrqStart = sysCpu[4] + sysCpu[5] + sysCpu[6]; |
| 3062 | } |
| 3063 | mUiStart = SystemClock.currentThreadTimeMillis(); |
| 3064 | } |
| 3065 | |
| 3066 | if (!mPageStarted) { |
| 3067 | mPageStarted = true; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 3068 | // if onResume() has been called, resumeWebViewTimers() does |
| 3069 | // nothing. |
| 3070 | resumeWebViewTimers(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | // reset sync timer to avoid sync starts during loading a page |
| 3074 | CookieSyncManager.getInstance().resetSync(); |
| 3075 | |
| 3076 | mInLoad = true; |
| 3077 | updateInLoadMenuItems(); |
| 3078 | if (!mIsNetworkUp) { |
| 3079 | if ( mAlertDialog == null) { |
| 3080 | mAlertDialog = new AlertDialog.Builder(BrowserActivity.this) |
| 3081 | .setTitle(R.string.loadSuspendedTitle) |
| 3082 | .setMessage(R.string.loadSuspended) |
| 3083 | .setPositiveButton(R.string.ok, null) |
| 3084 | .show(); |
| 3085 | } |
| 3086 | if (view != null) { |
| 3087 | view.setNetworkAvailable(false); |
| 3088 | } |
| 3089 | } |
| 3090 | |
| 3091 | // schedule to check memory condition |
| 3092 | mHandler.sendMessageDelayed(mHandler.obtainMessage(CHECK_MEMORY), |
| 3093 | CHECK_MEMORY_INTERVAL); |
| 3094 | } |
| 3095 | |
| 3096 | @Override |
| 3097 | public void onPageFinished(WebView view, String url) { |
| 3098 | // Reset the title and icon in case we stopped a provisional |
| 3099 | // load. |
| 3100 | resetTitleAndIcon(view); |
| 3101 | |
| 3102 | // Update the lock icon image only once we are done loading |
| 3103 | updateLockIconImage(mLockIconType); |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 3104 | updateScreenshot(view); |
Leon Scroggins | b6b7f9e | 2009-06-18 12:05:28 -0400 | [diff] [blame] | 3105 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3106 | // Performance probe |
The Android Open Source Project | cb9a0bb | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 3107 | if (false) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3108 | long[] sysCpu = new long[7]; |
| 3109 | if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null, |
| 3110 | sysCpu, null)) { |
| 3111 | String uiInfo = "UI thread used " |
| 3112 | + (SystemClock.currentThreadTimeMillis() - mUiStart) |
| 3113 | + " ms"; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 3114 | if (LOGD_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3115 | Log.d(LOGTAG, uiInfo); |
| 3116 | } |
| 3117 | //The string that gets written to the log |
| 3118 | String performanceString = "It took total " |
| 3119 | + (SystemClock.uptimeMillis() - mStart) |
| 3120 | + " ms clock time to load the page." |
| 3121 | + "\nbrowser process used " |
| 3122 | + (Process.getElapsedCpuTime() - mProcessStart) |
| 3123 | + " ms, user processes used " |
| 3124 | + (sysCpu[0] + sysCpu[1] - mUserStart) * 10 |
| 3125 | + " ms, kernel used " |
| 3126 | + (sysCpu[2] - mSystemStart) * 10 |
| 3127 | + " ms, idle took " + (sysCpu[3] - mIdleStart) * 10 |
| 3128 | + " ms and irq took " |
| 3129 | + (sysCpu[4] + sysCpu[5] + sysCpu[6] - mIrqStart) |
| 3130 | * 10 + " ms, " + uiInfo; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 3131 | if (LOGD_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3132 | Log.d(LOGTAG, performanceString + "\nWebpage: " + url); |
| 3133 | } |
| 3134 | if (url != null) { |
| 3135 | // strip the url to maintain consistency |
| 3136 | String newUrl = new String(url); |
| 3137 | if (newUrl.startsWith("http://www.")) { |
| 3138 | newUrl = newUrl.substring(11); |
| 3139 | } else if (newUrl.startsWith("http://")) { |
| 3140 | newUrl = newUrl.substring(7); |
| 3141 | } else if (newUrl.startsWith("https://www.")) { |
| 3142 | newUrl = newUrl.substring(12); |
| 3143 | } else if (newUrl.startsWith("https://")) { |
| 3144 | newUrl = newUrl.substring(8); |
| 3145 | } |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 3146 | if (LOGD_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3147 | Log.d(LOGTAG, newUrl + " loaded"); |
| 3148 | } |
| 3149 | /* |
| 3150 | if (sWhiteList.contains(newUrl)) { |
| 3151 | // The string that gets pushed to the statistcs |
| 3152 | // service |
| 3153 | performanceString = performanceString |
| 3154 | + "\nWebpage: " |
| 3155 | + newUrl |
| 3156 | + "\nCarrier: " |
| 3157 | + android.os.SystemProperties |
| 3158 | .get("gsm.sim.operator.alpha"); |
| 3159 | if (mWebView != null |
| 3160 | && mWebView.getContext() != null |
| 3161 | && mWebView.getContext().getSystemService( |
| 3162 | Context.CONNECTIVITY_SERVICE) != null) { |
| 3163 | ConnectivityManager cManager = |
| 3164 | (ConnectivityManager) mWebView |
| 3165 | .getContext().getSystemService( |
| 3166 | Context.CONNECTIVITY_SERVICE); |
| 3167 | NetworkInfo nInfo = cManager |
| 3168 | .getActiveNetworkInfo(); |
| 3169 | if (nInfo != null) { |
| 3170 | performanceString = performanceString |
| 3171 | + "\nNetwork Type: " |
| 3172 | + nInfo.getType().toString(); |
| 3173 | } |
| 3174 | } |
| 3175 | Checkin.logEvent(mResolver, |
| 3176 | Checkin.Events.Tag.WEBPAGE_LOAD, |
| 3177 | performanceString); |
| 3178 | Log.w(LOGTAG, "pushed to the statistics service"); |
| 3179 | } |
| 3180 | */ |
| 3181 | } |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | if (mInTrace) { |
| 3186 | mInTrace = false; |
| 3187 | Debug.stopMethodTracing(); |
| 3188 | } |
| 3189 | |
| 3190 | if (mPageStarted) { |
| 3191 | mPageStarted = false; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 3192 | // pauseWebViewTimers() will do nothing and return false if |
| 3193 | // onPause() is not called yet. |
| 3194 | if (pauseWebViewTimers()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3195 | if (mWakeLock.isHeld()) { |
| 3196 | mHandler.removeMessages(RELEASE_WAKELOCK); |
| 3197 | mWakeLock.release(); |
| 3198 | } |
| 3199 | } |
| 3200 | } |
| 3201 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3202 | mHandler.removeMessages(CHECK_MEMORY); |
| 3203 | checkMemory(); |
| 3204 | } |
| 3205 | |
| 3206 | // return true if want to hijack the url to let another app to handle it |
| 3207 | @Override |
| 3208 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
| 3209 | if (url.startsWith(SCHEME_WTAI)) { |
| 3210 | // wtai://wp/mc;number |
| 3211 | // number=string(phone-number) |
| 3212 | if (url.startsWith(SCHEME_WTAI_MC)) { |
| 3213 | Intent intent = new Intent(Intent.ACTION_VIEW, |
| 3214 | Uri.parse(WebView.SCHEME_TEL + |
| 3215 | url.substring(SCHEME_WTAI_MC.length()))); |
| 3216 | startActivity(intent); |
| 3217 | return true; |
| 3218 | } |
| 3219 | // wtai://wp/sd;dtmf |
| 3220 | // dtmf=string(dialstring) |
| 3221 | if (url.startsWith(SCHEME_WTAI_SD)) { |
| 3222 | // TODO |
| 3223 | // only send when there is active voice connection |
| 3224 | return false; |
| 3225 | } |
| 3226 | // wtai://wp/ap;number;name |
| 3227 | // number=string(phone-number) |
| 3228 | // name=string |
| 3229 | if (url.startsWith(SCHEME_WTAI_AP)) { |
| 3230 | // TODO |
| 3231 | return false; |
| 3232 | } |
| 3233 | } |
| 3234 | |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3235 | // The "about:" schemes are internal to the browser; don't |
| 3236 | // want these to be dispatched to other apps. |
| 3237 | if (url.startsWith("about:")) { |
| 3238 | return false; |
| 3239 | } |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3240 | |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3241 | Intent intent; |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3242 | |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3243 | // perform generic parsing of the URI to turn it into an Intent. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3244 | try { |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3245 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 3246 | } catch (URISyntaxException ex) { |
| 3247 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3248 | return false; |
| 3249 | } |
| 3250 | |
Grace Kloba | 5b078b5 | 2009-06-24 20:23:41 -0700 | [diff] [blame] | 3251 | // check whether the intent can be resolved. If not, we will see |
| 3252 | // whether we can download it from the Market. |
| 3253 | if (getPackageManager().resolveActivity(intent, 0) == null) { |
| 3254 | String packagename = intent.getPackage(); |
| 3255 | if (packagename != null) { |
| 3256 | intent = new Intent(Intent.ACTION_VIEW, Uri |
| 3257 | .parse("market://search?q=pname:" + packagename)); |
| 3258 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| 3259 | startActivity(intent); |
| 3260 | return true; |
| 3261 | } else { |
| 3262 | return false; |
| 3263 | } |
| 3264 | } |
| 3265 | |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3266 | // sanitize the Intent, ensuring web pages can not bypass browser |
| 3267 | // security (only access to BROWSABLE activities). |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3268 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 3269 | intent.setComponent(null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3270 | try { |
| 3271 | if (startActivityIfNeeded(intent, -1)) { |
| 3272 | return true; |
| 3273 | } |
| 3274 | } catch (ActivityNotFoundException ex) { |
| 3275 | // ignore the error. If no application can handle the URL, |
| 3276 | // eg about:blank, assume the browser can handle it. |
| 3277 | } |
| 3278 | |
| 3279 | if (mMenuIsDown) { |
| 3280 | openTab(url); |
| 3281 | closeOptionsMenu(); |
| 3282 | return true; |
| 3283 | } |
| 3284 | |
| 3285 | return false; |
| 3286 | } |
| 3287 | |
| 3288 | /** |
| 3289 | * Updates the lock icon. This method is called when we discover another |
| 3290 | * resource to be loaded for this page (for example, javascript). While |
| 3291 | * we update the icon type, we do not update the lock icon itself until |
| 3292 | * we are done loading, it is slightly more secure this way. |
| 3293 | */ |
| 3294 | @Override |
| 3295 | public void onLoadResource(WebView view, String url) { |
| 3296 | if (url != null && url.length() > 0) { |
| 3297 | // It is only if the page claims to be secure |
| 3298 | // that we may have to update the lock: |
| 3299 | if (mLockIconType == LOCK_ICON_SECURE) { |
| 3300 | // If NOT a 'safe' url, change the lock to mixed content! |
| 3301 | if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url) || URLUtil.isAboutUrl(url))) { |
| 3302 | mLockIconType = LOCK_ICON_MIXED; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 3303 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3304 | Log.v(LOGTAG, "BrowserActivity.updateLockIcon:" + |
| 3305 | " updated lock icon to " + mLockIconType + " due to " + url); |
| 3306 | } |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * Show the dialog, asking the user if they would like to continue after |
| 3314 | * an excessive number of HTTP redirects. |
| 3315 | */ |
| 3316 | @Override |
| 3317 | public void onTooManyRedirects(WebView view, final Message cancelMsg, |
| 3318 | final Message continueMsg) { |
| 3319 | new AlertDialog.Builder(BrowserActivity.this) |
| 3320 | .setTitle(R.string.browserFrameRedirect) |
| 3321 | .setMessage(R.string.browserFrame307Post) |
| 3322 | .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 3323 | public void onClick(DialogInterface dialog, int which) { |
| 3324 | continueMsg.sendToTarget(); |
| 3325 | }}) |
| 3326 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { |
| 3327 | public void onClick(DialogInterface dialog, int which) { |
| 3328 | cancelMsg.sendToTarget(); |
| 3329 | }}) |
| 3330 | .setOnCancelListener(new OnCancelListener() { |
| 3331 | public void onCancel(DialogInterface dialog) { |
| 3332 | cancelMsg.sendToTarget(); |
| 3333 | }}) |
| 3334 | .show(); |
| 3335 | } |
| 3336 | |
Patrick Scott | 37911c7 | 2009-03-24 18:02:58 -0700 | [diff] [blame] | 3337 | // Container class for the next error dialog that needs to be |
| 3338 | // displayed. |
| 3339 | class ErrorDialog { |
| 3340 | public final int mTitle; |
| 3341 | public final String mDescription; |
| 3342 | public final int mError; |
| 3343 | ErrorDialog(int title, String desc, int error) { |
| 3344 | mTitle = title; |
| 3345 | mDescription = desc; |
| 3346 | mError = error; |
| 3347 | } |
| 3348 | }; |
| 3349 | |
| 3350 | private void processNextError() { |
| 3351 | if (mQueuedErrors == null) { |
| 3352 | return; |
| 3353 | } |
| 3354 | // The first one is currently displayed so just remove it. |
| 3355 | mQueuedErrors.removeFirst(); |
| 3356 | if (mQueuedErrors.size() == 0) { |
| 3357 | mQueuedErrors = null; |
| 3358 | return; |
| 3359 | } |
| 3360 | showError(mQueuedErrors.getFirst()); |
| 3361 | } |
| 3362 | |
| 3363 | private DialogInterface.OnDismissListener mDialogListener = |
| 3364 | new DialogInterface.OnDismissListener() { |
| 3365 | public void onDismiss(DialogInterface d) { |
| 3366 | processNextError(); |
| 3367 | } |
| 3368 | }; |
| 3369 | private LinkedList<ErrorDialog> mQueuedErrors; |
| 3370 | |
| 3371 | private void queueError(int err, String desc) { |
| 3372 | if (mQueuedErrors == null) { |
| 3373 | mQueuedErrors = new LinkedList<ErrorDialog>(); |
| 3374 | } |
| 3375 | for (ErrorDialog d : mQueuedErrors) { |
| 3376 | if (d.mError == err) { |
| 3377 | // Already saw a similar error, ignore the new one. |
| 3378 | return; |
| 3379 | } |
| 3380 | } |
| 3381 | ErrorDialog errDialog = new ErrorDialog( |
| 3382 | err == EventHandler.FILE_NOT_FOUND_ERROR ? |
| 3383 | R.string.browserFrameFileErrorLabel : |
| 3384 | R.string.browserFrameNetworkErrorLabel, |
| 3385 | desc, err); |
| 3386 | mQueuedErrors.addLast(errDialog); |
| 3387 | |
| 3388 | // Show the dialog now if the queue was empty. |
| 3389 | if (mQueuedErrors.size() == 1) { |
| 3390 | showError(errDialog); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | private void showError(ErrorDialog errDialog) { |
| 3395 | AlertDialog d = new AlertDialog.Builder(BrowserActivity.this) |
| 3396 | .setTitle(errDialog.mTitle) |
| 3397 | .setMessage(errDialog.mDescription) |
| 3398 | .setPositiveButton(R.string.ok, null) |
| 3399 | .create(); |
| 3400 | d.setOnDismissListener(mDialogListener); |
| 3401 | d.show(); |
| 3402 | } |
| 3403 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3404 | /** |
| 3405 | * Show a dialog informing the user of the network error reported by |
| 3406 | * WebCore. |
| 3407 | */ |
| 3408 | @Override |
| 3409 | public void onReceivedError(WebView view, int errorCode, |
| 3410 | String description, String failingUrl) { |
| 3411 | if (errorCode != EventHandler.ERROR_LOOKUP && |
| 3412 | errorCode != EventHandler.ERROR_CONNECT && |
| 3413 | errorCode != EventHandler.ERROR_BAD_URL && |
| 3414 | errorCode != EventHandler.ERROR_UNSUPPORTED_SCHEME && |
| 3415 | errorCode != EventHandler.FILE_ERROR) { |
Patrick Scott | 37911c7 | 2009-03-24 18:02:58 -0700 | [diff] [blame] | 3416 | queueError(errorCode, description); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3417 | } |
Patrick Scott | 37911c7 | 2009-03-24 18:02:58 -0700 | [diff] [blame] | 3418 | Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl |
| 3419 | + " " + description); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3420 | |
| 3421 | // We need to reset the title after an error. |
| 3422 | resetTitleAndRevertLockIcon(); |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * Check with the user if it is ok to resend POST data as the page they |
| 3427 | * are trying to navigate to is the result of a POST. |
| 3428 | */ |
| 3429 | @Override |
| 3430 | public void onFormResubmission(WebView view, final Message dontResend, |
| 3431 | final Message resend) { |
| 3432 | new AlertDialog.Builder(BrowserActivity.this) |
| 3433 | .setTitle(R.string.browserFrameFormResubmitLabel) |
| 3434 | .setMessage(R.string.browserFrameFormResubmitMessage) |
| 3435 | .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 3436 | public void onClick(DialogInterface dialog, int which) { |
| 3437 | resend.sendToTarget(); |
| 3438 | }}) |
| 3439 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { |
| 3440 | public void onClick(DialogInterface dialog, int which) { |
| 3441 | dontResend.sendToTarget(); |
| 3442 | }}) |
| 3443 | .setOnCancelListener(new OnCancelListener() { |
| 3444 | public void onCancel(DialogInterface dialog) { |
| 3445 | dontResend.sendToTarget(); |
| 3446 | }}) |
| 3447 | .show(); |
| 3448 | } |
| 3449 | |
| 3450 | /** |
| 3451 | * Insert the url into the visited history database. |
| 3452 | * @param url The url to be inserted. |
| 3453 | * @param isReload True if this url is being reloaded. |
| 3454 | * FIXME: Not sure what to do when reloading the page. |
| 3455 | */ |
| 3456 | @Override |
| 3457 | public void doUpdateVisitedHistory(WebView view, String url, |
| 3458 | boolean isReload) { |
| 3459 | if (url.regionMatches(true, 0, "about:", 0, 6)) { |
| 3460 | return; |
| 3461 | } |
| 3462 | Browser.updateVisitedHistory(mResolver, url, true); |
| 3463 | WebIconDatabase.getInstance().retainIconForPageUrl(url); |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * Displays SSL error(s) dialog to the user. |
| 3468 | */ |
| 3469 | @Override |
| 3470 | public void onReceivedSslError( |
| 3471 | final WebView view, final SslErrorHandler handler, final SslError error) { |
| 3472 | |
| 3473 | if (mSettings.showSecurityWarnings()) { |
| 3474 | final LayoutInflater factory = |
| 3475 | LayoutInflater.from(BrowserActivity.this); |
| 3476 | final View warningsView = |
| 3477 | factory.inflate(R.layout.ssl_warnings, null); |
| 3478 | final LinearLayout placeholder = |
| 3479 | (LinearLayout)warningsView.findViewById(R.id.placeholder); |
| 3480 | |
| 3481 | if (error.hasError(SslError.SSL_UNTRUSTED)) { |
| 3482 | LinearLayout ll = (LinearLayout)factory |
| 3483 | .inflate(R.layout.ssl_warning, null); |
| 3484 | ((TextView)ll.findViewById(R.id.warning)) |
| 3485 | .setText(R.string.ssl_untrusted); |
| 3486 | placeholder.addView(ll); |
| 3487 | } |
| 3488 | |
| 3489 | if (error.hasError(SslError.SSL_IDMISMATCH)) { |
| 3490 | LinearLayout ll = (LinearLayout)factory |
| 3491 | .inflate(R.layout.ssl_warning, null); |
| 3492 | ((TextView)ll.findViewById(R.id.warning)) |
| 3493 | .setText(R.string.ssl_mismatch); |
| 3494 | placeholder.addView(ll); |
| 3495 | } |
| 3496 | |
| 3497 | if (error.hasError(SslError.SSL_EXPIRED)) { |
| 3498 | LinearLayout ll = (LinearLayout)factory |
| 3499 | .inflate(R.layout.ssl_warning, null); |
| 3500 | ((TextView)ll.findViewById(R.id.warning)) |
| 3501 | .setText(R.string.ssl_expired); |
| 3502 | placeholder.addView(ll); |
| 3503 | } |
| 3504 | |
| 3505 | if (error.hasError(SslError.SSL_NOTYETVALID)) { |
| 3506 | LinearLayout ll = (LinearLayout)factory |
| 3507 | .inflate(R.layout.ssl_warning, null); |
| 3508 | ((TextView)ll.findViewById(R.id.warning)) |
| 3509 | .setText(R.string.ssl_not_yet_valid); |
| 3510 | placeholder.addView(ll); |
| 3511 | } |
| 3512 | |
| 3513 | new AlertDialog.Builder(BrowserActivity.this) |
| 3514 | .setTitle(R.string.security_warning) |
| 3515 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3516 | .setView(warningsView) |
| 3517 | .setPositiveButton(R.string.ssl_continue, |
| 3518 | new DialogInterface.OnClickListener() { |
| 3519 | public void onClick(DialogInterface dialog, int whichButton) { |
| 3520 | handler.proceed(); |
| 3521 | } |
| 3522 | }) |
| 3523 | .setNeutralButton(R.string.view_certificate, |
| 3524 | new DialogInterface.OnClickListener() { |
| 3525 | public void onClick(DialogInterface dialog, int whichButton) { |
| 3526 | showSSLCertificateOnError(view, handler, error); |
| 3527 | } |
| 3528 | }) |
| 3529 | .setNegativeButton(R.string.cancel, |
| 3530 | new DialogInterface.OnClickListener() { |
| 3531 | public void onClick(DialogInterface dialog, int whichButton) { |
| 3532 | handler.cancel(); |
| 3533 | BrowserActivity.this.resetTitleAndRevertLockIcon(); |
| 3534 | } |
| 3535 | }) |
| 3536 | .setOnCancelListener( |
| 3537 | new DialogInterface.OnCancelListener() { |
| 3538 | public void onCancel(DialogInterface dialog) { |
| 3539 | handler.cancel(); |
| 3540 | BrowserActivity.this.resetTitleAndRevertLockIcon(); |
| 3541 | } |
| 3542 | }) |
| 3543 | .show(); |
| 3544 | } else { |
| 3545 | handler.proceed(); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | /** |
| 3550 | * Handles an HTTP authentication request. |
| 3551 | * |
| 3552 | * @param handler The authentication handler |
| 3553 | * @param host The host |
| 3554 | * @param realm The realm |
| 3555 | */ |
| 3556 | @Override |
| 3557 | public void onReceivedHttpAuthRequest(WebView view, |
| 3558 | final HttpAuthHandler handler, final String host, final String realm) { |
| 3559 | String username = null; |
| 3560 | String password = null; |
| 3561 | |
| 3562 | boolean reuseHttpAuthUsernamePassword = |
| 3563 | handler.useHttpAuthUsernamePassword(); |
| 3564 | |
| 3565 | if (reuseHttpAuthUsernamePassword && |
| 3566 | (mTabControl.getCurrentWebView() != null)) { |
| 3567 | String[] credentials = |
| 3568 | mTabControl.getCurrentWebView() |
| 3569 | .getHttpAuthUsernamePassword(host, realm); |
| 3570 | if (credentials != null && credentials.length == 2) { |
| 3571 | username = credentials[0]; |
| 3572 | password = credentials[1]; |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | if (username != null && password != null) { |
| 3577 | handler.proceed(username, password); |
| 3578 | } else { |
| 3579 | showHttpAuthentication(handler, host, realm, null, null, null, 0); |
| 3580 | } |
| 3581 | } |
| 3582 | |
| 3583 | @Override |
| 3584 | public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { |
| 3585 | if (mMenuIsDown) { |
| 3586 | // only check shortcut key when MENU is held |
| 3587 | return getWindow().isShortcutKey(event.getKeyCode(), event); |
| 3588 | } else { |
| 3589 | return false; |
| 3590 | } |
| 3591 | } |
| 3592 | |
| 3593 | @Override |
| 3594 | public void onUnhandledKeyEvent(WebView view, KeyEvent event) { |
| 3595 | if (view != mTabControl.getCurrentTopWebView()) { |
| 3596 | return; |
| 3597 | } |
| 3598 | if (event.isDown()) { |
| 3599 | BrowserActivity.this.onKeyDown(event.getKeyCode(), event); |
| 3600 | } else { |
| 3601 | BrowserActivity.this.onKeyUp(event.getKeyCode(), event); |
| 3602 | } |
| 3603 | } |
| 3604 | }; |
| 3605 | |
| 3606 | //-------------------------------------------------------------------------- |
| 3607 | // WebChromeClient implementation |
| 3608 | //-------------------------------------------------------------------------- |
| 3609 | |
| 3610 | /* package */ WebChromeClient getWebChromeClient() { |
| 3611 | return mWebChromeClient; |
| 3612 | } |
| 3613 | |
| 3614 | private final WebChromeClient mWebChromeClient = new WebChromeClient() { |
| 3615 | // Helper method to create a new tab or sub window. |
| 3616 | private void createWindow(final boolean dialog, final Message msg) { |
| 3617 | if (dialog) { |
| 3618 | mTabControl.createSubWindow(); |
| 3619 | final TabControl.Tab t = mTabControl.getCurrentTab(); |
| 3620 | attachSubWindow(t); |
| 3621 | WebView.WebViewTransport transport = |
| 3622 | (WebView.WebViewTransport) msg.obj; |
| 3623 | transport.setWebView(t.getSubWebView()); |
| 3624 | msg.sendToTarget(); |
| 3625 | } else { |
| 3626 | final TabControl.Tab parent = mTabControl.getCurrentTab(); |
| 3627 | // openTabAndShow will dispatch the message after creating the |
| 3628 | // new WebView. This will prevent another request from coming |
| 3629 | // in during the animation. |
Patrick Scott | 1536e73 | 2009-06-11 14:50:01 -0400 | [diff] [blame] | 3630 | final TabControl.Tab newTab = |
| 3631 | openTabAndShow(EMPTY_URL_DATA, msg, false, null); |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 3632 | if (newTab != parent) { |
| 3633 | parent.addChildTab(newTab); |
| 3634 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3635 | WebView.WebViewTransport transport = |
| 3636 | (WebView.WebViewTransport) msg.obj; |
| 3637 | transport.setWebView(mTabControl.getCurrentWebView()); |
| 3638 | } |
| 3639 | } |
| 3640 | |
| 3641 | @Override |
| 3642 | public boolean onCreateWindow(WebView view, final boolean dialog, |
| 3643 | final boolean userGesture, final Message resultMsg) { |
| 3644 | // Ignore these requests during tab animations or if the tab |
| 3645 | // overview is showing. |
| 3646 | if (mAnimationCount > 0 || mTabOverview != null) { |
| 3647 | return false; |
| 3648 | } |
| 3649 | // Short-circuit if we can't create any more tabs or sub windows. |
| 3650 | if (dialog && mTabControl.getCurrentSubWindow() != null) { |
| 3651 | new AlertDialog.Builder(BrowserActivity.this) |
| 3652 | .setTitle(R.string.too_many_subwindows_dialog_title) |
| 3653 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3654 | .setMessage(R.string.too_many_subwindows_dialog_message) |
| 3655 | .setPositiveButton(R.string.ok, null) |
| 3656 | .show(); |
| 3657 | return false; |
| 3658 | } else if (mTabControl.getTabCount() >= TabControl.MAX_TABS) { |
| 3659 | new AlertDialog.Builder(BrowserActivity.this) |
| 3660 | .setTitle(R.string.too_many_windows_dialog_title) |
| 3661 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3662 | .setMessage(R.string.too_many_windows_dialog_message) |
| 3663 | .setPositiveButton(R.string.ok, null) |
| 3664 | .show(); |
| 3665 | return false; |
| 3666 | } |
| 3667 | |
| 3668 | // Short-circuit if this was a user gesture. |
| 3669 | if (userGesture) { |
| 3670 | // createWindow will call openTabAndShow for new Windows and |
| 3671 | // that will call tabPicker which will increment |
| 3672 | // mAnimationCount. |
| 3673 | createWindow(dialog, resultMsg); |
| 3674 | return true; |
| 3675 | } |
| 3676 | |
| 3677 | // Allow the popup and create the appropriate window. |
| 3678 | final AlertDialog.OnClickListener allowListener = |
| 3679 | new AlertDialog.OnClickListener() { |
| 3680 | public void onClick(DialogInterface d, |
| 3681 | int which) { |
| 3682 | // Same comment as above for setting |
| 3683 | // mAnimationCount. |
| 3684 | createWindow(dialog, resultMsg); |
| 3685 | // Since we incremented mAnimationCount while the |
| 3686 | // dialog was up, we have to decrement it here. |
| 3687 | mAnimationCount--; |
| 3688 | } |
| 3689 | }; |
| 3690 | |
| 3691 | // Block the popup by returning a null WebView. |
| 3692 | final AlertDialog.OnClickListener blockListener = |
| 3693 | new AlertDialog.OnClickListener() { |
| 3694 | public void onClick(DialogInterface d, int which) { |
| 3695 | resultMsg.sendToTarget(); |
| 3696 | // We are not going to trigger an animation so |
| 3697 | // unblock keys and animation requests. |
| 3698 | mAnimationCount--; |
| 3699 | } |
| 3700 | }; |
| 3701 | |
| 3702 | // Build a confirmation dialog to display to the user. |
| 3703 | final AlertDialog d = |
| 3704 | new AlertDialog.Builder(BrowserActivity.this) |
| 3705 | .setTitle(R.string.attention) |
| 3706 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3707 | .setMessage(R.string.popup_window_attempt) |
| 3708 | .setPositiveButton(R.string.allow, allowListener) |
| 3709 | .setNegativeButton(R.string.block, blockListener) |
| 3710 | .setCancelable(false) |
| 3711 | .create(); |
| 3712 | |
| 3713 | // Show the confirmation dialog. |
| 3714 | d.show(); |
| 3715 | // We want to increment mAnimationCount here to prevent a |
| 3716 | // potential race condition. If the user allows a pop-up from a |
| 3717 | // site and that pop-up then triggers another pop-up, it is |
| 3718 | // possible to get the BACK key between here and when the dialog |
| 3719 | // appears. |
| 3720 | mAnimationCount++; |
| 3721 | return true; |
| 3722 | } |
| 3723 | |
| 3724 | @Override |
| 3725 | public void onCloseWindow(WebView window) { |
| 3726 | final int currentIndex = mTabControl.getCurrentIndex(); |
| 3727 | final TabControl.Tab parent = |
| 3728 | mTabControl.getCurrentTab().getParentTab(); |
| 3729 | if (parent != null) { |
| 3730 | // JavaScript can only close popup window. |
| 3731 | switchTabs(currentIndex, mTabControl.getTabIndex(parent), true); |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | @Override |
| 3736 | public void onProgressChanged(WebView view, int newProgress) { |
| 3737 | // Block progress updates to the title bar while the tab overview |
| 3738 | // is animating or being displayed. |
| 3739 | if (mAnimationCount == 0 && mTabOverview == null) { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 3740 | if (CUSTOM_BROWSER_BAR) { |
| 3741 | mTitleBar.setProgress(newProgress); |
| 3742 | } else { |
| 3743 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 3744 | newProgress * 100); |
| 3745 | |
| 3746 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | if (newProgress == 100) { |
| 3750 | // onProgressChanged() is called for sub-frame too while |
| 3751 | // onPageFinished() is only called for the main frame. sync |
| 3752 | // cookie and cache promptly here. |
| 3753 | CookieSyncManager.getInstance().sync(); |
The Android Open Source Project | cb9a0bb | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 3754 | if (mInLoad) { |
| 3755 | mInLoad = false; |
| 3756 | updateInLoadMenuItems(); |
| 3757 | } |
| 3758 | } else { |
| 3759 | // onPageFinished may have already been called but a subframe |
| 3760 | // is still loading and updating the progress. Reset mInLoad |
| 3761 | // and update the menu items. |
| 3762 | if (!mInLoad) { |
| 3763 | mInLoad = true; |
| 3764 | updateInLoadMenuItems(); |
| 3765 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | @Override |
| 3770 | public void onReceivedTitle(WebView view, String title) { |
Patrick Scott | 598c9cc | 2009-06-04 11:10:38 -0400 | [diff] [blame] | 3771 | String url = view.getUrl(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3772 | |
| 3773 | // here, if url is null, we want to reset the title |
| 3774 | setUrlTitle(url, title); |
| 3775 | |
| 3776 | if (url == null || |
| 3777 | url.length() >= SQLiteDatabase.SQLITE_MAX_LIKE_PATTERN_LENGTH) { |
| 3778 | return; |
| 3779 | } |
Leon Scroggins | fce182b | 2009-05-08 13:54:52 -0400 | [diff] [blame] | 3780 | // See if we can find the current url in our history database and |
| 3781 | // add the new title to it. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3782 | if (url.startsWith("http://www.")) { |
| 3783 | url = url.substring(11); |
| 3784 | } else if (url.startsWith("http://")) { |
| 3785 | url = url.substring(4); |
| 3786 | } |
| 3787 | try { |
| 3788 | url = "%" + url; |
| 3789 | String [] selArgs = new String[] { url }; |
| 3790 | |
| 3791 | String where = Browser.BookmarkColumns.URL + " LIKE ? AND " |
| 3792 | + Browser.BookmarkColumns.BOOKMARK + " = 0"; |
| 3793 | Cursor c = mResolver.query(Browser.BOOKMARKS_URI, |
| 3794 | Browser.HISTORY_PROJECTION, where, selArgs, null); |
| 3795 | if (c.moveToFirst()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3796 | // Current implementation of database only has one entry per |
| 3797 | // url. |
Leon Scroggins | fce182b | 2009-05-08 13:54:52 -0400 | [diff] [blame] | 3798 | ContentValues map = new ContentValues(); |
| 3799 | map.put(Browser.BookmarkColumns.TITLE, title); |
| 3800 | mResolver.update(Browser.BOOKMARKS_URI, map, |
| 3801 | "_id = " + c.getInt(0), null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3802 | } |
| 3803 | c.close(); |
| 3804 | } catch (IllegalStateException e) { |
| 3805 | Log.e(LOGTAG, "BrowserActivity onReceived title", e); |
| 3806 | } catch (SQLiteException ex) { |
| 3807 | Log.e(LOGTAG, "onReceivedTitle() caught SQLiteException: ", ex); |
| 3808 | } |
| 3809 | } |
| 3810 | |
| 3811 | @Override |
| 3812 | public void onReceivedIcon(WebView view, Bitmap icon) { |
| 3813 | updateIcon(view.getUrl(), icon); |
| 3814 | } |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3815 | |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3816 | @Override |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3817 | public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3818 | if (mCustomView != null) |
| 3819 | return; |
| 3820 | |
| 3821 | // Add the custom view to its container. |
| 3822 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 3823 | mCustomView = view; |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3824 | mCustomViewCallback = callback; |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3825 | // Save the menu state and set it to empty while the custom |
| 3826 | // view is showing. |
| 3827 | mOldMenuState = mMenuState; |
| 3828 | mMenuState = EMPTY_MENU; |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3829 | // Hide the content view. |
| 3830 | mContentView.setVisibility(View.GONE); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3831 | // Finally show the custom view container. |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3832 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 3833 | mCustomViewContainer.bringToFront(); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | @Override |
| 3837 | public void onHideCustomView() { |
| 3838 | if (mCustomView == null) |
| 3839 | return; |
| 3840 | |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3841 | // Hide the custom view. |
| 3842 | mCustomView.setVisibility(View.GONE); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3843 | // Remove the custom view from its container. |
| 3844 | mCustomViewContainer.removeView(mCustomView); |
| 3845 | mCustomView = null; |
| 3846 | // Reset the old menu state. |
| 3847 | mMenuState = mOldMenuState; |
| 3848 | mOldMenuState = EMPTY_MENU; |
| 3849 | mCustomViewContainer.setVisibility(View.GONE); |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3850 | mCustomViewCallback.onCustomViewHidden(); |
| 3851 | // Show the content view. |
| 3852 | mContentView.setVisibility(View.VISIBLE); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3853 | } |
| 3854 | |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3855 | /** |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 3856 | * The origin has exceeded its database quota. |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3857 | * @param url the URL that exceeded the quota |
| 3858 | * @param databaseIdentifier the identifier of the database on |
| 3859 | * which the transaction that caused the quota overflow was run |
| 3860 | * @param currentQuota the current quota for the origin. |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 3861 | * @param totalUsedQuota is the sum of all origins' quota. |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3862 | * @param quotaUpdater The callback to run when a decision to allow or |
| 3863 | * deny quota has been made. Don't forget to call this! |
| 3864 | */ |
| 3865 | @Override |
| 3866 | public void onExceededDatabaseQuota(String url, |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 3867 | String databaseIdentifier, long currentQuota, long totalUsedQuota, |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3868 | WebStorage.QuotaUpdater quotaUpdater) { |
Andrei Popescu | 79e82b7 | 2009-07-27 12:01:59 +0100 | [diff] [blame] | 3869 | mSettings.getWebStorageSizeManager().onExceededDatabaseQuota( |
| 3870 | url, databaseIdentifier, currentQuota, totalUsedQuota, |
| 3871 | quotaUpdater); |
| 3872 | } |
| 3873 | |
| 3874 | /** |
| 3875 | * The Application Cache has exceeded its max size. |
| 3876 | * @param spaceNeeded is the amount of disk space that would be needed |
| 3877 | * in order for the last appcache operation to succeed. |
| 3878 | * @param totalUsedQuota is the sum of all origins' quota. |
| 3879 | * @param quotaUpdater A callback to inform the WebCore thread that a new |
| 3880 | * app cache size is available. This callback must always be executed at |
| 3881 | * some point to ensure that the sleeping WebCore thread is woken up. |
| 3882 | */ |
| 3883 | @Override |
| 3884 | public void onReachedMaxAppCacheSize(long spaceNeeded, |
| 3885 | long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { |
| 3886 | mSettings.getWebStorageSizeManager().onReachedMaxAppCacheSize( |
| 3887 | spaceNeeded, totalUsedQuota, quotaUpdater); |
Ben Murdoch | 092dd5d | 2009-04-22 12:34:12 +0100 | [diff] [blame] | 3888 | } |
Ben Murdoch | 7db2634 | 2009-06-03 18:21:19 +0100 | [diff] [blame] | 3889 | |
| 3890 | /* Adds a JavaScript error message to the system log. |
| 3891 | * @param message The error message to report. |
| 3892 | * @param lineNumber The line number of the error. |
| 3893 | * @param sourceID The name of the source file that caused the error. |
| 3894 | */ |
| 3895 | @Override |
| 3896 | public void addMessageToConsole(String message, int lineNumber, String sourceID) { |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3897 | ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(true); |
| 3898 | errorConsole.addErrorMessage(message, sourceID, lineNumber); |
| 3899 | if (mShouldShowErrorConsole && |
| 3900 | errorConsole.getShowState() != ErrorConsoleView.SHOW_MAXIMIZED) { |
| 3901 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 3902 | } |
| 3903 | Log.w(LOGTAG, "Console: " + message + " " + sourceID + ":" + lineNumber); |
Ben Murdoch | 7db2634 | 2009-06-03 18:21:19 +0100 | [diff] [blame] | 3904 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3905 | }; |
| 3906 | |
| 3907 | /** |
| 3908 | * Notify the host application a download should be done, or that |
| 3909 | * the data should be streamed if a streaming viewer is available. |
| 3910 | * @param url The full url to the content that should be downloaded |
| 3911 | * @param contentDisposition Content-disposition http header, if |
| 3912 | * present. |
| 3913 | * @param mimetype The mimetype of the content reported by the server |
| 3914 | * @param contentLength The file size reported by the server |
| 3915 | */ |
| 3916 | public void onDownloadStart(String url, String userAgent, |
| 3917 | String contentDisposition, String mimetype, long contentLength) { |
| 3918 | // if we're dealing wih A/V content that's not explicitly marked |
| 3919 | // for download, check if it's streamable. |
| 3920 | if (contentDisposition == null |
| 3921 | || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) { |
| 3922 | // query the package manager to see if there's a registered handler |
| 3923 | // that matches. |
| 3924 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 3925 | intent.setDataAndType(Uri.parse(url), mimetype); |
| 3926 | if (getPackageManager().resolveActivity(intent, |
| 3927 | PackageManager.MATCH_DEFAULT_ONLY) != null) { |
| 3928 | // someone knows how to handle this mime type with this scheme, don't download. |
| 3929 | try { |
| 3930 | startActivity(intent); |
| 3931 | return; |
| 3932 | } catch (ActivityNotFoundException ex) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 3933 | if (LOGD_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3934 | Log.d(LOGTAG, "activity not found for " + mimetype |
| 3935 | + " over " + Uri.parse(url).getScheme(), ex); |
| 3936 | } |
| 3937 | // Best behavior is to fall back to a download in this case |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | onDownloadStartNoStream(url, userAgent, contentDisposition, mimetype, contentLength); |
| 3942 | } |
| 3943 | |
| 3944 | /** |
| 3945 | * Notify the host application a download should be done, even if there |
| 3946 | * is a streaming viewer available for thise type. |
| 3947 | * @param url The full url to the content that should be downloaded |
| 3948 | * @param contentDisposition Content-disposition http header, if |
| 3949 | * present. |
| 3950 | * @param mimetype The mimetype of the content reported by the server |
| 3951 | * @param contentLength The file size reported by the server |
| 3952 | */ |
| 3953 | /*package */ void onDownloadStartNoStream(String url, String userAgent, |
| 3954 | String contentDisposition, String mimetype, long contentLength) { |
| 3955 | |
| 3956 | String filename = URLUtil.guessFileName(url, |
| 3957 | contentDisposition, mimetype); |
| 3958 | |
| 3959 | // Check to see if we have an SDCard |
| 3960 | String status = Environment.getExternalStorageState(); |
| 3961 | if (!status.equals(Environment.MEDIA_MOUNTED)) { |
| 3962 | int title; |
| 3963 | String msg; |
| 3964 | |
| 3965 | // Check to see if the SDCard is busy, same as the music app |
| 3966 | if (status.equals(Environment.MEDIA_SHARED)) { |
| 3967 | msg = getString(R.string.download_sdcard_busy_dlg_msg); |
| 3968 | title = R.string.download_sdcard_busy_dlg_title; |
| 3969 | } else { |
| 3970 | msg = getString(R.string.download_no_sdcard_dlg_msg, filename); |
| 3971 | title = R.string.download_no_sdcard_dlg_title; |
| 3972 | } |
| 3973 | |
| 3974 | new AlertDialog.Builder(this) |
| 3975 | .setTitle(title) |
| 3976 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3977 | .setMessage(msg) |
| 3978 | .setPositiveButton(R.string.ok, null) |
| 3979 | .show(); |
| 3980 | return; |
| 3981 | } |
| 3982 | |
| 3983 | // java.net.URI is a lot stricter than KURL so we have to undo |
| 3984 | // KURL's percent-encoding and redo the encoding using java.net.URI. |
| 3985 | URI uri = null; |
| 3986 | try { |
| 3987 | // Undo the percent-encoding that KURL may have done. |
| 3988 | String newUrl = new String(URLUtil.decode(url.getBytes())); |
| 3989 | // Parse the url into pieces |
| 3990 | WebAddress w = new WebAddress(newUrl); |
| 3991 | String frag = null; |
| 3992 | String query = null; |
| 3993 | String path = w.mPath; |
| 3994 | // Break the path into path, query, and fragment |
| 3995 | if (path.length() > 0) { |
| 3996 | // Strip the fragment |
| 3997 | int idx = path.lastIndexOf('#'); |
| 3998 | if (idx != -1) { |
| 3999 | frag = path.substring(idx + 1); |
| 4000 | path = path.substring(0, idx); |
| 4001 | } |
| 4002 | idx = path.lastIndexOf('?'); |
| 4003 | if (idx != -1) { |
| 4004 | query = path.substring(idx + 1); |
| 4005 | path = path.substring(0, idx); |
| 4006 | } |
| 4007 | } |
| 4008 | uri = new URI(w.mScheme, w.mAuthInfo, w.mHost, w.mPort, path, |
| 4009 | query, frag); |
| 4010 | } catch (Exception e) { |
| 4011 | Log.e(LOGTAG, "Could not parse url for download: " + url, e); |
| 4012 | return; |
| 4013 | } |
| 4014 | |
| 4015 | // XXX: Have to use the old url since the cookies were stored using the |
| 4016 | // old percent-encoded url. |
| 4017 | String cookies = CookieManager.getInstance().getCookie(url); |
| 4018 | |
| 4019 | ContentValues values = new ContentValues(); |
Jean-Baptiste Queru | 3dc09b2 | 2009-03-31 16:49:44 -0700 | [diff] [blame] | 4020 | values.put(Downloads.COLUMN_URI, uri.toString()); |
| 4021 | values.put(Downloads.COLUMN_COOKIE_DATA, cookies); |
| 4022 | values.put(Downloads.COLUMN_USER_AGENT, userAgent); |
| 4023 | values.put(Downloads.COLUMN_NOTIFICATION_PACKAGE, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4024 | getPackageName()); |
Jean-Baptiste Queru | 3dc09b2 | 2009-03-31 16:49:44 -0700 | [diff] [blame] | 4025 | values.put(Downloads.COLUMN_NOTIFICATION_CLASS, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4026 | BrowserDownloadPage.class.getCanonicalName()); |
Jean-Baptiste Queru | 3dc09b2 | 2009-03-31 16:49:44 -0700 | [diff] [blame] | 4027 | values.put(Downloads.COLUMN_VISIBILITY, Downloads.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); |
| 4028 | values.put(Downloads.COLUMN_MIME_TYPE, mimetype); |
| 4029 | values.put(Downloads.COLUMN_FILE_NAME_HINT, filename); |
| 4030 | values.put(Downloads.COLUMN_DESCRIPTION, uri.getHost()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4031 | if (contentLength > 0) { |
Jean-Baptiste Queru | 3dc09b2 | 2009-03-31 16:49:44 -0700 | [diff] [blame] | 4032 | values.put(Downloads.COLUMN_TOTAL_BYTES, contentLength); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4033 | } |
| 4034 | if (mimetype == null) { |
| 4035 | // We must have long pressed on a link or image to download it. We |
| 4036 | // are not sure of the mimetype in this case, so do a head request |
| 4037 | new FetchUrlMimeType(this).execute(values); |
| 4038 | } else { |
| 4039 | final Uri contentUri = |
| 4040 | getContentResolver().insert(Downloads.CONTENT_URI, values); |
| 4041 | viewDownloads(contentUri); |
| 4042 | } |
| 4043 | |
| 4044 | } |
| 4045 | |
| 4046 | /** |
| 4047 | * Resets the lock icon. This method is called when we start a new load and |
| 4048 | * know the url to be loaded. |
| 4049 | */ |
| 4050 | private void resetLockIcon(String url) { |
| 4051 | // Save the lock-icon state (we revert to it if the load gets cancelled) |
| 4052 | saveLockIcon(); |
| 4053 | |
| 4054 | mLockIconType = LOCK_ICON_UNSECURE; |
| 4055 | if (URLUtil.isHttpsUrl(url)) { |
| 4056 | mLockIconType = LOCK_ICON_SECURE; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 4057 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4058 | Log.v(LOGTAG, "BrowserActivity.resetLockIcon:" + |
| 4059 | " reset lock icon to " + mLockIconType); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | updateLockIconImage(LOCK_ICON_UNSECURE); |
| 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Resets the lock icon. This method is called when the icon needs to be |
| 4068 | * reset but we do not know whether we are loading a secure or not secure |
| 4069 | * page. |
| 4070 | */ |
| 4071 | private void resetLockIcon() { |
| 4072 | // Save the lock-icon state (we revert to it if the load gets cancelled) |
| 4073 | saveLockIcon(); |
| 4074 | |
| 4075 | mLockIconType = LOCK_ICON_UNSECURE; |
| 4076 | |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 4077 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4078 | Log.v(LOGTAG, "BrowserActivity.resetLockIcon:" + |
| 4079 | " reset lock icon to " + mLockIconType); |
| 4080 | } |
| 4081 | |
| 4082 | updateLockIconImage(LOCK_ICON_UNSECURE); |
| 4083 | } |
| 4084 | |
| 4085 | /** |
| 4086 | * Updates the lock-icon image in the title-bar. |
| 4087 | */ |
| 4088 | private void updateLockIconImage(int lockIconType) { |
| 4089 | Drawable d = null; |
| 4090 | if (lockIconType == LOCK_ICON_SECURE) { |
| 4091 | d = mSecLockIcon; |
| 4092 | } else if (lockIconType == LOCK_ICON_MIXED) { |
| 4093 | d = mMixLockIcon; |
| 4094 | } |
| 4095 | // If the tab overview is animating or being shown, do not update the |
| 4096 | // lock icon. |
| 4097 | if (mAnimationCount == 0 && mTabOverview == null) { |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 4098 | if (CUSTOM_BROWSER_BAR) { |
| 4099 | mTitleBar.setLock(d); |
| 4100 | } else { |
| 4101 | getWindow().setFeatureDrawable(Window.FEATURE_RIGHT_ICON, d); |
| 4102 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | /** |
| 4107 | * Displays a page-info dialog. |
| 4108 | * @param tab The tab to show info about |
| 4109 | * @param fromShowSSLCertificateOnError The flag that indicates whether |
| 4110 | * this dialog was opened from the SSL-certificate-on-error dialog or |
| 4111 | * not. This is important, since we need to know whether to return to |
| 4112 | * the parent dialog or simply dismiss. |
| 4113 | */ |
| 4114 | private void showPageInfo(final TabControl.Tab tab, |
| 4115 | final boolean fromShowSSLCertificateOnError) { |
| 4116 | final LayoutInflater factory = LayoutInflater |
| 4117 | .from(this); |
| 4118 | |
| 4119 | final View pageInfoView = factory.inflate(R.layout.page_info, null); |
| 4120 | |
| 4121 | final WebView view = tab.getWebView(); |
| 4122 | |
| 4123 | String url = null; |
| 4124 | String title = null; |
| 4125 | |
| 4126 | if (view == null) { |
| 4127 | url = tab.getUrl(); |
| 4128 | title = tab.getTitle(); |
| 4129 | } else if (view == mTabControl.getCurrentWebView()) { |
| 4130 | // Use the cached title and url if this is the current WebView |
| 4131 | url = mUrl; |
| 4132 | title = mTitle; |
| 4133 | } else { |
| 4134 | url = view.getUrl(); |
| 4135 | title = view.getTitle(); |
| 4136 | } |
| 4137 | |
| 4138 | if (url == null) { |
| 4139 | url = ""; |
| 4140 | } |
| 4141 | if (title == null) { |
| 4142 | title = ""; |
| 4143 | } |
| 4144 | |
| 4145 | ((TextView) pageInfoView.findViewById(R.id.address)).setText(url); |
| 4146 | ((TextView) pageInfoView.findViewById(R.id.title)).setText(title); |
| 4147 | |
| 4148 | mPageInfoView = tab; |
| 4149 | mPageInfoFromShowSSLCertificateOnError = new Boolean(fromShowSSLCertificateOnError); |
| 4150 | |
| 4151 | AlertDialog.Builder alertDialogBuilder = |
| 4152 | new AlertDialog.Builder(this) |
| 4153 | .setTitle(R.string.page_info).setIcon(android.R.drawable.ic_dialog_info) |
| 4154 | .setView(pageInfoView) |
| 4155 | .setPositiveButton( |
| 4156 | R.string.ok, |
| 4157 | new DialogInterface.OnClickListener() { |
| 4158 | public void onClick(DialogInterface dialog, |
| 4159 | int whichButton) { |
| 4160 | mPageInfoDialog = null; |
| 4161 | mPageInfoView = null; |
| 4162 | mPageInfoFromShowSSLCertificateOnError = null; |
| 4163 | |
| 4164 | // if we came here from the SSL error dialog |
| 4165 | if (fromShowSSLCertificateOnError) { |
| 4166 | // go back to the SSL error dialog |
| 4167 | showSSLCertificateOnError( |
| 4168 | mSSLCertificateOnErrorView, |
| 4169 | mSSLCertificateOnErrorHandler, |
| 4170 | mSSLCertificateOnErrorError); |
| 4171 | } |
| 4172 | } |
| 4173 | }) |
| 4174 | .setOnCancelListener( |
| 4175 | new DialogInterface.OnCancelListener() { |
| 4176 | public void onCancel(DialogInterface dialog) { |
| 4177 | mPageInfoDialog = null; |
| 4178 | mPageInfoView = null; |
| 4179 | mPageInfoFromShowSSLCertificateOnError = null; |
| 4180 | |
| 4181 | // if we came here from the SSL error dialog |
| 4182 | if (fromShowSSLCertificateOnError) { |
| 4183 | // go back to the SSL error dialog |
| 4184 | showSSLCertificateOnError( |
| 4185 | mSSLCertificateOnErrorView, |
| 4186 | mSSLCertificateOnErrorHandler, |
| 4187 | mSSLCertificateOnErrorError); |
| 4188 | } |
| 4189 | } |
| 4190 | }); |
| 4191 | |
| 4192 | // if we have a main top-level page SSL certificate set or a certificate |
| 4193 | // error |
| 4194 | if (fromShowSSLCertificateOnError || |
| 4195 | (view != null && view.getCertificate() != null)) { |
| 4196 | // add a 'View Certificate' button |
| 4197 | alertDialogBuilder.setNeutralButton( |
| 4198 | R.string.view_certificate, |
| 4199 | new DialogInterface.OnClickListener() { |
| 4200 | public void onClick(DialogInterface dialog, |
| 4201 | int whichButton) { |
| 4202 | mPageInfoDialog = null; |
| 4203 | mPageInfoView = null; |
| 4204 | mPageInfoFromShowSSLCertificateOnError = null; |
| 4205 | |
| 4206 | // if we came here from the SSL error dialog |
| 4207 | if (fromShowSSLCertificateOnError) { |
| 4208 | // go back to the SSL error dialog |
| 4209 | showSSLCertificateOnError( |
| 4210 | mSSLCertificateOnErrorView, |
| 4211 | mSSLCertificateOnErrorHandler, |
| 4212 | mSSLCertificateOnErrorError); |
| 4213 | } else { |
| 4214 | // otherwise, display the top-most certificate from |
| 4215 | // the chain |
| 4216 | if (view.getCertificate() != null) { |
| 4217 | showSSLCertificate(tab); |
| 4218 | } |
| 4219 | } |
| 4220 | } |
| 4221 | }); |
| 4222 | } |
| 4223 | |
| 4224 | mPageInfoDialog = alertDialogBuilder.show(); |
| 4225 | } |
| 4226 | |
| 4227 | /** |
| 4228 | * Displays the main top-level page SSL certificate dialog |
| 4229 | * (accessible from the Page-Info dialog). |
| 4230 | * @param tab The tab to show certificate for. |
| 4231 | */ |
| 4232 | private void showSSLCertificate(final TabControl.Tab tab) { |
| 4233 | final View certificateView = |
| 4234 | inflateCertificateView(tab.getWebView().getCertificate()); |
| 4235 | if (certificateView == null) { |
| 4236 | return; |
| 4237 | } |
| 4238 | |
| 4239 | LayoutInflater factory = LayoutInflater.from(this); |
| 4240 | |
| 4241 | final LinearLayout placeholder = |
| 4242 | (LinearLayout)certificateView.findViewById(R.id.placeholder); |
| 4243 | |
| 4244 | LinearLayout ll = (LinearLayout) factory.inflate( |
| 4245 | R.layout.ssl_success, placeholder); |
| 4246 | ((TextView)ll.findViewById(R.id.success)) |
| 4247 | .setText(R.string.ssl_certificate_is_valid); |
| 4248 | |
| 4249 | mSSLCertificateView = tab; |
| 4250 | mSSLCertificateDialog = |
| 4251 | new AlertDialog.Builder(this) |
| 4252 | .setTitle(R.string.ssl_certificate).setIcon( |
| 4253 | R.drawable.ic_dialog_browser_certificate_secure) |
| 4254 | .setView(certificateView) |
| 4255 | .setPositiveButton(R.string.ok, |
| 4256 | new DialogInterface.OnClickListener() { |
| 4257 | public void onClick(DialogInterface dialog, |
| 4258 | int whichButton) { |
| 4259 | mSSLCertificateDialog = null; |
| 4260 | mSSLCertificateView = null; |
| 4261 | |
| 4262 | showPageInfo(tab, false); |
| 4263 | } |
| 4264 | }) |
| 4265 | .setOnCancelListener( |
| 4266 | new DialogInterface.OnCancelListener() { |
| 4267 | public void onCancel(DialogInterface dialog) { |
| 4268 | mSSLCertificateDialog = null; |
| 4269 | mSSLCertificateView = null; |
| 4270 | |
| 4271 | showPageInfo(tab, false); |
| 4272 | } |
| 4273 | }) |
| 4274 | .show(); |
| 4275 | } |
| 4276 | |
| 4277 | /** |
| 4278 | * Displays the SSL error certificate dialog. |
| 4279 | * @param view The target web-view. |
| 4280 | * @param handler The SSL error handler responsible for cancelling the |
| 4281 | * connection that resulted in an SSL error or proceeding per user request. |
| 4282 | * @param error The SSL error object. |
| 4283 | */ |
| 4284 | private void showSSLCertificateOnError( |
| 4285 | final WebView view, final SslErrorHandler handler, final SslError error) { |
| 4286 | |
| 4287 | final View certificateView = |
| 4288 | inflateCertificateView(error.getCertificate()); |
| 4289 | if (certificateView == null) { |
| 4290 | return; |
| 4291 | } |
| 4292 | |
| 4293 | LayoutInflater factory = LayoutInflater.from(this); |
| 4294 | |
| 4295 | final LinearLayout placeholder = |
| 4296 | (LinearLayout)certificateView.findViewById(R.id.placeholder); |
| 4297 | |
| 4298 | if (error.hasError(SslError.SSL_UNTRUSTED)) { |
| 4299 | LinearLayout ll = (LinearLayout)factory |
| 4300 | .inflate(R.layout.ssl_warning, placeholder); |
| 4301 | ((TextView)ll.findViewById(R.id.warning)) |
| 4302 | .setText(R.string.ssl_untrusted); |
| 4303 | } |
| 4304 | |
| 4305 | if (error.hasError(SslError.SSL_IDMISMATCH)) { |
| 4306 | LinearLayout ll = (LinearLayout)factory |
| 4307 | .inflate(R.layout.ssl_warning, placeholder); |
| 4308 | ((TextView)ll.findViewById(R.id.warning)) |
| 4309 | .setText(R.string.ssl_mismatch); |
| 4310 | } |
| 4311 | |
| 4312 | if (error.hasError(SslError.SSL_EXPIRED)) { |
| 4313 | LinearLayout ll = (LinearLayout)factory |
| 4314 | .inflate(R.layout.ssl_warning, placeholder); |
| 4315 | ((TextView)ll.findViewById(R.id.warning)) |
| 4316 | .setText(R.string.ssl_expired); |
| 4317 | } |
| 4318 | |
| 4319 | if (error.hasError(SslError.SSL_NOTYETVALID)) { |
| 4320 | LinearLayout ll = (LinearLayout)factory |
| 4321 | .inflate(R.layout.ssl_warning, placeholder); |
| 4322 | ((TextView)ll.findViewById(R.id.warning)) |
| 4323 | .setText(R.string.ssl_not_yet_valid); |
| 4324 | } |
| 4325 | |
| 4326 | mSSLCertificateOnErrorHandler = handler; |
| 4327 | mSSLCertificateOnErrorView = view; |
| 4328 | mSSLCertificateOnErrorError = error; |
| 4329 | mSSLCertificateOnErrorDialog = |
| 4330 | new AlertDialog.Builder(this) |
| 4331 | .setTitle(R.string.ssl_certificate).setIcon( |
| 4332 | R.drawable.ic_dialog_browser_certificate_partially_secure) |
| 4333 | .setView(certificateView) |
| 4334 | .setPositiveButton(R.string.ok, |
| 4335 | new DialogInterface.OnClickListener() { |
| 4336 | public void onClick(DialogInterface dialog, |
| 4337 | int whichButton) { |
| 4338 | mSSLCertificateOnErrorDialog = null; |
| 4339 | mSSLCertificateOnErrorView = null; |
| 4340 | mSSLCertificateOnErrorHandler = null; |
| 4341 | mSSLCertificateOnErrorError = null; |
| 4342 | |
| 4343 | mWebViewClient.onReceivedSslError( |
| 4344 | view, handler, error); |
| 4345 | } |
| 4346 | }) |
| 4347 | .setNeutralButton(R.string.page_info_view, |
| 4348 | new DialogInterface.OnClickListener() { |
| 4349 | public void onClick(DialogInterface dialog, |
| 4350 | int whichButton) { |
| 4351 | mSSLCertificateOnErrorDialog = null; |
| 4352 | |
| 4353 | // do not clear the dialog state: we will |
| 4354 | // need to show the dialog again once the |
| 4355 | // user is done exploring the page-info details |
| 4356 | |
| 4357 | showPageInfo(mTabControl.getTabFromView(view), |
| 4358 | true); |
| 4359 | } |
| 4360 | }) |
| 4361 | .setOnCancelListener( |
| 4362 | new DialogInterface.OnCancelListener() { |
| 4363 | public void onCancel(DialogInterface dialog) { |
| 4364 | mSSLCertificateOnErrorDialog = null; |
| 4365 | mSSLCertificateOnErrorView = null; |
| 4366 | mSSLCertificateOnErrorHandler = null; |
| 4367 | mSSLCertificateOnErrorError = null; |
| 4368 | |
| 4369 | mWebViewClient.onReceivedSslError( |
| 4370 | view, handler, error); |
| 4371 | } |
| 4372 | }) |
| 4373 | .show(); |
| 4374 | } |
| 4375 | |
| 4376 | /** |
| 4377 | * Inflates the SSL certificate view (helper method). |
| 4378 | * @param certificate The SSL certificate. |
| 4379 | * @return The resultant certificate view with issued-to, issued-by, |
| 4380 | * issued-on, expires-on, and possibly other fields set. |
| 4381 | * If the input certificate is null, returns null. |
| 4382 | */ |
| 4383 | private View inflateCertificateView(SslCertificate certificate) { |
| 4384 | if (certificate == null) { |
| 4385 | return null; |
| 4386 | } |
| 4387 | |
| 4388 | LayoutInflater factory = LayoutInflater.from(this); |
| 4389 | |
| 4390 | View certificateView = factory.inflate( |
| 4391 | R.layout.ssl_certificate, null); |
| 4392 | |
| 4393 | // issued to: |
| 4394 | SslCertificate.DName issuedTo = certificate.getIssuedTo(); |
| 4395 | if (issuedTo != null) { |
| 4396 | ((TextView) certificateView.findViewById(R.id.to_common)) |
| 4397 | .setText(issuedTo.getCName()); |
| 4398 | ((TextView) certificateView.findViewById(R.id.to_org)) |
| 4399 | .setText(issuedTo.getOName()); |
| 4400 | ((TextView) certificateView.findViewById(R.id.to_org_unit)) |
| 4401 | .setText(issuedTo.getUName()); |
| 4402 | } |
| 4403 | |
| 4404 | // issued by: |
| 4405 | SslCertificate.DName issuedBy = certificate.getIssuedBy(); |
| 4406 | if (issuedBy != null) { |
| 4407 | ((TextView) certificateView.findViewById(R.id.by_common)) |
| 4408 | .setText(issuedBy.getCName()); |
| 4409 | ((TextView) certificateView.findViewById(R.id.by_org)) |
| 4410 | .setText(issuedBy.getOName()); |
| 4411 | ((TextView) certificateView.findViewById(R.id.by_org_unit)) |
| 4412 | .setText(issuedBy.getUName()); |
| 4413 | } |
| 4414 | |
| 4415 | // issued on: |
| 4416 | String issuedOn = reformatCertificateDate( |
| 4417 | certificate.getValidNotBefore()); |
| 4418 | ((TextView) certificateView.findViewById(R.id.issued_on)) |
| 4419 | .setText(issuedOn); |
| 4420 | |
| 4421 | // expires on: |
| 4422 | String expiresOn = reformatCertificateDate( |
| 4423 | certificate.getValidNotAfter()); |
| 4424 | ((TextView) certificateView.findViewById(R.id.expires_on)) |
| 4425 | .setText(expiresOn); |
| 4426 | |
| 4427 | return certificateView; |
| 4428 | } |
| 4429 | |
| 4430 | /** |
| 4431 | * Re-formats the certificate date (Date.toString()) string to |
| 4432 | * a properly localized date string. |
| 4433 | * @return Properly localized version of the certificate date string and |
| 4434 | * the original certificate date string if fails to localize. |
| 4435 | * If the original string is null, returns an empty string "". |
| 4436 | */ |
| 4437 | private String reformatCertificateDate(String certificateDate) { |
| 4438 | String reformattedDate = null; |
| 4439 | |
| 4440 | if (certificateDate != null) { |
| 4441 | Date date = null; |
| 4442 | try { |
| 4443 | date = java.text.DateFormat.getInstance().parse(certificateDate); |
| 4444 | } catch (ParseException e) { |
| 4445 | date = null; |
| 4446 | } |
| 4447 | |
| 4448 | if (date != null) { |
| 4449 | reformattedDate = |
| 4450 | DateFormat.getDateFormat(this).format(date); |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | return reformattedDate != null ? reformattedDate : |
| 4455 | (certificateDate != null ? certificateDate : ""); |
| 4456 | } |
| 4457 | |
| 4458 | /** |
| 4459 | * Displays an http-authentication dialog. |
| 4460 | */ |
| 4461 | private void showHttpAuthentication(final HttpAuthHandler handler, |
| 4462 | final String host, final String realm, final String title, |
| 4463 | final String name, final String password, int focusId) { |
| 4464 | LayoutInflater factory = LayoutInflater.from(this); |
| 4465 | final View v = factory |
| 4466 | .inflate(R.layout.http_authentication, null); |
| 4467 | if (name != null) { |
| 4468 | ((EditText) v.findViewById(R.id.username_edit)).setText(name); |
| 4469 | } |
| 4470 | if (password != null) { |
| 4471 | ((EditText) v.findViewById(R.id.password_edit)).setText(password); |
| 4472 | } |
| 4473 | |
| 4474 | String titleText = title; |
| 4475 | if (titleText == null) { |
| 4476 | titleText = getText(R.string.sign_in_to).toString().replace( |
| 4477 | "%s1", host).replace("%s2", realm); |
| 4478 | } |
| 4479 | |
| 4480 | mHttpAuthHandler = handler; |
| 4481 | AlertDialog dialog = new AlertDialog.Builder(this) |
| 4482 | .setTitle(titleText) |
| 4483 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 4484 | .setView(v) |
| 4485 | .setPositiveButton(R.string.action, |
| 4486 | new DialogInterface.OnClickListener() { |
| 4487 | public void onClick(DialogInterface dialog, |
| 4488 | int whichButton) { |
| 4489 | String nm = ((EditText) v |
| 4490 | .findViewById(R.id.username_edit)) |
| 4491 | .getText().toString(); |
| 4492 | String pw = ((EditText) v |
| 4493 | .findViewById(R.id.password_edit)) |
| 4494 | .getText().toString(); |
| 4495 | BrowserActivity.this.setHttpAuthUsernamePassword |
| 4496 | (host, realm, nm, pw); |
| 4497 | handler.proceed(nm, pw); |
| 4498 | mHttpAuthenticationDialog = null; |
| 4499 | mHttpAuthHandler = null; |
| 4500 | }}) |
| 4501 | .setNegativeButton(R.string.cancel, |
| 4502 | new DialogInterface.OnClickListener() { |
| 4503 | public void onClick(DialogInterface dialog, |
| 4504 | int whichButton) { |
| 4505 | handler.cancel(); |
| 4506 | BrowserActivity.this.resetTitleAndRevertLockIcon(); |
| 4507 | mHttpAuthenticationDialog = null; |
| 4508 | mHttpAuthHandler = null; |
| 4509 | }}) |
| 4510 | .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 4511 | public void onCancel(DialogInterface dialog) { |
| 4512 | handler.cancel(); |
| 4513 | BrowserActivity.this.resetTitleAndRevertLockIcon(); |
| 4514 | mHttpAuthenticationDialog = null; |
| 4515 | mHttpAuthHandler = null; |
| 4516 | }}) |
| 4517 | .create(); |
| 4518 | // Make the IME appear when the dialog is displayed if applicable. |
| 4519 | dialog.getWindow().setSoftInputMode( |
| 4520 | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); |
| 4521 | dialog.show(); |
| 4522 | if (focusId != 0) { |
| 4523 | dialog.findViewById(focusId).requestFocus(); |
| 4524 | } else { |
| 4525 | v.findViewById(R.id.username_edit).requestFocus(); |
| 4526 | } |
| 4527 | mHttpAuthenticationDialog = dialog; |
| 4528 | } |
| 4529 | |
| 4530 | public int getProgress() { |
| 4531 | WebView w = mTabControl.getCurrentWebView(); |
| 4532 | if (w != null) { |
| 4533 | return w.getProgress(); |
| 4534 | } else { |
| 4535 | return 100; |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | /** |
| 4540 | * Set HTTP authentication password. |
| 4541 | * |
| 4542 | * @param host The host for the password |
| 4543 | * @param realm The realm for the password |
| 4544 | * @param username The username for the password. If it is null, it means |
| 4545 | * password can't be saved. |
| 4546 | * @param password The password |
| 4547 | */ |
| 4548 | public void setHttpAuthUsernamePassword(String host, String realm, |
| 4549 | String username, |
| 4550 | String password) { |
| 4551 | WebView w = mTabControl.getCurrentWebView(); |
| 4552 | if (w != null) { |
| 4553 | w.setHttpAuthUsernamePassword(host, realm, username, password); |
| 4554 | } |
| 4555 | } |
| 4556 | |
| 4557 | /** |
| 4558 | * connectivity manager says net has come or gone... inform the user |
| 4559 | * @param up true if net has come up, false if net has gone down |
| 4560 | */ |
| 4561 | public void onNetworkToggle(boolean up) { |
| 4562 | if (up == mIsNetworkUp) { |
| 4563 | return; |
| 4564 | } else if (up) { |
| 4565 | mIsNetworkUp = true; |
| 4566 | if (mAlertDialog != null) { |
| 4567 | mAlertDialog.cancel(); |
| 4568 | mAlertDialog = null; |
| 4569 | } |
| 4570 | } else { |
| 4571 | mIsNetworkUp = false; |
| 4572 | if (mInLoad && mAlertDialog == null) { |
| 4573 | mAlertDialog = new AlertDialog.Builder(this) |
| 4574 | .setTitle(R.string.loadSuspendedTitle) |
| 4575 | .setMessage(R.string.loadSuspended) |
| 4576 | .setPositiveButton(R.string.ok, null) |
| 4577 | .show(); |
| 4578 | } |
| 4579 | } |
| 4580 | WebView w = mTabControl.getCurrentWebView(); |
| 4581 | if (w != null) { |
| 4582 | w.setNetworkAvailable(up); |
| 4583 | } |
| 4584 | } |
| 4585 | |
| 4586 | @Override |
| 4587 | protected void onActivityResult(int requestCode, int resultCode, |
| 4588 | Intent intent) { |
| 4589 | switch (requestCode) { |
| 4590 | case COMBO_PAGE: |
| 4591 | if (resultCode == RESULT_OK && intent != null) { |
| 4592 | String data = intent.getAction(); |
| 4593 | Bundle extras = intent.getExtras(); |
| 4594 | if (extras != null && extras.getBoolean("new_window", false)) { |
Patrick Scott | b0e4fc7 | 2009-07-14 10:49:22 -0400 | [diff] [blame] | 4595 | final TabControl.Tab newTab = openTab(data); |
| 4596 | if (mSettings.openInBackground() && |
| 4597 | newTab != null && mTabOverview != null) { |
| 4598 | mTabControl.populatePickerData(newTab); |
| 4599 | mTabControl.setCurrentTab(newTab); |
| 4600 | mTabOverview.add(newTab); |
| 4601 | mTabOverview.setCurrentIndex( |
| 4602 | mTabControl.getCurrentIndex()); |
| 4603 | sendAnimateFromOverview(newTab, false, |
| 4604 | EMPTY_URL_DATA, TAB_OVERVIEW_DELAY, null); |
| 4605 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4606 | } else { |
| 4607 | final TabControl.Tab currentTab = |
| 4608 | mTabControl.getCurrentTab(); |
| 4609 | // If the Window overview is up and we are not in the |
| 4610 | // middle of an animation, animate away from it to the |
| 4611 | // current tab. |
| 4612 | if (mTabOverview != null && mAnimationCount == 0) { |
Grace Kloba | ec7eb37 | 2009-06-16 13:45:56 -0700 | [diff] [blame] | 4613 | sendAnimateFromOverview(currentTab, false, |
| 4614 | new UrlData(data), TAB_OVERVIEW_DELAY, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4615 | } else { |
| 4616 | dismissSubWindow(currentTab); |
| 4617 | if (data != null && data.length() != 0) { |
| 4618 | getTopWindow().loadUrl(data); |
| 4619 | } |
| 4620 | } |
| 4621 | } |
| 4622 | } |
| 4623 | break; |
| 4624 | default: |
| 4625 | break; |
| 4626 | } |
| 4627 | getTopWindow().requestFocus(); |
| 4628 | } |
| 4629 | |
| 4630 | /* |
| 4631 | * This method is called as a result of the user selecting the options |
| 4632 | * menu to see the download window, or when a download changes state. It |
| 4633 | * shows the download window ontop of the current window. |
| 4634 | */ |
| 4635 | /* package */ void viewDownloads(Uri downloadRecord) { |
| 4636 | Intent intent = new Intent(this, |
| 4637 | BrowserDownloadPage.class); |
| 4638 | intent.setData(downloadRecord); |
| 4639 | startActivityForResult(intent, this.DOWNLOAD_PAGE); |
| 4640 | |
| 4641 | } |
| 4642 | |
| 4643 | /** |
| 4644 | * Handle results from Tab Switcher mTabOverview tool |
| 4645 | */ |
| 4646 | private class TabListener implements ImageGrid.Listener { |
| 4647 | public void remove(int position) { |
| 4648 | // Note: Remove is not enabled if we have only one tab. |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 4649 | if (DEBUG && mTabControl.getTabCount() == 1) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4650 | throw new AssertionError(); |
| 4651 | } |
| 4652 | |
| 4653 | // Remember the current tab. |
| 4654 | TabControl.Tab current = mTabControl.getCurrentTab(); |
| 4655 | final TabControl.Tab remove = mTabControl.getTab(position); |
| 4656 | mTabControl.removeTab(remove); |
| 4657 | // If we removed the current tab, use the tab at position - 1 if |
| 4658 | // possible. |
| 4659 | if (current == remove) { |
| 4660 | // If the user removes the last tab, act like the New Tab item |
| 4661 | // was clicked on. |
| 4662 | if (mTabControl.getTabCount() == 0) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 4663 | current = mTabControl.createNewTab(); |
Grace Kloba | ec7eb37 | 2009-06-16 13:45:56 -0700 | [diff] [blame] | 4664 | sendAnimateFromOverview(current, true, new UrlData( |
| 4665 | mSettings.getHomePage()), TAB_OVERVIEW_DELAY, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4666 | } else { |
| 4667 | final int index = position > 0 ? (position - 1) : 0; |
| 4668 | current = mTabControl.getTab(index); |
| 4669 | } |
| 4670 | } |
| 4671 | |
| 4672 | // The tab overview could have been dismissed before this method is |
| 4673 | // called. |
| 4674 | if (mTabOverview != null) { |
| 4675 | // Remove the tab and change the index. |
| 4676 | mTabOverview.remove(position); |
| 4677 | mTabOverview.setCurrentIndex(mTabControl.getTabIndex(current)); |
| 4678 | } |
| 4679 | |
| 4680 | // Only the current tab ensures its WebView is non-null. This |
| 4681 | // implies that we are reloading the freed tab. |
| 4682 | mTabControl.setCurrentTab(current); |
| 4683 | } |
| 4684 | public void onClick(int index) { |
| 4685 | // Change the tab if necessary. |
| 4686 | // Index equals ImageGrid.CANCEL when pressing back from the tab |
| 4687 | // overview. |
| 4688 | if (index == ImageGrid.CANCEL) { |
| 4689 | index = mTabControl.getCurrentIndex(); |
| 4690 | // The current index is -1 if the current tab was removed. |
| 4691 | if (index == -1) { |
| 4692 | // Take the last tab as a fallback. |
| 4693 | index = mTabControl.getTabCount() - 1; |
| 4694 | } |
| 4695 | } |
| 4696 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4697 | // NEW_TAB means that the "New Tab" cell was clicked on. |
| 4698 | if (index == ImageGrid.NEW_TAB) { |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 4699 | openTabAndShow(mSettings.getHomePage(), null, false, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4700 | } else { |
Grace Kloba | ec7eb37 | 2009-06-16 13:45:56 -0700 | [diff] [blame] | 4701 | sendAnimateFromOverview(mTabControl.getTab(index), false, |
| 4702 | EMPTY_URL_DATA, 0, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4703 | } |
| 4704 | } |
| 4705 | } |
| 4706 | |
| 4707 | // A fake View that draws the WebView's picture with a fast zoom filter. |
| 4708 | // The View is used in case the tab is freed during the animation because |
| 4709 | // of low memory. |
| 4710 | private static class AnimatingView extends View { |
| 4711 | private static final int ZOOM_BITS = Paint.FILTER_BITMAP_FLAG | |
| 4712 | Paint.DITHER_FLAG | Paint.SUBPIXEL_TEXT_FLAG; |
| 4713 | private static final DrawFilter sZoomFilter = |
| 4714 | new PaintFlagsDrawFilter(ZOOM_BITS, Paint.LINEAR_TEXT_FLAG); |
| 4715 | private final Picture mPicture; |
| 4716 | private final float mScale; |
| 4717 | private final int mScrollX; |
| 4718 | private final int mScrollY; |
| 4719 | final TabControl.Tab mTab; |
| 4720 | |
| 4721 | AnimatingView(Context ctxt, TabControl.Tab t) { |
| 4722 | super(ctxt); |
| 4723 | mTab = t; |
Patrick Scott | ae641ac | 2009-04-20 13:51:49 -0400 | [diff] [blame] | 4724 | if (t != null && t.getTopWindow() != null) { |
| 4725 | // Use the top window in the animation since the tab overview |
| 4726 | // will display the top window in each cell. |
| 4727 | final WebView w = t.getTopWindow(); |
| 4728 | mPicture = w.capturePicture(); |
| 4729 | mScale = w.getScale() / w.getWidth(); |
| 4730 | mScrollX = w.getScrollX(); |
| 4731 | mScrollY = w.getScrollY(); |
| 4732 | } else { |
| 4733 | mPicture = null; |
| 4734 | mScale = 1.0f; |
| 4735 | mScrollX = mScrollY = 0; |
| 4736 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | @Override |
| 4740 | protected void onDraw(Canvas canvas) { |
| 4741 | canvas.save(); |
| 4742 | canvas.drawColor(Color.WHITE); |
| 4743 | if (mPicture != null) { |
| 4744 | canvas.setDrawFilter(sZoomFilter); |
| 4745 | float scale = getWidth() * mScale; |
| 4746 | canvas.scale(scale, scale); |
| 4747 | canvas.translate(-mScrollX, -mScrollY); |
| 4748 | canvas.drawPicture(mPicture); |
| 4749 | } |
| 4750 | canvas.restore(); |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | /** |
| 4755 | * Open the tab picker. This function will always use the current tab in |
| 4756 | * its animation. |
| 4757 | * @param stay boolean stating whether the tab picker is to remain open |
| 4758 | * (in which case it needs a listener and its menu) or not. |
| 4759 | * @param index The index of the tab to show as the selection in the tab |
| 4760 | * overview. |
| 4761 | * @param remove If true, the tab at index will be removed after the |
| 4762 | * animation completes. |
| 4763 | */ |
| 4764 | private void tabPicker(final boolean stay, final int index, |
| 4765 | final boolean remove) { |
| 4766 | if (mTabOverview != null) { |
| 4767 | return; |
| 4768 | } |
| 4769 | |
| 4770 | int size = mTabControl.getTabCount(); |
| 4771 | |
| 4772 | TabListener l = null; |
| 4773 | if (stay) { |
| 4774 | l = mTabListener = new TabListener(); |
| 4775 | } |
| 4776 | mTabOverview = new ImageGrid(this, stay, l); |
| 4777 | |
| 4778 | for (int i = 0; i < size; i++) { |
| 4779 | final TabControl.Tab t = mTabControl.getTab(i); |
| 4780 | mTabControl.populatePickerData(t); |
| 4781 | mTabOverview.add(t); |
| 4782 | } |
| 4783 | |
| 4784 | // Tell the tab overview to show the current tab, the tab overview will |
| 4785 | // handle the "New Tab" case. |
| 4786 | int currentIndex = mTabControl.getCurrentIndex(); |
| 4787 | mTabOverview.setCurrentIndex(currentIndex); |
| 4788 | |
| 4789 | // Attach the tab overview. |
| 4790 | mContentView.addView(mTabOverview, COVER_SCREEN_PARAMS); |
| 4791 | |
| 4792 | // Create a fake AnimatingView to animate the WebView's picture. |
| 4793 | final TabControl.Tab current = mTabControl.getCurrentTab(); |
| 4794 | final AnimatingView v = new AnimatingView(this, current); |
| 4795 | mContentView.addView(v, COVER_SCREEN_PARAMS); |
| 4796 | removeTabFromContentView(current); |
| 4797 | // Pause timers to get the animation smoother. |
| 4798 | current.getWebView().pauseTimers(); |
| 4799 | |
| 4800 | // Send a message so the tab picker has a chance to layout and get |
| 4801 | // positions for all the cells. |
| 4802 | mHandler.sendMessage(mHandler.obtainMessage(ANIMATE_TO_OVERVIEW, |
| 4803 | index, remove ? 1 : 0, v)); |
| 4804 | // Setting this will indicate that we are animating to the overview. We |
| 4805 | // set it here to prevent another request to animate from coming in |
| 4806 | // between now and when ANIMATE_TO_OVERVIEW is handled. |
| 4807 | mAnimationCount++; |
| 4808 | // Always change the title bar to the window overview title while |
| 4809 | // animating. |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 4810 | if (CUSTOM_BROWSER_BAR) { |
| 4811 | mTitleBar.setToTabPicker(); |
| 4812 | } else { |
| 4813 | getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, null); |
| 4814 | getWindow().setFeatureDrawable(Window.FEATURE_RIGHT_ICON, null); |
| 4815 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, |
| 4816 | Window.PROGRESS_VISIBILITY_OFF); |
| 4817 | setTitle(R.string.tab_picker_title); |
| 4818 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4819 | // Make the menu empty until the animation completes. |
| 4820 | mMenuState = EMPTY_MENU; |
| 4821 | } |
| 4822 | |
Leon Scroggins | e4b3bda | 2009-06-09 15:46:41 -0400 | [diff] [blame] | 4823 | /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4824 | WebView current = mTabControl.getCurrentWebView(); |
| 4825 | if (current == null) { |
| 4826 | return; |
| 4827 | } |
| 4828 | Intent intent = new Intent(this, |
| 4829 | CombinedBookmarkHistoryActivity.class); |
| 4830 | String title = current.getTitle(); |
| 4831 | String url = current.getUrl(); |
| 4832 | // Just in case the user opens bookmarks before a page finishes loading |
| 4833 | // so the current history item, and therefore the page, is null. |
| 4834 | if (null == url) { |
| 4835 | url = mLastEnteredUrl; |
| 4836 | // This can happen. |
| 4837 | if (null == url) { |
| 4838 | url = mSettings.getHomePage(); |
| 4839 | } |
| 4840 | } |
| 4841 | // In case the web page has not yet received its associated title. |
| 4842 | if (title == null) { |
| 4843 | title = url; |
| 4844 | } |
| 4845 | intent.putExtra("title", title); |
| 4846 | intent.putExtra("url", url); |
| 4847 | intent.putExtra("maxTabsOpen", |
| 4848 | mTabControl.getTabCount() >= TabControl.MAX_TABS); |
| 4849 | if (startWithHistory) { |
| 4850 | intent.putExtra(CombinedBookmarkHistoryActivity.STARTING_TAB, |
| 4851 | CombinedBookmarkHistoryActivity.HISTORY_TAB); |
| 4852 | } |
| 4853 | startActivityForResult(intent, COMBO_PAGE); |
| 4854 | } |
| 4855 | |
| 4856 | // Called when loading from context menu or LOAD_URL message |
| 4857 | private void loadURL(WebView view, String url) { |
| 4858 | // In case the user enters nothing. |
| 4859 | if (url != null && url.length() != 0 && view != null) { |
| 4860 | url = smartUrlFilter(url); |
| 4861 | if (!mWebViewClient.shouldOverrideUrlLoading(view, url)) { |
| 4862 | view.loadUrl(url); |
| 4863 | } |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | private void checkMemory() { |
| 4868 | ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); |
| 4869 | ((ActivityManager) getSystemService(ACTIVITY_SERVICE)) |
| 4870 | .getMemoryInfo(mi); |
| 4871 | // FIXME: mi.lowMemory is too aggressive, use (mi.availMem < |
| 4872 | // mi.threshold) for now |
| 4873 | // if (mi.lowMemory) { |
| 4874 | if (mi.availMem < mi.threshold) { |
| 4875 | Log.w(LOGTAG, "Browser is freeing memory now because: available=" |
| 4876 | + (mi.availMem / 1024) + "K threshold=" |
| 4877 | + (mi.threshold / 1024) + "K"); |
| 4878 | mTabControl.freeMemory(); |
| 4879 | } |
| 4880 | } |
| 4881 | |
| 4882 | private String smartUrlFilter(Uri inUri) { |
| 4883 | if (inUri != null) { |
| 4884 | return smartUrlFilter(inUri.toString()); |
| 4885 | } |
| 4886 | return null; |
| 4887 | } |
| 4888 | |
| 4889 | |
| 4890 | // get window count |
| 4891 | |
| 4892 | int getWindowCount(){ |
| 4893 | if(mTabControl != null){ |
| 4894 | return mTabControl.getTabCount(); |
| 4895 | } |
| 4896 | return 0; |
| 4897 | } |
| 4898 | |
Feng Qian | b34f87a | 2009-03-24 21:27:26 -0700 | [diff] [blame] | 4899 | protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile( |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4900 | "(?i)" + // switch on case insensitive matching |
| 4901 | "(" + // begin group for schema |
| 4902 | "(?:http|https|file):\\/\\/" + |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4903 | "|(?:inline|data|about|content|javascript):" + |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4904 | ")" + |
| 4905 | "(.*)" ); |
| 4906 | |
| 4907 | /** |
| 4908 | * Attempts to determine whether user input is a URL or search |
| 4909 | * terms. Anything with a space is passed to search. |
| 4910 | * |
| 4911 | * Converts to lowercase any mistakenly uppercased schema (i.e., |
| 4912 | * "Http://" converts to "http://" |
| 4913 | * |
| 4914 | * @return Original or modified URL |
| 4915 | * |
| 4916 | */ |
| 4917 | String smartUrlFilter(String url) { |
| 4918 | |
| 4919 | String inUrl = url.trim(); |
| 4920 | boolean hasSpace = inUrl.indexOf(' ') != -1; |
| 4921 | |
| 4922 | Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl); |
| 4923 | if (matcher.matches()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4924 | // force scheme to lowercase |
| 4925 | String scheme = matcher.group(1); |
| 4926 | String lcScheme = scheme.toLowerCase(); |
| 4927 | if (!lcScheme.equals(scheme)) { |
Mitsuru Oshima | 123ecfb | 2009-05-18 19:11:14 -0700 | [diff] [blame] | 4928 | inUrl = lcScheme + matcher.group(2); |
| 4929 | } |
| 4930 | if (hasSpace) { |
| 4931 | inUrl = inUrl.replace(" ", "%20"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4932 | } |
| 4933 | return inUrl; |
| 4934 | } |
| 4935 | if (hasSpace) { |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 4936 | // FIXME: Is this the correct place to add to searches? |
| 4937 | // what if someone else calls this function? |
| 4938 | int shortcut = parseUrlShortcut(inUrl); |
| 4939 | if (shortcut != SHORTCUT_INVALID) { |
| 4940 | Browser.addSearchUrl(mResolver, inUrl); |
| 4941 | String query = inUrl.substring(2); |
| 4942 | switch (shortcut) { |
| 4943 | case SHORTCUT_GOOGLE_SEARCH: |
Grace Kloba | 47fdfdb | 2009-06-30 11:15:34 -0700 | [diff] [blame] | 4944 | return URLUtil.composeSearchUrl(query, QuickSearch_G, QUERY_PLACE_HOLDER); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 4945 | case SHORTCUT_WIKIPEDIA_SEARCH: |
| 4946 | return URLUtil.composeSearchUrl(query, QuickSearch_W, QUERY_PLACE_HOLDER); |
| 4947 | case SHORTCUT_DICTIONARY_SEARCH: |
| 4948 | return URLUtil.composeSearchUrl(query, QuickSearch_D, QUERY_PLACE_HOLDER); |
| 4949 | case SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH: |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4950 | // FIXME: we need location in this case |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 4951 | return URLUtil.composeSearchUrl(query, QuickSearch_L, QUERY_PLACE_HOLDER); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4952 | } |
| 4953 | } |
| 4954 | } else { |
| 4955 | if (Regex.WEB_URL_PATTERN.matcher(inUrl).matches()) { |
| 4956 | return URLUtil.guessUrl(inUrl); |
| 4957 | } |
| 4958 | } |
| 4959 | |
| 4960 | Browser.addSearchUrl(mResolver, inUrl); |
Grace Kloba | 47fdfdb | 2009-06-30 11:15:34 -0700 | [diff] [blame] | 4961 | return URLUtil.composeSearchUrl(inUrl, QuickSearch_G, QUERY_PLACE_HOLDER); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4962 | } |
| 4963 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 4964 | /* package */ void setShouldShowErrorConsole(boolean flag) { |
| 4965 | if (flag == mShouldShowErrorConsole) { |
| 4966 | // Nothing to do. |
| 4967 | return; |
| 4968 | } |
| 4969 | |
| 4970 | mShouldShowErrorConsole = flag; |
| 4971 | |
| 4972 | ErrorConsoleView errorConsole = mTabControl.getCurrentErrorConsole(true); |
| 4973 | |
| 4974 | if (flag) { |
| 4975 | // Setting the show state of the console will cause it's the layout to be inflated. |
| 4976 | if (errorConsole.numberOfErrors() > 0) { |
| 4977 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 4978 | } else { |
| 4979 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 4980 | } |
| 4981 | |
| 4982 | // Now we can add it to the main view. |
| 4983 | mErrorConsoleContainer.addView(errorConsole, |
| 4984 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, |
| 4985 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 4986 | } else { |
| 4987 | mErrorConsoleContainer.removeView(errorConsole); |
| 4988 | } |
| 4989 | |
| 4990 | } |
| 4991 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4992 | private final static int LOCK_ICON_UNSECURE = 0; |
| 4993 | private final static int LOCK_ICON_SECURE = 1; |
| 4994 | private final static int LOCK_ICON_MIXED = 2; |
| 4995 | |
| 4996 | private int mLockIconType = LOCK_ICON_UNSECURE; |
| 4997 | private int mPrevLockType = LOCK_ICON_UNSECURE; |
| 4998 | |
| 4999 | private BrowserSettings mSettings; |
| 5000 | private TabControl mTabControl; |
| 5001 | private ContentResolver mResolver; |
| 5002 | private FrameLayout mContentView; |
| 5003 | private ImageGrid mTabOverview; |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 5004 | private View mCustomView; |
| 5005 | private FrameLayout mCustomViewContainer; |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 5006 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5007 | |
| 5008 | // FIXME, temp address onPrepareMenu performance problem. When we move everything out of |
| 5009 | // view, we should rewrite this. |
| 5010 | private int mCurrentMenuState = 0; |
| 5011 | private int mMenuState = R.id.MAIN_MENU; |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 5012 | private int mOldMenuState = EMPTY_MENU; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5013 | private static final int EMPTY_MENU = -1; |
| 5014 | private Menu mMenu; |
| 5015 | |
| 5016 | private FindDialog mFindDialog; |
| 5017 | // Used to prevent chording to result in firing two shortcuts immediately |
| 5018 | // one after another. Fixes bug 1211714. |
| 5019 | boolean mCanChord; |
| 5020 | |
| 5021 | private boolean mInLoad; |
| 5022 | private boolean mIsNetworkUp; |
| 5023 | |
| 5024 | private boolean mPageStarted; |
| 5025 | private boolean mActivityInPause = true; |
| 5026 | |
| 5027 | private boolean mMenuIsDown; |
| 5028 | |
| 5029 | private final KeyTracker mKeyTracker = new KeyTracker(this); |
| 5030 | |
| 5031 | // As trackball doesn't send repeat down, we have to track it ourselves |
| 5032 | private boolean mTrackTrackball; |
| 5033 | |
| 5034 | private static boolean mInTrace; |
| 5035 | |
| 5036 | // Performance probe |
| 5037 | private static final int[] SYSTEM_CPU_FORMAT = new int[] { |
| 5038 | Process.PROC_SPACE_TERM | Process.PROC_COMBINE, |
| 5039 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 1: user time |
| 5040 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 2: nice time |
| 5041 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 3: sys time |
| 5042 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 4: idle time |
| 5043 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 5: iowait time |
| 5044 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 6: irq time |
| 5045 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG // 7: softirq time |
| 5046 | }; |
| 5047 | |
| 5048 | private long mStart; |
| 5049 | private long mProcessStart; |
| 5050 | private long mUserStart; |
| 5051 | private long mSystemStart; |
| 5052 | private long mIdleStart; |
| 5053 | private long mIrqStart; |
| 5054 | |
| 5055 | private long mUiStart; |
| 5056 | |
| 5057 | private Drawable mMixLockIcon; |
| 5058 | private Drawable mSecLockIcon; |
| 5059 | private Drawable mGenericFavicon; |
| 5060 | |
| 5061 | /* hold a ref so we can auto-cancel if necessary */ |
| 5062 | private AlertDialog mAlertDialog; |
| 5063 | |
| 5064 | // Wait for credentials before loading google.com |
| 5065 | private ProgressDialog mCredsDlg; |
| 5066 | |
| 5067 | // The up-to-date URL and title (these can be different from those stored |
| 5068 | // in WebView, since it takes some time for the information in WebView to |
| 5069 | // get updated) |
| 5070 | private String mUrl; |
| 5071 | private String mTitle; |
| 5072 | |
| 5073 | // As PageInfo has different style for landscape / portrait, we have |
| 5074 | // to re-open it when configuration changed |
| 5075 | private AlertDialog mPageInfoDialog; |
| 5076 | private TabControl.Tab mPageInfoView; |
| 5077 | // If the Page-Info dialog is launched from the SSL-certificate-on-error |
| 5078 | // dialog, we should not just dismiss it, but should get back to the |
| 5079 | // SSL-certificate-on-error dialog. This flag is used to store this state |
| 5080 | private Boolean mPageInfoFromShowSSLCertificateOnError; |
| 5081 | |
| 5082 | // as SSLCertificateOnError has different style for landscape / portrait, |
| 5083 | // we have to re-open it when configuration changed |
| 5084 | private AlertDialog mSSLCertificateOnErrorDialog; |
| 5085 | private WebView mSSLCertificateOnErrorView; |
| 5086 | private SslErrorHandler mSSLCertificateOnErrorHandler; |
| 5087 | private SslError mSSLCertificateOnErrorError; |
| 5088 | |
| 5089 | // as SSLCertificate has different style for landscape / portrait, we |
| 5090 | // have to re-open it when configuration changed |
| 5091 | private AlertDialog mSSLCertificateDialog; |
| 5092 | private TabControl.Tab mSSLCertificateView; |
| 5093 | |
| 5094 | // as HttpAuthentication has different style for landscape / portrait, we |
| 5095 | // have to re-open it when configuration changed |
| 5096 | private AlertDialog mHttpAuthenticationDialog; |
| 5097 | private HttpAuthHandler mHttpAuthHandler; |
| 5098 | |
| 5099 | /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
| 5100 | new FrameLayout.LayoutParams( |
| 5101 | ViewGroup.LayoutParams.FILL_PARENT, |
| 5102 | ViewGroup.LayoutParams.FILL_PARENT); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 5103 | /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
| 5104 | new FrameLayout.LayoutParams( |
| 5105 | ViewGroup.LayoutParams.FILL_PARENT, |
| 5106 | ViewGroup.LayoutParams.FILL_PARENT, |
| 5107 | Gravity.CENTER); |
Grace Kloba | 47fdfdb | 2009-06-30 11:15:34 -0700 | [diff] [blame] | 5108 | // Google search |
| 5109 | final static String QuickSearch_G = "http://www.google.com/m?q=%s"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5110 | // Wikipedia search |
| 5111 | final static String QuickSearch_W = "http://en.wikipedia.org/w/index.php?search=%s&go=Go"; |
| 5112 | // Dictionary search |
| 5113 | final static String QuickSearch_D = "http://dictionary.reference.com/search?q=%s"; |
| 5114 | // Google Mobile Local search |
| 5115 | final static String QuickSearch_L = "http://www.google.com/m/search?site=local&q=%s&near=mountain+view"; |
| 5116 | |
| 5117 | final static String QUERY_PLACE_HOLDER = "%s"; |
| 5118 | |
| 5119 | // "source" parameter for Google search through search key |
| 5120 | final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key"; |
| 5121 | // "source" parameter for Google search through goto menu |
| 5122 | final static String GOOGLE_SEARCH_SOURCE_GOTO = "browser-goto"; |
| 5123 | // "source" parameter for Google search through simplily type |
| 5124 | final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type"; |
| 5125 | // "source" parameter for Google search suggested by the browser |
| 5126 | final static String GOOGLE_SEARCH_SOURCE_SUGGEST = "browser-suggest"; |
| 5127 | // "source" parameter for Google search from unknown source |
| 5128 | final static String GOOGLE_SEARCH_SOURCE_UNKNOWN = "unknown"; |
| 5129 | |
| 5130 | private final static String LOGTAG = "browser"; |
| 5131 | |
| 5132 | private TabListener mTabListener; |
| 5133 | |
| 5134 | private String mLastEnteredUrl; |
| 5135 | |
| 5136 | private PowerManager.WakeLock mWakeLock; |
| 5137 | private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes |
| 5138 | |
| 5139 | private Toast mStopToast; |
| 5140 | |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 5141 | private TitleBar mTitleBar; |
| 5142 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 5143 | private LinearLayout mErrorConsoleContainer = null; |
| 5144 | private boolean mShouldShowErrorConsole = false; |
| 5145 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5146 | // Used during animations to prevent other animations from being triggered. |
| 5147 | // A count is used since the animation to and from the Window overview can |
| 5148 | // overlap. A count of 0 means no animation where a count of > 0 means |
| 5149 | // there are animations in progress. |
| 5150 | private int mAnimationCount; |
| 5151 | |
| 5152 | // As the ids are dynamically created, we can't guarantee that they will |
| 5153 | // be in sequence, so this static array maps ids to a window number. |
| 5154 | final static private int[] WINDOW_SHORTCUT_ID_ARRAY = |
| 5155 | { R.id.window_one_menu_id, R.id.window_two_menu_id, R.id.window_three_menu_id, |
| 5156 | R.id.window_four_menu_id, R.id.window_five_menu_id, R.id.window_six_menu_id, |
| 5157 | R.id.window_seven_menu_id, R.id.window_eight_menu_id }; |
| 5158 | |
| 5159 | // monitor platform changes |
| 5160 | private IntentFilter mNetworkStateChangedFilter; |
| 5161 | private BroadcastReceiver mNetworkStateIntentReceiver; |
| 5162 | |
Grace Kloba | b4da0ad | 2009-05-14 14:45:40 -0700 | [diff] [blame] | 5163 | private BroadcastReceiver mPackageInstallationReceiver; |
| 5164 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5165 | // activity requestCode |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 5166 | final static int COMBO_PAGE = 1; |
| 5167 | final static int DOWNLOAD_PAGE = 2; |
| 5168 | final static int PREFERENCES_PAGE = 3; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5169 | |
| 5170 | // the frenquency of checking whether system memory is low |
| 5171 | final static int CHECK_MEMORY_INTERVAL = 30000; // 30 seconds |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5172 | |
| 5173 | /** |
| 5174 | * A UrlData class to abstract how the content will be set to WebView. |
| 5175 | * This base class uses loadUrl to show the content. |
| 5176 | */ |
| 5177 | private static class UrlData { |
| 5178 | String mUrl; |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 5179 | byte[] mPostData; |
| 5180 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5181 | UrlData(String url) { |
| 5182 | this.mUrl = url; |
| 5183 | } |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 5184 | |
| 5185 | void setPostData(byte[] postData) { |
| 5186 | mPostData = postData; |
| 5187 | } |
| 5188 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5189 | boolean isEmpty() { |
| 5190 | return mUrl == null || mUrl.length() == 0; |
| 5191 | } |
| 5192 | |
Mitsuru Oshima | 7944b7d | 2009-06-16 16:34:51 -0700 | [diff] [blame] | 5193 | public void loadIn(WebView webView) { |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 5194 | if (mPostData != null) { |
| 5195 | webView.postUrl(mUrl, mPostData); |
| 5196 | } else { |
| 5197 | webView.loadUrl(mUrl); |
| 5198 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5199 | } |
| 5200 | }; |
| 5201 | |
| 5202 | /** |
| 5203 | * A subclass of UrlData class that can display inlined content using |
| 5204 | * {@link WebView#loadDataWithBaseURL(String, String, String, String, String)}. |
| 5205 | */ |
| 5206 | private static class InlinedUrlData extends UrlData { |
| 5207 | InlinedUrlData(String inlined, String mimeType, String encoding, String failUrl) { |
| 5208 | super(failUrl); |
| 5209 | mInlined = inlined; |
| 5210 | mMimeType = mimeType; |
| 5211 | mEncoding = encoding; |
| 5212 | } |
| 5213 | String mMimeType; |
| 5214 | String mInlined; |
| 5215 | String mEncoding; |
Mitsuru Oshima | 7944b7d | 2009-06-16 16:34:51 -0700 | [diff] [blame] | 5216 | @Override |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5217 | boolean isEmpty() { |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 5218 | return mInlined == null || mInlined.length() == 0 || super.isEmpty(); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5219 | } |
| 5220 | |
Mitsuru Oshima | 7944b7d | 2009-06-16 16:34:51 -0700 | [diff] [blame] | 5221 | @Override |
| 5222 | public void loadIn(WebView webView) { |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 5223 | webView.loadDataWithBaseURL(null, mInlined, mMimeType, mEncoding, mUrl); |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | private static final UrlData EMPTY_URL_DATA = new UrlData(null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 5228 | } |