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