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