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