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