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 | |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 19 | import com.android.browser.ScrollWebView.ScrollListener; |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 20 | import com.android.browser.search.SearchEngine; |
Michael Kolb | 3f65c38 | 2010-08-20 15:31:16 -0700 | [diff] [blame] | 21 | import com.android.common.Search; |
| 22 | import com.android.common.speech.LoggingEvents; |
| 23 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 24 | import android.app.ActionBar; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | import android.app.Activity; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 26 | import android.app.AlertDialog; |
Steve Howard | 5a862fc | 2010-09-28 12:52:06 -0700 | [diff] [blame] | 27 | import android.app.DownloadManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 28 | import android.app.ProgressDialog; |
| 29 | import android.app.SearchManager; |
| 30 | import android.content.ActivityNotFoundException; |
| 31 | import android.content.BroadcastReceiver; |
Dianne Hackborn | 80f3262 | 2010-08-05 14:17:53 -0700 | [diff] [blame] | 32 | import android.content.ClipboardManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 33 | import android.content.ComponentName; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 34 | import android.content.ContentProvider; |
| 35 | import android.content.ContentProviderClient; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 36 | import android.content.ContentResolver; |
| 37 | import android.content.ContentValues; |
| 38 | import android.content.Context; |
| 39 | import android.content.DialogInterface; |
| 40 | import android.content.Intent; |
| 41 | import android.content.IntentFilter; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 42 | import android.content.pm.PackageManager; |
| 43 | import android.content.pm.ResolveInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 44 | import android.content.res.Configuration; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 45 | import android.database.Cursor; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 46 | import android.graphics.Bitmap; |
Andrei Popescu | 540035d | 2009-09-18 18:59:20 +0100 | [diff] [blame] | 47 | import android.graphics.BitmapFactory; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 48 | import android.graphics.Canvas; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 49 | import android.graphics.Picture; |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 50 | import android.graphics.PixelFormat; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 51 | import android.graphics.drawable.Drawable; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 52 | import android.net.ConnectivityManager; |
Andrei Popescu | 56199cc | 2010-01-12 22:39:16 +0000 | [diff] [blame] | 53 | import android.net.NetworkInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 54 | import android.net.Uri; |
| 55 | import android.net.WebAddress; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 56 | import android.net.http.SslCertificate; |
| 57 | import android.net.http.SslError; |
| 58 | import android.os.AsyncTask; |
| 59 | import android.os.Bundle; |
| 60 | import android.os.Debug; |
| 61 | import android.os.Environment; |
| 62 | import android.os.Handler; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 63 | import android.os.Message; |
| 64 | import android.os.PowerManager; |
| 65 | import android.os.Process; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 66 | import android.os.SystemClock; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 67 | import android.provider.Browser; |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 68 | import android.provider.BrowserContract; |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 69 | import android.provider.BrowserContract.Images; |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 70 | import android.provider.ContactsContract; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 71 | import android.provider.ContactsContract.Intents.Insert; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 72 | import android.provider.MediaStore; |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 73 | import android.speech.RecognizerResultsIntent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 74 | import android.text.TextUtils; |
| 75 | import android.text.format.DateFormat; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 76 | import android.util.Log; |
Dianne Hackborn | 385effd | 2010-02-24 20:03:04 -0800 | [diff] [blame] | 77 | import android.util.Patterns; |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 78 | import android.view.ActionMode; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 79 | import android.view.ContextMenu; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 80 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 81 | import android.view.Gravity; |
| 82 | import android.view.KeyEvent; |
| 83 | import android.view.LayoutInflater; |
| 84 | import android.view.Menu; |
| 85 | import android.view.MenuInflater; |
| 86 | import android.view.MenuItem; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 87 | import android.view.MenuItem.OnMenuItemClickListener; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 88 | import android.view.View; |
| 89 | import android.view.ViewGroup; |
| 90 | import android.view.Window; |
| 91 | import android.view.WindowManager; |
Svetoslav Ganov | 2b34599 | 2010-05-06 06:13:54 -0700 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityManager; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 93 | import android.webkit.CookieManager; |
| 94 | import android.webkit.CookieSyncManager; |
| 95 | import android.webkit.DownloadListener; |
| 96 | import android.webkit.HttpAuthHandler; |
| 97 | import android.webkit.SslErrorHandler; |
| 98 | import android.webkit.URLUtil; |
Leon Clarke | cb6cc86 | 2009-09-29 18:35:13 +0100 | [diff] [blame] | 99 | import android.webkit.ValueCallback; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 100 | import android.webkit.WebChromeClient; |
| 101 | import android.webkit.WebHistoryItem; |
| 102 | import android.webkit.WebIconDatabase; |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 103 | import android.webkit.WebSettings; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 104 | import android.webkit.WebView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 105 | import android.widget.FrameLayout; |
| 106 | import android.widget.LinearLayout; |
| 107 | import android.widget.TextView; |
| 108 | import android.widget.Toast; |
| 109 | |
Leon Scroggins | b6b7f9e | 2009-06-18 12:05:28 -0400 | [diff] [blame] | 110 | import java.io.ByteArrayOutputStream; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 111 | import java.io.File; |
Ben Murdoch | 4f75ba2 | 2009-10-27 11:48:28 +0000 | [diff] [blame] | 112 | import java.io.IOException; |
| 113 | import java.io.InputStream; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 114 | import java.net.MalformedURLException; |
Dianne Hackborn | 9918943 | 2009-06-17 18:06:18 -0700 | [diff] [blame] | 115 | import java.net.URISyntaxException; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 116 | import java.net.URL; |
| 117 | import java.net.URLEncoder; |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 118 | import java.util.Calendar; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 119 | import java.util.Date; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 120 | import java.util.HashMap; |
Grace Kloba | 00f54c5 | 2010-01-27 14:53:51 -0800 | [diff] [blame] | 121 | import java.util.Iterator; |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 122 | import java.util.Map; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 123 | import java.util.Vector; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 124 | import java.util.regex.Matcher; |
| 125 | import java.util.regex.Pattern; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 126 | |
| 127 | public class BrowserActivity extends Activity |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 128 | implements View.OnCreateContextMenuListener, DownloadListener, |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 129 | BookmarksHistoryCallbacks { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 130 | |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 131 | /* Define some aliases to make these debugging flags easier to refer to. |
| 132 | * This file imports android.provider.Browser, so we can't just refer to "Browser.DEBUG". |
| 133 | */ |
| 134 | private final static boolean DEBUG = com.android.browser.Browser.DEBUG; |
| 135 | private final static boolean LOGV_ENABLED = com.android.browser.Browser.LOGV_ENABLED; |
| 136 | private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; |
| 137 | |
Cary Clark | a977124 | 2009-08-11 16:42:26 -0400 | [diff] [blame] | 138 | private static class ClearThumbnails extends AsyncTask<File, Void, Void> { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 139 | @Override |
| 140 | public Void doInBackground(File... files) { |
| 141 | if (files != null) { |
| 142 | for (File f : files) { |
Cary Clark | d6be175 | 2009-08-12 12:56:42 -0400 | [diff] [blame] | 143 | if (!f.delete()) { |
| 144 | Log.e(LOGTAG, f.getPath() + " was not deleted"); |
| 145 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | return null; |
| 149 | } |
| 150 | } |
| 151 | |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 152 | /** |
| 153 | * This layout holds everything you see below the status bar, including the |
| 154 | * error console, the custom view container, and the webviews. |
| 155 | */ |
| 156 | private FrameLayout mBrowserFrameLayout; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 157 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 158 | private CombinedBookmarkHistoryView mComboView; |
| 159 | |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 160 | private boolean mXLargeScreenSize; |
| 161 | |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 162 | private Boolean mIsProviderPresent = null; |
| 163 | private Uri mRlzUri = null; |
| 164 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 165 | @Override |
| 166 | public void onCreate(Bundle icicle) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 167 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 168 | Log.v(LOGTAG, this + " onStart"); |
| 169 | } |
| 170 | super.onCreate(icicle); |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame^] | 171 | |
| 172 | // Keep a settings instance handy. |
| 173 | mSettings = BrowserSettings.getInstance(); |
| 174 | |
| 175 | // render the browser in OpenGL |
| 176 | if (mSettings.isHardwareAccelerated()) { |
| 177 | // Set the flag in the activity's window |
| 178 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, |
| 179 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 180 | } else { |
| 181 | // Clear the flag in the activity's window |
| 182 | this.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 183 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 184 | |
Mike Reed | d334bf5 | 2010-01-26 15:21:44 -0500 | [diff] [blame] | 185 | // enable this to test the browser in 32bit |
| 186 | if (false) { |
| 187 | getWindow().setFormat(PixelFormat.RGBX_8888); |
| 188 | BitmapFactory.setDefaultConfig(Bitmap.Config.ARGB_8888); |
| 189 | } |
| 190 | |
Bjorn Bringert | b1402a5 | 2010-10-12 10:53:12 +0100 | [diff] [blame] | 191 | if (((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).isEnabled()) { |
Svetoslav Ganov | 2b34599 | 2010-05-06 06:13:54 -0700 | [diff] [blame] | 192 | setDefaultKeyMode(DEFAULT_KEYS_DISABLE); |
| 193 | } else { |
| 194 | setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); |
| 195 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 196 | |
| 197 | mResolver = getContentResolver(); |
| 198 | |
Grace Kloba | 0923d69 | 2009-09-23 21:37:25 -0700 | [diff] [blame] | 199 | // If this was a web search request, pass it on to the default web |
| 200 | // search provider and finish this activity. |
| 201 | if (handleWebSearchIntent(getIntent())) { |
| 202 | finish(); |
| 203 | return; |
| 204 | } |
| 205 | |
Michael Kolb | 0506f2d | 2010-10-14 16:20:16 -0700 | [diff] [blame] | 206 | mSecLockIcon = getResources().getDrawable(R.drawable.ic_secure); |
| 207 | mMixLockIcon = getResources().getDrawable(R.drawable.ic_partial_secure); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 208 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 209 | // Create the tab control and our initial tab |
| 210 | mTabControl = new TabControl(this); |
| 211 | |
| 212 | mXLargeScreenSize = (getResources().getConfiguration().screenLayout |
| 213 | & Configuration.SCREENLAYOUT_SIZE_MASK) |
| 214 | == Configuration.SCREENLAYOUT_SIZE_XLARGE; |
| 215 | |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 216 | FrameLayout frameLayout = (FrameLayout) getWindow().getDecorView() |
Bjorn Bringert | b1402a5 | 2010-10-12 10:53:12 +0100 | [diff] [blame] | 217 | .findViewById(android.R.id.content); |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 218 | mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(this) |
| 219 | .inflate(R.layout.custom_screen, null); |
| 220 | mContentView = (FrameLayout) mBrowserFrameLayout.findViewById( |
| 221 | R.id.main_content); |
| 222 | mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout |
| 223 | .findViewById(R.id.error_console); |
| 224 | mCustomViewContainer = (FrameLayout) mBrowserFrameLayout |
| 225 | .findViewById(R.id.fullscreen_custom_content); |
| 226 | frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS); |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 227 | |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 228 | if (mXLargeScreenSize) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 229 | mTitleBar = new TitleBarXLarge(this); |
| 230 | mTitleBar.setProgress(100); |
| 231 | mFakeTitleBar = new TitleBarXLarge(this); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 232 | ActionBar actionBar = getActionBar(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 233 | mTabBar = new TabBar(this, mTabControl, (TitleBarXLarge) mFakeTitleBar); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 234 | actionBar.setCustomNavigationMode(mTabBar); |
Michael Kolb | 6877575 | 2010-08-19 12:42:01 -0700 | [diff] [blame] | 235 | // disable built in zoom controls |
| 236 | mTabControl.setDisplayZoomControls(false); |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 237 | } else { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 238 | mTitleBar = new TitleBar(this); |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 239 | // mTitleBar will be always be shown in the fully loaded mode on |
| 240 | // phone |
| 241 | mTitleBar.setProgress(100); |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 242 | mFakeTitleBar = new TitleBar(this); |
| 243 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 244 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 245 | // Open the icon database and retain all the bookmark urls for favicons |
| 246 | retainIconsOnStartup(); |
| 247 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 248 | mSettings.setTabControl(mTabControl); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 249 | |
| 250 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 251 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser"); |
| 252 | |
Patrick Scott | 6adacc9 | 2010-03-05 08:24:51 -0500 | [diff] [blame] | 253 | // Find out if the network is currently up. |
| 254 | ConnectivityManager cm = (ConnectivityManager) getSystemService( |
| 255 | Context.CONNECTIVITY_SERVICE); |
| 256 | NetworkInfo info = cm.getActiveNetworkInfo(); |
| 257 | if (info != null) { |
| 258 | mIsNetworkUp = info.isAvailable(); |
| 259 | } |
| 260 | |
Grace Kloba | a34f686 | 2009-07-31 16:28:17 -0700 | [diff] [blame] | 261 | /* enables registration for changes in network status from |
| 262 | http stack */ |
| 263 | mNetworkStateChangedFilter = new IntentFilter(); |
| 264 | mNetworkStateChangedFilter.addAction( |
| 265 | ConnectivityManager.CONNECTIVITY_ACTION); |
| 266 | mNetworkStateIntentReceiver = new BroadcastReceiver() { |
| 267 | @Override |
| 268 | public void onReceive(Context context, Intent intent) { |
| 269 | if (intent.getAction().equals( |
| 270 | ConnectivityManager.CONNECTIVITY_ACTION)) { |
Andrei Popescu | e4c9846 | 2010-02-19 15:44:13 +0000 | [diff] [blame] | 271 | |
| 272 | NetworkInfo info = intent.getParcelableExtra( |
| 273 | ConnectivityManager.EXTRA_NETWORK_INFO); |
| 274 | String typeName = info.getTypeName(); |
| 275 | String subtypeName = info.getSubtypeName(); |
| 276 | sendNetworkType(typeName.toLowerCase(), |
| 277 | (subtypeName != null ? subtypeName.toLowerCase() : "")); |
| 278 | |
| 279 | onNetworkToggle(info.isAvailable()); |
Grace Kloba | a34f686 | 2009-07-31 16:28:17 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | }; |
| 283 | |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 284 | // Unless the last browser usage was within 24 hours, destroy any |
| 285 | // remaining incognito tabs. |
| 286 | |
| 287 | Calendar lastActiveDate = icicle != null ? (Calendar) icicle.getSerializable("lastActiveDate") : null; |
| 288 | Calendar today = Calendar.getInstance(); |
| 289 | Calendar yesterday = Calendar.getInstance(); |
| 290 | yesterday.add(Calendar.DATE, -1); |
| 291 | |
| 292 | boolean dontRestoreIncognitoTabs = lastActiveDate == null |
| 293 | || lastActiveDate.before(yesterday) |
| 294 | || lastActiveDate.after(today); |
| 295 | |
| 296 | if (!mTabControl.restoreState(icicle, dontRestoreIncognitoTabs)) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 297 | // clear up the thumbnail directory if we can't restore the state as |
| 298 | // none of the files in the directory are referenced any more. |
| 299 | new ClearThumbnails().execute( |
| 300 | mTabControl.getThumbnailDir().listFiles()); |
Grace Kloba | aab3f09 | 2009-07-30 12:29:51 -0700 | [diff] [blame] | 301 | // there is no quit on Android. But if we can't restore the state, |
| 302 | // we can treat it as a new Browser, remove the old session cookies. |
| 303 | CookieManager.getInstance().removeSessionCookie(); |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 304 | // remove any incognito files |
| 305 | WebView.cleanupPrivateBrowsingFiles(this); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 306 | final Intent intent = getIntent(); |
| 307 | final Bundle extra = intent.getExtras(); |
| 308 | // Create an initial tab. |
| 309 | // If the intent is ACTION_VIEW and data is not null, the Browser is |
| 310 | // invoked to view the content by another application. In this case, |
| 311 | // the tab will be close when exit. |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 312 | UrlData urlData = getUrlDataFromIntent(intent); |
| 313 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 314 | String action = intent.getAction(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 315 | final Tab t = mTabControl.createNewTab( |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 316 | (Intent.ACTION_VIEW.equals(action) && |
| 317 | intent.getData() != null) |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 318 | || RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS |
| 319 | .equals(action), |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 320 | intent.getStringExtra(Browser.EXTRA_APPLICATION_ID), |
| 321 | urlData.mUrl, false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 322 | mTabControl.setCurrentTab(t); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 323 | attachTabToContentView(t); |
| 324 | WebView webView = t.getWebView(); |
| 325 | if (extra != null) { |
| 326 | int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0); |
| 327 | if (scale > 0 && scale <= 1000) { |
| 328 | webView.setInitialScale(scale); |
| 329 | } |
| 330 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 331 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 332 | if (urlData.isEmpty()) { |
Shimeng (Simon) Wang | 98d5fce | 2010-03-16 13:23:39 -0700 | [diff] [blame] | 333 | loadUrl(webView, mSettings.getHomePage()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 334 | } else { |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 335 | loadUrlDataIn(t, urlData); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 336 | } |
| 337 | } else { |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 338 | if (dontRestoreIncognitoTabs) { |
| 339 | WebView.cleanupPrivateBrowsingFiles(this); |
| 340 | } |
| 341 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 342 | // TabControl.restoreState() will create a new tab even if |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 343 | // restoring the state fails. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 344 | attachTabToContentView(mTabControl.getCurrentTab()); |
| 345 | } |
Grace Kloba | 615c6c9 | 2009-08-03 10:22:44 -0700 | [diff] [blame] | 346 | |
Cary Clark | b4b8318 | 2010-07-01 12:36:56 -0400 | [diff] [blame] | 347 | // Delete old thumbnails to save space |
| 348 | File dir = mTabControl.getThumbnailDir(); |
| 349 | if (dir.exists()) { |
| 350 | for (String child : dir.list()) { |
| 351 | File f = new File(dir, child); |
| 352 | f.delete(); |
| 353 | } |
| 354 | } |
| 355 | |
Feng Qian | b3c02da | 2009-06-29 15:58:08 -0700 | [diff] [blame] | 356 | // Read JavaScript flags if it exists. |
| 357 | String jsFlags = mSettings.getJsFlags(); |
| 358 | if (jsFlags.trim().length() != 0) { |
| 359 | mTabControl.getCurrentWebView().setJsFlags(jsFlags); |
| 360 | } |
Bjorn Bringert | a761181 | 2010-03-24 11:12:02 +0000 | [diff] [blame] | 361 | |
| 362 | // Start watching the default geolocation permissions |
| 363 | mSystemAllowGeolocationOrigins |
| 364 | = new SystemAllowGeolocationOrigins(getApplicationContext()); |
| 365 | mSystemAllowGeolocationOrigins.start(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 368 | ScrollListener getScrollListener() { |
| 369 | return mTabBar; |
| 370 | } |
| 371 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 372 | /** |
| 373 | * Feed the previously stored results strings to the BrowserProvider so that |
| 374 | * the SearchDialog will show them instead of the standard searches. |
| 375 | * @param result String to show on the editable line of the SearchDialog. |
| 376 | */ |
| 377 | /* package */ void showVoiceSearchResults(String result) { |
| 378 | ContentProviderClient client = mResolver.acquireContentProviderClient( |
| 379 | Browser.BOOKMARKS_URI); |
| 380 | ContentProvider prov = client.getLocalContentProvider(); |
| 381 | BrowserProvider bp = (BrowserProvider) prov; |
| 382 | bp.setQueryResults(mTabControl.getCurrentTab().getVoiceSearchResults()); |
| 383 | client.release(); |
| 384 | |
Leon Scroggins | fbb3f15 | 2010-03-09 17:26:56 -0500 | [diff] [blame] | 385 | Bundle bundle = createGoogleSearchSourceBundle( |
| 386 | GOOGLE_SEARCH_SOURCE_SEARCHKEY); |
| 387 | bundle.putBoolean(SearchManager.CONTEXT_IS_VOICE, true); |
| 388 | startSearch(result, false, bundle, false); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 389 | } |
| 390 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 391 | @Override |
| 392 | protected void onNewIntent(Intent intent) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 393 | Tab current = mTabControl.getCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 394 | // When a tab is closed on exit, the current tab index is set to -1. |
| 395 | // Reset before proceed as Browser requires the current tab to be set. |
| 396 | if (current == null) { |
| 397 | // Try to reset the tab in case the index was incorrect. |
| 398 | current = mTabControl.getTab(0); |
| 399 | if (current == null) { |
| 400 | // No tabs at all so just ignore this intent. |
| 401 | return; |
| 402 | } |
| 403 | mTabControl.setCurrentTab(current); |
| 404 | attachTabToContentView(current); |
| 405 | resetTitleAndIcon(current.getWebView()); |
| 406 | } |
| 407 | final String action = intent.getAction(); |
| 408 | final int flags = intent.getFlags(); |
| 409 | if (Intent.ACTION_MAIN.equals(action) || |
| 410 | (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) { |
| 411 | // just resume the browser |
| 412 | return; |
| 413 | } |
Leon Scroggins | b8a844d | 2010-03-18 15:06:15 -0400 | [diff] [blame] | 414 | // In case the SearchDialog is open. |
| 415 | ((SearchManager) getSystemService(Context.SEARCH_SERVICE)) |
| 416 | .stopSearch(); |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 417 | boolean activateVoiceSearch = RecognizerResultsIntent |
| 418 | .ACTION_VOICE_SEARCH_RESULTS.equals(action); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 419 | if (Intent.ACTION_VIEW.equals(action) |
| 420 | || Intent.ACTION_SEARCH.equals(action) |
| 421 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 422 | || Intent.ACTION_WEB_SEARCH.equals(action) |
| 423 | || activateVoiceSearch) { |
Leon Scroggins | 3b18ce3 | 2010-02-08 17:35:59 -0500 | [diff] [blame] | 424 | if (current.isInVoiceSearchMode()) { |
| 425 | String title = current.getVoiceDisplayTitle(); |
| 426 | if (title != null && title.equals(intent.getStringExtra( |
| 427 | SearchManager.QUERY))) { |
| 428 | // The user submitted the same search as the last voice |
| 429 | // search, so do nothing. |
| 430 | return; |
| 431 | } |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 432 | if (Intent.ACTION_SEARCH.equals(action) |
| 433 | && current.voiceSearchSourceIsGoogle()) { |
| 434 | Intent logIntent = new Intent( |
| 435 | LoggingEvents.ACTION_LOG_EVENT); |
| 436 | logIntent.putExtra(LoggingEvents.EXTRA_EVENT, |
| 437 | LoggingEvents.VoiceSearch.QUERY_UPDATED); |
| 438 | logIntent.putExtra( |
| 439 | LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE, |
| 440 | intent.getDataString()); |
| 441 | sendBroadcast(logIntent); |
| 442 | // Note, onPageStarted will revert the voice title bar |
| 443 | // When http://b/issue?id=2379215 is fixed, we should update |
| 444 | // the title bar here. |
| 445 | } |
Leon Scroggins | 3b18ce3 | 2010-02-08 17:35:59 -0500 | [diff] [blame] | 446 | } |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 447 | // If this was a search request (e.g. search query directly typed into the address bar), |
| 448 | // pass it on to the default web search provider. |
| 449 | if (handleWebSearchIntent(intent)) { |
| 450 | return; |
| 451 | } |
| 452 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 453 | UrlData urlData = getUrlDataFromIntent(intent); |
| 454 | if (urlData.isEmpty()) { |
| 455 | urlData = new UrlData(mSettings.getHomePage()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 456 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 457 | |
Grace Kloba | cc63403 | 2009-07-28 15:58:19 -0700 | [diff] [blame] | 458 | final String appId = intent |
| 459 | .getStringExtra(Browser.EXTRA_APPLICATION_ID); |
Leon Scroggins | 4720868 | 2010-04-07 17:59:48 -0400 | [diff] [blame] | 460 | if ((Intent.ACTION_VIEW.equals(action) |
| 461 | // If a voice search has no appId, it means that it came |
| 462 | // from the browser. In that case, reuse the current tab. |
| 463 | || (activateVoiceSearch && appId != null)) |
Grace Kloba | cc63403 | 2009-07-28 15:58:19 -0700 | [diff] [blame] | 464 | && !getPackageName().equals(appId) |
| 465 | && (flags & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 466 | Tab appTab = mTabControl.getTabFromId(appId); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 467 | if (appTab != null) { |
| 468 | Log.i(LOGTAG, "Reusing tab for " + appId); |
| 469 | // Dismiss the subwindow if applicable. |
| 470 | dismissSubWindow(appTab); |
| 471 | // Since we might kill the WebView, remove it from the |
| 472 | // content view first. |
| 473 | removeTabFromContentView(appTab); |
| 474 | // Recreate the main WebView after destroying the old one. |
| 475 | // If the WebView has the same original url and is on that |
| 476 | // page, it can be reused. |
| 477 | boolean needsLoad = |
Leon Scroggins | 6eac63e | 2010-03-15 18:19:14 -0400 | [diff] [blame] | 478 | mTabControl.recreateWebView(appTab, urlData); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 479 | |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 480 | if (current != appTab) { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 481 | switchToTab(mTabControl.getTabIndex(appTab)); |
| 482 | if (needsLoad) { |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 483 | loadUrlDataIn(appTab, urlData); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 484 | } |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 485 | } else { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 486 | // If the tab was the current tab, we have to attach |
| 487 | // it to the view system again. |
| 488 | attachTabToContentView(appTab); |
| 489 | if (needsLoad) { |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 490 | loadUrlDataIn(appTab, urlData); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | return; |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 494 | } else { |
| 495 | // No matching application tab, try to find a regular tab |
| 496 | // with a matching url. |
| 497 | appTab = mTabControl.findUnusedTabWithUrl(urlData.mUrl); |
Leon Scroggins | 25515f8 | 2009-08-19 15:31:58 -0400 | [diff] [blame] | 498 | if (appTab != null) { |
| 499 | if (current != appTab) { |
| 500 | switchToTab(mTabControl.getTabIndex(appTab)); |
| 501 | } |
| 502 | // Otherwise, we are already viewing the correct tab. |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 503 | } else { |
| 504 | // if FLAG_ACTIVITY_BROUGHT_TO_FRONT flag is on, the url |
| 505 | // will be opened in a new tab unless we have reached |
| 506 | // MAX_TABS. Then the url will be opened in the current |
| 507 | // tab. If a new tab is created, it will have "true" for |
| 508 | // exit on close. |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 509 | openTabAndShow(urlData, true, appId); |
Patrick Scott | cd11589 | 2009-07-16 09:42:58 -0400 | [diff] [blame] | 510 | } |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 511 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 512 | } else { |
Grace Kloba | 638d3f4 | 2009-11-23 10:35:04 -0800 | [diff] [blame] | 513 | if (!urlData.isEmpty() |
| 514 | && urlData.mUrl.startsWith("about:debug")) { |
| 515 | if ("about:debug.dom".equals(urlData.mUrl)) { |
| 516 | current.getWebView().dumpDomTree(false); |
| 517 | } else if ("about:debug.dom.file".equals(urlData.mUrl)) { |
| 518 | current.getWebView().dumpDomTree(true); |
| 519 | } else if ("about:debug.render".equals(urlData.mUrl)) { |
| 520 | current.getWebView().dumpRenderTree(false); |
| 521 | } else if ("about:debug.render.file".equals(urlData.mUrl)) { |
| 522 | current.getWebView().dumpRenderTree(true); |
| 523 | } else if ("about:debug.display".equals(urlData.mUrl)) { |
| 524 | current.getWebView().dumpDisplayTree(); |
| 525 | } else { |
| 526 | mSettings.toggleDebugSettings(); |
| 527 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 528 | return; |
| 529 | } |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 530 | // Get rid of the subwindow if it exists |
| 531 | dismissSubWindow(current); |
Leon Scroggins | 8588d15 | 2010-04-15 11:01:53 -0400 | [diff] [blame] | 532 | // If the current Tab is being used as an application tab, |
| 533 | // remove the association, since the new Intent means that it is |
| 534 | // no longer associated with that application. |
| 535 | current.setAppId(null); |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 536 | loadUrlDataIn(current, urlData); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 541 | /** |
| 542 | * Launches the default web search activity with the query parameters if the given intent's data |
| 543 | * are identified as plain search terms and not URLs/shortcuts. |
| 544 | * @return true if the intent was handled and web search activity was launched, false if not. |
| 545 | */ |
| 546 | private boolean handleWebSearchIntent(Intent intent) { |
| 547 | if (intent == null) return false; |
| 548 | |
| 549 | String url = null; |
| 550 | final String action = intent.getAction(); |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 551 | if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS.equals( |
| 552 | action)) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 553 | return false; |
| 554 | } |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 555 | if (Intent.ACTION_VIEW.equals(action)) { |
Grace Kloba | 1e70505 | 2009-09-29 13:13:36 -0700 | [diff] [blame] | 556 | Uri data = intent.getData(); |
| 557 | if (data != null) url = data.toString(); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 558 | } else if (Intent.ACTION_SEARCH.equals(action) |
| 559 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
| 560 | || Intent.ACTION_WEB_SEARCH.equals(action)) { |
| 561 | url = intent.getStringExtra(SearchManager.QUERY); |
| 562 | } |
Bjorn Bringert | 0485170 | 2009-09-22 10:36:01 +0100 | [diff] [blame] | 563 | return handleWebSearchRequest(url, intent.getBundleExtra(SearchManager.APP_DATA), |
| 564 | intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Launches the default web search activity with the query parameters if the given url string |
| 569 | * was identified as plain search terms and not URL/shortcut. |
| 570 | * @return true if the request was handled and web search activity was launched, false if not. |
| 571 | */ |
Bjorn Bringert | 0485170 | 2009-09-22 10:36:01 +0100 | [diff] [blame] | 572 | private boolean handleWebSearchRequest(String inUrl, Bundle appData, String extraData) { |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 573 | if (inUrl == null) return false; |
| 574 | |
| 575 | // In general, we shouldn't modify URL from Intent. |
| 576 | // But currently, we get the user-typed URL from search box as well. |
| 577 | String url = fixUrl(inUrl).trim(); |
| 578 | |
Leon Scroggins | 956cf01 | 2010-10-07 13:51:57 -0400 | [diff] [blame] | 579 | // URLs are handled by the regular flow of control, so |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 580 | // return early. |
Dan Egnor | 5ee906c | 2009-11-18 12:11:49 -0800 | [diff] [blame] | 581 | if (Patterns.WEB_URL.matcher(url).matches() |
Leon Scroggins | 956cf01 | 2010-10-07 13:51:57 -0400 | [diff] [blame] | 582 | || ACCEPTED_URI_SCHEMA.matcher(url).matches()) { |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 583 | return false; |
| 584 | } |
| 585 | |
Leon Scroggins | 8d06e36 | 2010-03-24 14:45:57 -0400 | [diff] [blame] | 586 | final ContentResolver cr = mResolver; |
| 587 | final String newUrl = url; |
Elliott Slaughter | 627d96f | 2010-08-18 16:35:30 -0700 | [diff] [blame] | 588 | if (mTabControl == null || !mTabControl.getCurrentWebView().isPrivateBrowsingEnabled()) { |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 589 | new AsyncTask<Void, Void, Void>() { |
| 590 | @Override |
| 591 | protected Void doInBackground(Void... unused) { |
| 592 | Browser.updateVisitedHistory(cr, newUrl, false); |
| 593 | Browser.addSearchUrl(cr, newUrl); |
| 594 | return null; |
| 595 | } |
| 596 | }.execute(); |
| 597 | } |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 598 | |
Bjorn Bringert | d69f51d | 2010-09-13 14:06:41 +0100 | [diff] [blame] | 599 | SearchEngine searchEngine = mSettings.getSearchEngine(); |
| 600 | if (searchEngine == null) return false; |
| 601 | searchEngine.startSearch(this, url, appData, extraData); |
Satish Sampath | 565505b | 2009-05-29 15:37:27 +0100 | [diff] [blame] | 602 | |
| 603 | return true; |
| 604 | } |
| 605 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 606 | private UrlData getUrlDataFromIntent(Intent intent) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 607 | String url = ""; |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 608 | Map<String, String> headers = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 609 | if (intent != null) { |
| 610 | final String action = intent.getAction(); |
| 611 | if (Intent.ACTION_VIEW.equals(action)) { |
| 612 | url = smartUrlFilter(intent.getData()); |
| 613 | if (url != null && url.startsWith("content:")) { |
| 614 | /* Append mimetype so webview knows how to display */ |
| 615 | String mimeType = intent.resolveType(getContentResolver()); |
| 616 | if (mimeType != null) { |
| 617 | url += "?" + mimeType; |
| 618 | } |
| 619 | } |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 620 | if (url != null && url.startsWith("http")) { |
Grace Kloba | 00f54c5 | 2010-01-27 14:53:51 -0800 | [diff] [blame] | 621 | final Bundle pairs = intent |
| 622 | .getBundleExtra(Browser.EXTRA_HEADERS); |
Grace Kloba | 2d508ed | 2010-01-28 11:39:15 -0800 | [diff] [blame] | 623 | if (pairs != null && !pairs.isEmpty()) { |
Grace Kloba | 00f54c5 | 2010-01-27 14:53:51 -0800 | [diff] [blame] | 624 | Iterator<String> iter = pairs.keySet().iterator(); |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 625 | headers = new HashMap<String, String>(); |
Grace Kloba | 00f54c5 | 2010-01-27 14:53:51 -0800 | [diff] [blame] | 626 | while (iter.hasNext()) { |
| 627 | String key = iter.next(); |
| 628 | headers.put(key, pairs.getString(key)); |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 629 | } |
| 630 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 631 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 632 | } else if (Intent.ACTION_SEARCH.equals(action) |
| 633 | || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action) |
| 634 | || Intent.ACTION_WEB_SEARCH.equals(action)) { |
| 635 | url = intent.getStringExtra(SearchManager.QUERY); |
| 636 | if (url != null) { |
| 637 | mLastEnteredUrl = url; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 638 | // In general, we shouldn't modify URL from Intent. |
| 639 | // But currently, we get the user-typed URL from search box as well. |
| 640 | url = fixUrl(url); |
| 641 | url = smartUrlFilter(url); |
Leon Scroggins | 8d06e36 | 2010-03-24 14:45:57 -0400 | [diff] [blame] | 642 | final ContentResolver cr = mResolver; |
| 643 | final String newUrl = url; |
Elliott Slaughter | 8389e99 | 2010-08-20 15:44:08 -0700 | [diff] [blame] | 644 | if (mTabControl == null |
| 645 | || mTabControl.getCurrentWebView() == null |
| 646 | || !mTabControl.getCurrentWebView().isPrivateBrowsingEnabled()) { |
| 647 | new AsyncTask<Void, Void, Void>() { |
| 648 | @Override |
| 649 | protected Void doInBackground(Void... unused) { |
| 650 | Browser.updateVisitedHistory(cr, newUrl, false); |
| 651 | return null; |
| 652 | } |
| 653 | }.execute(); |
| 654 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 655 | String searchSource = "&source=android-" + GOOGLE_SEARCH_SOURCE_SUGGEST + "&"; |
| 656 | if (url.contains(searchSource)) { |
| 657 | String source = null; |
| 658 | final Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA); |
| 659 | if (appData != null) { |
Bjorn Bringert | 10d1cca | 2010-02-10 14:22:12 +0000 | [diff] [blame] | 660 | source = appData.getString(Search.SOURCE); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 661 | } |
| 662 | if (TextUtils.isEmpty(source)) { |
| 663 | source = GOOGLE_SEARCH_SOURCE_UNKNOWN; |
| 664 | } |
| 665 | url = url.replace(searchSource, "&source=android-"+source+"&"); |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | } |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 670 | return new UrlData(url, headers, intent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 671 | } |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 672 | /* package */ void showVoiceTitleBar(String title) { |
| 673 | mTitleBar.setInVoiceMode(true); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 674 | mTitleBar.setDisplayTitle(title); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 675 | mFakeTitleBar.setInVoiceMode(true); |
| 676 | mFakeTitleBar.setDisplayTitle(title); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 677 | } |
| 678 | /* package */ void revertVoiceTitleBar() { |
| 679 | mTitleBar.setInVoiceMode(false); |
Leon Scroggins | 003a5dd | 2010-03-10 12:13:14 -0500 | [diff] [blame] | 680 | mTitleBar.setDisplayTitle(mUrl); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 681 | mFakeTitleBar.setInVoiceMode(false); |
| 682 | mFakeTitleBar.setDisplayTitle(mUrl); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 683 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 684 | /* package */ static String fixUrl(String inUrl) { |
Cary Clark | 652ff87 | 2009-09-10 13:34:44 -0400 | [diff] [blame] | 685 | // FIXME: Converting the url to lower case |
| 686 | // duplicates functionality in smartUrlFilter(). |
| 687 | // However, changing all current callers of fixUrl to |
| 688 | // call smartUrlFilter in addition may have unwanted |
| 689 | // consequences, and is deferred for now. |
| 690 | int colon = inUrl.indexOf(':'); |
| 691 | boolean allLower = true; |
| 692 | for (int index = 0; index < colon; index++) { |
| 693 | char ch = inUrl.charAt(index); |
| 694 | if (!Character.isLetter(ch)) { |
| 695 | break; |
| 696 | } |
| 697 | allLower &= Character.isLowerCase(ch); |
| 698 | if (index == colon - 1 && !allLower) { |
| 699 | inUrl = inUrl.substring(0, colon).toLowerCase() |
| 700 | + inUrl.substring(colon); |
| 701 | } |
| 702 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 703 | if (inUrl.startsWith("http://") || inUrl.startsWith("https://")) |
| 704 | return inUrl; |
| 705 | if (inUrl.startsWith("http:") || |
| 706 | inUrl.startsWith("https:")) { |
| 707 | if (inUrl.startsWith("http:/") || inUrl.startsWith("https:/")) { |
| 708 | inUrl = inUrl.replaceFirst("/", "//"); |
| 709 | } else inUrl = inUrl.replaceFirst(":", "://"); |
| 710 | } |
| 711 | return inUrl; |
| 712 | } |
| 713 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 714 | @Override |
| 715 | protected void onResume() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 716 | super.onResume(); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 717 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 718 | Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this); |
| 719 | } |
| 720 | |
| 721 | if (!mActivityInPause) { |
| 722 | Log.e(LOGTAG, "BrowserActivity is already resumed."); |
| 723 | return; |
| 724 | } |
| 725 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 726 | mTabControl.resumeCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 727 | mActivityInPause = false; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 728 | resumeWebViewTimers(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 729 | |
| 730 | if (mWakeLock.isHeld()) { |
| 731 | mHandler.removeMessages(RELEASE_WAKELOCK); |
| 732 | mWakeLock.release(); |
| 733 | } |
| 734 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 735 | registerReceiver(mNetworkStateIntentReceiver, |
| 736 | mNetworkStateChangedFilter); |
| 737 | WebView.enablePlatformNotifications(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 740 | /** |
| 741 | * Since the actual title bar is embedded in the WebView, and removing it |
Leon Scroggins | fe87bd3 | 2009-10-06 10:10:00 -0400 | [diff] [blame] | 742 | * would change its appearance, use a different TitleBar to show overlayed |
| 743 | * at the top of the screen, when the menu is open or the page is loading. |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 744 | */ |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 745 | private TitleBarBase mFakeTitleBar; |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 746 | |
| 747 | /** |
| 748 | * Keeps track of whether the options menu is open. This is important in |
| 749 | * determining whether to show or hide the title bar overlay. |
| 750 | */ |
| 751 | private boolean mOptionsMenuOpen; |
| 752 | |
| 753 | /** |
| 754 | * Only meaningful when mOptionsMenuOpen is true. This variable keeps track |
| 755 | * of whether the configuration has changed. The first onMenuOpened call |
| 756 | * after a configuration change is simply a reopening of the same menu |
| 757 | * (i.e. mIconView did not change). |
| 758 | */ |
| 759 | private boolean mConfigChanged; |
| 760 | |
| 761 | /** |
| 762 | * Whether or not the options menu is in its smaller, icon menu form. When |
| 763 | * true, we want the title bar overlay to be up. When false, we do not. |
| 764 | * Only meaningful if mOptionsMenuOpen is true. |
| 765 | */ |
| 766 | private boolean mIconView; |
| 767 | |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 768 | @Override |
| 769 | public boolean onMenuOpened(int featureId, Menu menu) { |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 770 | if (Window.FEATURE_OPTIONS_PANEL == featureId) { |
| 771 | if (mOptionsMenuOpen) { |
| 772 | if (mConfigChanged) { |
| 773 | // We do not need to make any changes to the state of the |
| 774 | // title bar, since the only thing that happened was a |
| 775 | // change in orientation |
| 776 | mConfigChanged = false; |
| 777 | } else { |
| 778 | if (mIconView) { |
| 779 | // Switching the menu to expanded view, so hide the |
| 780 | // title bar. |
| 781 | hideFakeTitleBar(); |
| 782 | mIconView = false; |
| 783 | } else { |
| 784 | // Switching the menu back to icon view, so show the |
| 785 | // title bar once again. |
| 786 | showFakeTitleBar(); |
| 787 | mIconView = true; |
| 788 | } |
| 789 | } |
| 790 | } else { |
| 791 | // The options menu is closed, so open it, and show the title |
| 792 | showFakeTitleBar(); |
| 793 | mOptionsMenuOpen = true; |
| 794 | mConfigChanged = false; |
| 795 | mIconView = true; |
| 796 | } |
| 797 | } |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 798 | return true; |
| 799 | } |
| 800 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 801 | void showFakeTitleBar() { |
| 802 | if (!isFakeTitleBarShowing() && mActiveTabsPage == null && !mActivityInPause) { |
Grace Kloba | 847c25b | 2010-03-30 16:00:26 -0700 | [diff] [blame] | 803 | WebView mainView = mTabControl.getCurrentWebView(); |
| 804 | // if there is no current WebView, don't show the faked title bar; |
Grace Kloba | 6519070 | 2010-04-02 23:37:26 -0700 | [diff] [blame] | 805 | if (mainView == null) { |
Cary Clark | a046455 | 2009-09-29 13:00:45 -0400 | [diff] [blame] | 806 | return; |
| 807 | } |
Leon Scroggins | 79e36d9 | 2010-04-29 16:01:46 +0100 | [diff] [blame] | 808 | // Do not need to check for null, since the current tab will have |
| 809 | // at least a main WebView, or we would have returned above. |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 810 | if (isInCustomActionMode()) { |
| 811 | // Do not show the fake title bar, while a custom ActionMode |
| 812 | // (i.e. find or select) is showing. |
Leon Scroggins | 79e36d9 | 2010-04-29 16:01:46 +0100 | [diff] [blame] | 813 | return; |
| 814 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 815 | if (mXLargeScreenSize) { |
| 816 | mContentView.addView(mFakeTitleBar); |
| 817 | mTabBar.onShowTitleBar(); |
| 818 | } else { |
| 819 | WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 820 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 821 | // Add the title bar to the window manager so it can receive |
| 822 | // touches |
| 823 | // while the menu is up |
| 824 | WindowManager.LayoutParams params = |
| 825 | new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
| 826 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 827 | WindowManager.LayoutParams.TYPE_APPLICATION, |
| 828 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, |
| 829 | PixelFormat.TRANSLUCENT); |
| 830 | params.gravity = Gravity.TOP; |
| 831 | boolean atTop = mainView.getScrollY() == 0; |
| 832 | params.windowAnimations = atTop ? 0 : R.style.TitleBar; |
| 833 | manager.addView(mFakeTitleBar, params); |
| 834 | } |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | @Override |
| 839 | public void onOptionsMenuClosed(Menu menu) { |
| 840 | mOptionsMenuOpen = false; |
Leon Scroggins | a27ff19 | 2009-09-14 12:58:04 -0400 | [diff] [blame] | 841 | if (!mInLoad) { |
| 842 | hideFakeTitleBar(); |
| 843 | } else if (!mIconView) { |
| 844 | // The page is currently loading, and we are in expanded mode, so |
| 845 | // we were not showing the menu. Show it once again. It will be |
| 846 | // removed when the page finishes. |
| 847 | showFakeTitleBar(); |
| 848 | } |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 849 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 850 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 851 | void stopScrolling() { |
| 852 | ((ScrollWebView) mTabControl.getCurrentWebView()).stopScroll(); |
| 853 | } |
| 854 | |
| 855 | void hideFakeTitleBar() { |
| 856 | if (!isFakeTitleBarShowing()) return; |
| 857 | if (mXLargeScreenSize) { |
| 858 | mContentView.removeView(mFakeTitleBar); |
| 859 | mTabBar.onHideTitleBar(); |
| 860 | } else { |
| 861 | WindowManager.LayoutParams params = |
| 862 | (WindowManager.LayoutParams) mFakeTitleBar.getLayoutParams(); |
| 863 | WebView mainView = mTabControl.getCurrentWebView(); |
| 864 | // Although we decided whether or not to animate based on the |
| 865 | // current |
| 866 | // scroll position, the scroll position may have changed since the |
| 867 | // fake title bar was displayed. Make sure it has the appropriate |
| 868 | // animation/lack thereof before removing. |
| 869 | params.windowAnimations = |
| 870 | mainView != null && mainView.getScrollY() == 0 ? 0 : R.style.TitleBar; |
| 871 | WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); |
| 872 | manager.updateViewLayout(mFakeTitleBar, params); |
| 873 | manager.removeView(mFakeTitleBar); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | boolean isFakeTitleBarShowing() { |
| 878 | return (mFakeTitleBar.getParent() != null); |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 879 | } |
| 880 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 881 | /** |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 882 | * Special method for the fake title bar to call when displaying its context |
| 883 | * menu, since it is in its own Window, and its parent does not show a |
| 884 | * context menu. |
| 885 | */ |
| 886 | /* package */ void showTitleBarContextMenu() { |
Cary Clark | 65f4a3c | 2009-09-28 17:05:06 -0400 | [diff] [blame] | 887 | if (null == mTitleBar.getParent()) { |
| 888 | return; |
| 889 | } |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 890 | openContextMenu(mTitleBar); |
| 891 | } |
| 892 | |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 893 | @Override |
| 894 | public void onContextMenuClosed(Menu menu) { |
| 895 | super.onContextMenuClosed(menu); |
| 896 | if (mInLoad) { |
| 897 | showFakeTitleBar(); |
| 898 | } |
| 899 | } |
| 900 | |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 901 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 902 | * onSaveInstanceState(Bundle map) |
| 903 | * onSaveInstanceState is called right before onStop(). The map contains |
| 904 | * the saved state. |
| 905 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 906 | @Override |
| 907 | protected void onSaveInstanceState(Bundle outState) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 908 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 909 | Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this); |
| 910 | } |
| 911 | // the default implementation requires each view to have an id. As the |
| 912 | // browser handles the state itself and it doesn't use id for the views, |
| 913 | // don't call the default implementation. Otherwise it will trigger the |
| 914 | // warning like this, "couldn't save which view has focus because the |
| 915 | // focused view XXX has no id". |
| 916 | |
| 917 | // Save all the tabs |
| 918 | mTabControl.saveState(outState); |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 919 | |
| 920 | // Save time so that we know how old incognito tabs (if any) are. |
| 921 | outState.putSerializable("lastActiveDate", Calendar.getInstance()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 922 | } |
| 923 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 924 | @Override |
| 925 | protected void onPause() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 926 | super.onPause(); |
| 927 | |
| 928 | if (mActivityInPause) { |
| 929 | Log.e(LOGTAG, "BrowserActivity is already paused."); |
| 930 | return; |
| 931 | } |
| 932 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 933 | mTabControl.pauseCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 934 | mActivityInPause = true; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 935 | if (mTabControl.getCurrentIndex() >= 0 && !pauseWebViewTimers()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 936 | mWakeLock.acquire(); |
| 937 | mHandler.sendMessageDelayed(mHandler |
| 938 | .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT); |
| 939 | } |
| 940 | |
Leon Scroggins | a2ab6a7 | 2009-09-11 11:49:52 -0400 | [diff] [blame] | 941 | // FIXME: This removes the active tabs page and resets the menu to |
| 942 | // MAIN_MENU. A better solution might be to do this work in onNewIntent |
| 943 | // but then we would need to save it in onSaveInstanceState and restore |
| 944 | // it in onCreate/onRestoreInstanceState |
| 945 | if (mActiveTabsPage != null) { |
| 946 | removeActiveTabPage(true); |
| 947 | } |
| 948 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 949 | cancelStopToast(); |
| 950 | |
| 951 | // unregister network state listener |
| 952 | unregisterReceiver(mNetworkStateIntentReceiver); |
| 953 | WebView.disablePlatformNotifications(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 954 | } |
| 955 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 956 | @Override |
| 957 | protected void onDestroy() { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 958 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 959 | Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this); |
| 960 | } |
| 961 | super.onDestroy(); |
Grace Kloba | 0923d69 | 2009-09-23 21:37:25 -0700 | [diff] [blame] | 962 | |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 963 | if (mUploadMessage != null) { |
| 964 | mUploadMessage.onReceiveValue(null); |
| 965 | mUploadMessage = null; |
| 966 | } |
| 967 | |
Grace Kloba | 0923d69 | 2009-09-23 21:37:25 -0700 | [diff] [blame] | 968 | if (mTabControl == null) return; |
| 969 | |
Grace Kloba | 1fc98a3 | 2009-10-21 13:23:08 -0700 | [diff] [blame] | 970 | // Remove the fake title bar if it is there |
| 971 | hideFakeTitleBar(); |
| 972 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 973 | // Remove the current tab and sub window |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 974 | Tab t = mTabControl.getCurrentTab(); |
Patrick Scott | fb5e77f | 2009-04-08 19:17:37 -0700 | [diff] [blame] | 975 | if (t != null) { |
| 976 | dismissSubWindow(t); |
| 977 | removeTabFromContentView(t); |
| 978 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 979 | // Destroy all the tabs |
| 980 | mTabControl.destroy(); |
| 981 | WebIconDatabase.getInstance().close(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 982 | |
Bjorn Bringert | a761181 | 2010-03-24 11:12:02 +0000 | [diff] [blame] | 983 | // Stop watching the default geolocation permissions |
| 984 | mSystemAllowGeolocationOrigins.stop(); |
| 985 | mSystemAllowGeolocationOrigins = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | @Override |
| 989 | public void onConfigurationChanged(Configuration newConfig) { |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 990 | mConfigChanged = true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 991 | super.onConfigurationChanged(newConfig); |
| 992 | |
| 993 | if (mPageInfoDialog != null) { |
| 994 | mPageInfoDialog.dismiss(); |
| 995 | showPageInfo( |
| 996 | mPageInfoView, |
Leon Scroggins | c7b92f8 | 2010-01-11 18:17:31 -0500 | [diff] [blame] | 997 | mPageInfoFromShowSSLCertificateOnError); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 998 | } |
| 999 | if (mSSLCertificateDialog != null) { |
| 1000 | mSSLCertificateDialog.dismiss(); |
| 1001 | showSSLCertificate( |
| 1002 | mSSLCertificateView); |
| 1003 | } |
| 1004 | if (mSSLCertificateOnErrorDialog != null) { |
| 1005 | mSSLCertificateOnErrorDialog.dismiss(); |
| 1006 | showSSLCertificateOnError( |
| 1007 | mSSLCertificateOnErrorView, |
| 1008 | mSSLCertificateOnErrorHandler, |
| 1009 | mSSLCertificateOnErrorError); |
| 1010 | } |
| 1011 | if (mHttpAuthenticationDialog != null) { |
Bjorn Bringert | 2573892 | 2010-10-12 10:56:20 +0100 | [diff] [blame] | 1012 | mHttpAuthenticationDialog.reshow(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1013 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1014 | } |
| 1015 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1016 | @Override |
| 1017 | public void onLowMemory() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1018 | super.onLowMemory(); |
| 1019 | mTabControl.freeMemory(); |
| 1020 | } |
| 1021 | |
Cary Clark | ff4d92c | 2010-03-25 11:17:03 -0400 | [diff] [blame] | 1022 | private void resumeWebViewTimers() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1023 | Tab tab = mTabControl.getCurrentTab(); |
Cary Clark | ff4d92c | 2010-03-25 11:17:03 -0400 | [diff] [blame] | 1024 | if (tab == null) return; // monkey can trigger this |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1025 | boolean inLoad = tab.inLoad(); |
| 1026 | if ((!mActivityInPause && !inLoad) || (mActivityInPause && inLoad)) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1027 | CookieSyncManager.getInstance().startSync(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1028 | WebView w = tab.getWebView(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1029 | if (w != null) { |
| 1030 | w.resumeTimers(); |
| 1031 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 1035 | private boolean pauseWebViewTimers() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1036 | Tab tab = mTabControl.getCurrentTab(); |
| 1037 | boolean inLoad = tab.inLoad(); |
| 1038 | if (mActivityInPause && !inLoad) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1039 | CookieSyncManager.getInstance().stopSync(); |
| 1040 | WebView w = mTabControl.getCurrentWebView(); |
| 1041 | if (w != null) { |
| 1042 | w.pauseTimers(); |
| 1043 | } |
| 1044 | return true; |
| 1045 | } else { |
| 1046 | return false; |
| 1047 | } |
| 1048 | } |
| 1049 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1050 | // Open the icon database and retain all the icons for visited sites. |
| 1051 | private void retainIconsOnStartup() { |
| 1052 | final WebIconDatabase db = WebIconDatabase.getInstance(); |
| 1053 | db.open(getDir("icons", 0).getPath()); |
Leon Scroggins | 2c0f611 | 2010-03-12 18:09:39 -0500 | [diff] [blame] | 1054 | Cursor c = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1055 | try { |
Leon Scroggins | 2c0f611 | 2010-03-12 18:09:39 -0500 | [diff] [blame] | 1056 | c = Browser.getAllBookmarks(mResolver); |
| 1057 | if (c.moveToFirst()) { |
| 1058 | int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL); |
| 1059 | do { |
| 1060 | String url = c.getString(urlIndex); |
| 1061 | db.retainIconForPageUrl(url); |
| 1062 | } while (c.moveToNext()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1063 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1064 | } catch (IllegalStateException e) { |
| 1065 | Log.e(LOGTAG, "retainIconsOnStartup", e); |
Leon Scroggins | 2c0f611 | 2010-03-12 18:09:39 -0500 | [diff] [blame] | 1066 | } finally { |
| 1067 | if (c!= null) c.close(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | // Helper method for getting the top window. |
| 1072 | WebView getTopWindow() { |
| 1073 | return mTabControl.getCurrentTopWebView(); |
| 1074 | } |
| 1075 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1076 | TabControl getTabControl() { |
| 1077 | return mTabControl; |
| 1078 | } |
| 1079 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1080 | @Override |
| 1081 | public boolean onCreateOptionsMenu(Menu menu) { |
| 1082 | super.onCreateOptionsMenu(menu); |
| 1083 | |
| 1084 | MenuInflater inflater = getMenuInflater(); |
| 1085 | inflater.inflate(R.menu.browser, menu); |
| 1086 | mMenu = menu; |
| 1087 | updateInLoadMenuItems(); |
| 1088 | return true; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * As the menu can be open when loading state changes |
| 1093 | * we must manually update the state of the stop/reload menu |
| 1094 | * item |
| 1095 | */ |
| 1096 | private void updateInLoadMenuItems() { |
| 1097 | if (mMenu == null) { |
| 1098 | return; |
| 1099 | } |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 1100 | MenuItem dest = mMenu.findItem(R.id.stop_reload_menu_id); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1101 | MenuItem src = mInLoad ? |
| 1102 | mMenu.findItem(R.id.stop_menu_id): |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 1103 | mMenu.findItem(R.id.reload_menu_id); |
| 1104 | if (src != null) { |
| 1105 | dest.setIcon(src.getIcon()); |
| 1106 | dest.setTitle(src.getTitle()); |
| 1107 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | @Override |
| 1111 | public boolean onContextItemSelected(MenuItem item) { |
| 1112 | // chording is not an issue with context menus, but we use the same |
| 1113 | // options selector, so set mCanChord to true so we can access them. |
| 1114 | mCanChord = true; |
| 1115 | int id = item.getItemId(); |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1116 | boolean result = true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1117 | switch (id) { |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1118 | // For the context menu from the title bar |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1119 | case R.id.title_bar_copy_page_url: |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1120 | Tab currentTab = mTabControl.getCurrentTab(); |
| 1121 | if (null == currentTab) { |
| 1122 | result = false; |
| 1123 | break; |
| 1124 | } |
| 1125 | WebView mainView = currentTab.getWebView(); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1126 | if (null == mainView) { |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1127 | result = false; |
| 1128 | break; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1129 | } |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1130 | copy(mainView.getUrl()); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1131 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1132 | // -- Browser context menu |
| 1133 | case R.id.open_context_menu_id: |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1134 | case R.id.bookmark_context_menu_id: |
| 1135 | case R.id.save_link_context_menu_id: |
| 1136 | case R.id.share_link_context_menu_id: |
| 1137 | case R.id.copy_link_context_menu_id: |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1138 | final WebView webView = getTopWindow(); |
| 1139 | if (null == webView) { |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1140 | result = false; |
| 1141 | break; |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 1142 | } |
| 1143 | final HashMap hrefMap = new HashMap(); |
| 1144 | hrefMap.put("webview", webView); |
| 1145 | final Message msg = mHandler.obtainMessage( |
| 1146 | FOCUS_NODE_HREF, id, 0, hrefMap); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1147 | webView.requestFocusNodeHref(msg); |
| 1148 | break; |
| 1149 | |
| 1150 | default: |
| 1151 | // For other context menus |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1152 | result = onOptionsItemSelected(item); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1153 | } |
| 1154 | mCanChord = false; |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1155 | return result; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | private Bundle createGoogleSearchSourceBundle(String source) { |
| 1159 | Bundle bundle = new Bundle(); |
Bjorn Bringert | 10d1cca | 2010-02-10 14:22:12 +0000 | [diff] [blame] | 1160 | bundle.putString(Search.SOURCE, source); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1161 | return bundle; |
| 1162 | } |
| 1163 | |
Leon Scroggins | 8ad2992 | 2010-02-16 12:33:55 -0500 | [diff] [blame] | 1164 | /* package */ void editUrl() { |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 1165 | if (mOptionsMenuOpen) closeOptionsMenu(); |
Leon Scroggins | 5bbe980 | 2009-07-31 13:10:55 -0400 | [diff] [blame] | 1166 | String url = (getTopWindow() == null) ? null : getTopWindow().getUrl(); |
Grace Kloba | 83f4734 | 2009-07-20 10:44:31 -0700 | [diff] [blame] | 1167 | startSearch(mSettings.getHomePage().equals(url) ? null : url, true, |
Leon Scroggins | 8ad2992 | 2010-02-16 12:33:55 -0500 | [diff] [blame] | 1168 | null, false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1169 | } |
| 1170 | |
Leon Scroggins | 8ad2992 | 2010-02-16 12:33:55 -0500 | [diff] [blame] | 1171 | /** |
| 1172 | * Overriding this to insert a local information bundle |
| 1173 | */ |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1174 | @Override |
| 1175 | public void startSearch(String initialQuery, boolean selectInitialQuery, |
| 1176 | Bundle appSearchData, boolean globalSearch) { |
| 1177 | if (appSearchData == null) { |
| 1178 | appSearchData = createGoogleSearchSourceBundle(GOOGLE_SEARCH_SOURCE_TYPE); |
| 1179 | } |
Leon Scroggins III | 430057d | 2010-09-14 10:57:37 -0400 | [diff] [blame] | 1180 | |
| 1181 | SearchEngine searchEngine = mSettings.getSearchEngine(); |
| 1182 | if (searchEngine != null && !searchEngine.supportsVoiceSearch()) { |
| 1183 | appSearchData.putBoolean(SearchManager.DISABLE_VOICE_SEARCH, true); |
| 1184 | } |
| 1185 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1186 | super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch); |
| 1187 | } |
| 1188 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1189 | /** |
| 1190 | * Switch tabs. Called by the TitleBarSet when sliding the title bar |
| 1191 | * results in changing tabs. |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1192 | * @param index Index of the tab to change to, as defined by |
| 1193 | * mTabControl.getTabIndex(Tab t). |
| 1194 | * @return boolean True if we successfully switched to a different tab. If |
| 1195 | * the indexth tab is null, or if that tab is the same as |
| 1196 | * the current one, return false. |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1197 | */ |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1198 | /* package */ boolean switchToTab(int index) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1199 | Tab tab = mTabControl.getTab(index); |
| 1200 | Tab currentTab = mTabControl.getCurrentTab(); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1201 | if (tab == null || tab == currentTab) { |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1202 | return false; |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1203 | } |
| 1204 | if (currentTab != null) { |
| 1205 | // currentTab may be null if it was just removed. In that case, |
| 1206 | // we do not need to remove it |
| 1207 | removeTabFromContentView(currentTab); |
| 1208 | } |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1209 | mTabControl.setCurrentTab(tab); |
| 1210 | attachTabToContentView(tab); |
Grace Kloba | eb6eef4 | 2009-09-15 17:56:32 -0700 | [diff] [blame] | 1211 | resetTitleIconAndProgress(); |
| 1212 | updateLockIconToLatest(); |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1213 | return true; |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1214 | } |
| 1215 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1216 | /* package */ Tab openTabToHomePage() { |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1217 | return openTabAndShow(mSettings.getHomePage(), false, null); |
| 1218 | } |
| 1219 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1220 | /* package */ void closeCurrentWindow() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1221 | final Tab current = mTabControl.getCurrentTab(); |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1222 | if (mTabControl.getTabCount() == 1) { |
Leon Scroggins | 3044423 | 2009-09-04 18:36:20 -0400 | [diff] [blame] | 1223 | // This is the last tab. Open a new one, with the home |
| 1224 | // page and close the current one. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1225 | openTabToHomePage(); |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1226 | closeTab(current); |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1227 | return; |
| 1228 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1229 | final Tab parent = current.getParentTab(); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1230 | int indexToShow = -1; |
| 1231 | if (parent != null) { |
| 1232 | indexToShow = mTabControl.getTabIndex(parent); |
| 1233 | } else { |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1234 | final int currentIndex = mTabControl.getCurrentIndex(); |
| 1235 | // Try to move to the tab to the right |
| 1236 | indexToShow = currentIndex + 1; |
| 1237 | if (indexToShow > mTabControl.getTabCount() - 1) { |
| 1238 | // Try to move to the tab to the left |
| 1239 | indexToShow = currentIndex - 1; |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1240 | } |
| 1241 | } |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1242 | if (switchToTab(indexToShow)) { |
| 1243 | // Close window |
| 1244 | closeTab(current); |
| 1245 | } |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1248 | private ActiveTabsPage mActiveTabsPage; |
| 1249 | |
| 1250 | /** |
| 1251 | * Remove the active tabs page. |
| 1252 | * @param needToAttach If true, the active tabs page did not attach a tab |
| 1253 | * to the content view, so we need to do that here. |
| 1254 | */ |
| 1255 | /* package */ void removeActiveTabPage(boolean needToAttach) { |
| 1256 | mContentView.removeView(mActiveTabsPage); |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 1257 | mTitleBar.setVisibility(View.VISIBLE); |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1258 | mActiveTabsPage = null; |
| 1259 | mMenuState = R.id.MAIN_MENU; |
| 1260 | if (needToAttach) { |
| 1261 | attachTabToContentView(mTabControl.getCurrentTab()); |
| 1262 | } |
| 1263 | getTopWindow().requestFocus(); |
| 1264 | } |
| 1265 | |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1266 | @Override |
Adam Powell | d797305 | 2010-11-15 21:10:48 -0800 | [diff] [blame] | 1267 | public void onActionModeStarted(ActionMode mode) { |
| 1268 | super.onActionModeStarted(mode); |
Adam Powell | 6c6e86f | 2010-11-16 11:06:24 -0800 | [diff] [blame] | 1269 | mActionMode = mode; |
Leon Scroggins | 4fc12cb | 2010-08-24 14:24:05 -0400 | [diff] [blame] | 1270 | hideFakeTitleBar(); |
| 1271 | // Would like to change the MENU, but onEndActionMode may not be called |
Adam Powell | d797305 | 2010-11-15 21:10:48 -0800 | [diff] [blame] | 1272 | // TODO onActionModeFinished will notify when an action mode ends |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1275 | @Override |
| 1276 | public boolean onOptionsItemSelected(MenuItem item) { |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 1277 | if (item.getGroupId() != R.id.CONTEXT_MENU) { |
| 1278 | // menu remains active, so ensure comboview is dismissed |
| 1279 | // if main menu option is selected |
| 1280 | removeComboView(); |
| 1281 | } |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 1282 | // check the action bar button before mCanChord check, as the prepare call |
| 1283 | // doesn't come for action bar buttons |
| 1284 | if (item.getItemId() == R.id.newtab) { |
Michael Kolb | 300b7f0 | 2010-08-25 13:47:24 -0700 | [diff] [blame] | 1285 | openTabToHomePage(); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 1286 | return true; |
| 1287 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1288 | if (!mCanChord) { |
| 1289 | // The user has already fired a shortcut with this hold down of the |
| 1290 | // menu key. |
| 1291 | return false; |
| 1292 | } |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1293 | if (null == getTopWindow()) { |
Leon Scroggins | 0d7ae0e | 2009-06-05 11:04:45 -0400 | [diff] [blame] | 1294 | return false; |
| 1295 | } |
Grace Kloba | 6ee9c49 | 2009-07-13 10:04:34 -0700 | [diff] [blame] | 1296 | if (mMenuIsDown) { |
| 1297 | // The shortcut action consumes the MENU. Even if it is still down, |
| 1298 | // it won't trigger the next shortcut action. In the case of the |
| 1299 | // shortcut action triggering a new activity, like Bookmarks, we |
| 1300 | // won't get onKeyUp for MENU. So it is important to reset it here. |
| 1301 | mMenuIsDown = false; |
| 1302 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1303 | switch (item.getItemId()) { |
| 1304 | // -- Main menu |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 1305 | case R.id.new_tab_menu_id: |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1306 | openTabToHomePage(); |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 1307 | break; |
| 1308 | |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 1309 | case R.id.incognito_menu_id: |
| 1310 | openIncognitoTab(); |
| 1311 | break; |
| 1312 | |
Leon Scroggins | 64b80f3 | 2009-08-07 12:03:34 -0400 | [diff] [blame] | 1313 | case R.id.goto_menu_id: |
Leon Scroggins | 8ad2992 | 2010-02-16 12:33:55 -0500 | [diff] [blame] | 1314 | editUrl(); |
Leon Scroggins | b3a5bed | 2009-09-28 11:21:56 -0400 | [diff] [blame] | 1315 | break; |
| 1316 | |
| 1317 | case R.id.bookmarks_menu_id: |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 1318 | bookmarksOrHistoryPicker(false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1319 | break; |
| 1320 | |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1321 | case R.id.active_tabs_menu_id: |
| 1322 | mActiveTabsPage = new ActiveTabsPage(this, mTabControl); |
| 1323 | removeTabFromContentView(mTabControl.getCurrentTab()); |
Leon Scroggins | d746a94 | 2010-05-19 13:21:44 -0400 | [diff] [blame] | 1324 | mTitleBar.setVisibility(View.GONE); |
Leon Scroggins | 43de616 | 2009-09-14 19:59:58 -0400 | [diff] [blame] | 1325 | hideFakeTitleBar(); |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1326 | mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS); |
| 1327 | mActiveTabsPage.requestFocus(); |
| 1328 | mMenuState = EMPTY_MENU; |
| 1329 | break; |
| 1330 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1331 | case R.id.add_bookmark_menu_id: |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 1332 | bookmarkCurrentPage(AddBookmarkPage.DEFAULT_FOLDER_ID); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1333 | break; |
| 1334 | |
| 1335 | case R.id.stop_reload_menu_id: |
| 1336 | if (mInLoad) { |
| 1337 | stopLoading(); |
| 1338 | } else { |
| 1339 | getTopWindow().reload(); |
| 1340 | } |
| 1341 | break; |
| 1342 | |
| 1343 | case R.id.back_menu_id: |
| 1344 | getTopWindow().goBack(); |
| 1345 | break; |
| 1346 | |
| 1347 | case R.id.forward_menu_id: |
| 1348 | getTopWindow().goForward(); |
| 1349 | break; |
| 1350 | |
| 1351 | case R.id.close_menu_id: |
| 1352 | // Close the subwindow if it exists. |
| 1353 | if (mTabControl.getCurrentSubWindow() != null) { |
| 1354 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 1355 | break; |
| 1356 | } |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1357 | closeCurrentWindow(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1358 | break; |
| 1359 | |
| 1360 | case R.id.homepage_menu_id: |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1361 | Tab current = mTabControl.getCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1362 | if (current != null) { |
| 1363 | dismissSubWindow(current); |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 1364 | loadUrl(current.getWebView(), mSettings.getHomePage()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1365 | } |
| 1366 | break; |
| 1367 | |
| 1368 | case R.id.preferences_menu_id: |
| 1369 | Intent intent = new Intent(this, |
| 1370 | BrowserPreferencesPage.class); |
Leon Scroggins | d530494 | 2009-12-10 16:11:39 -0500 | [diff] [blame] | 1371 | intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE, |
| 1372 | getTopWindow().getUrl()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1373 | startActivityForResult(intent, PREFERENCES_PAGE); |
| 1374 | break; |
| 1375 | |
| 1376 | case R.id.find_menu_id: |
Leon Scroggins | 4fc12cb | 2010-08-24 14:24:05 -0400 | [diff] [blame] | 1377 | getTopWindow().showFindDialog(null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1378 | break; |
| 1379 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1380 | case R.id.page_info_menu_id: |
| 1381 | showPageInfo(mTabControl.getCurrentTab(), false); |
| 1382 | break; |
| 1383 | |
| 1384 | case R.id.classic_history_menu_id: |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 1385 | bookmarksOrHistoryPicker(true); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1386 | break; |
| 1387 | |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1388 | case R.id.title_bar_share_page_url: |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1389 | case R.id.share_page_menu_id: |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 1390 | Tab currentTab = mTabControl.getCurrentTab(); |
| 1391 | if (null == currentTab) { |
| 1392 | mCanChord = false; |
| 1393 | return false; |
| 1394 | } |
| 1395 | currentTab.populatePickerData(); |
| 1396 | sharePage(this, currentTab.getTitle(), |
| 1397 | currentTab.getUrl(), currentTab.getFavicon(), |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 1398 | createScreenshot(currentTab.getWebView(), getDesiredThumbnailWidth(this), |
| 1399 | getDesiredThumbnailHeight(this))); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1400 | break; |
| 1401 | |
| 1402 | case R.id.dump_nav_menu_id: |
| 1403 | getTopWindow().debugDump(); |
| 1404 | break; |
| 1405 | |
Andrei Popescu | 7a8b88b | 2010-02-02 00:30:38 +0000 | [diff] [blame] | 1406 | case R.id.dump_counters_menu_id: |
| 1407 | getTopWindow().dumpV8Counters(); |
| 1408 | break; |
| 1409 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1410 | case R.id.zoom_in_menu_id: |
| 1411 | getTopWindow().zoomIn(); |
| 1412 | break; |
| 1413 | |
| 1414 | case R.id.zoom_out_menu_id: |
| 1415 | getTopWindow().zoomOut(); |
| 1416 | break; |
| 1417 | |
| 1418 | case R.id.view_downloads_menu_id: |
Leon Scroggins III | a682a3c | 2010-09-27 12:32:40 -0400 | [diff] [blame] | 1419 | viewDownloads(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1420 | break; |
| 1421 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1422 | case R.id.window_one_menu_id: |
| 1423 | case R.id.window_two_menu_id: |
| 1424 | case R.id.window_three_menu_id: |
| 1425 | case R.id.window_four_menu_id: |
| 1426 | case R.id.window_five_menu_id: |
| 1427 | case R.id.window_six_menu_id: |
| 1428 | case R.id.window_seven_menu_id: |
| 1429 | case R.id.window_eight_menu_id: |
| 1430 | { |
| 1431 | int menuid = item.getItemId(); |
| 1432 | for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) { |
| 1433 | if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1434 | Tab desiredTab = mTabControl.getTab(id); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1435 | if (desiredTab != null && |
| 1436 | desiredTab != mTabControl.getCurrentTab()) { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1437 | switchToTab(id); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1438 | } |
| 1439 | break; |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | break; |
| 1444 | |
| 1445 | default: |
| 1446 | if (!super.onOptionsItemSelected(item)) { |
| 1447 | return false; |
| 1448 | } |
| 1449 | // Otherwise fall through. |
| 1450 | } |
| 1451 | mCanChord = false; |
| 1452 | return true; |
| 1453 | } |
| 1454 | |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 1455 | /** |
| 1456 | * add the current page as a bookmark to the given folder id |
| 1457 | * @param folderId use -1 for the default folder |
| 1458 | */ |
| 1459 | /* package */ void bookmarkCurrentPage(long folderId) { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1460 | Intent i = new Intent(BrowserActivity.this, |
| 1461 | AddBookmarkPage.class); |
| 1462 | WebView w = getTopWindow(); |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 1463 | i.putExtra(BrowserContract.Bookmarks.URL, w.getUrl()); |
| 1464 | i.putExtra(BrowserContract.Bookmarks.TITLE, w.getTitle()); |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 1465 | String touchIconUrl = w.getTouchIconUrl(); |
| 1466 | if (touchIconUrl != null) { |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 1467 | i.putExtra(AddBookmarkPage.TOUCH_ICON_URL, touchIconUrl); |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 1468 | WebSettings settings = w.getSettings(); |
| 1469 | if (settings != null) { |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 1470 | i.putExtra(AddBookmarkPage.USER_AGENT, |
| 1471 | settings.getUserAgentString()); |
Leon Scroggins | 88d0803 | 2010-10-21 15:17:10 -0400 | [diff] [blame] | 1472 | } |
| 1473 | } |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 1474 | i.putExtra(BrowserContract.Bookmarks.THUMBNAIL, |
| 1475 | createScreenshot(w, getDesiredThumbnailWidth(this), |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 1476 | getDesiredThumbnailHeight(this))); |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 1477 | i.putExtra(BrowserContract.Bookmarks.FAVICON, w.getFavicon()); |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 1478 | i.putExtra(BrowserContract.Bookmarks.PARENT, |
| 1479 | folderId); |
Leon Scroggins III | 76a0e9c | 2010-10-05 16:10:01 -0400 | [diff] [blame] | 1480 | // Put the dialog at the upper right of the screen, covering the |
| 1481 | // star on the title bar. |
| 1482 | i.putExtra("gravity", Gravity.RIGHT | Gravity.TOP); |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1483 | startActivity(i); |
| 1484 | } |
| 1485 | |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1486 | /* |
| 1487 | * True if a custom ActionMode (i.e. find or select) is in use. |
| 1488 | */ |
| 1489 | private boolean isInCustomActionMode() { |
| 1490 | return mActionMode != null; |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /* |
Leon Scroggins | 4fc12cb | 2010-08-24 14:24:05 -0400 | [diff] [blame] | 1494 | * End the current ActionMode. |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1495 | */ |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1496 | void endActionMode() { |
| 1497 | if (mActionMode != null) { |
Leon Scroggins | 4fc12cb | 2010-08-24 14:24:05 -0400 | [diff] [blame] | 1498 | ActionMode mode = mActionMode; |
| 1499 | onEndActionMode(); |
| 1500 | mode.finish(); |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | /* |
| 1505 | * Called by find and select when they are finished. Replace title bars |
| 1506 | * as necessary. |
| 1507 | */ |
| 1508 | public void onEndActionMode() { |
| 1509 | if (!isInCustomActionMode()) return; |
Leon Scroggins | 79e36d9 | 2010-04-29 16:01:46 +0100 | [diff] [blame] | 1510 | if (mInLoad) { |
| 1511 | // The title bar was hidden, because otherwise it would cover up the |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1512 | // find or select dialog. Now that the dialog has been removed, |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1513 | // show the fake title bar once again. |
Leon Scroggins | 79e36d9 | 2010-04-29 16:01:46 +0100 | [diff] [blame] | 1514 | showFakeTitleBar(); |
| 1515 | } |
Leon Scroggins | 4fc12cb | 2010-08-24 14:24:05 -0400 | [diff] [blame] | 1516 | // Would like to return the menu state to normal, but this does not |
| 1517 | // necessarily get called. |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1518 | mActionMode = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 1521 | // For select and find, we keep track of the ActionMode so that |
| 1522 | // finish() can be called as desired. |
| 1523 | private ActionMode mActionMode; |
| 1524 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1525 | @Override |
| 1526 | public boolean onPrepareOptionsMenu(Menu menu) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1527 | // This happens when the user begins to hold down the menu key, so |
| 1528 | // allow them to chord to get a shortcut. |
| 1529 | mCanChord = true; |
| 1530 | // Note: setVisible will decide whether an item is visible; while |
| 1531 | // setEnabled() will decide whether an item is enabled, which also means |
| 1532 | // whether the matching shortcut key will function. |
| 1533 | super.onPrepareOptionsMenu(menu); |
| 1534 | switch (mMenuState) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1535 | case EMPTY_MENU: |
| 1536 | if (mCurrentMenuState != mMenuState) { |
| 1537 | menu.setGroupVisible(R.id.MAIN_MENU, false); |
| 1538 | menu.setGroupEnabled(R.id.MAIN_MENU, false); |
| 1539 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1540 | } |
| 1541 | break; |
| 1542 | default: |
| 1543 | if (mCurrentMenuState != mMenuState) { |
| 1544 | menu.setGroupVisible(R.id.MAIN_MENU, true); |
| 1545 | menu.setGroupEnabled(R.id.MAIN_MENU, true); |
| 1546 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1547 | } |
| 1548 | final WebView w = getTopWindow(); |
| 1549 | boolean canGoBack = false; |
| 1550 | boolean canGoForward = false; |
| 1551 | boolean isHome = false; |
| 1552 | if (w != null) { |
| 1553 | canGoBack = w.canGoBack(); |
| 1554 | canGoForward = w.canGoForward(); |
| 1555 | isHome = mSettings.getHomePage().equals(w.getUrl()); |
| 1556 | } |
| 1557 | final MenuItem back = menu.findItem(R.id.back_menu_id); |
| 1558 | back.setEnabled(canGoBack); |
| 1559 | |
| 1560 | final MenuItem home = menu.findItem(R.id.homepage_menu_id); |
| 1561 | home.setEnabled(!isHome); |
| 1562 | |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 1563 | final MenuItem forward = menu.findItem(R.id.forward_menu_id); |
| 1564 | forward.setEnabled(canGoForward); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1565 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 1566 | if (!mXLargeScreenSize) { |
| 1567 | final MenuItem newtab = menu.findItem(R.id.new_tab_menu_id); |
| 1568 | newtab.setEnabled(mTabControl.canCreateNewTab()); |
| 1569 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1570 | // decide whether to show the share link option |
| 1571 | PackageManager pm = getPackageManager(); |
| 1572 | Intent send = new Intent(Intent.ACTION_SEND); |
| 1573 | send.setType("text/plain"); |
| 1574 | ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY); |
| 1575 | menu.findItem(R.id.share_page_menu_id).setVisible(ri != null); |
| 1576 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1577 | boolean isNavDump = mSettings.isNavDump(); |
| 1578 | final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id); |
| 1579 | nav.setVisible(isNavDump); |
| 1580 | nav.setEnabled(isNavDump); |
Andrei Popescu | 7a8b88b | 2010-02-02 00:30:38 +0000 | [diff] [blame] | 1581 | |
| 1582 | boolean showDebugSettings = mSettings.showDebugSettings(); |
| 1583 | final MenuItem counter = menu.findItem(R.id.dump_counters_menu_id); |
| 1584 | counter.setVisible(showDebugSettings); |
| 1585 | counter.setEnabled(showDebugSettings); |
| 1586 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1587 | break; |
| 1588 | } |
| 1589 | mCurrentMenuState = mMenuState; |
| 1590 | return true; |
| 1591 | } |
| 1592 | |
| 1593 | @Override |
| 1594 | public void onCreateContextMenu(ContextMenu menu, View v, |
| 1595 | ContextMenuInfo menuInfo) { |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 1596 | if (v instanceof TitleBarBase) { |
Leon Scroggins | 4e9f89b | 2010-02-22 16:54:14 -0500 | [diff] [blame] | 1597 | return; |
| 1598 | } |
Michael Kolb | 772927a | 2010-10-13 19:23:42 -0700 | [diff] [blame] | 1599 | if (!(v instanceof WebView)) { |
| 1600 | return; |
| 1601 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1602 | WebView webview = (WebView) v; |
| 1603 | WebView.HitTestResult result = webview.getHitTestResult(); |
| 1604 | if (result == null) { |
| 1605 | return; |
| 1606 | } |
| 1607 | |
| 1608 | int type = result.getType(); |
| 1609 | if (type == WebView.HitTestResult.UNKNOWN_TYPE) { |
| 1610 | Log.w(LOGTAG, |
| 1611 | "We should not show context menu when nothing is touched"); |
| 1612 | return; |
| 1613 | } |
| 1614 | if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) { |
| 1615 | // let TextView handles context menu |
| 1616 | return; |
| 1617 | } |
| 1618 | |
| 1619 | // Note, http://b/issue?id=1106666 is requesting that |
| 1620 | // an inflated menu can be used again. This is not available |
| 1621 | // yet, so inflate each time (yuk!) |
| 1622 | MenuInflater inflater = getMenuInflater(); |
| 1623 | inflater.inflate(R.menu.browsercontext, menu); |
| 1624 | |
| 1625 | // Show the correct menu group |
Leon Scroggins III | 9e997c7 | 2010-05-26 13:25:16 -0400 | [diff] [blame] | 1626 | final String extra = result.getExtra(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1627 | menu.setGroupVisible(R.id.PHONE_MENU, |
| 1628 | type == WebView.HitTestResult.PHONE_TYPE); |
| 1629 | menu.setGroupVisible(R.id.EMAIL_MENU, |
| 1630 | type == WebView.HitTestResult.EMAIL_TYPE); |
| 1631 | menu.setGroupVisible(R.id.GEO_MENU, |
| 1632 | type == WebView.HitTestResult.GEO_TYPE); |
| 1633 | menu.setGroupVisible(R.id.IMAGE_MENU, |
| 1634 | type == WebView.HitTestResult.IMAGE_TYPE |
| 1635 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
| 1636 | menu.setGroupVisible(R.id.ANCHOR_MENU, |
| 1637 | type == WebView.HitTestResult.SRC_ANCHOR_TYPE |
| 1638 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
| 1639 | |
| 1640 | // Setup custom handling depending on the type |
| 1641 | switch (type) { |
| 1642 | case WebView.HitTestResult.PHONE_TYPE: |
| 1643 | menu.setHeaderTitle(Uri.decode(extra)); |
| 1644 | menu.findItem(R.id.dial_context_menu_id).setIntent( |
| 1645 | new Intent(Intent.ACTION_VIEW, Uri |
| 1646 | .parse(WebView.SCHEME_TEL + extra))); |
| 1647 | Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 1648 | addIntent.putExtra(Insert.PHONE, Uri.decode(extra)); |
Cary Clark | 5e335a3 | 2009-09-22 14:53:11 -0400 | [diff] [blame] | 1649 | addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1650 | menu.findItem(R.id.add_contact_context_menu_id).setIntent( |
| 1651 | addIntent); |
| 1652 | menu.findItem(R.id.copy_phone_context_menu_id).setOnMenuItemClickListener( |
| 1653 | new Copy(extra)); |
| 1654 | break; |
| 1655 | |
| 1656 | case WebView.HitTestResult.EMAIL_TYPE: |
| 1657 | menu.setHeaderTitle(extra); |
| 1658 | menu.findItem(R.id.email_context_menu_id).setIntent( |
| 1659 | new Intent(Intent.ACTION_VIEW, Uri |
| 1660 | .parse(WebView.SCHEME_MAILTO + extra))); |
| 1661 | menu.findItem(R.id.copy_mail_context_menu_id).setOnMenuItemClickListener( |
| 1662 | new Copy(extra)); |
| 1663 | break; |
| 1664 | |
| 1665 | case WebView.HitTestResult.GEO_TYPE: |
| 1666 | menu.setHeaderTitle(extra); |
| 1667 | menu.findItem(R.id.map_context_menu_id).setIntent( |
| 1668 | new Intent(Intent.ACTION_VIEW, Uri |
| 1669 | .parse(WebView.SCHEME_GEO |
| 1670 | + URLEncoder.encode(extra)))); |
| 1671 | menu.findItem(R.id.copy_geo_context_menu_id).setOnMenuItemClickListener( |
| 1672 | new Copy(extra)); |
| 1673 | break; |
| 1674 | |
| 1675 | case WebView.HitTestResult.SRC_ANCHOR_TYPE: |
| 1676 | case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE: |
| 1677 | TextView titleView = (TextView) LayoutInflater.from(this) |
| 1678 | .inflate(android.R.layout.browser_link_context_header, |
| 1679 | null); |
| 1680 | titleView.setText(extra); |
| 1681 | menu.setHeaderView(titleView); |
| 1682 | // decide whether to show the open link in new tab option |
Leon Scroggins III | 9e997c7 | 2010-05-26 13:25:16 -0400 | [diff] [blame] | 1683 | boolean showNewTab = mTabControl.canCreateNewTab(); |
| 1684 | MenuItem newTabItem |
| 1685 | = menu.findItem(R.id.open_newtab_context_menu_id); |
| 1686 | newTabItem.setVisible(showNewTab); |
| 1687 | if (showNewTab) { |
| 1688 | newTabItem.setOnMenuItemClickListener( |
| 1689 | new MenuItem.OnMenuItemClickListener() { |
| 1690 | public boolean onMenuItemClick(MenuItem item) { |
| 1691 | final Tab parent = mTabControl.getCurrentTab(); |
Michael Kolb | 68792c8 | 2010-08-09 16:39:18 -0700 | [diff] [blame] | 1692 | final Tab newTab = openTab(extra, false); |
Leon Scroggins III | 9e997c7 | 2010-05-26 13:25:16 -0400 | [diff] [blame] | 1693 | if (newTab != parent) { |
| 1694 | parent.addChildTab(newTab); |
| 1695 | } |
| 1696 | return true; |
| 1697 | } |
| 1698 | }); |
| 1699 | } |
Ben Murdoch | de35362 | 2009-10-12 10:29:00 +0100 | [diff] [blame] | 1700 | menu.findItem(R.id.bookmark_context_menu_id).setVisible( |
| 1701 | Bookmarks.urlHasAcceptableScheme(extra)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1702 | PackageManager pm = getPackageManager(); |
| 1703 | Intent send = new Intent(Intent.ACTION_SEND); |
| 1704 | send.setType("text/plain"); |
| 1705 | ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY); |
| 1706 | menu.findItem(R.id.share_link_context_menu_id).setVisible(ri != null); |
| 1707 | if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) { |
| 1708 | break; |
| 1709 | } |
| 1710 | // otherwise fall through to handle image part |
| 1711 | case WebView.HitTestResult.IMAGE_TYPE: |
| 1712 | if (type == WebView.HitTestResult.IMAGE_TYPE) { |
| 1713 | menu.setHeaderTitle(extra); |
| 1714 | } |
| 1715 | menu.findItem(R.id.view_image_context_menu_id).setIntent( |
| 1716 | new Intent(Intent.ACTION_VIEW, Uri.parse(extra))); |
| 1717 | menu.findItem(R.id.download_context_menu_id). |
| 1718 | setOnMenuItemClickListener(new Download(extra)); |
Ben Murdoch | 4f75ba2 | 2009-10-27 11:48:28 +0000 | [diff] [blame] | 1719 | menu.findItem(R.id.set_wallpaper_context_menu_id). |
| 1720 | setOnMenuItemClickListener(new SetAsWallpaper(extra)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1721 | break; |
| 1722 | |
| 1723 | default: |
| 1724 | Log.w(LOGTAG, "We should not get here."); |
| 1725 | break; |
| 1726 | } |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 1727 | hideFakeTitleBar(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1730 | // Attach the given tab to the content view. |
Grace Kloba | c928c30 | 2009-09-17 11:51:21 -0700 | [diff] [blame] | 1731 | // this should only be called for the current tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1732 | private void attachTabToContentView(Tab t) { |
Steve Block | 2bc6991 | 2009-07-30 14:45:13 +0100 | [diff] [blame] | 1733 | // Attach the container that contains the main WebView and any other UI |
| 1734 | // associated with the tab. |
Patrick Scott | d011953 | 2009-09-17 08:00:31 -0400 | [diff] [blame] | 1735 | t.attachTabToContentView(mContentView); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1736 | |
| 1737 | if (mShouldShowErrorConsole) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1738 | ErrorConsoleView errorConsole = t.getErrorConsole(true); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1739 | if (errorConsole.numberOfErrors() == 0) { |
| 1740 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 1741 | } else { |
| 1742 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 1743 | } |
| 1744 | |
| 1745 | mErrorConsoleContainer.addView(errorConsole, |
Romain Guy | 15b8ec6 | 2010-01-08 15:06:43 -0800 | [diff] [blame] | 1746 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1747 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 1748 | } |
| 1749 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1750 | WebView view = t.getWebView(); |
| 1751 | view.setEmbeddedTitleBar(mTitleBar); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 1752 | if (t.isInVoiceSearchMode()) { |
| 1753 | showVoiceTitleBar(t.getVoiceDisplayTitle()); |
| 1754 | } else { |
| 1755 | revertVoiceTitleBar(); |
| 1756 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1757 | // Request focus on the top window. |
| 1758 | t.getTopWindow().requestFocus(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1759 | if (mTabControl.getTabChangeListener() != null) { |
| 1760 | mTabControl.getTabChangeListener().onCurrentTab(t); |
| 1761 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | // Attach a sub window to the main WebView of the given tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1765 | void attachSubWindow(Tab t) { |
Patrick Scott | d011953 | 2009-09-17 08:00:31 -0400 | [diff] [blame] | 1766 | t.attachSubWindow(mContentView); |
| 1767 | getTopWindow().requestFocus(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | // Remove the given tab from the content view. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1771 | private void removeTabFromContentView(Tab t) { |
Steve Block | 2bc6991 | 2009-07-30 14:45:13 +0100 | [diff] [blame] | 1772 | // Remove the container that contains the main WebView. |
Patrick Scott | d011953 | 2009-09-17 08:00:31 -0400 | [diff] [blame] | 1773 | t.removeTabFromContentView(mContentView); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1774 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1775 | ErrorConsoleView errorConsole = t.getErrorConsole(false); |
| 1776 | if (errorConsole != null) { |
| 1777 | mErrorConsoleContainer.removeView(errorConsole); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 1778 | } |
| 1779 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1780 | WebView view = t.getWebView(); |
| 1781 | if (view != null) { |
| 1782 | view.setEmbeddedTitleBar(null); |
Leon Scroggins | bb85b90 | 2009-09-14 19:27:20 -0400 | [diff] [blame] | 1783 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | // Remove the sub window if it exists. Also called by TabControl when the |
| 1787 | // user clicks the 'X' to dismiss a sub window. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1788 | /* package */ void dismissSubWindow(Tab t) { |
Patrick Scott | d011953 | 2009-09-17 08:00:31 -0400 | [diff] [blame] | 1789 | t.removeSubWindow(mContentView); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1790 | // dismiss the subwindow. This will destroy the WebView. |
| 1791 | t.dismissSubWindow(); |
Patrick Scott | d011953 | 2009-09-17 08:00:31 -0400 | [diff] [blame] | 1792 | getTopWindow().requestFocus(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1793 | } |
| 1794 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1795 | // A wrapper function of {@link #openTabAndShow(UrlData, boolean, String)} |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 1796 | // that accepts url as string. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1797 | private Tab openTabAndShow(String url, boolean closeOnExit, String appId) { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1798 | return openTabAndShow(new UrlData(url), closeOnExit, appId); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | // This method does a ton of stuff. It will attempt to create a new tab |
| 1802 | // if we haven't reached MAX_TABS. Otherwise it uses the current tab. If |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1803 | // url isn't null, it will load the given url. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1804 | /* package */Tab openTabAndShow(UrlData urlData, boolean closeOnExit, |
| 1805 | String appId) { |
| 1806 | final Tab currentTab = mTabControl.getCurrentTab(); |
| 1807 | if (mTabControl.canCreateNewTab()) { |
| 1808 | final Tab tab = mTabControl.createNewTab(closeOnExit, appId, |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 1809 | urlData.mUrl, false); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1810 | WebView webview = tab.getWebView(); |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 1811 | // If the last tab was removed from the active tabs page, currentTab |
| 1812 | // will be null. |
| 1813 | if (currentTab != null) { |
| 1814 | removeTabFromContentView(currentTab); |
| 1815 | } |
Patrick Scott | 8bbd69f | 2009-08-14 13:35:53 -0400 | [diff] [blame] | 1816 | // We must set the new tab as the current tab to reflect the old |
| 1817 | // animation behavior. |
| 1818 | mTabControl.setCurrentTab(tab); |
Grace Kloba | eb6eef4 | 2009-09-15 17:56:32 -0700 | [diff] [blame] | 1819 | attachTabToContentView(tab); |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 1820 | if (!urlData.isEmpty()) { |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 1821 | loadUrlDataIn(tab, urlData); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1822 | } |
| 1823 | return tab; |
| 1824 | } else { |
| 1825 | // Get rid of the subwindow if it exists |
| 1826 | dismissSubWindow(currentTab); |
| 1827 | if (!urlData.isEmpty()) { |
| 1828 | // Load the given url. |
Patrick Scott | 9d53da0 | 2010-02-19 10:19:01 -0500 | [diff] [blame] | 1829 | loadUrlDataIn(currentTab, urlData); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1830 | } |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 1831 | return currentTab; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1832 | } |
| 1833 | } |
| 1834 | |
Michael Kolb | 68792c8 | 2010-08-09 16:39:18 -0700 | [diff] [blame] | 1835 | private Tab openTab(String url, boolean forceForeground) { |
| 1836 | if (mSettings.openInBackground() && !forceForeground) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1837 | Tab t = mTabControl.createNewTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1838 | if (t != null) { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1839 | WebView view = t.getWebView(); |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 1840 | loadUrl(view, url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1841 | } |
Grace Kloba | c918184 | 2009-04-14 08:53:22 -0700 | [diff] [blame] | 1842 | return t; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1843 | } else { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 1844 | return openTabAndShow(url, false, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
Elliott Slaughter | f0f0395 | 2010-07-14 18:10:36 -0700 | [diff] [blame] | 1848 | /* package */ Tab openIncognitoTab() { |
| 1849 | if (mTabControl.canCreateNewTab()) { |
| 1850 | Tab currentTab = mTabControl.getCurrentTab(); |
| 1851 | Tab tab = mTabControl.createNewTab(false, null, null, true); |
| 1852 | if (currentTab != null) { |
| 1853 | removeTabFromContentView(currentTab); |
| 1854 | } |
| 1855 | mTabControl.setCurrentTab(tab); |
| 1856 | attachTabToContentView(tab); |
| 1857 | return tab; |
| 1858 | } |
| 1859 | return null; |
| 1860 | } |
| 1861 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1862 | private class Copy implements OnMenuItemClickListener { |
| 1863 | private CharSequence mText; |
| 1864 | |
| 1865 | public boolean onMenuItemClick(MenuItem item) { |
| 1866 | copy(mText); |
| 1867 | return true; |
| 1868 | } |
| 1869 | |
| 1870 | public Copy(CharSequence toCopy) { |
| 1871 | mText = toCopy; |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | private class Download implements OnMenuItemClickListener { |
| 1876 | private String mText; |
| 1877 | |
| 1878 | public boolean onMenuItemClick(MenuItem item) { |
| 1879 | onDownloadStartNoStream(mText, null, null, null, -1); |
| 1880 | return true; |
| 1881 | } |
| 1882 | |
| 1883 | public Download(String toDownload) { |
| 1884 | mText = toDownload; |
| 1885 | } |
| 1886 | } |
| 1887 | |
Ben Murdoch | 4f75ba2 | 2009-10-27 11:48:28 +0000 | [diff] [blame] | 1888 | private class SetAsWallpaper extends Thread implements |
| 1889 | OnMenuItemClickListener, DialogInterface.OnCancelListener { |
| 1890 | private URL mUrl; |
| 1891 | private ProgressDialog mWallpaperProgress; |
| 1892 | private boolean mCanceled = false; |
| 1893 | |
| 1894 | public SetAsWallpaper(String url) { |
| 1895 | try { |
| 1896 | mUrl = new URL(url); |
| 1897 | } catch (MalformedURLException e) { |
| 1898 | mUrl = null; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | public void onCancel(DialogInterface dialog) { |
| 1903 | mCanceled = true; |
| 1904 | } |
| 1905 | |
| 1906 | public boolean onMenuItemClick(MenuItem item) { |
| 1907 | if (mUrl != null) { |
| 1908 | // The user may have tried to set a image with a large file size as their |
| 1909 | // background so it may take a few moments to perform the operation. Display |
| 1910 | // a progress spinner while it is working. |
| 1911 | mWallpaperProgress = new ProgressDialog(BrowserActivity.this); |
| 1912 | mWallpaperProgress.setIndeterminate(true); |
| 1913 | mWallpaperProgress.setMessage(getText(R.string.progress_dialog_setting_wallpaper)); |
| 1914 | mWallpaperProgress.setCancelable(true); |
| 1915 | mWallpaperProgress.setOnCancelListener(this); |
| 1916 | mWallpaperProgress.show(); |
| 1917 | start(); |
| 1918 | } |
| 1919 | return true; |
| 1920 | } |
| 1921 | |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 1922 | @Override |
Ben Murdoch | 4f75ba2 | 2009-10-27 11:48:28 +0000 | [diff] [blame] | 1923 | public void run() { |
| 1924 | Drawable oldWallpaper = BrowserActivity.this.getWallpaper(); |
| 1925 | try { |
| 1926 | // TODO: This will cause the resource to be downloaded again, when we |
| 1927 | // should in most cases be able to grab it from the cache. To fix this |
| 1928 | // we should query WebCore to see if we can access a cached version and |
| 1929 | // instead open an input stream on that. This pattern could also be used |
| 1930 | // in the download manager where the same problem exists. |
| 1931 | InputStream inputstream = mUrl.openStream(); |
| 1932 | if (inputstream != null) { |
| 1933 | setWallpaper(inputstream); |
| 1934 | } |
| 1935 | } catch (IOException e) { |
| 1936 | Log.e(LOGTAG, "Unable to set new wallpaper"); |
| 1937 | // Act as though the user canceled the operation so we try to |
| 1938 | // restore the old wallpaper. |
| 1939 | mCanceled = true; |
| 1940 | } |
| 1941 | |
| 1942 | if (mCanceled) { |
| 1943 | // Restore the old wallpaper if the user cancelled whilst we were setting |
| 1944 | // the new wallpaper. |
| 1945 | int width = oldWallpaper.getIntrinsicWidth(); |
| 1946 | int height = oldWallpaper.getIntrinsicHeight(); |
| 1947 | Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); |
| 1948 | Canvas canvas = new Canvas(bm); |
| 1949 | oldWallpaper.setBounds(0, 0, width, height); |
| 1950 | oldWallpaper.draw(canvas); |
| 1951 | try { |
| 1952 | setWallpaper(bm); |
| 1953 | } catch (IOException e) { |
| 1954 | Log.e(LOGTAG, "Unable to restore old wallpaper."); |
| 1955 | } |
| 1956 | mCanceled = false; |
| 1957 | } |
| 1958 | |
| 1959 | if (mWallpaperProgress.isShowing()) { |
| 1960 | mWallpaperProgress.dismiss(); |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1965 | private void copy(CharSequence text) { |
Dianne Hackborn | 80f3262 | 2010-08-05 14:17:53 -0700 | [diff] [blame] | 1966 | ClipboardManager cm = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); |
| 1967 | cm.setText(text); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1971 | * Resets the browser title-view to whatever it must be |
| 1972 | * (for example, if we had a loading error) |
| 1973 | * When we have a new page, we call resetTitle, when we |
| 1974 | * have to reset the titlebar to whatever it used to be |
| 1975 | * (for example, if the user chose to stop loading), we |
| 1976 | * call resetTitleAndRevertLockIcon. |
| 1977 | */ |
| 1978 | /* package */ void resetTitleAndRevertLockIcon() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1979 | mTabControl.getCurrentTab().revertLockIcon(); |
| 1980 | updateLockIconToLatest(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1981 | resetTitleIconAndProgress(); |
| 1982 | } |
| 1983 | |
| 1984 | /** |
| 1985 | * Reset the title, favicon, and progress. |
| 1986 | */ |
| 1987 | private void resetTitleIconAndProgress() { |
| 1988 | WebView current = mTabControl.getCurrentWebView(); |
| 1989 | if (current == null) { |
| 1990 | return; |
| 1991 | } |
| 1992 | resetTitleAndIcon(current); |
| 1993 | int progress = current.getProgress(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1994 | current.getWebChromeClient().onProgressChanged(current, progress); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | // Reset the title and the icon based on the given item. |
| 1998 | private void resetTitleAndIcon(WebView view) { |
| 1999 | WebHistoryItem item = view.copyBackForwardList().getCurrentItem(); |
| 2000 | if (item != null) { |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 2001 | setUrlTitle(item.getUrl(), item.getTitle()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2002 | setFavicon(item.getFavicon()); |
| 2003 | } else { |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 2004 | setUrlTitle(null, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2005 | setFavicon(null); |
| 2006 | } |
| 2007 | } |
| 2008 | |
| 2009 | /** |
| 2010 | * Sets a title composed of the URL and the title string. |
| 2011 | * @param url The URL of the site being loaded. |
| 2012 | * @param title The title of the site being loaded. |
| 2013 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2014 | void setUrlTitle(String url, String title) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2015 | mUrl = url; |
| 2016 | mTitle = title; |
| 2017 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 2018 | // If we are in voice search mode, the title has already been set. |
| 2019 | if (mTabControl.getCurrentTab().isInVoiceSearchMode()) return; |
| 2020 | mTitleBar.setDisplayTitle(url); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 2021 | mFakeTitleBar.setDisplayTitle(url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2025 | * @param url The URL to build a title version of the URL from. |
| 2026 | * @return The title version of the URL or null if fails. |
| 2027 | * The title version of the URL can be either the URL hostname, |
| 2028 | * or the hostname with an "https://" prefix (for secure URLs), |
| 2029 | * or an empty string if, for example, the URL in question is a |
| 2030 | * file:// URL with no hostname. |
| 2031 | */ |
Leon Scroggins | 32e14a6 | 2009-06-11 10:26:34 -0400 | [diff] [blame] | 2032 | /* package */ static String buildTitleUrl(String url) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2033 | String titleUrl = null; |
| 2034 | |
| 2035 | if (url != null) { |
| 2036 | try { |
| 2037 | // parse the url string |
| 2038 | URL urlObj = new URL(url); |
| 2039 | if (urlObj != null) { |
| 2040 | titleUrl = ""; |
| 2041 | |
| 2042 | String protocol = urlObj.getProtocol(); |
| 2043 | String host = urlObj.getHost(); |
| 2044 | |
| 2045 | if (host != null && 0 < host.length()) { |
| 2046 | titleUrl = host; |
| 2047 | if (protocol != null) { |
| 2048 | // if a secure site, add an "https://" prefix! |
| 2049 | if (protocol.equalsIgnoreCase("https")) { |
| 2050 | titleUrl = protocol + "://" + host; |
| 2051 | } |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | } catch (MalformedURLException e) {} |
| 2056 | } |
| 2057 | |
| 2058 | return titleUrl; |
| 2059 | } |
| 2060 | |
| 2061 | // Set the favicon in the title bar. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2062 | void setFavicon(Bitmap icon) { |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 2063 | mTitleBar.setFavicon(icon); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 2064 | mFakeTitleBar.setFavicon(icon); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | /** |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 2068 | * Close the tab, remove its associated title bar, and adjust mTabControl's |
| 2069 | * current tab to a valid value. |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 2070 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2071 | /* package */ void closeTab(Tab t) { |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 2072 | int currentIndex = mTabControl.getCurrentIndex(); |
| 2073 | int removeIndex = mTabControl.getTabIndex(t); |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 2074 | mTabControl.removeTab(t); |
Leon Scroggins | 0a64ba5 | 2009-09-08 15:35:33 -0400 | [diff] [blame] | 2075 | if (currentIndex >= removeIndex && currentIndex != 0) { |
| 2076 | currentIndex--; |
| 2077 | } |
| 2078 | mTabControl.setCurrentTab(mTabControl.getTab(currentIndex)); |
Andrei Popescu | a5bf1de | 2009-09-23 16:39:23 +0100 | [diff] [blame] | 2079 | resetTitleIconAndProgress(); |
Leon Scroggins | 654899b | 2010-06-25 16:25:23 -0400 | [diff] [blame] | 2080 | updateLockIconToLatest(); |
Elliott Slaughter | e440a88 | 2010-08-20 13:54:45 -0700 | [diff] [blame] | 2081 | |
| 2082 | if (!mTabControl.hasAnyOpenIncognitoTabs()) { |
| 2083 | WebView.cleanupPrivateBrowsingFiles(this); |
| 2084 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2085 | } |
| 2086 | |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 2087 | /* package */ void goBackOnePageOrQuit() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2088 | Tab current = mTabControl.getCurrentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2089 | if (current == null) { |
| 2090 | /* |
| 2091 | * Instead of finishing the activity, simply push this to the back |
| 2092 | * of the stack and let ActivityManager to choose the foreground |
| 2093 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2094 | * root of the task. So we can use either true or false for |
| 2095 | * moveTaskToBack(). |
| 2096 | */ |
| 2097 | moveTaskToBack(true); |
Grace Kloba | 00d85e7 | 2009-09-23 18:50:05 -0700 | [diff] [blame] | 2098 | return; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2099 | } |
| 2100 | WebView w = current.getWebView(); |
| 2101 | if (w.canGoBack()) { |
| 2102 | w.goBack(); |
| 2103 | } else { |
| 2104 | // Check to see if we are closing a window that was created by |
| 2105 | // another window. If so, we switch back to that window. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2106 | Tab parent = current.getParentTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2107 | if (parent != null) { |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 2108 | switchToTab(mTabControl.getTabIndex(parent)); |
| 2109 | // Now we close the other tab |
| 2110 | closeTab(current); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2111 | } else { |
| 2112 | if (current.closeOnExit()) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2113 | // force the tab's inLoad() to be false as we are going to |
| 2114 | // either finish the activity or remove the tab. This will |
| 2115 | // ensure pauseWebViewTimers() taking action. |
| 2116 | mTabControl.getCurrentTab().clearInLoad(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2117 | if (mTabControl.getTabCount() == 1) { |
| 2118 | finish(); |
| 2119 | return; |
| 2120 | } |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 2121 | // call pauseWebViewTimers() now, we won't be able to call |
| 2122 | // it in onPause() as the WebView won't be valid. |
Grace Kloba | ec1b5ad | 2009-08-18 08:42:32 -0700 | [diff] [blame] | 2123 | // Temporarily change mActivityInPause to be true as |
| 2124 | // pauseWebViewTimers() will do nothing if mActivityInPause |
| 2125 | // is false. |
Grace Kloba | 918e1d7 | 2009-08-13 14:55:06 -0700 | [diff] [blame] | 2126 | boolean savedState = mActivityInPause; |
| 2127 | if (savedState) { |
Grace Kloba | ec1b5ad | 2009-08-18 08:42:32 -0700 | [diff] [blame] | 2128 | Log.e(LOGTAG, "BrowserActivity is already paused " |
| 2129 | + "while handing goBackOnePageOrQuit."); |
Grace Kloba | 918e1d7 | 2009-08-13 14:55:06 -0700 | [diff] [blame] | 2130 | } |
| 2131 | mActivityInPause = true; |
Mike Reed | 7bfa63b | 2009-05-28 11:08:32 -0400 | [diff] [blame] | 2132 | pauseWebViewTimers(); |
Grace Kloba | 918e1d7 | 2009-08-13 14:55:06 -0700 | [diff] [blame] | 2133 | mActivityInPause = savedState; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2134 | removeTabFromContentView(current); |
| 2135 | mTabControl.removeTab(current); |
| 2136 | } |
| 2137 | /* |
| 2138 | * Instead of finishing the activity, simply push this to the back |
| 2139 | * of the stack and let ActivityManager to choose the foreground |
| 2140 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2141 | * root of the task. So we can use either true or false for |
| 2142 | * moveTaskToBack(). |
| 2143 | */ |
| 2144 | moveTaskToBack(true); |
| 2145 | } |
| 2146 | } |
| 2147 | } |
| 2148 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2149 | boolean isMenuDown() { |
| 2150 | return mMenuIsDown; |
| 2151 | } |
| 2152 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2153 | @Override |
| 2154 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Leon Scroggins | f65b50d | 2009-12-08 10:44:28 -0500 | [diff] [blame] | 2155 | // Even if MENU is already held down, we need to call to super to open |
| 2156 | // the IME on long press. |
| 2157 | if (KeyEvent.KEYCODE_MENU == keyCode) { |
| 2158 | mMenuIsDown = true; |
| 2159 | return super.onKeyDown(keyCode, event); |
| 2160 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2161 | // The default key mode is DEFAULT_KEYS_SEARCH_LOCAL. As the MENU is |
| 2162 | // still down, we don't want to trigger the search. Pretend to consume |
| 2163 | // the key and do nothing. |
| 2164 | if (mMenuIsDown) return true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2165 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2166 | switch(keyCode) { |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2167 | case KeyEvent.KEYCODE_SPACE: |
Grace Kloba | da0fe55 | 2009-09-22 18:17:24 -0700 | [diff] [blame] | 2168 | // WebView/WebTextView handle the keys in the KeyDown. As |
| 2169 | // the Activity's shortcut keys are only handled when WebView |
| 2170 | // doesn't, have to do it in onKeyDown instead of onKeyUp. |
| 2171 | if (event.isShiftPressed()) { |
| 2172 | getTopWindow().pageUp(false); |
| 2173 | } else { |
| 2174 | getTopWindow().pageDown(false); |
| 2175 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2176 | return true; |
| 2177 | case KeyEvent.KEYCODE_BACK: |
| 2178 | if (event.getRepeatCount() == 0) { |
| 2179 | event.startTracking(); |
| 2180 | return true; |
| 2181 | } else if (mCustomView == null && mActiveTabsPage == null |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 2182 | && mComboView == null |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2183 | && event.isLongPress()) { |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 2184 | bookmarksOrHistoryPicker(true); |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2185 | return true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2186 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2187 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2188 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2189 | return super.onKeyDown(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2192 | @Override |
| 2193 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 2194 | switch(keyCode) { |
| 2195 | case KeyEvent.KEYCODE_MENU: |
| 2196 | mMenuIsDown = false; |
| 2197 | break; |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2198 | case KeyEvent.KEYCODE_BACK: |
| 2199 | if (event.isTracking() && !event.isCanceled()) { |
| 2200 | if (mCustomView != null) { |
| 2201 | // if a custom view is showing, hide it |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2202 | mTabControl.getCurrentWebView().getWebChromeClient() |
| 2203 | .onHideCustomView(); |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2204 | } else if (mActiveTabsPage != null) { |
| 2205 | // if tab page is showing, hide it |
| 2206 | removeActiveTabPage(true); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 2207 | } else if (mComboView != null) { |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 2208 | if (!mComboView.onBackPressed()) { |
| 2209 | removeComboView(); |
| 2210 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2211 | } else { |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2212 | WebView subwindow = mTabControl.getCurrentSubWindow(); |
| 2213 | if (subwindow != null) { |
| 2214 | if (subwindow.canGoBack()) { |
| 2215 | subwindow.goBack(); |
| 2216 | } else { |
| 2217 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 2218 | } |
| 2219 | } else { |
| 2220 | goBackOnePageOrQuit(); |
| 2221 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2222 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2223 | return true; |
| 2224 | } |
| 2225 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2226 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 2227 | return super.onKeyUp(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2228 | } |
| 2229 | |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 2230 | /* package */ void stopLoading() { |
Ben Murdoch | b7cc8b4 | 2009-09-28 10:59:09 +0100 | [diff] [blame] | 2231 | mDidStopLoad = true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2232 | resetTitleAndRevertLockIcon(); |
| 2233 | WebView w = getTopWindow(); |
| 2234 | w.stopLoading(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2235 | // FIXME: before refactor, it is using mWebViewClient. So I keep the |
| 2236 | // same logic here. But for subwindow case, should we call into the main |
| 2237 | // WebView's onPageFinished as we never call its onPageStarted and if |
| 2238 | // the page finishes itself, we don't call onPageFinished. |
| 2239 | mTabControl.getCurrentWebView().getWebViewClient().onPageFinished(w, |
| 2240 | w.getUrl()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2241 | |
| 2242 | cancelStopToast(); |
| 2243 | mStopToast = Toast |
| 2244 | .makeText(this, R.string.stopping, Toast.LENGTH_SHORT); |
| 2245 | mStopToast.show(); |
| 2246 | } |
| 2247 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2248 | boolean didUserStopLoading() { |
| 2249 | return mDidStopLoad; |
| 2250 | } |
| 2251 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2252 | private void cancelStopToast() { |
| 2253 | if (mStopToast != null) { |
| 2254 | mStopToast.cancel(); |
| 2255 | mStopToast = null; |
| 2256 | } |
| 2257 | } |
| 2258 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2259 | // called by a UI or non-UI thread to post the message |
| 2260 | public void postMessage(int what, int arg1, int arg2, Object obj, |
| 2261 | long delayMillis) { |
| 2262 | mHandler.sendMessageDelayed(mHandler.obtainMessage(what, arg1, arg2, |
| 2263 | obj), delayMillis); |
| 2264 | } |
| 2265 | |
| 2266 | // called by a UI or non-UI thread to remove the message |
| 2267 | void removeMessages(int what, Object object) { |
| 2268 | mHandler.removeMessages(what, object); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | // public message ids |
| 2272 | public final static int LOAD_URL = 1001; |
| 2273 | public final static int STOP_LOAD = 1002; |
| 2274 | |
| 2275 | // Message Ids |
| 2276 | private static final int FOCUS_NODE_HREF = 102; |
Grace Kloba | 92c18a5 | 2009-07-31 23:48:32 -0700 | [diff] [blame] | 2277 | private static final int RELEASE_WAKELOCK = 107; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2278 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2279 | static final int UPDATE_BOOKMARK_THUMBNAIL = 108; |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2280 | |
Michael Kolb | 300b7f0 | 2010-08-25 13:47:24 -0700 | [diff] [blame] | 2281 | private static final int OPEN_BOOKMARKS = 201; |
| 2282 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2283 | // Private handler for handling javascript and saving passwords |
| 2284 | private Handler mHandler = new Handler() { |
| 2285 | |
Michael Kolb | e0a3666 | 2010-06-29 10:37:12 -0700 | [diff] [blame] | 2286 | @Override |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2287 | public void handleMessage(Message msg) { |
| 2288 | switch (msg.what) { |
Michael Kolb | 300b7f0 | 2010-08-25 13:47:24 -0700 | [diff] [blame] | 2289 | case OPEN_BOOKMARKS: |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 2290 | bookmarksOrHistoryPicker(false); |
Michael Kolb | 300b7f0 | 2010-08-25 13:47:24 -0700 | [diff] [blame] | 2291 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2292 | case FOCUS_NODE_HREF: |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2293 | { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2294 | String url = (String) msg.getData().get("url"); |
Ben Murdoch | 90d088c | 2009-11-17 18:14:04 +0000 | [diff] [blame] | 2295 | String title = (String) msg.getData().get("title"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2296 | if (url == null || url.length() == 0) { |
| 2297 | break; |
| 2298 | } |
| 2299 | HashMap focusNodeMap = (HashMap) msg.obj; |
| 2300 | WebView view = (WebView) focusNodeMap.get("webview"); |
| 2301 | // Only apply the action if the top window did not change. |
| 2302 | if (getTopWindow() != view) { |
| 2303 | break; |
| 2304 | } |
| 2305 | switch (msg.arg1) { |
| 2306 | case R.id.open_context_menu_id: |
| 2307 | case R.id.view_image_context_menu_id: |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 2308 | loadUrlFromContext(getTopWindow(), url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2309 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2310 | case R.id.bookmark_context_menu_id: |
| 2311 | Intent intent = new Intent(BrowserActivity.this, |
| 2312 | AddBookmarkPage.class); |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 2313 | intent.putExtra(BrowserContract.Bookmarks.URL, url); |
| 2314 | intent.putExtra(BrowserContract.Bookmarks.TITLE, |
| 2315 | title); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2316 | startActivity(intent); |
| 2317 | break; |
| 2318 | case R.id.share_link_context_menu_id: |
Leon Scroggins | 3e20445 | 2010-05-10 11:06:03 -0400 | [diff] [blame] | 2319 | sharePage(BrowserActivity.this, title, url, null, |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 2320 | null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2321 | break; |
| 2322 | case R.id.copy_link_context_menu_id: |
| 2323 | copy(url); |
| 2324 | break; |
| 2325 | case R.id.save_link_context_menu_id: |
| 2326 | case R.id.download_context_menu_id: |
| 2327 | onDownloadStartNoStream(url, null, null, null, -1); |
| 2328 | break; |
| 2329 | } |
| 2330 | break; |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2331 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2332 | |
| 2333 | case LOAD_URL: |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 2334 | loadUrlFromContext(getTopWindow(), (String) msg.obj); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2335 | break; |
| 2336 | |
| 2337 | case STOP_LOAD: |
| 2338 | stopLoading(); |
| 2339 | break; |
| 2340 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2341 | case RELEASE_WAKELOCK: |
| 2342 | if (mWakeLock.isHeld()) { |
| 2343 | mWakeLock.release(); |
Grace Kloba | 5d0e02e | 2009-10-05 15:15:36 -0700 | [diff] [blame] | 2344 | // if we reach here, Browser should be still in the |
| 2345 | // background loading after WAKELOCK_TIMEOUT (5-min). |
| 2346 | // To avoid burning the battery, stop loading. |
| 2347 | mTabControl.stopAllLoading(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2348 | } |
| 2349 | break; |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2350 | |
| 2351 | case UPDATE_BOOKMARK_THUMBNAIL: |
| 2352 | WebView view = (WebView) msg.obj; |
| 2353 | if (view != null) { |
| 2354 | updateScreenshot(view); |
| 2355 | } |
| 2356 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2357 | } |
| 2358 | } |
| 2359 | }; |
| 2360 | |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 2361 | /** |
| 2362 | * Share a page, providing the title, url, favicon, and a screenshot. Uses |
| 2363 | * an {@link Intent} to launch the Activity chooser. |
| 2364 | * @param c Context used to launch a new Activity. |
| 2365 | * @param title Title of the page. Stored in the Intent with |
Paul Westbrook | 03e6d39 | 2010-02-12 10:33:29 -0800 | [diff] [blame] | 2366 | * {@link Intent#EXTRA_SUBJECT} |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 2367 | * @param url URL of the page. Stored in the Intent with |
| 2368 | * {@link Intent#EXTRA_TEXT} |
| 2369 | * @param favicon Bitmap of the favicon for the page. Stored in the Intent |
| 2370 | * with {@link Browser#EXTRA_SHARE_FAVICON} |
| 2371 | * @param screenshot Bitmap of a screenshot of the page. Stored in the |
| 2372 | * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT} |
| 2373 | */ |
| 2374 | public static final void sharePage(Context c, String title, String url, |
| 2375 | Bitmap favicon, Bitmap screenshot) { |
| 2376 | Intent send = new Intent(Intent.ACTION_SEND); |
| 2377 | send.setType("text/plain"); |
| 2378 | send.putExtra(Intent.EXTRA_TEXT, url); |
Paul Westbrook | 03e6d39 | 2010-02-12 10:33:29 -0800 | [diff] [blame] | 2379 | send.putExtra(Intent.EXTRA_SUBJECT, title); |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 2380 | send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon); |
| 2381 | send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot); |
| 2382 | try { |
| 2383 | c.startActivity(Intent.createChooser(send, c.getString( |
| 2384 | R.string.choosertitle_sharevia))); |
| 2385 | } catch(android.content.ActivityNotFoundException ex) { |
| 2386 | // if no app handles it, do nothing |
| 2387 | } |
| 2388 | } |
| 2389 | |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 2390 | private void updateScreenshot(WebView view) { |
| 2391 | // If this is a bookmarked site, add a screenshot to the database. |
| 2392 | // FIXME: When should we update? Every time? |
| 2393 | // FIXME: Would like to make sure there is actually something to |
| 2394 | // draw, but the API for that (WebViewCore.pictureReady()) is not |
| 2395 | // currently accessible here. |
Ben Murdoch | aac7aa6 | 2009-09-17 16:57:40 +0100 | [diff] [blame] | 2396 | |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 2397 | final Bitmap bm = createScreenshot(view, getDesiredThumbnailWidth(this), |
| 2398 | getDesiredThumbnailHeight(this)); |
Patrick Scott | cb192b5 | 2010-04-14 14:38:55 -0400 | [diff] [blame] | 2399 | if (bm == null) { |
| 2400 | return; |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 2401 | } |
Patrick Scott | cb192b5 | 2010-04-14 14:38:55 -0400 | [diff] [blame] | 2402 | |
| 2403 | final ContentResolver cr = getContentResolver(); |
| 2404 | final String url = view.getUrl(); |
| 2405 | final String originalUrl = view.getOriginalUrl(); |
| 2406 | |
| 2407 | new AsyncTask<Void, Void, Void>() { |
| 2408 | @Override |
| 2409 | protected Void doInBackground(Void... unused) { |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 2410 | Cursor cursor = null; |
Patrick Scott | cb192b5 | 2010-04-14 14:38:55 -0400 | [diff] [blame] | 2411 | try { |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 2412 | cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url); |
| 2413 | if (cursor != null && cursor.moveToFirst()) { |
| 2414 | final ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| 2415 | bm.compress(Bitmap.CompressFormat.PNG, 100, os); |
| 2416 | |
| 2417 | ContentValues values = new ContentValues(); |
| 2418 | values.put(Images.THUMBNAIL, os.toByteArray()); |
| 2419 | values.put(Images.URL, cursor.getString(0)); |
| 2420 | |
| 2421 | do { |
| 2422 | cr.update(Images.CONTENT_URI, values, null, null); |
| 2423 | } while (cursor.moveToNext()); |
Patrick Scott | cb192b5 | 2010-04-14 14:38:55 -0400 | [diff] [blame] | 2424 | } |
| 2425 | } catch (IllegalStateException e) { |
| 2426 | // Ignore |
| 2427 | } finally { |
Jeff Hamilton | 1a80565 | 2010-09-07 12:36:30 -0700 | [diff] [blame] | 2428 | if (cursor != null) cursor.close(); |
Patrick Scott | cb192b5 | 2010-04-14 14:38:55 -0400 | [diff] [blame] | 2429 | } |
| 2430 | return null; |
| 2431 | } |
| 2432 | }.execute(); |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 2433 | } |
| 2434 | |
Leon Scroggins | 06ec5f2 | 2009-09-17 12:46:04 -0400 | [diff] [blame] | 2435 | /** |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 2436 | * Return the desired width for thumbnail screenshots, which are stored in |
| 2437 | * the database, and used on the bookmarks screen. |
| 2438 | * @param context Context for finding out the density of the screen. |
Jeff Hamilton | f302637 | 2010-08-19 00:12:27 -0500 | [diff] [blame] | 2439 | * @return desired width for thumbnail screenshot. |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 2440 | */ |
| 2441 | /* package */ static int getDesiredThumbnailWidth(Context context) { |
Jeff Hamilton | f302637 | 2010-08-19 00:12:27 -0500 | [diff] [blame] | 2442 | return context.getResources().getDimensionPixelOffset(R.dimen.bookmarkThumbnailWidth); |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | /** |
| 2446 | * Return the desired height for thumbnail screenshots, which are stored in |
| 2447 | * the database, and used on the bookmarks screen. |
| 2448 | * @param context Context for finding out the density of the screen. |
Jeff Hamilton | f302637 | 2010-08-19 00:12:27 -0500 | [diff] [blame] | 2449 | * @return desired height for thumbnail screenshot. |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 2450 | */ |
| 2451 | /* package */ static int getDesiredThumbnailHeight(Context context) { |
Jeff Hamilton | f302637 | 2010-08-19 00:12:27 -0500 | [diff] [blame] | 2452 | return context.getResources().getDimensionPixelOffset(R.dimen.bookmarkThumbnailHeight); |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 2453 | } |
Leon Scroggins | 06ec5f2 | 2009-09-17 12:46:04 -0400 | [diff] [blame] | 2454 | |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 2455 | private Bitmap createScreenshot(WebView view, int width, int height) { |
Ben Murdoch | dcc2b6f | 2009-09-21 14:29:20 +0100 | [diff] [blame] | 2456 | Picture thumbnail = view.capturePicture(); |
Leon Scroggins | 4580057 | 2009-09-29 16:38:47 -0400 | [diff] [blame] | 2457 | if (thumbnail == null) { |
| 2458 | return null; |
| 2459 | } |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 2460 | Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); |
Ben Murdoch | dcc2b6f | 2009-09-21 14:29:20 +0100 | [diff] [blame] | 2461 | Canvas canvas = new Canvas(bm); |
| 2462 | // May need to tweak these values to determine what is the |
| 2463 | // best scale factor |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2464 | int thumbnailWidth = thumbnail.getWidth(); |
Ben Murdoch | ae59c3f | 2009-10-20 18:30:28 +0100 | [diff] [blame] | 2465 | int thumbnailHeight = thumbnail.getHeight(); |
| 2466 | float scaleFactorX = 1.0f; |
| 2467 | float scaleFactorY = 1.0f; |
Ben Murdoch | 2694e23 | 2009-09-29 09:41:11 +0100 | [diff] [blame] | 2468 | if (thumbnailWidth > 0) { |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 2469 | scaleFactorX = (float) width / (float)thumbnailWidth; |
Ben Murdoch | ae59c3f | 2009-10-20 18:30:28 +0100 | [diff] [blame] | 2470 | } else { |
| 2471 | return null; |
Leon Scroggins | 06ec5f2 | 2009-09-17 12:46:04 -0400 | [diff] [blame] | 2472 | } |
Ben Murdoch | ae59c3f | 2009-10-20 18:30:28 +0100 | [diff] [blame] | 2473 | |
| 2474 | if (view.getWidth() > view.getHeight() && |
| 2475 | thumbnailHeight < view.getHeight() && thumbnailHeight > 0) { |
| 2476 | // If the device is in landscape and the page is shorter |
| 2477 | // than the height of the view, stretch the thumbnail to fill the |
| 2478 | // space. |
Ben Murdoch | 87cc65d | 2010-06-29 20:34:10 +0100 | [diff] [blame] | 2479 | scaleFactorY = (float) height / (float)thumbnailHeight; |
Ben Murdoch | ae59c3f | 2009-10-20 18:30:28 +0100 | [diff] [blame] | 2480 | } else { |
| 2481 | // In the portrait case, this looks nice. |
| 2482 | scaleFactorY = scaleFactorX; |
| 2483 | } |
| 2484 | |
| 2485 | canvas.scale(scaleFactorX, scaleFactorY); |
| 2486 | |
Ben Murdoch | dcc2b6f | 2009-09-21 14:29:20 +0100 | [diff] [blame] | 2487 | thumbnail.draw(canvas); |
| 2488 | return bm; |
| 2489 | } |
| 2490 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2491 | // ------------------------------------------------------------------------- |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2492 | // Helper function for WebViewClient. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2493 | //------------------------------------------------------------------------- |
| 2494 | |
| 2495 | // Use in overrideUrlLoading |
| 2496 | /* package */ final static String SCHEME_WTAI = "wtai://wp/"; |
| 2497 | /* package */ final static String SCHEME_WTAI_MC = "wtai://wp/mc;"; |
| 2498 | /* package */ final static String SCHEME_WTAI_SD = "wtai://wp/sd;"; |
| 2499 | /* package */ final static String SCHEME_WTAI_AP = "wtai://wp/ap;"; |
| 2500 | |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 2501 | // Keep this initial progress in sync with initialProgressValue (* 100) |
| 2502 | // in ProgressTracker.cpp |
| 2503 | private final static int INITIAL_PROGRESS = 10; |
| 2504 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2505 | void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 2506 | // when BrowserActivity just starts, onPageStarted may be called before |
| 2507 | // onResume as it is triggered from onCreate. Call resumeWebViewTimers |
| 2508 | // to start the timer. As we won't switch tabs while an activity is in |
| 2509 | // pause state, we can ensure calling resume and pause in pair. |
| 2510 | if (mActivityInPause) resumeWebViewTimers(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2511 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2512 | resetLockIcon(url); |
| 2513 | setUrlTitle(url, null); |
| 2514 | setFavicon(favicon); |
Leon Scroggins | 8cf8f68 | 2009-11-04 11:13:50 -0800 | [diff] [blame] | 2515 | // Show some progress so that the user knows the page is beginning to |
| 2516 | // load |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 2517 | onProgressChanged(view, INITIAL_PROGRESS); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2518 | mDidStopLoad = false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2519 | if (!mIsNetworkUp) createAndShowNetworkDialog(); |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 2520 | endActionMode(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2521 | if (mSettings.isTracing()) { |
| 2522 | String host; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2523 | try { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2524 | WebAddress uri = new WebAddress(url); |
Bjorn Bringert | 131ab51 | 2010-10-12 16:25:47 +0100 | [diff] [blame] | 2525 | host = uri.getHost(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2526 | } catch (android.net.ParseException ex) { |
| 2527 | host = "browser"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2528 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2529 | host = host.replace('.', '_'); |
| 2530 | host += ".trace"; |
| 2531 | mInTrace = true; |
| 2532 | Debug.startMethodTracing(host, 20 * 1024 * 1024); |
| 2533 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2534 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2535 | // Performance probe |
| 2536 | if (false) { |
| 2537 | mStart = SystemClock.uptimeMillis(); |
| 2538 | mProcessStart = Process.getElapsedCpuTime(); |
| 2539 | long[] sysCpu = new long[7]; |
| 2540 | if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null, |
| 2541 | sysCpu, null)) { |
| 2542 | mUserStart = sysCpu[0] + sysCpu[1]; |
| 2543 | mSystemStart = sysCpu[2]; |
| 2544 | mIdleStart = sysCpu[3]; |
| 2545 | mIrqStart = sysCpu[4] + sysCpu[5] + sysCpu[6]; |
| 2546 | } |
| 2547 | mUiStart = SystemClock.currentThreadTimeMillis(); |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | void onPageFinished(WebView view, String url) { |
| 2552 | // Reset the title and icon in case we stopped a provisional load. |
| 2553 | resetTitleAndIcon(view); |
| 2554 | // Update the lock icon image only once we are done loading |
| 2555 | updateLockIconToLatest(); |
| 2556 | // pause the WebView timer and release the wake lock if it is finished |
| 2557 | // while BrowserActivity is in pause state. |
| 2558 | if (mActivityInPause && pauseWebViewTimers()) { |
| 2559 | if (mWakeLock.isHeld()) { |
| 2560 | mHandler.removeMessages(RELEASE_WAKELOCK); |
| 2561 | mWakeLock.release(); |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | // Performance probe |
| 2566 | if (false) { |
| 2567 | long[] sysCpu = new long[7]; |
| 2568 | if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null, |
| 2569 | sysCpu, null)) { |
| 2570 | String uiInfo = "UI thread used " |
| 2571 | + (SystemClock.currentThreadTimeMillis() - mUiStart) |
| 2572 | + " ms"; |
| 2573 | if (LOGD_ENABLED) { |
| 2574 | Log.d(LOGTAG, uiInfo); |
| 2575 | } |
| 2576 | //The string that gets written to the log |
| 2577 | String performanceString = "It took total " |
| 2578 | + (SystemClock.uptimeMillis() - mStart) |
| 2579 | + " ms clock time to load the page." |
| 2580 | + "\nbrowser process used " |
| 2581 | + (Process.getElapsedCpuTime() - mProcessStart) |
| 2582 | + " ms, user processes used " |
| 2583 | + (sysCpu[0] + sysCpu[1] - mUserStart) * 10 |
| 2584 | + " ms, kernel used " |
| 2585 | + (sysCpu[2] - mSystemStart) * 10 |
| 2586 | + " ms, idle took " + (sysCpu[3] - mIdleStart) * 10 |
| 2587 | + " ms and irq took " |
| 2588 | + (sysCpu[4] + sysCpu[5] + sysCpu[6] - mIrqStart) |
| 2589 | * 10 + " ms, " + uiInfo; |
| 2590 | if (LOGD_ENABLED) { |
| 2591 | Log.d(LOGTAG, performanceString + "\nWebpage: " + url); |
| 2592 | } |
| 2593 | if (url != null) { |
| 2594 | // strip the url to maintain consistency |
| 2595 | String newUrl = new String(url); |
| 2596 | if (newUrl.startsWith("http://www.")) { |
| 2597 | newUrl = newUrl.substring(11); |
| 2598 | } else if (newUrl.startsWith("http://")) { |
| 2599 | newUrl = newUrl.substring(7); |
| 2600 | } else if (newUrl.startsWith("https://www.")) { |
| 2601 | newUrl = newUrl.substring(12); |
| 2602 | } else if (newUrl.startsWith("https://")) { |
| 2603 | newUrl = newUrl.substring(8); |
| 2604 | } |
| 2605 | if (LOGD_ENABLED) { |
| 2606 | Log.d(LOGTAG, newUrl + " loaded"); |
| 2607 | } |
Grace Kloba | 5b078b5 | 2009-06-24 20:23:41 -0700 | [diff] [blame] | 2608 | } |
| 2609 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2610 | } |
Grace Kloba | 5b078b5 | 2009-06-24 20:23:41 -0700 | [diff] [blame] | 2611 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2612 | if (mInTrace) { |
| 2613 | mInTrace = false; |
| 2614 | Debug.stopMethodTracing(); |
| 2615 | } |
| 2616 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2617 | |
Grace Kloba | e7fe26b | 2010-06-28 16:23:33 -0700 | [diff] [blame] | 2618 | private void closeEmptyChildTab() { |
| 2619 | Tab current = mTabControl.getCurrentTab(); |
| 2620 | if (current != null |
| 2621 | && current.getWebView().copyBackForwardList().getSize() == 0) { |
| 2622 | Tab parent = current.getParentTab(); |
| 2623 | if (parent != null) { |
| 2624 | switchToTab(mTabControl.getTabIndex(parent)); |
| 2625 | closeTab(current); |
| 2626 | } |
| 2627 | } |
| 2628 | } |
| 2629 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2630 | boolean shouldOverrideUrlLoading(WebView view, String url) { |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 2631 | if (view.isPrivateBrowsingEnabled()) { |
| 2632 | // Don't allow urls to leave the browser app when in private browsing mode |
| 2633 | loadUrl(view, url); |
| 2634 | return true; |
| 2635 | } |
| 2636 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2637 | if (url.startsWith(SCHEME_WTAI)) { |
| 2638 | // wtai://wp/mc;number |
| 2639 | // number=string(phone-number) |
| 2640 | if (url.startsWith(SCHEME_WTAI_MC)) { |
| 2641 | Intent intent = new Intent(Intent.ACTION_VIEW, |
| 2642 | Uri.parse(WebView.SCHEME_TEL + |
| 2643 | url.substring(SCHEME_WTAI_MC.length()))); |
| 2644 | startActivity(intent); |
Grace Kloba | e7fe26b | 2010-06-28 16:23:33 -0700 | [diff] [blame] | 2645 | // before leaving BrowserActivity, close the empty child tab. |
| 2646 | // If a new tab is created through JavaScript open to load this |
| 2647 | // url, we would like to close it as we will load this url in a |
| 2648 | // different Activity. |
| 2649 | closeEmptyChildTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2650 | return true; |
| 2651 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2652 | // wtai://wp/sd;dtmf |
| 2653 | // dtmf=string(dialstring) |
| 2654 | if (url.startsWith(SCHEME_WTAI_SD)) { |
| 2655 | // TODO: only send when there is active voice connection |
| 2656 | return false; |
| 2657 | } |
| 2658 | // wtai://wp/ap;number;name |
| 2659 | // number=string(phone-number) |
| 2660 | // name=string |
| 2661 | if (url.startsWith(SCHEME_WTAI_AP)) { |
| 2662 | // TODO |
| 2663 | return false; |
| 2664 | } |
| 2665 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2666 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2667 | // The "about:" schemes are internal to the browser; don't want these to |
| 2668 | // be dispatched to other apps. |
| 2669 | if (url.startsWith("about:")) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2670 | return false; |
| 2671 | } |
| 2672 | |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 2673 | // If this is a Google search, attempt to add an RLZ string (if one isn't already present). |
| 2674 | if (rlzProviderPresent()) { |
| 2675 | Uri siteUri = Uri.parse(url); |
| 2676 | if (needsRlzString(siteUri)) { |
| 2677 | String rlz = null; |
| 2678 | Cursor cur = null; |
| 2679 | try { |
| 2680 | cur = getContentResolver().query(getRlzUri(), null, null, null, null); |
| 2681 | if (cur != null && cur.moveToFirst() && !cur.isNull(0)) { |
| 2682 | url = siteUri.buildUpon() |
| 2683 | .appendQueryParameter("rlz", cur.getString(0)) |
| 2684 | .build().toString(); |
| 2685 | } |
| 2686 | } finally { |
| 2687 | if (cur != null) { |
| 2688 | cur.close(); |
| 2689 | } |
| 2690 | } |
| 2691 | loadUrl(view, url); |
| 2692 | return true; |
| 2693 | } |
| 2694 | } |
| 2695 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2696 | Intent intent; |
| 2697 | // perform generic parsing of the URI to turn it into an Intent. |
| 2698 | try { |
| 2699 | intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 2700 | } catch (URISyntaxException ex) { |
| 2701 | Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage()); |
| 2702 | return false; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2703 | } |
| 2704 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2705 | // check whether the intent can be resolved. If not, we will see |
| 2706 | // whether we can download it from the Market. |
| 2707 | if (getPackageManager().resolveActivity(intent, 0) == null) { |
| 2708 | String packagename = intent.getPackage(); |
| 2709 | if (packagename != null) { |
| 2710 | intent = new Intent(Intent.ACTION_VIEW, Uri |
| 2711 | .parse("market://search?q=pname:" + packagename)); |
| 2712 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| 2713 | startActivity(intent); |
Grace Kloba | e7fe26b | 2010-06-28 16:23:33 -0700 | [diff] [blame] | 2714 | // before leaving BrowserActivity, close the empty child tab. |
| 2715 | // If a new tab is created through JavaScript open to load this |
| 2716 | // url, we would like to close it as we will load this url in a |
| 2717 | // different Activity. |
| 2718 | closeEmptyChildTab(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2719 | return true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2720 | } else { |
| 2721 | return false; |
| 2722 | } |
| 2723 | } |
| 2724 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2725 | // sanitize the Intent, ensuring web pages can not bypass browser |
| 2726 | // security (only access to BROWSABLE activities). |
| 2727 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| 2728 | intent.setComponent(null); |
| 2729 | try { |
| 2730 | if (startActivityIfNeeded(intent, -1)) { |
Grace Kloba | e7fe26b | 2010-06-28 16:23:33 -0700 | [diff] [blame] | 2731 | // before leaving BrowserActivity, close the empty child tab. |
| 2732 | // If a new tab is created through JavaScript open to load this |
| 2733 | // url, we would like to close it as we will load this url in a |
| 2734 | // different Activity. |
| 2735 | closeEmptyChildTab(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2736 | return true; |
| 2737 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2738 | } catch (ActivityNotFoundException ex) { |
| 2739 | // ignore the error. If no application can handle the URL, |
| 2740 | // eg about:blank, assume the browser can handle it. |
| 2741 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2742 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2743 | if (mMenuIsDown) { |
Michael Kolb | 68792c8 | 2010-08-09 16:39:18 -0700 | [diff] [blame] | 2744 | openTab(url, false); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2745 | closeOptionsMenu(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2746 | return true; |
| 2747 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2748 | return false; |
| 2749 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2750 | |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 2751 | // Determine whether the RLZ provider is present on the system. |
| 2752 | private boolean rlzProviderPresent() { |
| 2753 | if (mIsProviderPresent == null) { |
| 2754 | PackageManager pm = getPackageManager(); |
| 2755 | mIsProviderPresent = pm.resolveContentProvider(BrowserSettings.RLZ_PROVIDER, 0) != null; |
| 2756 | } |
| 2757 | return mIsProviderPresent; |
| 2758 | } |
| 2759 | |
| 2760 | // Retrieve the RLZ access point string and cache the URI used to retrieve RLZ values. |
| 2761 | private Uri getRlzUri() { |
| 2762 | if (mRlzUri == null) { |
| 2763 | String ap = getResources().getString(R.string.rlz_access_point); |
| 2764 | mRlzUri = Uri.withAppendedPath(BrowserSettings.RLZ_PROVIDER_URI, ap); |
| 2765 | } |
| 2766 | return mRlzUri; |
| 2767 | } |
| 2768 | |
| 2769 | // Determine if this URI appears to be for a Google search and does not have an RLZ parameter. |
| 2770 | // Taken largely from Chrome source, src/chrome/browser/google_url_tracker.cc |
| 2771 | private static boolean needsRlzString(Uri uri) { |
Bill Napier | c50e71a | 2010-08-27 14:03:03 -0700 | [diff] [blame] | 2772 | String scheme = uri.getScheme(); |
| 2773 | if (("http".equals(scheme) || "https".equals(scheme)) && |
| 2774 | (uri.getQueryParameter("q") != null) && (uri.getQueryParameter("rlz") == null)) { |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 2775 | String host = uri.getHost(); |
| 2776 | if (host == null) { |
| 2777 | return false; |
| 2778 | } |
| 2779 | String[] hostComponents = host.split("\\."); |
| 2780 | |
| 2781 | if (hostComponents.length < 2) { |
| 2782 | return false; |
| 2783 | } |
| 2784 | int googleComponent = hostComponents.length - 2; |
| 2785 | String component = hostComponents[googleComponent]; |
| 2786 | if (!"google".equals(component)) { |
| 2787 | if (hostComponents.length < 3 || |
| 2788 | (!"co".equals(component) && !"com".equals(component))) { |
| 2789 | return false; |
| 2790 | } |
| 2791 | googleComponent = hostComponents.length - 3; |
| 2792 | if (!"google".equals(hostComponents[googleComponent])) { |
| 2793 | return false; |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | // Google corp network handling. |
| 2798 | if (googleComponent > 0 && "corp".equals(hostComponents[googleComponent - 1])) { |
| 2799 | return false; |
| 2800 | } |
| 2801 | |
| 2802 | return true; |
| 2803 | } |
| 2804 | return false; |
| 2805 | } |
| 2806 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2807 | // ------------------------------------------------------------------------- |
| 2808 | // Helper function for WebChromeClient |
| 2809 | // ------------------------------------------------------------------------- |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2810 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2811 | void onProgressChanged(WebView view, int newProgress) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 2812 | |
| 2813 | // On the phone, the fake title bar will always cover up the |
| 2814 | // regular title bar (or the regular one is offscreen), so only the |
| 2815 | // fake title bar needs to change its progress |
| 2816 | mFakeTitleBar.setProgress(newProgress); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2817 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2818 | if (newProgress == 100) { |
| 2819 | // onProgressChanged() may continue to be called after the main |
| 2820 | // frame has finished loading, as any remaining sub frames continue |
| 2821 | // to load. We'll only get called once though with newProgress as |
| 2822 | // 100 when everything is loaded. (onPageFinished is called once |
| 2823 | // when the main frame completes loading regardless of the state of |
| 2824 | // any sub frames so calls to onProgressChanges may continue after |
| 2825 | // onPageFinished has executed) |
| 2826 | if (mInLoad) { |
| 2827 | mInLoad = false; |
Leon Scroggins | a27ff19 | 2009-09-14 12:58:04 -0400 | [diff] [blame] | 2828 | updateInLoadMenuItems(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2829 | // If the options menu is open, leave the title bar |
| 2830 | if (!mOptionsMenuOpen || !mIconView) { |
| 2831 | hideFakeTitleBar(); |
The Android Open Source Project | cb9a0bb | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2832 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2833 | } |
Leon Scroggins | aa37e7f | 2010-03-05 11:51:20 -0500 | [diff] [blame] | 2834 | } else { |
| 2835 | if (!mInLoad) { |
| 2836 | // onPageFinished may have already been called but a subframe is |
| 2837 | // still loading and updating the progress. Reset mInLoad and |
| 2838 | // update the menu items. |
| 2839 | mInLoad = true; |
| 2840 | updateInLoadMenuItems(); |
| 2841 | } |
| 2842 | // When the page first begins to load, the Activity may still be |
| 2843 | // paused, in which case showFakeTitleBar will do nothing. Call |
| 2844 | // again as the page continues to load so that it will be shown. |
| 2845 | // (Calling it will the fake title bar is already showing will also |
| 2846 | // do nothing. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2847 | if (!mOptionsMenuOpen || mIconView) { |
| 2848 | // This page has begun to load, so show the title bar |
| 2849 | showFakeTitleBar(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2850 | } |
| 2851 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2852 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2853 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2854 | void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { |
Derek Sollenberger | 8ff57db | 2009-12-08 15:39:55 -0500 | [diff] [blame] | 2855 | // if a view already exists then immediately terminate the new one |
| 2856 | if (mCustomView != null) { |
| 2857 | callback.onCustomViewHidden(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2858 | return; |
Derek Sollenberger | 8ff57db | 2009-12-08 15:39:55 -0500 | [diff] [blame] | 2859 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2860 | |
| 2861 | // Add the custom view to its container. |
| 2862 | mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER); |
| 2863 | mCustomView = view; |
| 2864 | mCustomViewCallback = callback; |
| 2865 | // Save the menu state and set it to empty while the custom |
| 2866 | // view is showing. |
| 2867 | mOldMenuState = mMenuState; |
| 2868 | mMenuState = EMPTY_MENU; |
| 2869 | // Hide the content view. |
| 2870 | mContentView.setVisibility(View.GONE); |
| 2871 | // Finally show the custom view container. |
Andrei Popescu | 163ab74 | 2009-10-20 17:58:23 +0100 | [diff] [blame] | 2872 | setStatusBarVisibility(false); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2873 | mCustomViewContainer.setVisibility(View.VISIBLE); |
| 2874 | mCustomViewContainer.bringToFront(); |
| 2875 | } |
| 2876 | |
| 2877 | void onHideCustomView() { |
| 2878 | if (mCustomView == null) |
| 2879 | return; |
| 2880 | |
| 2881 | // Hide the custom view. |
| 2882 | mCustomView.setVisibility(View.GONE); |
| 2883 | // Remove the custom view from its container. |
| 2884 | mCustomViewContainer.removeView(mCustomView); |
| 2885 | mCustomView = null; |
| 2886 | // Reset the old menu state. |
| 2887 | mMenuState = mOldMenuState; |
| 2888 | mOldMenuState = EMPTY_MENU; |
| 2889 | mCustomViewContainer.setVisibility(View.GONE); |
| 2890 | mCustomViewCallback.onCustomViewHidden(); |
| 2891 | // Show the content view. |
Andrei Popescu | 163ab74 | 2009-10-20 17:58:23 +0100 | [diff] [blame] | 2892 | setStatusBarVisibility(true); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2893 | mContentView.setVisibility(View.VISIBLE); |
| 2894 | } |
| 2895 | |
| 2896 | Bitmap getDefaultVideoPoster() { |
| 2897 | if (mDefaultVideoPoster == null) { |
| 2898 | mDefaultVideoPoster = BitmapFactory.decodeResource( |
| 2899 | getResources(), R.drawable.default_video_poster); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 2900 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2901 | return mDefaultVideoPoster; |
| 2902 | } |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 2903 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2904 | View getVideoLoadingProgressView() { |
| 2905 | if (mVideoProgressView == null) { |
| 2906 | LayoutInflater inflater = LayoutInflater.from(BrowserActivity.this); |
| 2907 | mVideoProgressView = inflater.inflate( |
| 2908 | R.layout.video_loading_progress, null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2909 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2910 | return mVideoProgressView; |
| 2911 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 2912 | |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 2913 | /* |
| 2914 | * The Object used to inform the WebView of the file to upload. |
| 2915 | */ |
| 2916 | private ValueCallback<Uri> mUploadMessage; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2917 | private String mCameraFilePath; |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 2918 | |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2919 | void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { |
| 2920 | |
| 2921 | final String imageMimeType = "image/*"; |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2922 | final String videoMimeType = "video/*"; |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 2923 | final String audioMimeType = "audio/*"; |
Ben Murdoch | b50d740 | 2010-07-16 12:42:22 +0100 | [diff] [blame] | 2924 | final String mediaSourceKey = "capture"; |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2925 | final String mediaSourceValueCamera = "camera"; |
Ben Murdoch | b50d740 | 2010-07-16 12:42:22 +0100 | [diff] [blame] | 2926 | final String mediaSourceValueFileSystem = "filesystem"; |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2927 | final String mediaSourceValueCamcorder = "camcorder"; |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 2928 | final String mediaSourceValueMicrophone = "microphone"; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2929 | |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 2930 | // media source can be 'filesystem' or 'camera' or 'camcorder' or 'microphone'. |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2931 | String mediaSource = ""; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2932 | |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2933 | // We add the camera intent if there was no accept type (or '*/*' or 'image/*'). |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2934 | boolean addCameraIntent = true; |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2935 | // We add the camcorder intent if there was no accept type (or '*/*' or 'video/*'). |
| 2936 | boolean addCamcorderIntent = true; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2937 | |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2938 | if (mUploadMessage != null) { |
| 2939 | // Already a file picker operation in progress. |
| 2940 | return; |
| 2941 | } |
| 2942 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2943 | mUploadMessage = uploadMsg; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2944 | |
| 2945 | // Parse the accept type. |
| 2946 | String params[] = acceptType.split(";"); |
| 2947 | String mimeType = params[0]; |
| 2948 | |
| 2949 | for (String p : params) { |
| 2950 | String[] keyValue = p.split("="); |
| 2951 | if (keyValue.length == 2) { |
| 2952 | // Process key=value parameters. |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2953 | if (mediaSourceKey.equals(keyValue[0])) { |
| 2954 | mediaSource = keyValue[1]; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | // This intent will display the standard OPENABLE file picker. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2960 | Intent i = new Intent(Intent.ACTION_GET_CONTENT); |
| 2961 | i.addCategory(Intent.CATEGORY_OPENABLE); |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2962 | |
| 2963 | // Create an intent to add to the standard file picker that will |
| 2964 | // capture an image from the camera. We'll combine this intent with |
| 2965 | // the standard OPENABLE picker unless the web developer specifically |
| 2966 | // requested the camera or gallery be opened by passing a parameter |
| 2967 | // in the accept type. |
| 2968 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
| 2969 | File externalDataDir = Environment.getExternalStoragePublicDirectory( |
| 2970 | Environment.DIRECTORY_DCIM); |
| 2971 | File cameraDataDir = new File(externalDataDir.getAbsolutePath() + |
| 2972 | File.separator + "browser-photos"); |
| 2973 | cameraDataDir.mkdirs(); |
| 2974 | mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator + |
| 2975 | System.currentTimeMillis() + ".jpg"; |
| 2976 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath))); |
| 2977 | |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2978 | Intent camcorderIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
| 2979 | |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 2980 | Intent soundRecIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); |
| 2981 | |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2982 | if (mimeType.equals(imageMimeType)) { |
| 2983 | i.setType(imageMimeType); |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2984 | addCamcorderIntent = false; |
| 2985 | if (mediaSource.equals(mediaSourceValueCamera)) { |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2986 | // Specified 'image/*' and requested the camera, so go ahead and launch the camera |
| 2987 | // directly. |
| 2988 | BrowserActivity.this.startActivityForResult(cameraIntent, FILE_SELECTED); |
| 2989 | return; |
Ben Murdoch | b50d740 | 2010-07-16 12:42:22 +0100 | [diff] [blame] | 2990 | } else if (mediaSource.equals(mediaSourceValueFileSystem)) { |
| 2991 | // Specified filesytem as the source, so don't want to consider the camera. |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 2992 | addCameraIntent = false; |
| 2993 | } |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 2994 | } else if (mimeType.equals(videoMimeType)) { |
| 2995 | i.setType(videoMimeType); |
| 2996 | addCameraIntent = false; |
| 2997 | // The camcorder saves it's own file and returns it to us in the intent, so |
| 2998 | // we don't need to generate one here. |
| 2999 | mCameraFilePath = null; |
| 3000 | |
| 3001 | if (mediaSource.equals(mediaSourceValueCamcorder)) { |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 3002 | // Specified 'video/*' and requested the camcorder, so go ahead and launch the |
| 3003 | // camcorder directly. |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 3004 | BrowserActivity.this.startActivityForResult(camcorderIntent, FILE_SELECTED); |
| 3005 | return; |
Ben Murdoch | b50d740 | 2010-07-16 12:42:22 +0100 | [diff] [blame] | 3006 | } else if (mediaSource.equals(mediaSourceValueFileSystem)) { |
| 3007 | // Specified filesystem as the source, so don't want to consider the camcorder. |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 3008 | addCamcorderIntent = false; |
| 3009 | } |
Ben Murdoch | 039bd47 | 2010-07-21 21:26:57 +0100 | [diff] [blame] | 3010 | } else if (mimeType.equals(audioMimeType)) { |
| 3011 | i.setType(audioMimeType); |
| 3012 | addCameraIntent = false; |
| 3013 | addCamcorderIntent = false; |
| 3014 | if (mediaSource.equals(mediaSourceValueMicrophone)) { |
| 3015 | // Specified 'audio/*' and requested microphone, so go ahead and launch the sound |
| 3016 | // recorder. |
| 3017 | BrowserActivity.this.startActivityForResult(soundRecIntent, FILE_SELECTED); |
| 3018 | return; |
| 3019 | } |
| 3020 | // On a default system, there is no single option to open an audio "gallery". Both the |
| 3021 | // sound recorder and music browser respond to the OPENABLE/audio/* intent unlike the |
| 3022 | // image/* and video/* OPENABLE intents where the image / video gallery are the only |
| 3023 | // respondants (and so the user is not prompted by default). |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3024 | } else { |
| 3025 | i.setType("*/*"); |
| 3026 | } |
| 3027 | |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 3028 | // Combine the chooser and the extra choices (like camera or camcorder) |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3029 | Intent chooser = new Intent(Intent.ACTION_CHOOSER); |
| 3030 | chooser.putExtra(Intent.EXTRA_INTENT, i); |
| 3031 | |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 3032 | Vector<Intent> extraInitialIntents = new Vector<Intent>(0); |
| 3033 | |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3034 | if (addCameraIntent) { |
Ben Murdoch | 6af492a | 2010-06-15 12:38:17 +0100 | [diff] [blame] | 3035 | extraInitialIntents.add(cameraIntent); |
| 3036 | } |
| 3037 | |
| 3038 | if (addCamcorderIntent) { |
| 3039 | extraInitialIntents.add(camcorderIntent); |
| 3040 | } |
| 3041 | |
| 3042 | if (extraInitialIntents.size() > 0) { |
| 3043 | Intent[] extraIntents = new Intent[extraInitialIntents.size()]; |
| 3044 | chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraInitialIntents.toArray(extraIntents)); |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3045 | } |
| 3046 | |
| 3047 | chooser.putExtra(Intent.EXTRA_TITLE, getString(R.string.choose_upload)); |
| 3048 | BrowserActivity.this.startActivityForResult(chooser, FILE_SELECTED); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | // ------------------------------------------------------------------------- |
| 3052 | // Implement functions for DownloadListener |
| 3053 | // ------------------------------------------------------------------------- |
| 3054 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3055 | /** |
| 3056 | * Notify the host application a download should be done, or that |
| 3057 | * the data should be streamed if a streaming viewer is available. |
| 3058 | * @param url The full url to the content that should be downloaded |
| 3059 | * @param contentDisposition Content-disposition http header, if |
| 3060 | * present. |
| 3061 | * @param mimetype The mimetype of the content reported by the server |
| 3062 | * @param contentLength The file size reported by the server |
| 3063 | */ |
| 3064 | public void onDownloadStart(String url, String userAgent, |
| 3065 | String contentDisposition, String mimetype, long contentLength) { |
| 3066 | // if we're dealing wih A/V content that's not explicitly marked |
| 3067 | // for download, check if it's streamable. |
| 3068 | if (contentDisposition == null |
Patrick Scott | e1fb966 | 2009-08-31 14:31:52 -0400 | [diff] [blame] | 3069 | || !contentDisposition.regionMatches( |
| 3070 | true, 0, "attachment", 0, 10)) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3071 | // query the package manager to see if there's a registered handler |
| 3072 | // that matches. |
| 3073 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 3074 | intent.setDataAndType(Uri.parse(url), mimetype); |
Patrick Scott | e1fb966 | 2009-08-31 14:31:52 -0400 | [diff] [blame] | 3075 | ResolveInfo info = getPackageManager().resolveActivity(intent, |
| 3076 | PackageManager.MATCH_DEFAULT_ONLY); |
| 3077 | if (info != null) { |
| 3078 | ComponentName myName = getComponentName(); |
| 3079 | // If we resolved to ourselves, we don't want to attempt to |
| 3080 | // load the url only to try and download it again. |
| 3081 | if (!myName.getPackageName().equals( |
| 3082 | info.activityInfo.packageName) |
| 3083 | || !myName.getClassName().equals( |
| 3084 | info.activityInfo.name)) { |
| 3085 | // someone (other than us) knows how to handle this mime |
| 3086 | // type with this scheme, don't download. |
| 3087 | try { |
| 3088 | startActivity(intent); |
| 3089 | return; |
| 3090 | } catch (ActivityNotFoundException ex) { |
| 3091 | if (LOGD_ENABLED) { |
| 3092 | Log.d(LOGTAG, "activity not found for " + mimetype |
| 3093 | + " over " + Uri.parse(url).getScheme(), |
| 3094 | ex); |
| 3095 | } |
| 3096 | // Best behavior is to fall back to a download in this |
| 3097 | // case |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3098 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3099 | } |
| 3100 | } |
| 3101 | } |
| 3102 | onDownloadStartNoStream(url, userAgent, contentDisposition, mimetype, contentLength); |
| 3103 | } |
| 3104 | |
Kristian Monsen | fa52d17 | 2010-03-25 18:29:21 +0000 | [diff] [blame] | 3105 | // This is to work around the fact that java.net.URI throws Exceptions |
| 3106 | // instead of just encoding URL's properly |
| 3107 | // Helper method for onDownloadStartNoStream |
| 3108 | private static String encodePath(String path) { |
| 3109 | char[] chars = path.toCharArray(); |
| 3110 | |
| 3111 | boolean needed = false; |
| 3112 | for (char c : chars) { |
| 3113 | if (c == '[' || c == ']') { |
| 3114 | needed = true; |
| 3115 | break; |
| 3116 | } |
| 3117 | } |
| 3118 | if (needed == false) { |
| 3119 | return path; |
| 3120 | } |
| 3121 | |
| 3122 | StringBuilder sb = new StringBuilder(""); |
| 3123 | for (char c : chars) { |
| 3124 | if (c == '[' || c == ']') { |
| 3125 | sb.append('%'); |
| 3126 | sb.append(Integer.toHexString(c)); |
| 3127 | } else { |
| 3128 | sb.append(c); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | return sb.toString(); |
| 3133 | } |
| 3134 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3135 | /** |
| 3136 | * Notify the host application a download should be done, even if there |
| 3137 | * is a streaming viewer available for thise type. |
| 3138 | * @param url The full url to the content that should be downloaded |
| 3139 | * @param contentDisposition Content-disposition http header, if |
| 3140 | * present. |
| 3141 | * @param mimetype The mimetype of the content reported by the server |
| 3142 | * @param contentLength The file size reported by the server |
| 3143 | */ |
| 3144 | /*package */ void onDownloadStartNoStream(String url, String userAgent, |
| 3145 | String contentDisposition, String mimetype, long contentLength) { |
| 3146 | |
| 3147 | String filename = URLUtil.guessFileName(url, |
| 3148 | contentDisposition, mimetype); |
| 3149 | |
| 3150 | // Check to see if we have an SDCard |
| 3151 | String status = Environment.getExternalStorageState(); |
| 3152 | if (!status.equals(Environment.MEDIA_MOUNTED)) { |
| 3153 | int title; |
| 3154 | String msg; |
| 3155 | |
| 3156 | // Check to see if the SDCard is busy, same as the music app |
| 3157 | if (status.equals(Environment.MEDIA_SHARED)) { |
| 3158 | msg = getString(R.string.download_sdcard_busy_dlg_msg); |
| 3159 | title = R.string.download_sdcard_busy_dlg_title; |
| 3160 | } else { |
| 3161 | msg = getString(R.string.download_no_sdcard_dlg_msg, filename); |
| 3162 | title = R.string.download_no_sdcard_dlg_title; |
| 3163 | } |
| 3164 | |
| 3165 | new AlertDialog.Builder(this) |
| 3166 | .setTitle(title) |
| 3167 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 3168 | .setMessage(msg) |
| 3169 | .setPositiveButton(R.string.ok, null) |
| 3170 | .show(); |
| 3171 | return; |
| 3172 | } |
| 3173 | |
Kristian Monsen | fa52d17 | 2010-03-25 18:29:21 +0000 | [diff] [blame] | 3174 | // java.net.URI is a lot stricter than KURL so we have to encode some |
| 3175 | // extra characters. Fix for b 2538060 and b 1634719 |
| 3176 | WebAddress webAddress; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3177 | try { |
Kristian Monsen | fa52d17 | 2010-03-25 18:29:21 +0000 | [diff] [blame] | 3178 | webAddress = new WebAddress(url); |
Bjorn Bringert | 131ab51 | 2010-10-12 16:25:47 +0100 | [diff] [blame] | 3179 | webAddress.setPath(encodePath(webAddress.getPath())); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3180 | } catch (Exception e) { |
Kristian Monsen | fa52d17 | 2010-03-25 18:29:21 +0000 | [diff] [blame] | 3181 | // This only happens for very bad urls, we want to chatch the |
| 3182 | // exception here |
| 3183 | Log.e(LOGTAG, "Exception trying to parse url:" + url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3184 | return; |
| 3185 | } |
| 3186 | |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3187 | String addressString = webAddress.toString(); |
| 3188 | Uri uri = Uri.parse(addressString); |
| 3189 | DownloadManager.Request request = new DownloadManager.Request(uri); |
| 3190 | request.setMimeType(mimetype); |
| 3191 | request.setDestinationInExternalFilesDir(this, null, filename); |
Vasu Nori | 1d88aa0 | 2010-11-04 18:16:10 -0700 | [diff] [blame] | 3192 | // let this downloaded file be scanned by MediaScanner - so that it can show up |
| 3193 | // in Gallery app, for example. |
| 3194 | request.allowScanningByMediaScanner(); |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3195 | request.setDescription(webAddress.getHost()); |
Vasu Nori | c54d328 | 2010-10-29 13:31:09 -0700 | [diff] [blame] | 3196 | String cookies = CookieManager.getInstance().getCookie(url); |
| 3197 | request.addRequestHeader("cookie", cookies); |
Leon Scroggins | 09ccfc7 | 2010-10-28 16:22:24 -0400 | [diff] [blame] | 3198 | request.setNotificationVisibility( |
| 3199 | DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3200 | if (mimetype == null) { |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3201 | ContentValues values = new ContentValues(); |
| 3202 | values.put(FetchUrlMimeType.URI, addressString); |
| 3203 | // XXX: Have to use the old url since the cookies were stored using the |
| 3204 | // old percent-encoded url. |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3205 | values.put(FetchUrlMimeType.COOKIE_DATA, cookies); |
| 3206 | values.put(FetchUrlMimeType.USER_AGENT, userAgent); |
| 3207 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3208 | // We must have long pressed on a link or image to download it. We |
| 3209 | // are not sure of the mimetype in this case, so do a head request |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3210 | new FetchUrlMimeType(this, request).execute(values); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3211 | } else { |
Leon Scroggins | c607653 | 2010-10-22 15:06:59 -0400 | [diff] [blame] | 3212 | DownloadManager manager |
| 3213 | = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); |
| 3214 | manager.enqueue(request); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3215 | } |
Leon Scroggins | 9191a7f | 2010-03-18 14:44:44 -0400 | [diff] [blame] | 3216 | Toast.makeText(this, R.string.download_pending, Toast.LENGTH_SHORT) |
| 3217 | .show(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3218 | } |
| 3219 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3220 | // ------------------------------------------------------------------------- |
| 3221 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3222 | /** |
| 3223 | * Resets the lock icon. This method is called when we start a new load and |
| 3224 | * know the url to be loaded. |
| 3225 | */ |
| 3226 | private void resetLockIcon(String url) { |
| 3227 | // Save the lock-icon state (we revert to it if the load gets cancelled) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3228 | mTabControl.getCurrentTab().resetLockIcon(url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3229 | updateLockIconImage(LOCK_ICON_UNSECURE); |
| 3230 | } |
| 3231 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3232 | /** |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 3233 | * Update the lock icon to correspond to our latest state. |
| 3234 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3235 | private void updateLockIconToLatest() { |
Leon Scroggins | 91f65fc | 2010-06-29 13:52:39 -0400 | [diff] [blame] | 3236 | Tab t = mTabControl.getCurrentTab(); |
| 3237 | if (t != null) { |
| 3238 | updateLockIconImage(t.getLockIconType()); |
| 3239 | } |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3243 | * Updates the lock-icon image in the title-bar. |
| 3244 | */ |
| 3245 | private void updateLockIconImage(int lockIconType) { |
| 3246 | Drawable d = null; |
| 3247 | if (lockIconType == LOCK_ICON_SECURE) { |
| 3248 | d = mSecLockIcon; |
| 3249 | } else if (lockIconType == LOCK_ICON_MIXED) { |
| 3250 | d = mMixLockIcon; |
| 3251 | } |
Leon Scroggins | 6857939 | 2009-09-15 15:31:54 -0400 | [diff] [blame] | 3252 | mTitleBar.setLock(d); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 3253 | mFakeTitleBar.setLock(d); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | /** |
| 3257 | * Displays a page-info dialog. |
| 3258 | * @param tab The tab to show info about |
| 3259 | * @param fromShowSSLCertificateOnError The flag that indicates whether |
| 3260 | * this dialog was opened from the SSL-certificate-on-error dialog or |
| 3261 | * not. This is important, since we need to know whether to return to |
| 3262 | * the parent dialog or simply dismiss. |
| 3263 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3264 | private void showPageInfo(final Tab tab, |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3265 | final boolean fromShowSSLCertificateOnError) { |
| 3266 | final LayoutInflater factory = LayoutInflater |
| 3267 | .from(this); |
| 3268 | |
| 3269 | final View pageInfoView = factory.inflate(R.layout.page_info, null); |
| 3270 | |
| 3271 | final WebView view = tab.getWebView(); |
| 3272 | |
| 3273 | String url = null; |
| 3274 | String title = null; |
| 3275 | |
| 3276 | if (view == null) { |
| 3277 | url = tab.getUrl(); |
| 3278 | title = tab.getTitle(); |
| 3279 | } else if (view == mTabControl.getCurrentWebView()) { |
| 3280 | // Use the cached title and url if this is the current WebView |
| 3281 | url = mUrl; |
| 3282 | title = mTitle; |
| 3283 | } else { |
| 3284 | url = view.getUrl(); |
| 3285 | title = view.getTitle(); |
| 3286 | } |
| 3287 | |
| 3288 | if (url == null) { |
| 3289 | url = ""; |
| 3290 | } |
| 3291 | if (title == null) { |
| 3292 | title = ""; |
| 3293 | } |
| 3294 | |
| 3295 | ((TextView) pageInfoView.findViewById(R.id.address)).setText(url); |
| 3296 | ((TextView) pageInfoView.findViewById(R.id.title)).setText(title); |
| 3297 | |
| 3298 | mPageInfoView = tab; |
Leon Scroggins | c7b92f8 | 2010-01-11 18:17:31 -0500 | [diff] [blame] | 3299 | mPageInfoFromShowSSLCertificateOnError = fromShowSSLCertificateOnError; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3300 | |
| 3301 | AlertDialog.Builder alertDialogBuilder = |
| 3302 | new AlertDialog.Builder(this) |
| 3303 | .setTitle(R.string.page_info).setIcon(android.R.drawable.ic_dialog_info) |
| 3304 | .setView(pageInfoView) |
| 3305 | .setPositiveButton( |
| 3306 | R.string.ok, |
| 3307 | new DialogInterface.OnClickListener() { |
| 3308 | public void onClick(DialogInterface dialog, |
| 3309 | int whichButton) { |
| 3310 | mPageInfoDialog = null; |
| 3311 | mPageInfoView = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3312 | |
| 3313 | // if we came here from the SSL error dialog |
| 3314 | if (fromShowSSLCertificateOnError) { |
| 3315 | // go back to the SSL error dialog |
| 3316 | showSSLCertificateOnError( |
| 3317 | mSSLCertificateOnErrorView, |
| 3318 | mSSLCertificateOnErrorHandler, |
| 3319 | mSSLCertificateOnErrorError); |
| 3320 | } |
| 3321 | } |
| 3322 | }) |
| 3323 | .setOnCancelListener( |
| 3324 | new DialogInterface.OnCancelListener() { |
| 3325 | public void onCancel(DialogInterface dialog) { |
| 3326 | mPageInfoDialog = null; |
| 3327 | mPageInfoView = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3328 | |
| 3329 | // if we came here from the SSL error dialog |
| 3330 | if (fromShowSSLCertificateOnError) { |
| 3331 | // go back to the SSL error dialog |
| 3332 | showSSLCertificateOnError( |
| 3333 | mSSLCertificateOnErrorView, |
| 3334 | mSSLCertificateOnErrorHandler, |
| 3335 | mSSLCertificateOnErrorError); |
| 3336 | } |
| 3337 | } |
| 3338 | }); |
| 3339 | |
| 3340 | // if we have a main top-level page SSL certificate set or a certificate |
| 3341 | // error |
| 3342 | if (fromShowSSLCertificateOnError || |
| 3343 | (view != null && view.getCertificate() != null)) { |
| 3344 | // add a 'View Certificate' button |
| 3345 | alertDialogBuilder.setNeutralButton( |
| 3346 | R.string.view_certificate, |
| 3347 | new DialogInterface.OnClickListener() { |
| 3348 | public void onClick(DialogInterface dialog, |
| 3349 | int whichButton) { |
| 3350 | mPageInfoDialog = null; |
| 3351 | mPageInfoView = null; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3352 | |
| 3353 | // if we came here from the SSL error dialog |
| 3354 | if (fromShowSSLCertificateOnError) { |
| 3355 | // go back to the SSL error dialog |
| 3356 | showSSLCertificateOnError( |
| 3357 | mSSLCertificateOnErrorView, |
| 3358 | mSSLCertificateOnErrorHandler, |
| 3359 | mSSLCertificateOnErrorError); |
| 3360 | } else { |
| 3361 | // otherwise, display the top-most certificate from |
| 3362 | // the chain |
| 3363 | if (view.getCertificate() != null) { |
| 3364 | showSSLCertificate(tab); |
| 3365 | } |
| 3366 | } |
| 3367 | } |
| 3368 | }); |
| 3369 | } |
| 3370 | |
| 3371 | mPageInfoDialog = alertDialogBuilder.show(); |
| 3372 | } |
| 3373 | |
| 3374 | /** |
| 3375 | * Displays the main top-level page SSL certificate dialog |
| 3376 | * (accessible from the Page-Info dialog). |
| 3377 | * @param tab The tab to show certificate for. |
| 3378 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3379 | private void showSSLCertificate(final Tab tab) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3380 | final View certificateView = |
| 3381 | inflateCertificateView(tab.getWebView().getCertificate()); |
| 3382 | if (certificateView == null) { |
| 3383 | return; |
| 3384 | } |
| 3385 | |
| 3386 | LayoutInflater factory = LayoutInflater.from(this); |
| 3387 | |
| 3388 | final LinearLayout placeholder = |
| 3389 | (LinearLayout)certificateView.findViewById(R.id.placeholder); |
| 3390 | |
| 3391 | LinearLayout ll = (LinearLayout) factory.inflate( |
| 3392 | R.layout.ssl_success, placeholder); |
| 3393 | ((TextView)ll.findViewById(R.id.success)) |
| 3394 | .setText(R.string.ssl_certificate_is_valid); |
| 3395 | |
| 3396 | mSSLCertificateView = tab; |
| 3397 | mSSLCertificateDialog = |
| 3398 | new AlertDialog.Builder(this) |
| 3399 | .setTitle(R.string.ssl_certificate).setIcon( |
| 3400 | R.drawable.ic_dialog_browser_certificate_secure) |
| 3401 | .setView(certificateView) |
| 3402 | .setPositiveButton(R.string.ok, |
| 3403 | new DialogInterface.OnClickListener() { |
| 3404 | public void onClick(DialogInterface dialog, |
| 3405 | int whichButton) { |
| 3406 | mSSLCertificateDialog = null; |
| 3407 | mSSLCertificateView = null; |
| 3408 | |
| 3409 | showPageInfo(tab, false); |
| 3410 | } |
| 3411 | }) |
| 3412 | .setOnCancelListener( |
| 3413 | new DialogInterface.OnCancelListener() { |
| 3414 | public void onCancel(DialogInterface dialog) { |
| 3415 | mSSLCertificateDialog = null; |
| 3416 | mSSLCertificateView = null; |
| 3417 | |
| 3418 | showPageInfo(tab, false); |
| 3419 | } |
| 3420 | }) |
| 3421 | .show(); |
| 3422 | } |
| 3423 | |
| 3424 | /** |
| 3425 | * Displays the SSL error certificate dialog. |
| 3426 | * @param view The target web-view. |
| 3427 | * @param handler The SSL error handler responsible for cancelling the |
| 3428 | * connection that resulted in an SSL error or proceeding per user request. |
| 3429 | * @param error The SSL error object. |
| 3430 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3431 | void showSSLCertificateOnError( |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3432 | final WebView view, final SslErrorHandler handler, final SslError error) { |
| 3433 | |
| 3434 | final View certificateView = |
| 3435 | inflateCertificateView(error.getCertificate()); |
| 3436 | if (certificateView == null) { |
| 3437 | return; |
| 3438 | } |
| 3439 | |
| 3440 | LayoutInflater factory = LayoutInflater.from(this); |
| 3441 | |
| 3442 | final LinearLayout placeholder = |
| 3443 | (LinearLayout)certificateView.findViewById(R.id.placeholder); |
| 3444 | |
| 3445 | if (error.hasError(SslError.SSL_UNTRUSTED)) { |
| 3446 | LinearLayout ll = (LinearLayout)factory |
| 3447 | .inflate(R.layout.ssl_warning, placeholder); |
| 3448 | ((TextView)ll.findViewById(R.id.warning)) |
| 3449 | .setText(R.string.ssl_untrusted); |
| 3450 | } |
| 3451 | |
| 3452 | if (error.hasError(SslError.SSL_IDMISMATCH)) { |
| 3453 | LinearLayout ll = (LinearLayout)factory |
| 3454 | .inflate(R.layout.ssl_warning, placeholder); |
| 3455 | ((TextView)ll.findViewById(R.id.warning)) |
| 3456 | .setText(R.string.ssl_mismatch); |
| 3457 | } |
| 3458 | |
| 3459 | if (error.hasError(SslError.SSL_EXPIRED)) { |
| 3460 | LinearLayout ll = (LinearLayout)factory |
| 3461 | .inflate(R.layout.ssl_warning, placeholder); |
| 3462 | ((TextView)ll.findViewById(R.id.warning)) |
| 3463 | .setText(R.string.ssl_expired); |
| 3464 | } |
| 3465 | |
| 3466 | if (error.hasError(SslError.SSL_NOTYETVALID)) { |
| 3467 | LinearLayout ll = (LinearLayout)factory |
| 3468 | .inflate(R.layout.ssl_warning, placeholder); |
| 3469 | ((TextView)ll.findViewById(R.id.warning)) |
| 3470 | .setText(R.string.ssl_not_yet_valid); |
| 3471 | } |
| 3472 | |
| 3473 | mSSLCertificateOnErrorHandler = handler; |
| 3474 | mSSLCertificateOnErrorView = view; |
| 3475 | mSSLCertificateOnErrorError = error; |
| 3476 | mSSLCertificateOnErrorDialog = |
| 3477 | new AlertDialog.Builder(this) |
| 3478 | .setTitle(R.string.ssl_certificate).setIcon( |
| 3479 | R.drawable.ic_dialog_browser_certificate_partially_secure) |
| 3480 | .setView(certificateView) |
| 3481 | .setPositiveButton(R.string.ok, |
| 3482 | new DialogInterface.OnClickListener() { |
| 3483 | public void onClick(DialogInterface dialog, |
| 3484 | int whichButton) { |
| 3485 | mSSLCertificateOnErrorDialog = null; |
| 3486 | mSSLCertificateOnErrorView = null; |
| 3487 | mSSLCertificateOnErrorHandler = null; |
| 3488 | mSSLCertificateOnErrorError = null; |
| 3489 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3490 | view.getWebViewClient().onReceivedSslError( |
| 3491 | view, handler, error); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3492 | } |
| 3493 | }) |
| 3494 | .setNeutralButton(R.string.page_info_view, |
| 3495 | new DialogInterface.OnClickListener() { |
| 3496 | public void onClick(DialogInterface dialog, |
| 3497 | int whichButton) { |
| 3498 | mSSLCertificateOnErrorDialog = null; |
| 3499 | |
| 3500 | // do not clear the dialog state: we will |
| 3501 | // need to show the dialog again once the |
| 3502 | // user is done exploring the page-info details |
| 3503 | |
| 3504 | showPageInfo(mTabControl.getTabFromView(view), |
| 3505 | true); |
| 3506 | } |
| 3507 | }) |
| 3508 | .setOnCancelListener( |
| 3509 | new DialogInterface.OnCancelListener() { |
| 3510 | public void onCancel(DialogInterface dialog) { |
| 3511 | mSSLCertificateOnErrorDialog = null; |
| 3512 | mSSLCertificateOnErrorView = null; |
| 3513 | mSSLCertificateOnErrorHandler = null; |
| 3514 | mSSLCertificateOnErrorError = null; |
| 3515 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3516 | view.getWebViewClient().onReceivedSslError( |
| 3517 | view, handler, error); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3518 | } |
| 3519 | }) |
| 3520 | .show(); |
| 3521 | } |
| 3522 | |
| 3523 | /** |
| 3524 | * Inflates the SSL certificate view (helper method). |
| 3525 | * @param certificate The SSL certificate. |
| 3526 | * @return The resultant certificate view with issued-to, issued-by, |
| 3527 | * issued-on, expires-on, and possibly other fields set. |
| 3528 | * If the input certificate is null, returns null. |
| 3529 | */ |
| 3530 | private View inflateCertificateView(SslCertificate certificate) { |
| 3531 | if (certificate == null) { |
| 3532 | return null; |
| 3533 | } |
| 3534 | |
| 3535 | LayoutInflater factory = LayoutInflater.from(this); |
| 3536 | |
| 3537 | View certificateView = factory.inflate( |
| 3538 | R.layout.ssl_certificate, null); |
| 3539 | |
| 3540 | // issued to: |
| 3541 | SslCertificate.DName issuedTo = certificate.getIssuedTo(); |
| 3542 | if (issuedTo != null) { |
| 3543 | ((TextView) certificateView.findViewById(R.id.to_common)) |
| 3544 | .setText(issuedTo.getCName()); |
| 3545 | ((TextView) certificateView.findViewById(R.id.to_org)) |
| 3546 | .setText(issuedTo.getOName()); |
| 3547 | ((TextView) certificateView.findViewById(R.id.to_org_unit)) |
| 3548 | .setText(issuedTo.getUName()); |
| 3549 | } |
| 3550 | |
| 3551 | // issued by: |
| 3552 | SslCertificate.DName issuedBy = certificate.getIssuedBy(); |
| 3553 | if (issuedBy != null) { |
| 3554 | ((TextView) certificateView.findViewById(R.id.by_common)) |
| 3555 | .setText(issuedBy.getCName()); |
| 3556 | ((TextView) certificateView.findViewById(R.id.by_org)) |
| 3557 | .setText(issuedBy.getOName()); |
| 3558 | ((TextView) certificateView.findViewById(R.id.by_org_unit)) |
| 3559 | .setText(issuedBy.getUName()); |
| 3560 | } |
| 3561 | |
| 3562 | // issued on: |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3563 | String issuedOn = formatCertificateDate( |
| 3564 | certificate.getValidNotBeforeDate()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3565 | ((TextView) certificateView.findViewById(R.id.issued_on)) |
| 3566 | .setText(issuedOn); |
| 3567 | |
| 3568 | // expires on: |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3569 | String expiresOn = formatCertificateDate( |
| 3570 | certificate.getValidNotAfterDate()); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3571 | ((TextView) certificateView.findViewById(R.id.expires_on)) |
| 3572 | .setText(expiresOn); |
| 3573 | |
| 3574 | return certificateView; |
| 3575 | } |
| 3576 | |
| 3577 | /** |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3578 | * Formats the certificate date to a properly localized date string. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3579 | * @return Properly localized version of the certificate date string and |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3580 | * the "" if it fails to localize. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3581 | */ |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3582 | private String formatCertificateDate(Date certificateDate) { |
| 3583 | if (certificateDate == null) { |
| 3584 | return ""; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3585 | } |
Brian Carlstrom | 95a2e4a | 2010-03-02 10:02:34 -0800 | [diff] [blame] | 3586 | String formattedDate = DateFormat.getDateFormat(this).format(certificateDate); |
| 3587 | if (formattedDate == null) { |
| 3588 | return ""; |
| 3589 | } |
| 3590 | return formattedDate; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * Displays an http-authentication dialog. |
| 3595 | */ |
Bjorn Bringert | 2573892 | 2010-10-12 10:56:20 +0100 | [diff] [blame] | 3596 | void showHttpAuthentication(final HttpAuthHandler handler, String host, String realm) { |
| 3597 | mHttpAuthenticationDialog = new HttpAuthenticationDialog(this, host, realm); |
| 3598 | mHttpAuthenticationDialog.setOkListener(new HttpAuthenticationDialog.OkListener() { |
| 3599 | public void onOk(String host, String realm, String username, String password) { |
| 3600 | BrowserActivity.this.setHttpAuthUsernamePassword(host, realm, username, password); |
| 3601 | handler.proceed(username, password); |
| 3602 | mHttpAuthenticationDialog = null; |
| 3603 | } |
| 3604 | }); |
| 3605 | mHttpAuthenticationDialog.setCancelListener(new HttpAuthenticationDialog.CancelListener() { |
| 3606 | public void onCancel() { |
| 3607 | handler.cancel(); |
| 3608 | BrowserActivity.this.resetTitleAndRevertLockIcon(); |
| 3609 | mHttpAuthenticationDialog = null; |
| 3610 | } |
| 3611 | }); |
| 3612 | mHttpAuthenticationDialog.show(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | public int getProgress() { |
| 3616 | WebView w = mTabControl.getCurrentWebView(); |
| 3617 | if (w != null) { |
| 3618 | return w.getProgress(); |
| 3619 | } else { |
| 3620 | return 100; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | /** |
| 3625 | * Set HTTP authentication password. |
| 3626 | * |
| 3627 | * @param host The host for the password |
| 3628 | * @param realm The realm for the password |
| 3629 | * @param username The username for the password. If it is null, it means |
| 3630 | * password can't be saved. |
| 3631 | * @param password The password |
| 3632 | */ |
| 3633 | public void setHttpAuthUsernamePassword(String host, String realm, |
| 3634 | String username, |
| 3635 | String password) { |
Steve Block | 95a53b2 | 2010-03-25 17:24:58 +0000 | [diff] [blame] | 3636 | WebView w = getTopWindow(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3637 | if (w != null) { |
| 3638 | w.setHttpAuthUsernamePassword(host, realm, username, password); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | /** |
| 3643 | * connectivity manager says net has come or gone... inform the user |
| 3644 | * @param up true if net has come up, false if net has gone down |
| 3645 | */ |
| 3646 | public void onNetworkToggle(boolean up) { |
| 3647 | if (up == mIsNetworkUp) { |
| 3648 | return; |
| 3649 | } else if (up) { |
| 3650 | mIsNetworkUp = true; |
| 3651 | if (mAlertDialog != null) { |
| 3652 | mAlertDialog.cancel(); |
| 3653 | mAlertDialog = null; |
| 3654 | } |
| 3655 | } else { |
| 3656 | mIsNetworkUp = false; |
Patrick Scott | eb6ab2a | 2009-09-16 10:00:17 -0400 | [diff] [blame] | 3657 | if (mInLoad) { |
| 3658 | createAndShowNetworkDialog(); |
| 3659 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3660 | } |
| 3661 | WebView w = mTabControl.getCurrentWebView(); |
| 3662 | if (w != null) { |
| 3663 | w.setNetworkAvailable(up); |
| 3664 | } |
| 3665 | } |
| 3666 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3667 | boolean isNetworkUp() { |
| 3668 | return mIsNetworkUp; |
| 3669 | } |
| 3670 | |
Patrick Scott | eb6ab2a | 2009-09-16 10:00:17 -0400 | [diff] [blame] | 3671 | // This method shows the network dialog alerting the user that the net is |
| 3672 | // down. It will only show the dialog if mAlertDialog is null. |
| 3673 | private void createAndShowNetworkDialog() { |
| 3674 | if (mAlertDialog == null) { |
| 3675 | mAlertDialog = new AlertDialog.Builder(this) |
| 3676 | .setTitle(R.string.loadSuspendedTitle) |
| 3677 | .setMessage(R.string.loadSuspended) |
| 3678 | .setPositiveButton(R.string.ok, null) |
| 3679 | .show(); |
| 3680 | } |
| 3681 | } |
| 3682 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 3683 | /** |
| 3684 | * callback from ComboPage when bookmark/history selection |
| 3685 | */ |
| 3686 | @Override |
| 3687 | public void onUrlSelected(String url, boolean newTab) { |
| 3688 | removeComboView(); |
| 3689 | if (!TextUtils.isEmpty(url)) { |
| 3690 | if (newTab) { |
| 3691 | openTab(url, false); |
| 3692 | } else { |
| 3693 | final Tab currentTab = mTabControl.getCurrentTab(); |
| 3694 | dismissSubWindow(currentTab); |
| 3695 | loadUrl(getTopWindow(), url); |
| 3696 | } |
| 3697 | } |
| 3698 | } |
| 3699 | |
| 3700 | /** |
| 3701 | * callback from ComboPage when dismissed |
| 3702 | */ |
| 3703 | @Override |
| 3704 | public void onComboCanceled() { |
| 3705 | removeComboView(); |
| 3706 | } |
| 3707 | |
| 3708 | /** |
| 3709 | * dismiss the ComboPage |
| 3710 | */ |
| 3711 | /* package */ void removeComboView() { |
| 3712 | if (mComboView != null) { |
| 3713 | mContentView.removeView(mComboView); |
| 3714 | mTitleBar.setVisibility(View.VISIBLE); |
| 3715 | mMenuState = R.id.MAIN_MENU; |
| 3716 | attachTabToContentView(mTabControl.getCurrentTab()); |
| 3717 | getTopWindow().requestFocus(); |
| 3718 | mComboView = null; |
| 3719 | } |
| 3720 | } |
| 3721 | |
| 3722 | /** |
| 3723 | * callback from ComboPage when clear history is requested |
| 3724 | */ |
| 3725 | public void onRemoveParentChildRelationships() { |
| 3726 | mTabControl.removeParentChildRelationShips(); |
| 3727 | } |
| 3728 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3729 | @Override |
| 3730 | protected void onActivityResult(int requestCode, int resultCode, |
| 3731 | Intent intent) { |
Grace Kloba | bb394f3 | 2009-11-19 10:26:37 -0800 | [diff] [blame] | 3732 | if (getTopWindow() == null) return; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3733 | switch (requestCode) { |
Leon Scroggins | fde9746 | 2010-01-11 13:06:21 -0500 | [diff] [blame] | 3734 | case PREFERENCES_PAGE: |
| 3735 | if (resultCode == RESULT_OK && intent != null) { |
| 3736 | String action = intent.getStringExtra(Intent.EXTRA_TEXT); |
| 3737 | if (BrowserSettings.PREF_CLEAR_HISTORY.equals(action)) { |
| 3738 | mTabControl.removeParentChildRelationShips(); |
| 3739 | } |
| 3740 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3741 | break; |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 3742 | // Choose a file from the file picker. |
| 3743 | case FILE_SELECTED: |
| 3744 | if (null == mUploadMessage) break; |
| 3745 | Uri result = intent == null || resultCode != RESULT_OK ? null |
| 3746 | : intent.getData(); |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3747 | |
| 3748 | // As we ask the camera to save the result of the user taking |
| 3749 | // a picture, the camera application does not return anything other |
| 3750 | // than RESULT_OK. So we need to check whether the file we expected |
| 3751 | // was written to disk in the in the case that we |
| 3752 | // did not get an intent returned but did get a RESULT_OK. If it was, |
| 3753 | // we assume that this result has came back from the camera. |
| 3754 | if (result == null && intent == null && resultCode == RESULT_OK) { |
| 3755 | File cameraFile = new File(mCameraFilePath); |
| 3756 | if (cameraFile.exists()) { |
| 3757 | result = Uri.fromFile(cameraFile); |
Ben Murdoch | 07d3473 | 2010-05-27 18:34:46 +0100 | [diff] [blame] | 3758 | // Broadcast to the media scanner that we have a new photo |
| 3759 | // so it will be added into the gallery for the user. |
| 3760 | sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result)); |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3761 | } |
| 3762 | } |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 3763 | mUploadMessage.onReceiveValue(result); |
| 3764 | mUploadMessage = null; |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 3765 | mCameraFilePath = null; |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 3766 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3767 | default: |
| 3768 | break; |
| 3769 | } |
Leon Scroggins | 3044423 | 2009-09-04 18:36:20 -0400 | [diff] [blame] | 3770 | getTopWindow().requestFocus(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | /* |
| 3774 | * This method is called as a result of the user selecting the options |
Leon Scroggins | f08809b | 2010-01-21 09:27:46 -0500 | [diff] [blame] | 3775 | * menu to see the download window. It shows the download window on top of |
| 3776 | * the current window. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3777 | */ |
Leon Scroggins III | a682a3c | 2010-09-27 12:32:40 -0400 | [diff] [blame] | 3778 | private void viewDownloads() { |
| 3779 | Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
| 3780 | startActivity(intent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 3783 | /** |
| 3784 | * Open the Go page. |
| 3785 | * @param startWithHistory If true, open starting on the history tab. |
| 3786 | * Otherwise, start with the bookmarks tab. |
Leon Scroggins | 160a7e7 | 2009-08-14 18:28:01 -0400 | [diff] [blame] | 3787 | */ |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 3788 | /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) { |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 3789 | if (mTabControl.getCurrentWebView() == null) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3790 | return; |
| 3791 | } |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 3792 | Bundle extras = new Bundle(); |
Leon Scroggins | 3044423 | 2009-09-04 18:36:20 -0400 | [diff] [blame] | 3793 | // Disable opening in a new window if we have maxed out the windows |
Leon Scroggins | bc92285 | 2010-10-22 12:15:27 -0400 | [diff] [blame] | 3794 | extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, |
| 3795 | !mTabControl.canCreateNewTab()); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 3796 | |
| 3797 | mComboView = new CombinedBookmarkHistoryView(this, |
| 3798 | startWithHistory ? CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY |
| 3799 | : CombinedBookmarkHistoryView.FRAGMENT_ID_BOOKMARKS, |
| 3800 | extras); |
| 3801 | removeTabFromContentView(mTabControl.getCurrentTab()); |
| 3802 | mTitleBar.setVisibility(View.GONE); |
| 3803 | hideFakeTitleBar(); |
| 3804 | mContentView.addView(mComboView, COVER_SCREEN_PARAMS); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | // Called when loading from context menu or LOAD_URL message |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 3808 | private void loadUrlFromContext(WebView view, String url) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3809 | // In case the user enters nothing. |
| 3810 | if (url != null && url.length() != 0 && view != null) { |
| 3811 | url = smartUrlFilter(url); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3812 | if (!view.getWebViewClient().shouldOverrideUrlLoading(view, url)) { |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 3813 | loadUrl(view, url); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | } |
| 3817 | |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 3818 | /** |
| 3819 | * Load the URL into the given WebView and update the title bar |
| 3820 | * to reflect the new load. Call this instead of WebView.loadUrl |
| 3821 | * directly. |
| 3822 | * @param view The WebView used to load url. |
| 3823 | * @param url The URL to load. |
| 3824 | */ |
| 3825 | private void loadUrl(WebView view, String url) { |
| 3826 | updateTitleBarForNewLoad(view, url); |
| 3827 | view.loadUrl(url); |
| 3828 | } |
| 3829 | |
| 3830 | /** |
| 3831 | * Load UrlData into a Tab and update the title bar to reflect the new |
| 3832 | * load. Call this instead of UrlData.loadIn directly. |
| 3833 | * @param t The Tab used to load. |
| 3834 | * @param data The UrlData being loaded. |
| 3835 | */ |
| 3836 | private void loadUrlDataIn(Tab t, UrlData data) { |
| 3837 | updateTitleBarForNewLoad(t.getWebView(), data.mUrl); |
| 3838 | data.loadIn(t); |
| 3839 | } |
| 3840 | |
| 3841 | /** |
| 3842 | * If the WebView is the top window, update the title bar to reflect |
| 3843 | * loading the new URL. i.e. set its text, clear the favicon (which |
| 3844 | * will be set once the page begins loading), and set the progress to |
| 3845 | * INITIAL_PROGRESS to show that the page has begun to load. Called |
| 3846 | * by loadUrl and loadUrlDataIn. |
| 3847 | * @param view The WebView that is starting a load. |
| 3848 | * @param url The URL that is being loaded. |
| 3849 | */ |
| 3850 | private void updateTitleBarForNewLoad(WebView view, String url) { |
| 3851 | if (view == getTopWindow()) { |
| 3852 | setUrlTitle(url, null); |
| 3853 | setFavicon(null); |
| 3854 | onProgressChanged(view, INITIAL_PROGRESS); |
| 3855 | } |
| 3856 | } |
| 3857 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3858 | private String smartUrlFilter(Uri inUri) { |
| 3859 | if (inUri != null) { |
| 3860 | return smartUrlFilter(inUri.toString()); |
| 3861 | } |
| 3862 | return null; |
| 3863 | } |
| 3864 | |
Feng Qian | b34f87a | 2009-03-24 21:27:26 -0700 | [diff] [blame] | 3865 | protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile( |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3866 | "(?i)" + // switch on case insensitive matching |
| 3867 | "(" + // begin group for schema |
| 3868 | "(?:http|https|file):\\/\\/" + |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 3869 | "|(?:inline|data|about|content|javascript):" + |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3870 | ")" + |
| 3871 | "(.*)" ); |
| 3872 | |
| 3873 | /** |
| 3874 | * Attempts to determine whether user input is a URL or search |
| 3875 | * terms. Anything with a space is passed to search. |
| 3876 | * |
| 3877 | * Converts to lowercase any mistakenly uppercased schema (i.e., |
| 3878 | * "Http://" converts to "http://" |
| 3879 | * |
| 3880 | * @return Original or modified URL |
| 3881 | * |
| 3882 | */ |
| 3883 | String smartUrlFilter(String url) { |
| 3884 | |
| 3885 | String inUrl = url.trim(); |
| 3886 | boolean hasSpace = inUrl.indexOf(' ') != -1; |
| 3887 | |
| 3888 | Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl); |
| 3889 | if (matcher.matches()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3890 | // force scheme to lowercase |
| 3891 | String scheme = matcher.group(1); |
| 3892 | String lcScheme = scheme.toLowerCase(); |
| 3893 | if (!lcScheme.equals(scheme)) { |
Mitsuru Oshima | 123ecfb | 2009-05-18 19:11:14 -0700 | [diff] [blame] | 3894 | inUrl = lcScheme + matcher.group(2); |
| 3895 | } |
| 3896 | if (hasSpace) { |
| 3897 | inUrl = inUrl.replace(" ", "%20"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3898 | } |
| 3899 | return inUrl; |
| 3900 | } |
Leon Scroggins | 956cf01 | 2010-10-07 13:51:57 -0400 | [diff] [blame] | 3901 | if (!hasSpace) { |
Dan Egnor | 5ee906c | 2009-11-18 12:11:49 -0800 | [diff] [blame] | 3902 | if (Patterns.WEB_URL.matcher(inUrl).matches()) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3903 | return URLUtil.guessUrl(inUrl); |
| 3904 | } |
| 3905 | } |
| 3906 | |
Leon Scroggins | 956cf01 | 2010-10-07 13:51:57 -0400 | [diff] [blame] | 3907 | // FIXME: Is this the correct place to add to searches? |
| 3908 | // what if someone else calls this function? |
| 3909 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3910 | Browser.addSearchUrl(mResolver, inUrl); |
Grace Kloba | 47fdfdb | 2009-06-30 11:15:34 -0700 | [diff] [blame] | 3911 | return URLUtil.composeSearchUrl(inUrl, QuickSearch_G, QUERY_PLACE_HOLDER); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3912 | } |
| 3913 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3914 | /* package */ void setShouldShowErrorConsole(boolean flag) { |
| 3915 | if (flag == mShouldShowErrorConsole) { |
| 3916 | // Nothing to do. |
| 3917 | return; |
| 3918 | } |
Leon Scroggins III | a9e35b6 | 2010-09-16 15:30:15 -0400 | [diff] [blame] | 3919 | Tab t = mTabControl.getCurrentTab(); |
| 3920 | if (t == null) { |
| 3921 | // There is no current tab so we cannot toggle the error console |
| 3922 | return; |
| 3923 | } |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3924 | |
| 3925 | mShouldShowErrorConsole = flag; |
| 3926 | |
Leon Scroggins III | a9e35b6 | 2010-09-16 15:30:15 -0400 | [diff] [blame] | 3927 | ErrorConsoleView errorConsole = t.getErrorConsole(true); |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3928 | |
| 3929 | if (flag) { |
| 3930 | // Setting the show state of the console will cause it's the layout to be inflated. |
| 3931 | if (errorConsole.numberOfErrors() > 0) { |
| 3932 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 3933 | } else { |
| 3934 | errorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 3935 | } |
| 3936 | |
| 3937 | // Now we can add it to the main view. |
| 3938 | mErrorConsoleContainer.addView(errorConsole, |
Romain Guy | 15b8ec6 | 2010-01-08 15:06:43 -0800 | [diff] [blame] | 3939 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 3940 | ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 3941 | } else { |
| 3942 | mErrorConsoleContainer.removeView(errorConsole); |
| 3943 | } |
| 3944 | |
| 3945 | } |
| 3946 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 3947 | boolean shouldShowErrorConsole() { |
| 3948 | return mShouldShowErrorConsole; |
| 3949 | } |
| 3950 | |
Andrei Popescu | 163ab74 | 2009-10-20 17:58:23 +0100 | [diff] [blame] | 3951 | private void setStatusBarVisibility(boolean visible) { |
| 3952 | int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 3953 | getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN); |
| 3954 | } |
| 3955 | |
Andrei Popescu | 56199cc | 2010-01-12 22:39:16 +0000 | [diff] [blame] | 3956 | |
| 3957 | private void sendNetworkType(String type, String subtype) { |
| 3958 | WebView w = mTabControl.getCurrentWebView(); |
| 3959 | if (w != null) { |
| 3960 | w.setNetworkType(type, subtype); |
| 3961 | } |
| 3962 | } |
| 3963 | |
Grace Kloba | eb6eef4 | 2009-09-15 17:56:32 -0700 | [diff] [blame] | 3964 | final static int LOCK_ICON_UNSECURE = 0; |
| 3965 | final static int LOCK_ICON_SECURE = 1; |
| 3966 | final static int LOCK_ICON_MIXED = 2; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3967 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3968 | private BrowserSettings mSettings; |
| 3969 | private TabControl mTabControl; |
| 3970 | private ContentResolver mResolver; |
| 3971 | private FrameLayout mContentView; |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3972 | private View mCustomView; |
| 3973 | private FrameLayout mCustomViewContainer; |
Andrei Popescu | c9b5556 | 2009-07-07 10:51:15 +0100 | [diff] [blame] | 3974 | private WebChromeClient.CustomViewCallback mCustomViewCallback; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3975 | |
| 3976 | // FIXME, temp address onPrepareMenu performance problem. When we move everything out of |
| 3977 | // view, we should rewrite this. |
| 3978 | private int mCurrentMenuState = 0; |
| 3979 | private int mMenuState = R.id.MAIN_MENU; |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 3980 | private int mOldMenuState = EMPTY_MENU; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3981 | private static final int EMPTY_MENU = -1; |
| 3982 | private Menu mMenu; |
| 3983 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3984 | // Used to prevent chording to result in firing two shortcuts immediately |
| 3985 | // one after another. Fixes bug 1211714. |
| 3986 | boolean mCanChord; |
| 3987 | |
| 3988 | private boolean mInLoad; |
| 3989 | private boolean mIsNetworkUp; |
Ben Murdoch | b7cc8b4 | 2009-09-28 10:59:09 +0100 | [diff] [blame] | 3990 | private boolean mDidStopLoad; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3991 | |
Cary Clark | 1f10cbf | 2010-03-22 11:45:23 -0400 | [diff] [blame] | 3992 | /* package */ boolean mActivityInPause = true; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3993 | |
| 3994 | private boolean mMenuIsDown; |
| 3995 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 3996 | private static boolean mInTrace; |
| 3997 | |
| 3998 | // Performance probe |
| 3999 | private static final int[] SYSTEM_CPU_FORMAT = new int[] { |
| 4000 | Process.PROC_SPACE_TERM | Process.PROC_COMBINE, |
| 4001 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 1: user time |
| 4002 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 2: nice time |
| 4003 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 3: sys time |
| 4004 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 4: idle time |
| 4005 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 5: iowait time |
| 4006 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 6: irq time |
| 4007 | Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG // 7: softirq time |
| 4008 | }; |
| 4009 | |
| 4010 | private long mStart; |
| 4011 | private long mProcessStart; |
| 4012 | private long mUserStart; |
| 4013 | private long mSystemStart; |
| 4014 | private long mIdleStart; |
| 4015 | private long mIrqStart; |
| 4016 | |
| 4017 | private long mUiStart; |
| 4018 | |
| 4019 | private Drawable mMixLockIcon; |
| 4020 | private Drawable mSecLockIcon; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4021 | |
| 4022 | /* hold a ref so we can auto-cancel if necessary */ |
| 4023 | private AlertDialog mAlertDialog; |
| 4024 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4025 | // The up-to-date URL and title (these can be different from those stored |
| 4026 | // in WebView, since it takes some time for the information in WebView to |
| 4027 | // get updated) |
| 4028 | private String mUrl; |
| 4029 | private String mTitle; |
| 4030 | |
| 4031 | // As PageInfo has different style for landscape / portrait, we have |
| 4032 | // to re-open it when configuration changed |
| 4033 | private AlertDialog mPageInfoDialog; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 4034 | private Tab mPageInfoView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4035 | // If the Page-Info dialog is launched from the SSL-certificate-on-error |
| 4036 | // dialog, we should not just dismiss it, but should get back to the |
| 4037 | // SSL-certificate-on-error dialog. This flag is used to store this state |
Leon Scroggins | c7b92f8 | 2010-01-11 18:17:31 -0500 | [diff] [blame] | 4038 | private boolean mPageInfoFromShowSSLCertificateOnError; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4039 | |
| 4040 | // as SSLCertificateOnError has different style for landscape / portrait, |
| 4041 | // we have to re-open it when configuration changed |
| 4042 | private AlertDialog mSSLCertificateOnErrorDialog; |
| 4043 | private WebView mSSLCertificateOnErrorView; |
| 4044 | private SslErrorHandler mSSLCertificateOnErrorHandler; |
| 4045 | private SslError mSSLCertificateOnErrorError; |
| 4046 | |
| 4047 | // as SSLCertificate has different style for landscape / portrait, we |
| 4048 | // have to re-open it when configuration changed |
| 4049 | private AlertDialog mSSLCertificateDialog; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 4050 | private Tab mSSLCertificateView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4051 | |
| 4052 | // as HttpAuthentication has different style for landscape / portrait, we |
| 4053 | // have to re-open it when configuration changed |
Bjorn Bringert | 2573892 | 2010-10-12 10:56:20 +0100 | [diff] [blame] | 4054 | private HttpAuthenticationDialog mHttpAuthenticationDialog; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4055 | |
| 4056 | /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = |
| 4057 | new FrameLayout.LayoutParams( |
Romain Guy | 15b8ec6 | 2010-01-08 15:06:43 -0800 | [diff] [blame] | 4058 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 4059 | ViewGroup.LayoutParams.MATCH_PARENT); |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 4060 | /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = |
| 4061 | new FrameLayout.LayoutParams( |
Romain Guy | 15b8ec6 | 2010-01-08 15:06:43 -0800 | [diff] [blame] | 4062 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 4063 | ViewGroup.LayoutParams.MATCH_PARENT, |
Andrei Popescu | adc008d | 2009-06-26 14:11:30 +0100 | [diff] [blame] | 4064 | Gravity.CENTER); |
Grace Kloba | 47fdfdb | 2009-06-30 11:15:34 -0700 | [diff] [blame] | 4065 | // Google search |
| 4066 | 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] | 4067 | |
| 4068 | final static String QUERY_PLACE_HOLDER = "%s"; |
| 4069 | |
| 4070 | // "source" parameter for Google search through search key |
| 4071 | final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key"; |
| 4072 | // "source" parameter for Google search through goto menu |
| 4073 | final static String GOOGLE_SEARCH_SOURCE_GOTO = "browser-goto"; |
| 4074 | // "source" parameter for Google search through simplily type |
| 4075 | final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type"; |
| 4076 | // "source" parameter for Google search suggested by the browser |
| 4077 | final static String GOOGLE_SEARCH_SOURCE_SUGGEST = "browser-suggest"; |
| 4078 | // "source" parameter for Google search from unknown source |
| 4079 | final static String GOOGLE_SEARCH_SOURCE_UNKNOWN = "unknown"; |
| 4080 | |
| 4081 | private final static String LOGTAG = "browser"; |
| 4082 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4083 | private String mLastEnteredUrl; |
| 4084 | |
| 4085 | private PowerManager.WakeLock mWakeLock; |
| 4086 | private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes |
| 4087 | |
| 4088 | private Toast mStopToast; |
| 4089 | |
Leon Scroggins | 571b376 | 2010-05-26 10:25:01 -0400 | [diff] [blame] | 4090 | private TitleBarBase mTitleBar; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 4091 | private TabBar mTabBar; |
Leon Scroggins | 81db366 | 2009-06-04 17:45:11 -0400 | [diff] [blame] | 4092 | |
Ben Murdoch | bff2d60 | 2009-07-01 20:19:05 +0100 | [diff] [blame] | 4093 | private LinearLayout mErrorConsoleContainer = null; |
| 4094 | private boolean mShouldShowErrorConsole = false; |
| 4095 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4096 | // As the ids are dynamically created, we can't guarantee that they will |
| 4097 | // be in sequence, so this static array maps ids to a window number. |
| 4098 | final static private int[] WINDOW_SHORTCUT_ID_ARRAY = |
| 4099 | { R.id.window_one_menu_id, R.id.window_two_menu_id, R.id.window_three_menu_id, |
| 4100 | R.id.window_four_menu_id, R.id.window_five_menu_id, R.id.window_six_menu_id, |
| 4101 | R.id.window_seven_menu_id, R.id.window_eight_menu_id }; |
| 4102 | |
| 4103 | // monitor platform changes |
| 4104 | private IntentFilter mNetworkStateChangedFilter; |
| 4105 | private BroadcastReceiver mNetworkStateIntentReceiver; |
| 4106 | |
Bjorn Bringert | a761181 | 2010-03-24 11:12:02 +0000 | [diff] [blame] | 4107 | private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins; |
| 4108 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4109 | // activity requestCode |
Nicolas Roard | 78a98e4 | 2009-05-11 13:34:17 +0100 | [diff] [blame] | 4110 | final static int PREFERENCES_PAGE = 3; |
Leon Scroggins | 8d5fa43 | 2009-10-02 15:55:59 -0400 | [diff] [blame] | 4111 | final static int FILE_SELECTED = 4; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4112 | |
Andrei Popescu | 540035d | 2009-09-18 18:59:20 +0100 | [diff] [blame] | 4113 | // the default <video> poster |
| 4114 | private Bitmap mDefaultVideoPoster; |
| 4115 | // the video progress view |
| 4116 | private View mVideoProgressView; |
| 4117 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4118 | /** |
| 4119 | * A UrlData class to abstract how the content will be set to WebView. |
| 4120 | * This base class uses loadUrl to show the content. |
| 4121 | */ |
Leon Scroggins | 6eac63e | 2010-03-15 18:19:14 -0400 | [diff] [blame] | 4122 | /* package */ static class UrlData { |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 4123 | final String mUrl; |
| 4124 | final Map<String, String> mHeaders; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4125 | final Intent mVoiceIntent; |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 4126 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4127 | UrlData(String url) { |
| 4128 | this.mUrl = url; |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 4129 | this.mHeaders = null; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4130 | this.mVoiceIntent = null; |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4131 | } |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 4132 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4133 | UrlData(String url, Map<String, String> headers, Intent intent) { |
Grace Kloba | 068e48b | 2010-01-26 18:11:27 -0800 | [diff] [blame] | 4134 | this.mUrl = url; |
| 4135 | this.mHeaders = headers; |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 4136 | if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS |
| 4137 | .equals(intent.getAction())) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4138 | this.mVoiceIntent = intent; |
| 4139 | } else { |
| 4140 | this.mVoiceIntent = null; |
| 4141 | } |
Grace Kloba | 60e095c | 2009-06-16 11:50:55 -0700 | [diff] [blame] | 4142 | } |
| 4143 | |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4144 | boolean isEmpty() { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4145 | return mVoiceIntent == null && (mUrl == null || mUrl.length() == 0); |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
Leon Scroggins | 92472e8 | 2010-02-17 16:32:28 -0500 | [diff] [blame] | 4148 | /** |
| 4149 | * Load this UrlData into the given Tab. Use loadUrlDataIn to update |
| 4150 | * the title bar as well. |
| 4151 | */ |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 4152 | public void loadIn(Tab t) { |
| 4153 | if (mVoiceIntent != null) { |
| 4154 | t.activateVoiceSearchMode(mVoiceIntent); |
| 4155 | } else { |
| 4156 | t.getWebView().loadUrl(mUrl, mHeaders); |
| 4157 | } |
Mitsuru Oshima | 25ad8ab | 2009-06-10 16:26:07 -0700 | [diff] [blame] | 4158 | } |
| 4159 | }; |
| 4160 | |
Leon Scroggins | 1f005d3 | 2009-08-10 17:36:42 -0400 | [diff] [blame] | 4161 | /* package */ static final UrlData EMPTY_URL_DATA = new UrlData(null); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 4162 | } |