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