Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
| 20 | import android.app.DownloadManager; |
| 21 | import android.app.SearchManager; |
| 22 | import android.content.ClipboardManager; |
| 23 | import android.content.ContentProvider; |
| 24 | import android.content.ContentProviderClient; |
| 25 | import android.content.ContentResolver; |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 26 | import android.content.ContentUris; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 27 | import android.content.ContentValues; |
| 28 | import android.content.Context; |
| 29 | import android.content.Intent; |
| 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.ResolveInfo; |
| 32 | import android.content.res.Configuration; |
John Reck | 30b065e | 2011-07-19 10:58:05 -0700 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 34 | import android.database.ContentObserver; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 35 | import android.database.Cursor; |
| 36 | import android.database.sqlite.SQLiteDatabase; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 37 | import android.graphics.Bitmap; |
| 38 | import android.graphics.Canvas; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
| 40 | import android.net.http.SslError; |
| 41 | import android.os.AsyncTask; |
| 42 | import android.os.Bundle; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 43 | import android.os.Environment; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 44 | import android.os.Handler; |
| 45 | import android.os.Message; |
| 46 | import android.os.PowerManager; |
| 47 | import android.os.PowerManager.WakeLock; |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 48 | import android.preference.PreferenceActivity; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 49 | import android.provider.Browser; |
| 50 | import android.provider.BrowserContract; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 51 | import android.provider.BrowserContract.Images; |
| 52 | import android.provider.ContactsContract; |
| 53 | import android.provider.ContactsContract.Intents.Insert; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 54 | import android.speech.RecognizerIntent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 55 | import android.text.TextUtils; |
| 56 | import android.util.Log; |
John Reck | a00cbbd | 2010-12-16 12:38:19 -0800 | [diff] [blame] | 57 | import android.util.Patterns; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 58 | import android.view.ActionMode; |
| 59 | import android.view.ContextMenu; |
| 60 | import android.view.ContextMenu.ContextMenuInfo; |
| 61 | import android.view.Gravity; |
| 62 | import android.view.KeyEvent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 63 | import android.view.Menu; |
| 64 | import android.view.MenuInflater; |
| 65 | import android.view.MenuItem; |
| 66 | import android.view.MenuItem.OnMenuItemClickListener; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 67 | import android.view.MotionEvent; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 68 | import android.view.View; |
| 69 | import android.webkit.CookieManager; |
| 70 | import android.webkit.CookieSyncManager; |
| 71 | import android.webkit.HttpAuthHandler; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 72 | import android.webkit.MimeTypeMap; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 73 | import android.webkit.SslErrorHandler; |
| 74 | import android.webkit.ValueCallback; |
| 75 | import android.webkit.WebChromeClient; |
| 76 | import android.webkit.WebIconDatabase; |
| 77 | import android.webkit.WebSettings; |
| 78 | import android.webkit.WebView; |
Leon Scroggins | ac99384 | 2011-02-02 12:54:07 -0500 | [diff] [blame] | 79 | import android.widget.Toast; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 80 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 81 | import com.android.browser.IntentHandler.UrlData; |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 82 | import com.android.browser.UI.ComboViews; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 83 | import com.android.browser.provider.BrowserProvider; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 84 | import com.android.browser.provider.BrowserProvider2.Thumbnails; |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 85 | import com.android.browser.provider.SnapshotProvider.Snapshots; |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 86 | import com.android.browser.search.SearchEngine; |
| 87 | import com.android.common.Search; |
| 88 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 89 | import java.io.ByteArrayOutputStream; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 90 | import java.io.File; |
| 91 | import java.io.FileOutputStream; |
| 92 | import java.io.IOException; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 93 | import java.net.URLEncoder; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 94 | import java.text.DateFormat; |
| 95 | import java.text.SimpleDateFormat; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 96 | import java.util.ArrayList; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 97 | import java.util.Calendar; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 98 | import java.util.Date; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 99 | import java.util.HashMap; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 100 | import java.util.List; |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 101 | import java.util.Map; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Controller for browser |
| 105 | */ |
| 106 | public class Controller |
| 107 | implements WebViewController, UiController { |
| 108 | |
| 109 | private static final String LOGTAG = "Controller"; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 110 | private static final String SEND_APP_ID_EXTRA = |
| 111 | "android.speech.extras.SEND_APPLICATION_ID_EXTRA"; |
Michael Kolb | a4261fd | 2011-05-05 11:27:37 -0700 | [diff] [blame] | 112 | private static final String INCOGNITO_URI = "browser:incognito"; |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 113 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 114 | |
| 115 | // public message ids |
| 116 | public final static int LOAD_URL = 1001; |
| 117 | public final static int STOP_LOAD = 1002; |
| 118 | |
| 119 | // Message Ids |
| 120 | private static final int FOCUS_NODE_HREF = 102; |
| 121 | private static final int RELEASE_WAKELOCK = 107; |
| 122 | |
| 123 | static final int UPDATE_BOOKMARK_THUMBNAIL = 108; |
| 124 | |
| 125 | private static final int OPEN_BOOKMARKS = 201; |
| 126 | |
| 127 | private static final int EMPTY_MENU = -1; |
| 128 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | // activity requestCode |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 130 | final static int COMBO_VIEW = 1; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 131 | final static int PREFERENCES_PAGE = 3; |
| 132 | final static int FILE_SELECTED = 4; |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 133 | final static int AUTOFILL_SETUP = 5; |
| 134 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 135 | private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes |
| 136 | |
| 137 | // As the ids are dynamically created, we can't guarantee that they will |
| 138 | // be in sequence, so this static array maps ids to a window number. |
| 139 | final static private int[] WINDOW_SHORTCUT_ID_ARRAY = |
| 140 | { R.id.window_one_menu_id, R.id.window_two_menu_id, |
| 141 | R.id.window_three_menu_id, R.id.window_four_menu_id, |
| 142 | R.id.window_five_menu_id, R.id.window_six_menu_id, |
| 143 | R.id.window_seven_menu_id, R.id.window_eight_menu_id }; |
| 144 | |
| 145 | // "source" parameter for Google search through search key |
| 146 | final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key"; |
| 147 | // "source" parameter for Google search through simplily type |
| 148 | final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type"; |
| 149 | |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 150 | // "no-crash-recovery" parameter in intent to suppress crash recovery |
Guang Zhu | 9e78f51 | 2011-05-04 11:45:11 -0700 | [diff] [blame] | 151 | final static String NO_CRASH_RECOVERY = "no-crash-recovery"; |
| 152 | |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 153 | // A bitmap that is re-used in createScreenshot as scratch space |
| 154 | private static Bitmap sThumbnailBitmap; |
| 155 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 156 | private Activity mActivity; |
| 157 | private UI mUi; |
| 158 | private TabControl mTabControl; |
| 159 | private BrowserSettings mSettings; |
| 160 | private WebViewFactory mFactory; |
| 161 | |
| 162 | private WakeLock mWakeLock; |
| 163 | |
| 164 | private UrlHandler mUrlHandler; |
| 165 | private UploadHandler mUploadHandler; |
| 166 | private IntentHandler mIntentHandler; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 167 | private PageDialogsHandler mPageDialogsHandler; |
| 168 | private NetworkStateHandler mNetworkHandler; |
| 169 | |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 170 | private Message mAutoFillSetupMessage; |
| 171 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 172 | private boolean mShouldShowErrorConsole; |
| 173 | |
| 174 | private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins; |
| 175 | |
| 176 | // FIXME, temp address onPrepareMenu performance problem. |
| 177 | // When we move everything out of view, we should rewrite this. |
| 178 | private int mCurrentMenuState = 0; |
| 179 | private int mMenuState = R.id.MAIN_MENU; |
| 180 | private int mOldMenuState = EMPTY_MENU; |
| 181 | private Menu mCachedMenu; |
| 182 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 183 | private boolean mMenuIsDown; |
| 184 | |
| 185 | // For select and find, we keep track of the ActionMode so that |
| 186 | // finish() can be called as desired. |
| 187 | private ActionMode mActionMode; |
| 188 | |
| 189 | /** |
| 190 | * Only meaningful when mOptionsMenuOpen is true. This variable keeps track |
| 191 | * of whether the configuration has changed. The first onMenuOpened call |
| 192 | * after a configuration change is simply a reopening of the same menu |
| 193 | * (i.e. mIconView did not change). |
| 194 | */ |
| 195 | private boolean mConfigChanged; |
| 196 | |
| 197 | /** |
| 198 | * Keeps track of whether the options menu is open. This is important in |
| 199 | * determining whether to show or hide the title bar overlay |
| 200 | */ |
| 201 | private boolean mOptionsMenuOpen; |
| 202 | |
| 203 | /** |
| 204 | * Whether or not the options menu is in its bigger, popup menu form. When |
| 205 | * true, we want the title bar overlay to be gone. When false, we do not. |
| 206 | * Only meaningful if mOptionsMenuOpen is true. |
| 207 | */ |
| 208 | private boolean mExtendedMenuOpen; |
| 209 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 210 | private boolean mActivityPaused = true; |
| 211 | private boolean mLoadStopped; |
| 212 | |
| 213 | private Handler mHandler; |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 214 | // Checks to see when the bookmarks database has changed, and updates the |
| 215 | // Tabs' notion of whether they represent bookmarked sites. |
| 216 | private ContentObserver mBookmarksObserver; |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 217 | private CrashRecoveryHandler mCrashRecoveryHandler; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 218 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 219 | private boolean mBlockEvents; |
| 220 | |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 221 | public Controller(Activity browser) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 222 | mActivity = browser; |
| 223 | mSettings = BrowserSettings.getInstance(); |
| 224 | mTabControl = new TabControl(this); |
| 225 | mSettings.setController(this); |
John Reck | 378a410 | 2011-06-09 16:23:01 -0700 | [diff] [blame] | 226 | mCrashRecoveryHandler = CrashRecoveryHandler.initialize(this); |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 227 | mCrashRecoveryHandler.preloadCrashState(); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 228 | mFactory = new BrowserWebViewFactory(browser); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 229 | |
| 230 | mUrlHandler = new UrlHandler(this); |
| 231 | mIntentHandler = new IntentHandler(mActivity, this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 232 | mPageDialogsHandler = new PageDialogsHandler(mActivity, this); |
| 233 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 234 | startHandler(); |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 235 | mBookmarksObserver = new ContentObserver(mHandler) { |
| 236 | @Override |
| 237 | public void onChange(boolean selfChange) { |
| 238 | int size = mTabControl.getTabCount(); |
| 239 | for (int i = 0; i < size; i++) { |
| 240 | mTabControl.getTab(i).updateBookmarkedStatus(); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | }; |
| 245 | browser.getContentResolver().registerContentObserver( |
| 246 | BrowserContract.Bookmarks.CONTENT_URI, true, mBookmarksObserver); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 247 | |
| 248 | mNetworkHandler = new NetworkStateHandler(mActivity, this); |
| 249 | // Start watching the default geolocation permissions |
| 250 | mSystemAllowGeolocationOrigins = |
| 251 | new SystemAllowGeolocationOrigins(mActivity.getApplicationContext()); |
| 252 | mSystemAllowGeolocationOrigins.start(); |
| 253 | |
John Reck | af262e7 | 2011-07-25 13:55:44 -0700 | [diff] [blame] | 254 | openIconDatabase(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 255 | } |
| 256 | |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 257 | void start(final Intent intent) { |
| 258 | // mCrashRecoverHandler has any previously saved state. |
| 259 | mCrashRecoveryHandler.startRecovery(intent); |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 260 | } |
| 261 | |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 262 | void doStart(final Bundle icicle, final Intent intent) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 263 | // Unless the last browser usage was within 24 hours, destroy any |
| 264 | // remaining incognito tabs. |
| 265 | |
| 266 | Calendar lastActiveDate = icicle != null ? |
| 267 | (Calendar) icicle.getSerializable("lastActiveDate") : null; |
| 268 | Calendar today = Calendar.getInstance(); |
| 269 | Calendar yesterday = Calendar.getInstance(); |
| 270 | yesterday.add(Calendar.DATE, -1); |
| 271 | |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 272 | final boolean restoreIncognitoTabs = !(lastActiveDate == null |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 273 | || lastActiveDate.before(yesterday) |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 274 | || lastActiveDate.after(today)); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 275 | |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 276 | // Find out if we will restore any state and remember the tab. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 277 | final long currentTabId = |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 278 | mTabControl.canRestoreState(icicle, restoreIncognitoTabs); |
Kristian Monsen | 2cd9701 | 2010-12-07 11:11:40 +0000 | [diff] [blame] | 279 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 280 | if (currentTabId == -1) { |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 281 | // Not able to restore so we go ahead and clear session cookies. We |
| 282 | // must do this before trying to login the user as we don't want to |
| 283 | // clear any session cookies set during login. |
| 284 | CookieManager.getInstance().removeSessionCookie(); |
| 285 | } |
| 286 | |
Patrick Scott | d43e75a | 2011-03-14 14:47:23 -0400 | [diff] [blame] | 287 | GoogleAccountLogin.startLoginIfNeeded(mActivity, |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 288 | new Runnable() { |
| 289 | @Override public void run() { |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 290 | onPreloginFinished(icicle, intent, currentTabId, |
| 291 | restoreIncognitoTabs); |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 292 | } |
| 293 | }); |
| 294 | } |
| 295 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 296 | private void onPreloginFinished(Bundle icicle, Intent intent, long currentTabId, |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 297 | boolean restoreIncognitoTabs) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 298 | if (currentTabId == -1) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 299 | BackgroundHandler.execute(new PruneThumbnails(mActivity, null)); |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 300 | if (intent == null) { |
| 301 | // This won't happen under common scenarios. The icicle is |
| 302 | // not null, but there aren't any tabs to restore. |
| 303 | openTabToHomePage(); |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 304 | } else { |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 305 | final Bundle extra = intent.getExtras(); |
| 306 | // Create an initial tab. |
| 307 | // If the intent is ACTION_VIEW and data is not null, the Browser is |
| 308 | // invoked to view the content by another application. In this case, |
| 309 | // the tab will be close when exit. |
| 310 | UrlData urlData = IntentHandler.getUrlDataFromIntent(intent); |
| 311 | Tab t = null; |
| 312 | if (urlData.isEmpty()) { |
| 313 | t = openTabToHomePage(); |
| 314 | } else { |
| 315 | t = openTab(urlData); |
| 316 | } |
| 317 | if (t != null) { |
| 318 | t.setAppId(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID)); |
| 319 | } |
| 320 | WebView webView = t.getWebView(); |
| 321 | if (extra != null) { |
| 322 | int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0); |
| 323 | if (scale > 0 && scale <= 1000) { |
| 324 | webView.setInitialScale(scale); |
| 325 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 328 | mUi.updateTabs(mTabControl.getTabs()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 329 | } else { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 330 | mTabControl.restoreState(icicle, currentTabId, restoreIncognitoTabs, |
Patrick Scott | 7d50a93 | 2011-02-04 09:27:26 -0500 | [diff] [blame] | 331 | mUi.needsRestoreAllTabs()); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 332 | List<Tab> tabs = mTabControl.getTabs(); |
| 333 | ArrayList<Long> restoredTabs = new ArrayList<Long>(tabs.size()); |
| 334 | for (Tab t : tabs) { |
| 335 | restoredTabs.add(t.getId()); |
| 336 | } |
| 337 | BackgroundHandler.execute(new PruneThumbnails(mActivity, restoredTabs)); |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 338 | if (tabs.size() == 0) { |
| 339 | openTabToHomePage(); |
| 340 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 341 | mUi.updateTabs(tabs); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 342 | // TabControl.restoreState() will create a new tab even if |
| 343 | // restoring the state fails. |
| 344 | setActiveTab(mTabControl.getCurrentTab()); |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 345 | // Intent is non-null when framework thinks the browser should be |
| 346 | // launching with a new intent (icicle is null). |
| 347 | if (intent != null) { |
John Reck | 9dd4a41 | 2011-10-05 14:55:30 -0700 | [diff] [blame] | 348 | mIntentHandler.onNewIntent(intent); |
| 349 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 350 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 351 | // Read JavaScript flags if it exists. |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 352 | String jsFlags = getSettings().getJsEngineFlags(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 353 | if (jsFlags.trim().length() != 0) { |
| 354 | getCurrentWebView().setJsFlags(jsFlags); |
| 355 | } |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 356 | if (intent != null |
| 357 | && BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) { |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 358 | bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 359 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 360 | } |
| 361 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 362 | private static class PruneThumbnails implements Runnable { |
| 363 | private Context mContext; |
| 364 | private List<Long> mIds; |
| 365 | |
| 366 | PruneThumbnails(Context context, List<Long> preserveIds) { |
| 367 | mContext = context.getApplicationContext(); |
| 368 | mIds = preserveIds; |
| 369 | } |
| 370 | |
| 371 | @Override |
| 372 | public void run() { |
| 373 | ContentResolver cr = mContext.getContentResolver(); |
| 374 | if (mIds == null || mIds.size() == 0) { |
| 375 | cr.delete(Thumbnails.CONTENT_URI, null, null); |
| 376 | } else { |
| 377 | int length = mIds.size(); |
| 378 | StringBuilder where = new StringBuilder(); |
| 379 | where.append(Thumbnails._ID); |
| 380 | where.append(" not in ("); |
| 381 | for (int i = 0; i < length; i++) { |
| 382 | where.append(mIds.get(i)); |
| 383 | if (i < (length - 1)) { |
| 384 | where.append(","); |
| 385 | } |
| 386 | } |
| 387 | where.append(")"); |
| 388 | cr.delete(Thumbnails.CONTENT_URI, where.toString(), null); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | } |
| 393 | |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 394 | @Override |
| 395 | public WebViewFactory getWebViewFactory() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 396 | return mFactory; |
| 397 | } |
| 398 | |
| 399 | @Override |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 400 | public void onSetWebView(Tab tab, WebView view) { |
| 401 | mUi.onSetWebView(tab, view); |
| 402 | } |
| 403 | |
| 404 | @Override |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 405 | public void createSubWindow(Tab tab) { |
| 406 | endActionMode(); |
| 407 | WebView mainView = tab.getWebView(); |
| 408 | WebView subView = mFactory.createWebView((mainView == null) |
| 409 | ? false |
| 410 | : mainView.isPrivateBrowsingEnabled()); |
| 411 | mUi.createSubWindow(tab, subView); |
| 412 | } |
| 413 | |
| 414 | @Override |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 415 | public Context getContext() { |
| 416 | return mActivity; |
| 417 | } |
| 418 | |
| 419 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 420 | public Activity getActivity() { |
| 421 | return mActivity; |
| 422 | } |
| 423 | |
| 424 | void setUi(UI ui) { |
| 425 | mUi = ui; |
| 426 | } |
| 427 | |
| 428 | BrowserSettings getSettings() { |
| 429 | return mSettings; |
| 430 | } |
| 431 | |
| 432 | IntentHandler getIntentHandler() { |
| 433 | return mIntentHandler; |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public UI getUi() { |
| 438 | return mUi; |
| 439 | } |
| 440 | |
| 441 | int getMaxTabs() { |
| 442 | return mActivity.getResources().getInteger(R.integer.max_tabs); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public TabControl getTabControl() { |
| 447 | return mTabControl; |
| 448 | } |
| 449 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 450 | @Override |
| 451 | public List<Tab> getTabs() { |
| 452 | return mTabControl.getTabs(); |
| 453 | } |
| 454 | |
John Reck | af262e7 | 2011-07-25 13:55:44 -0700 | [diff] [blame] | 455 | // Open the icon database. |
| 456 | private void openIconDatabase() { |
| 457 | // We have to call getInstance on the UI thread |
| 458 | final WebIconDatabase instance = WebIconDatabase.getInstance(); |
| 459 | BackgroundHandler.execute(new Runnable() { |
Ben Murdoch | 9446b93 | 2010-11-25 16:20:14 +0000 | [diff] [blame] | 460 | |
John Reck | af262e7 | 2011-07-25 13:55:44 -0700 | [diff] [blame] | 461 | @Override |
| 462 | public void run() { |
| 463 | instance.open(mActivity.getDir("icons", 0).getPath()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 464 | } |
John Reck | af262e7 | 2011-07-25 13:55:44 -0700 | [diff] [blame] | 465 | }); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | private void startHandler() { |
| 469 | mHandler = new Handler() { |
| 470 | |
| 471 | @Override |
| 472 | public void handleMessage(Message msg) { |
| 473 | switch (msg.what) { |
| 474 | case OPEN_BOOKMARKS: |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 475 | bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 476 | break; |
| 477 | case FOCUS_NODE_HREF: |
| 478 | { |
| 479 | String url = (String) msg.getData().get("url"); |
| 480 | String title = (String) msg.getData().get("title"); |
Cary Clark | 043c2d6 | 2010-12-15 11:19:39 -0500 | [diff] [blame] | 481 | String src = (String) msg.getData().get("src"); |
| 482 | if (url == "") url = src; // use image if no anchor |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 483 | if (TextUtils.isEmpty(url)) { |
| 484 | break; |
| 485 | } |
| 486 | HashMap focusNodeMap = (HashMap) msg.obj; |
| 487 | WebView view = (WebView) focusNodeMap.get("webview"); |
| 488 | // Only apply the action if the top window did not change. |
| 489 | if (getCurrentTopWebView() != view) { |
| 490 | break; |
| 491 | } |
| 492 | switch (msg.arg1) { |
| 493 | case R.id.open_context_menu_id: |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 494 | loadUrlFromContext(url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 495 | break; |
Cary Clark | 043c2d6 | 2010-12-15 11:19:39 -0500 | [diff] [blame] | 496 | case R.id.view_image_context_menu_id: |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 497 | loadUrlFromContext(src); |
Cary Clark | 043c2d6 | 2010-12-15 11:19:39 -0500 | [diff] [blame] | 498 | break; |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 499 | case R.id.open_newtab_context_menu_id: |
| 500 | final Tab parent = mTabControl.getCurrentTab(); |
John Reck | 5949c66 | 2011-05-27 09:52:29 -0700 | [diff] [blame] | 501 | openTab(url, parent, |
| 502 | !mSettings.openInBackground(), true); |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 503 | break; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 504 | case R.id.copy_link_context_menu_id: |
| 505 | copy(url); |
| 506 | break; |
| 507 | case R.id.save_link_context_menu_id: |
| 508 | case R.id.download_context_menu_id: |
Leon Scroggins | 63c0266 | 2010-11-18 15:16:27 -0500 | [diff] [blame] | 509 | DownloadHandler.onDownloadStartNoStream( |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 510 | mActivity, url, null, null, null, |
| 511 | view.isPrivateBrowsingEnabled()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 512 | break; |
| 513 | } |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | case LOAD_URL: |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 518 | loadUrlFromContext((String) msg.obj); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 519 | break; |
| 520 | |
| 521 | case STOP_LOAD: |
| 522 | stopLoading(); |
| 523 | break; |
| 524 | |
| 525 | case RELEASE_WAKELOCK: |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 526 | if (mWakeLock != null && mWakeLock.isHeld()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 527 | mWakeLock.release(); |
| 528 | // if we reach here, Browser should be still in the |
| 529 | // background loading after WAKELOCK_TIMEOUT (5-min). |
| 530 | // To avoid burning the battery, stop loading. |
| 531 | mTabControl.stopAllLoading(); |
| 532 | } |
| 533 | break; |
| 534 | |
| 535 | case UPDATE_BOOKMARK_THUMBNAIL: |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 536 | Tab tab = (Tab) msg.obj; |
| 537 | if (tab != null) { |
| 538 | updateScreenshot(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 539 | } |
| 540 | break; |
| 541 | } |
| 542 | } |
| 543 | }; |
| 544 | |
| 545 | } |
| 546 | |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 547 | @Override |
Martijn Coenen | b2f9355 | 2011-06-14 10:48:35 +0200 | [diff] [blame] | 548 | public Tab getCurrentTab() { |
| 549 | return mTabControl.getCurrentTab(); |
| 550 | } |
| 551 | |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 552 | @Override |
| 553 | public void shareCurrentPage() { |
| 554 | shareCurrentPage(mTabControl.getCurrentTab()); |
| 555 | } |
| 556 | |
| 557 | private void shareCurrentPage(Tab tab) { |
| 558 | if (tab != null) { |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 559 | sharePage(mActivity, tab.getTitle(), |
| 560 | tab.getUrl(), tab.getFavicon(), |
| 561 | createScreenshot(tab.getWebView(), |
| 562 | getDesiredThumbnailWidth(mActivity), |
| 563 | getDesiredThumbnailHeight(mActivity))); |
| 564 | } |
| 565 | } |
| 566 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 567 | /** |
| 568 | * Share a page, providing the title, url, favicon, and a screenshot. Uses |
| 569 | * an {@link Intent} to launch the Activity chooser. |
| 570 | * @param c Context used to launch a new Activity. |
| 571 | * @param title Title of the page. Stored in the Intent with |
| 572 | * {@link Intent#EXTRA_SUBJECT} |
| 573 | * @param url URL of the page. Stored in the Intent with |
| 574 | * {@link Intent#EXTRA_TEXT} |
| 575 | * @param favicon Bitmap of the favicon for the page. Stored in the Intent |
| 576 | * with {@link Browser#EXTRA_SHARE_FAVICON} |
| 577 | * @param screenshot Bitmap of a screenshot of the page. Stored in the |
| 578 | * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT} |
| 579 | */ |
| 580 | static final void sharePage(Context c, String title, String url, |
| 581 | Bitmap favicon, Bitmap screenshot) { |
| 582 | Intent send = new Intent(Intent.ACTION_SEND); |
| 583 | send.setType("text/plain"); |
| 584 | send.putExtra(Intent.EXTRA_TEXT, url); |
| 585 | send.putExtra(Intent.EXTRA_SUBJECT, title); |
| 586 | send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon); |
| 587 | send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot); |
| 588 | try { |
| 589 | c.startActivity(Intent.createChooser(send, c.getString( |
| 590 | R.string.choosertitle_sharevia))); |
| 591 | } catch(android.content.ActivityNotFoundException ex) { |
| 592 | // if no app handles it, do nothing |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | private void copy(CharSequence text) { |
| 597 | ClipboardManager cm = (ClipboardManager) mActivity |
| 598 | .getSystemService(Context.CLIPBOARD_SERVICE); |
| 599 | cm.setText(text); |
| 600 | } |
| 601 | |
| 602 | // lifecycle |
| 603 | |
| 604 | protected void onConfgurationChanged(Configuration config) { |
| 605 | mConfigChanged = true; |
| 606 | if (mPageDialogsHandler != null) { |
| 607 | mPageDialogsHandler.onConfigurationChanged(config); |
| 608 | } |
| 609 | mUi.onConfigurationChanged(config); |
| 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public void handleNewIntent(Intent intent) { |
Michael Kolb | 59e232c | 2011-08-18 17:19:53 -0700 | [diff] [blame] | 614 | if (!mUi.isWebShowing()) { |
| 615 | mUi.showWeb(false); |
| 616 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 617 | mIntentHandler.onNewIntent(intent); |
| 618 | } |
| 619 | |
| 620 | protected void onPause() { |
Michael Kolb | 11fe02d | 2011-02-02 09:52:16 -0800 | [diff] [blame] | 621 | if (mUi.isCustomViewShowing()) { |
| 622 | hideCustomView(); |
| 623 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 624 | if (mActivityPaused) { |
| 625 | Log.e(LOGTAG, "BrowserActivity is already paused."); |
| 626 | return; |
| 627 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 628 | mActivityPaused = true; |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 629 | Tab tab = mTabControl.getCurrentTab(); |
| 630 | if (tab != null) { |
| 631 | tab.pause(); |
| 632 | if (!pauseWebViewTimers(tab)) { |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 633 | if (mWakeLock == null) { |
| 634 | PowerManager pm = (PowerManager) mActivity |
| 635 | .getSystemService(Context.POWER_SERVICE); |
| 636 | mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser"); |
| 637 | } |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 638 | mWakeLock.acquire(); |
| 639 | mHandler.sendMessageDelayed(mHandler |
| 640 | .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT); |
| 641 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 642 | } |
| 643 | mUi.onPause(); |
| 644 | mNetworkHandler.onPause(); |
| 645 | |
| 646 | WebView.disablePlatformNotifications(); |
Ben Murdoch | 015e1e3 | 2011-09-01 23:45:31 +0100 | [diff] [blame] | 647 | NfcHandler.unregister(mActivity); |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 648 | if (sThumbnailBitmap != null) { |
| 649 | sThumbnailBitmap.recycle(); |
| 650 | sThumbnailBitmap = null; |
| 651 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 652 | } |
| 653 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 654 | void onSaveInstanceState(Bundle outState) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 655 | // Save all the tabs |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 656 | Bundle saveState = createSaveState(); |
| 657 | |
| 658 | // crash recovery manages all save & restore state |
| 659 | mCrashRecoveryHandler.writeState(saveState); |
| 660 | mSettings.setLastRunPaused(true); |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * Save the current state to outState. Does not write the state to |
| 665 | * disk. |
| 666 | * @return Bundle containing the current state of all tabs. |
| 667 | */ |
| 668 | /* package */ Bundle createSaveState() { |
| 669 | Bundle saveState = new Bundle(); |
| 670 | mTabControl.saveState(saveState); |
| 671 | if (!saveState.isEmpty()) { |
John Reck | 24f1826 | 2011-06-17 14:47:20 -0700 | [diff] [blame] | 672 | // Save time so that we know how old incognito tabs (if any) are. |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 673 | saveState.putSerializable("lastActiveDate", Calendar.getInstance()); |
John Reck | 24f1826 | 2011-06-17 14:47:20 -0700 | [diff] [blame] | 674 | } |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 675 | return saveState; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | void onResume() { |
| 679 | if (!mActivityPaused) { |
| 680 | Log.e(LOGTAG, "BrowserActivity is already resumed."); |
| 681 | return; |
| 682 | } |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 683 | mSettings.setLastRunPaused(false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 684 | mActivityPaused = false; |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 685 | Tab current = mTabControl.getCurrentTab(); |
| 686 | if (current != null) { |
| 687 | current.resume(); |
| 688 | resumeWebViewTimers(current); |
| 689 | } |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 690 | releaseWakeLock(); |
Martijn Coenen | b2f9355 | 2011-06-14 10:48:35 +0200 | [diff] [blame] | 691 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 692 | mUi.onResume(); |
| 693 | mNetworkHandler.onResume(); |
| 694 | WebView.enablePlatformNotifications(); |
Ben Murdoch | 015e1e3 | 2011-09-01 23:45:31 +0100 | [diff] [blame] | 695 | NfcHandler.register(mActivity, this); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 696 | } |
| 697 | |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 698 | private void releaseWakeLock() { |
| 699 | if (mWakeLock != null && mWakeLock.isHeld()) { |
| 700 | mHandler.removeMessages(RELEASE_WAKELOCK); |
| 701 | mWakeLock.release(); |
| 702 | } |
| 703 | } |
| 704 | |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 705 | /** |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 706 | * resume all WebView timers using the WebView instance of the given tab |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 707 | * @param tab guaranteed non-null |
| 708 | */ |
| 709 | private void resumeWebViewTimers(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 710 | boolean inLoad = tab.inPageLoad(); |
| 711 | if ((!mActivityPaused && !inLoad) || (mActivityPaused && inLoad)) { |
| 712 | CookieSyncManager.getInstance().startSync(); |
| 713 | WebView w = tab.getWebView(); |
Mathew Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 714 | WebViewTimersControl.getInstance().onBrowserActivityResume(w); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 715 | } |
| 716 | } |
| 717 | |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 718 | /** |
| 719 | * Pause all WebView timers using the WebView of the given tab |
| 720 | * @param tab |
| 721 | * @return true if the timers are paused or tab is null |
| 722 | */ |
| 723 | private boolean pauseWebViewTimers(Tab tab) { |
| 724 | if (tab == null) { |
| 725 | return true; |
| 726 | } else if (!tab.inPageLoad()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 727 | CookieSyncManager.getInstance().stopSync(); |
Mathew Inwood | e1dbb95 | 2011-07-08 17:27:38 +0100 | [diff] [blame] | 728 | WebViewTimersControl.getInstance().onBrowserActivityPause(getCurrentWebView()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 729 | return true; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 730 | } |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 731 | return false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | void onDestroy() { |
John Reck | 38b4bf5 | 2011-02-22 14:39:34 -0800 | [diff] [blame] | 735 | if (mUploadHandler != null && !mUploadHandler.handled()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 736 | mUploadHandler.onResult(Activity.RESULT_CANCELED, null); |
| 737 | mUploadHandler = null; |
| 738 | } |
| 739 | if (mTabControl == null) return; |
| 740 | mUi.onDestroy(); |
| 741 | // Remove the current tab and sub window |
| 742 | Tab t = mTabControl.getCurrentTab(); |
| 743 | if (t != null) { |
| 744 | dismissSubWindow(t); |
| 745 | removeTab(t); |
| 746 | } |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 747 | mActivity.getContentResolver().unregisterContentObserver(mBookmarksObserver); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 748 | // Destroy all the tabs |
| 749 | mTabControl.destroy(); |
| 750 | WebIconDatabase.getInstance().close(); |
| 751 | // Stop watching the default geolocation permissions |
| 752 | mSystemAllowGeolocationOrigins.stop(); |
| 753 | mSystemAllowGeolocationOrigins = null; |
| 754 | } |
| 755 | |
| 756 | protected boolean isActivityPaused() { |
| 757 | return mActivityPaused; |
| 758 | } |
| 759 | |
| 760 | protected void onLowMemory() { |
| 761 | mTabControl.freeMemory(); |
| 762 | } |
| 763 | |
| 764 | @Override |
| 765 | public boolean shouldShowErrorConsole() { |
| 766 | return mShouldShowErrorConsole; |
| 767 | } |
| 768 | |
| 769 | protected void setShouldShowErrorConsole(boolean show) { |
| 770 | if (show == mShouldShowErrorConsole) { |
| 771 | // Nothing to do. |
| 772 | return; |
| 773 | } |
| 774 | mShouldShowErrorConsole = show; |
| 775 | Tab t = mTabControl.getCurrentTab(); |
| 776 | if (t == null) { |
| 777 | // There is no current tab so we cannot toggle the error console |
| 778 | return; |
| 779 | } |
| 780 | mUi.setShouldShowErrorConsole(t, show); |
| 781 | } |
| 782 | |
| 783 | @Override |
| 784 | public void stopLoading() { |
| 785 | mLoadStopped = true; |
| 786 | Tab tab = mTabControl.getCurrentTab(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 787 | WebView w = getCurrentTopWebView(); |
| 788 | w.stopLoading(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 789 | mUi.onPageStopped(tab); |
| 790 | } |
| 791 | |
| 792 | boolean didUserStopLoading() { |
| 793 | return mLoadStopped; |
| 794 | } |
| 795 | |
| 796 | // WebViewController |
| 797 | |
| 798 | @Override |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 799 | public void onPageStarted(Tab tab, WebView view, Bitmap favicon) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 800 | |
| 801 | // We've started to load a new page. If there was a pending message |
| 802 | // to save a screenshot then we will now take the new page and save |
| 803 | // an incorrect screenshot. Therefore, remove any pending thumbnail |
| 804 | // messages from the queue. |
| 805 | mHandler.removeMessages(Controller.UPDATE_BOOKMARK_THUMBNAIL, |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 806 | tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 807 | |
| 808 | // reset sync timer to avoid sync starts during loading a page |
| 809 | CookieSyncManager.getInstance().resetSync(); |
| 810 | |
| 811 | if (!mNetworkHandler.isNetworkUp()) { |
| 812 | view.setNetworkAvailable(false); |
| 813 | } |
| 814 | |
| 815 | // when BrowserActivity just starts, onPageStarted may be called before |
| 816 | // onResume as it is triggered from onCreate. Call resumeWebViewTimers |
| 817 | // to start the timer. As we won't switch tabs while an activity is in |
| 818 | // pause state, we can ensure calling resume and pause in pair. |
| 819 | if (mActivityPaused) { |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 820 | resumeWebViewTimers(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 821 | } |
| 822 | mLoadStopped = false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 823 | endActionMode(); |
| 824 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 825 | mUi.onTabDataChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 826 | |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 827 | String url = tab.getUrl(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 828 | // update the bookmark database for favicon |
| 829 | maybeUpdateFavicon(tab, null, url, favicon); |
| 830 | |
| 831 | Performance.tracePageStart(url); |
| 832 | |
| 833 | // Performance probe |
| 834 | if (false) { |
| 835 | Performance.onPageStarted(); |
| 836 | } |
| 837 | |
| 838 | } |
| 839 | |
| 840 | @Override |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 841 | public void onPageFinished(Tab tab) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 842 | mUi.onTabDataChanged(tab); |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 843 | if (!tab.isPrivateBrowsingEnabled() |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 844 | && !TextUtils.isEmpty(tab.getUrl()) |
| 845 | && !tab.isSnapshot()) { |
John Reck | a169628 | 2011-07-08 14:10:37 -0700 | [diff] [blame] | 846 | // Only update the bookmark screenshot if the user did not |
| 847 | // cancel the load early and there is not already |
| 848 | // a pending update for the tab. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 849 | if (tab.inForeground() && !didUserStopLoading() |
| 850 | || !tab.inForeground()) { |
John Reck | a169628 | 2011-07-08 14:10:37 -0700 | [diff] [blame] | 851 | if (!mHandler.hasMessages(UPDATE_BOOKMARK_THUMBNAIL, tab)) { |
| 852 | mHandler.sendMessageDelayed(mHandler.obtainMessage( |
| 853 | UPDATE_BOOKMARK_THUMBNAIL, 0, 0, tab), |
| 854 | 500); |
| 855 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | // pause the WebView timer and release the wake lock if it is finished |
| 859 | // while BrowserActivity is in pause state. |
Michael Kolb | 7097693 | 2010-11-30 11:34:01 -0800 | [diff] [blame] | 860 | if (mActivityPaused && pauseWebViewTimers(tab)) { |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 861 | releaseWakeLock(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 862 | } |
Martijn Coenen | b2f9355 | 2011-06-14 10:48:35 +0200 | [diff] [blame] | 863 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 864 | // Performance probe |
| 865 | if (false) { |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 866 | Performance.onPageFinished(tab.getUrl()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | Performance.tracePageFinished(); |
| 870 | } |
| 871 | |
| 872 | @Override |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 873 | public void onProgressChanged(Tab tab) { |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 874 | mCrashRecoveryHandler.backupState(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 875 | int newProgress = tab.getLoadProgress(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 876 | |
| 877 | if (newProgress == 100) { |
| 878 | CookieSyncManager.getInstance().sync(); |
| 879 | // onProgressChanged() may continue to be called after the main |
| 880 | // frame has finished loading, as any remaining sub frames continue |
| 881 | // to load. We'll only get called once though with newProgress as |
| 882 | // 100 when everything is loaded. (onPageFinished is called once |
| 883 | // when the main frame completes loading regardless of the state of |
| 884 | // any sub frames so calls to onProgressChanges may continue after |
| 885 | // onPageFinished has executed) |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 886 | if (tab.inPageLoad()) { |
| 887 | updateInLoadMenuItems(mCachedMenu, tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 888 | } |
| 889 | } else { |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 890 | if (!tab.inPageLoad()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 891 | // onPageFinished may have already been called but a subframe is |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 892 | // still loading |
| 893 | // updating the progress and |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 894 | // update the menu items. |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 895 | updateInLoadMenuItems(mCachedMenu, tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 896 | } |
| 897 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 898 | mUi.onProgressChanged(tab); |
| 899 | } |
| 900 | |
| 901 | @Override |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 902 | public void onUpdatedSecurityState(Tab tab) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 903 | mUi.onTabDataChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | @Override |
| 907 | public void onReceivedTitle(Tab tab, final String title) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 908 | mUi.onTabDataChanged(tab); |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 909 | final String pageUrl = tab.getOriginalUrl(); |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 910 | if (TextUtils.isEmpty(pageUrl) || pageUrl.length() |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 911 | >= SQLiteDatabase.SQLITE_MAX_LIKE_PATTERN_LENGTH) { |
| 912 | return; |
| 913 | } |
| 914 | // Update the title in the history database if not in private browsing mode |
| 915 | if (!tab.isPrivateBrowsingEnabled()) { |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 916 | DataController.getInstance(mActivity).updateHistoryTitle(pageUrl, title); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 917 | } |
| 918 | } |
| 919 | |
| 920 | @Override |
| 921 | public void onFavicon(Tab tab, WebView view, Bitmap icon) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 922 | mUi.onTabDataChanged(tab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 923 | maybeUpdateFavicon(tab, view.getOriginalUrl(), view.getUrl(), icon); |
| 924 | } |
| 925 | |
| 926 | @Override |
Michael Kolb | 18eb377 | 2010-12-10 14:29:51 -0800 | [diff] [blame] | 927 | public boolean shouldOverrideUrlLoading(Tab tab, WebView view, String url) { |
| 928 | return mUrlHandler.shouldOverrideUrlLoading(tab, view, url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | @Override |
| 932 | public boolean shouldOverrideKeyEvent(KeyEvent event) { |
| 933 | if (mMenuIsDown) { |
| 934 | // only check shortcut key when MENU is held |
| 935 | return mActivity.getWindow().isShortcutKey(event.getKeyCode(), |
| 936 | event); |
| 937 | } else { |
| 938 | return false; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | @Override |
| 943 | public void onUnhandledKeyEvent(KeyEvent event) { |
| 944 | if (!isActivityPaused()) { |
| 945 | if (event.getAction() == KeyEvent.ACTION_DOWN) { |
| 946 | mActivity.onKeyDown(event.getKeyCode(), event); |
| 947 | } else { |
| 948 | mActivity.onKeyUp(event.getKeyCode(), event); |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | @Override |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 954 | public void doUpdateVisitedHistory(Tab tab, boolean isReload) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 955 | // Don't save anything in private browsing mode |
| 956 | if (tab.isPrivateBrowsingEnabled()) return; |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 957 | String url = tab.getOriginalUrl(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 958 | |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 959 | if (TextUtils.isEmpty(url) |
| 960 | || url.regionMatches(true, 0, "about:", 0, 6)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 961 | return; |
| 962 | } |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 963 | DataController.getInstance(mActivity).updateVisitedHistory(url); |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 964 | mCrashRecoveryHandler.backupState(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | @Override |
| 968 | public void getVisitedHistory(final ValueCallback<String[]> callback) { |
| 969 | AsyncTask<Void, Void, String[]> task = |
| 970 | new AsyncTask<Void, Void, String[]>() { |
| 971 | @Override |
| 972 | public String[] doInBackground(Void... unused) { |
| 973 | return Browser.getVisitedHistory(mActivity.getContentResolver()); |
| 974 | } |
| 975 | @Override |
| 976 | public void onPostExecute(String[] result) { |
| 977 | callback.onReceiveValue(result); |
| 978 | } |
| 979 | }; |
| 980 | task.execute(); |
| 981 | } |
| 982 | |
| 983 | @Override |
| 984 | public void onReceivedHttpAuthRequest(Tab tab, WebView view, |
| 985 | final HttpAuthHandler handler, final String host, |
| 986 | final String realm) { |
| 987 | String username = null; |
| 988 | String password = null; |
| 989 | |
| 990 | boolean reuseHttpAuthUsernamePassword |
| 991 | = handler.useHttpAuthUsernamePassword(); |
| 992 | |
| 993 | if (reuseHttpAuthUsernamePassword && view != null) { |
| 994 | String[] credentials = view.getHttpAuthUsernamePassword(host, realm); |
| 995 | if (credentials != null && credentials.length == 2) { |
| 996 | username = credentials[0]; |
| 997 | password = credentials[1]; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | if (username != null && password != null) { |
| 1002 | handler.proceed(username, password); |
| 1003 | } else { |
Ben Murdoch | fdd3711 | 2011-08-05 15:48:14 +0100 | [diff] [blame] | 1004 | if (tab.inForeground() && !handler.suppressDialog()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1005 | mPageDialogsHandler.showHttpAuthentication(tab, handler, host, realm); |
| 1006 | } else { |
| 1007 | handler.cancel(); |
| 1008 | } |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | @Override |
| 1013 | public void onDownloadStart(Tab tab, String url, String userAgent, |
| 1014 | String contentDisposition, String mimetype, long contentLength) { |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 1015 | WebView w = tab.getWebView(); |
Leon Scroggins | 63c0266 | 2010-11-18 15:16:27 -0500 | [diff] [blame] | 1016 | DownloadHandler.onDownloadStart(mActivity, url, userAgent, |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 1017 | contentDisposition, mimetype, w.isPrivateBrowsingEnabled()); |
| 1018 | if (w.copyBackForwardList().getSize() == 0) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1019 | // This Tab was opened for the sole purpose of downloading a |
| 1020 | // file. Remove it. |
| 1021 | if (tab == mTabControl.getCurrentTab()) { |
| 1022 | // In this case, the Tab is still on top. |
| 1023 | goBackOnePageOrQuit(); |
| 1024 | } else { |
| 1025 | // In this case, it is not. |
| 1026 | closeTab(tab); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | @Override |
| 1032 | public Bitmap getDefaultVideoPoster() { |
| 1033 | return mUi.getDefaultVideoPoster(); |
| 1034 | } |
| 1035 | |
| 1036 | @Override |
| 1037 | public View getVideoLoadingProgressView() { |
| 1038 | return mUi.getVideoLoadingProgressView(); |
| 1039 | } |
| 1040 | |
| 1041 | @Override |
| 1042 | public void showSslCertificateOnError(WebView view, SslErrorHandler handler, |
| 1043 | SslError error) { |
| 1044 | mPageDialogsHandler.showSSLCertificateOnError(view, handler, error); |
| 1045 | } |
| 1046 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 1047 | @Override |
| 1048 | public void showAutoLogin(Tab tab) { |
| 1049 | assert tab.inForeground(); |
| 1050 | // Update the title bar to show the auto-login request. |
| 1051 | mUi.showAutoLogin(tab); |
| 1052 | } |
| 1053 | |
| 1054 | @Override |
| 1055 | public void hideAutoLogin(Tab tab) { |
| 1056 | assert tab.inForeground(); |
| 1057 | mUi.hideAutoLogin(tab); |
| 1058 | } |
| 1059 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1060 | // helper method |
| 1061 | |
| 1062 | /* |
| 1063 | * Update the favorites icon if the private browsing isn't enabled and the |
| 1064 | * icon is valid. |
| 1065 | */ |
| 1066 | private void maybeUpdateFavicon(Tab tab, final String originalUrl, |
| 1067 | final String url, Bitmap favicon) { |
| 1068 | if (favicon == null) { |
| 1069 | return; |
| 1070 | } |
| 1071 | if (!tab.isPrivateBrowsingEnabled()) { |
| 1072 | Bookmarks.updateFavicon(mActivity |
| 1073 | .getContentResolver(), originalUrl, url, favicon); |
| 1074 | } |
| 1075 | } |
| 1076 | |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 1077 | @Override |
| 1078 | public void bookmarkedStatusHasChanged(Tab tab) { |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1079 | // TODO: Switch to using onTabDataChanged after b/3262950 is fixed |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 1080 | mUi.bookmarkedStatusHasChanged(tab); |
| 1081 | } |
| 1082 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1083 | // end WebViewController |
| 1084 | |
| 1085 | protected void pageUp() { |
| 1086 | getCurrentTopWebView().pageUp(false); |
| 1087 | } |
| 1088 | |
| 1089 | protected void pageDown() { |
| 1090 | getCurrentTopWebView().pageDown(false); |
| 1091 | } |
| 1092 | |
| 1093 | // callback from phone title bar |
| 1094 | public void editUrl() { |
| 1095 | if (mOptionsMenuOpen) mActivity.closeOptionsMenu(); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 1096 | mUi.editUrl(false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 1099 | public void startVoiceSearch() { |
| 1100 | Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); |
| 1101 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, |
| 1102 | RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH); |
| 1103 | intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, |
| 1104 | mActivity.getComponentName().flattenToString()); |
| 1105 | intent.putExtra(SEND_APP_ID_EXTRA, false); |
Michael Kolb | 17c4eba | 2011-01-10 13:10:07 -0800 | [diff] [blame] | 1106 | intent.putExtra(RecognizerIntent.EXTRA_WEB_SEARCH_ONLY, true); |
Michael Kolb | cfa3af5 | 2010-12-14 10:36:11 -0800 | [diff] [blame] | 1107 | mActivity.startActivity(intent); |
| 1108 | } |
| 1109 | |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 1110 | @Override |
| 1111 | public void activateVoiceSearchMode(String title, List<String> results) { |
| 1112 | mUi.showVoiceTitleBar(title, results); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | public void revertVoiceSearchMode(Tab tab) { |
| 1116 | mUi.revertVoiceTitleBar(tab); |
| 1117 | } |
| 1118 | |
Michael Kolb | 736990c | 2011-03-20 10:01:20 -0700 | [diff] [blame] | 1119 | public boolean supportsVoiceSearch() { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1120 | SearchEngine searchEngine = getSettings().getSearchEngine(); |
Michael Kolb | 736990c | 2011-03-20 10:01:20 -0700 | [diff] [blame] | 1121 | return (searchEngine != null && searchEngine.supportsVoiceSearch()); |
| 1122 | } |
| 1123 | |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 1124 | public void showCustomView(Tab tab, View view, int requestedOrientation, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1125 | WebChromeClient.CustomViewCallback callback) { |
| 1126 | if (tab.inForeground()) { |
| 1127 | if (mUi.isCustomViewShowing()) { |
| 1128 | callback.onCustomViewHidden(); |
| 1129 | return; |
| 1130 | } |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 1131 | mUi.showCustomView(view, requestedOrientation, callback); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1132 | // Save the menu state and set it to empty while the custom |
| 1133 | // view is showing. |
| 1134 | mOldMenuState = mMenuState; |
| 1135 | mMenuState = EMPTY_MENU; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 1136 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | @Override |
| 1141 | public void hideCustomView() { |
| 1142 | if (mUi.isCustomViewShowing()) { |
| 1143 | mUi.onHideCustomView(); |
| 1144 | // Reset the old menu state. |
| 1145 | mMenuState = mOldMenuState; |
| 1146 | mOldMenuState = EMPTY_MENU; |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 1147 | mActivity.invalidateOptionsMenu(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | protected void onActivityResult(int requestCode, int resultCode, |
| 1152 | Intent intent) { |
| 1153 | if (getCurrentTopWebView() == null) return; |
| 1154 | switch (requestCode) { |
| 1155 | case PREFERENCES_PAGE: |
| 1156 | if (resultCode == Activity.RESULT_OK && intent != null) { |
| 1157 | String action = intent.getStringExtra(Intent.EXTRA_TEXT); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1158 | if (PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY.equals(action)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1159 | mTabControl.removeParentChildRelationShips(); |
| 1160 | } |
| 1161 | } |
| 1162 | break; |
| 1163 | case FILE_SELECTED: |
Ben Murdoch | 51f6a2f | 2011-02-21 12:27:07 +0000 | [diff] [blame] | 1164 | // Chose a file from the file picker. |
John Reck | 9dfcdb1 | 2011-02-22 16:40:46 -0800 | [diff] [blame] | 1165 | if (null == mUploadHandler) break; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1166 | mUploadHandler.onResult(resultCode, intent); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1167 | break; |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 1168 | case AUTOFILL_SETUP: |
| 1169 | // Determine whether a profile was actually set up or not |
| 1170 | // and if so, send the message back to the WebTextView to |
| 1171 | // fill the form with the new profile. |
| 1172 | if (getSettings().getAutoFillProfile() != null) { |
| 1173 | mAutoFillSetupMessage.sendToTarget(); |
| 1174 | mAutoFillSetupMessage = null; |
| 1175 | } |
| 1176 | break; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1177 | case COMBO_VIEW: |
| 1178 | if (intent == null || resultCode != Activity.RESULT_OK) { |
| 1179 | break; |
| 1180 | } |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 1181 | mUi.showWeb(false); |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1182 | if (Intent.ACTION_VIEW.equals(intent.getAction())) { |
| 1183 | Tab t = getCurrentTab(); |
| 1184 | Uri uri = intent.getData(); |
| 1185 | loadUrl(t, uri.toString()); |
| 1186 | } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_ALL)) { |
| 1187 | String[] urls = intent.getStringArrayExtra( |
| 1188 | ComboViewActivity.EXTRA_OPEN_ALL); |
| 1189 | Tab parent = getCurrentTab(); |
| 1190 | for (String url : urls) { |
| 1191 | parent = openTab(url, parent, |
| 1192 | !mSettings.openInBackground(), true); |
| 1193 | } |
| 1194 | } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_SNAPSHOT)) { |
| 1195 | long id = intent.getLongExtra( |
| 1196 | ComboViewActivity.EXTRA_OPEN_SNAPSHOT, -1); |
| 1197 | if (id >= 0) { |
| 1198 | createNewSnapshotTab(id, true); |
| 1199 | } |
| 1200 | } |
| 1201 | break; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1202 | default: |
| 1203 | break; |
| 1204 | } |
| 1205 | getCurrentTopWebView().requestFocus(); |
| 1206 | } |
| 1207 | |
| 1208 | /** |
| 1209 | * Open the Go page. |
| 1210 | * @param startWithHistory If true, open starting on the history tab. |
| 1211 | * Otherwise, start with the bookmarks tab. |
| 1212 | */ |
| 1213 | @Override |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1214 | public void bookmarksOrHistoryPicker(ComboViews startView) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1215 | if (mTabControl.getCurrentWebView() == null) { |
| 1216 | return; |
| 1217 | } |
Michael Kolb | bd3dd94 | 2011-01-12 11:09:38 -0800 | [diff] [blame] | 1218 | // clear action mode |
| 1219 | if (isInCustomActionMode()) { |
| 1220 | endActionMode(); |
| 1221 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1222 | Bundle extras = new Bundle(); |
| 1223 | // Disable opening in a new window if we have maxed out the windows |
| 1224 | extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, |
| 1225 | !mTabControl.canCreateNewTab()); |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1226 | mUi.showComboView(startView, extras); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | // combo view callbacks |
| 1230 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1231 | // key handling |
| 1232 | protected void onBackKey() { |
| 1233 | if (!mUi.onBackKey()) { |
| 1234 | WebView subwindow = mTabControl.getCurrentSubWindow(); |
| 1235 | if (subwindow != null) { |
| 1236 | if (subwindow.canGoBack()) { |
| 1237 | subwindow.goBack(); |
| 1238 | } else { |
| 1239 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 1240 | } |
| 1241 | } else { |
| 1242 | goBackOnePageOrQuit(); |
| 1243 | } |
| 1244 | } |
| 1245 | } |
| 1246 | |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 1247 | protected boolean onMenuKey() { |
| 1248 | return mUi.onMenuKey(); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1251 | // menu handling and state |
| 1252 | // TODO: maybe put into separate handler |
| 1253 | |
| 1254 | protected boolean onCreateOptionsMenu(Menu menu) { |
John Reck | d73c5a2 | 2010-12-22 10:22:50 -0800 | [diff] [blame] | 1255 | if (mMenuState == EMPTY_MENU) { |
| 1256 | return false; |
| 1257 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1258 | MenuInflater inflater = mActivity.getMenuInflater(); |
| 1259 | inflater.inflate(R.menu.browser, menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1260 | return true; |
| 1261 | } |
| 1262 | |
| 1263 | protected void onCreateContextMenu(ContextMenu menu, View v, |
| 1264 | ContextMenuInfo menuInfo) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 1265 | if (v instanceof TitleBar) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1266 | return; |
| 1267 | } |
| 1268 | if (!(v instanceof WebView)) { |
| 1269 | return; |
| 1270 | } |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 1271 | final WebView webview = (WebView) v; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1272 | WebView.HitTestResult result = webview.getHitTestResult(); |
| 1273 | if (result == null) { |
| 1274 | return; |
| 1275 | } |
| 1276 | |
| 1277 | int type = result.getType(); |
| 1278 | if (type == WebView.HitTestResult.UNKNOWN_TYPE) { |
| 1279 | Log.w(LOGTAG, |
| 1280 | "We should not show context menu when nothing is touched"); |
| 1281 | return; |
| 1282 | } |
| 1283 | if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) { |
| 1284 | // let TextView handles context menu |
| 1285 | return; |
| 1286 | } |
| 1287 | |
| 1288 | // Note, http://b/issue?id=1106666 is requesting that |
| 1289 | // an inflated menu can be used again. This is not available |
| 1290 | // yet, so inflate each time (yuk!) |
| 1291 | MenuInflater inflater = mActivity.getMenuInflater(); |
| 1292 | inflater.inflate(R.menu.browsercontext, menu); |
| 1293 | |
| 1294 | // Show the correct menu group |
| 1295 | final String extra = result.getExtra(); |
| 1296 | menu.setGroupVisible(R.id.PHONE_MENU, |
| 1297 | type == WebView.HitTestResult.PHONE_TYPE); |
| 1298 | menu.setGroupVisible(R.id.EMAIL_MENU, |
| 1299 | type == WebView.HitTestResult.EMAIL_TYPE); |
| 1300 | menu.setGroupVisible(R.id.GEO_MENU, |
| 1301 | type == WebView.HitTestResult.GEO_TYPE); |
| 1302 | menu.setGroupVisible(R.id.IMAGE_MENU, |
| 1303 | type == WebView.HitTestResult.IMAGE_TYPE |
| 1304 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
| 1305 | menu.setGroupVisible(R.id.ANCHOR_MENU, |
| 1306 | type == WebView.HitTestResult.SRC_ANCHOR_TYPE |
| 1307 | || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE); |
Cary Clark | 8974d28 | 2010-11-22 10:46:05 -0500 | [diff] [blame] | 1308 | boolean hitText = type == WebView.HitTestResult.SRC_ANCHOR_TYPE |
| 1309 | || type == WebView.HitTestResult.PHONE_TYPE |
| 1310 | || type == WebView.HitTestResult.EMAIL_TYPE |
| 1311 | || type == WebView.HitTestResult.GEO_TYPE; |
| 1312 | menu.setGroupVisible(R.id.SELECT_TEXT_MENU, hitText); |
| 1313 | if (hitText) { |
| 1314 | menu.findItem(R.id.select_text_menu_id) |
| 1315 | .setOnMenuItemClickListener(new SelectText(webview)); |
| 1316 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1317 | // Setup custom handling depending on the type |
| 1318 | switch (type) { |
| 1319 | case WebView.HitTestResult.PHONE_TYPE: |
| 1320 | menu.setHeaderTitle(Uri.decode(extra)); |
| 1321 | menu.findItem(R.id.dial_context_menu_id).setIntent( |
| 1322 | new Intent(Intent.ACTION_VIEW, Uri |
| 1323 | .parse(WebView.SCHEME_TEL + extra))); |
| 1324 | Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
| 1325 | addIntent.putExtra(Insert.PHONE, Uri.decode(extra)); |
| 1326 | addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); |
| 1327 | menu.findItem(R.id.add_contact_context_menu_id).setIntent( |
| 1328 | addIntent); |
| 1329 | menu.findItem(R.id.copy_phone_context_menu_id) |
| 1330 | .setOnMenuItemClickListener( |
| 1331 | new Copy(extra)); |
| 1332 | break; |
| 1333 | |
| 1334 | case WebView.HitTestResult.EMAIL_TYPE: |
| 1335 | menu.setHeaderTitle(extra); |
| 1336 | menu.findItem(R.id.email_context_menu_id).setIntent( |
| 1337 | new Intent(Intent.ACTION_VIEW, Uri |
| 1338 | .parse(WebView.SCHEME_MAILTO + extra))); |
| 1339 | menu.findItem(R.id.copy_mail_context_menu_id) |
| 1340 | .setOnMenuItemClickListener( |
| 1341 | new Copy(extra)); |
| 1342 | break; |
| 1343 | |
| 1344 | case WebView.HitTestResult.GEO_TYPE: |
| 1345 | menu.setHeaderTitle(extra); |
| 1346 | menu.findItem(R.id.map_context_menu_id).setIntent( |
| 1347 | new Intent(Intent.ACTION_VIEW, Uri |
| 1348 | .parse(WebView.SCHEME_GEO |
| 1349 | + URLEncoder.encode(extra)))); |
| 1350 | menu.findItem(R.id.copy_geo_context_menu_id) |
| 1351 | .setOnMenuItemClickListener( |
| 1352 | new Copy(extra)); |
| 1353 | break; |
| 1354 | |
| 1355 | case WebView.HitTestResult.SRC_ANCHOR_TYPE: |
| 1356 | case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE: |
Michael Kolb | 4c537ce | 2011-01-13 15:19:33 -0800 | [diff] [blame] | 1357 | menu.setHeaderTitle(extra); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1358 | // decide whether to show the open link in new tab option |
| 1359 | boolean showNewTab = mTabControl.canCreateNewTab(); |
| 1360 | MenuItem newTabItem |
| 1361 | = menu.findItem(R.id.open_newtab_context_menu_id); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1362 | newTabItem.setTitle(getSettings().openInBackground() |
Michael Kolb | 2dd65c8 | 2011-01-14 11:07:38 -0800 | [diff] [blame] | 1363 | ? R.string.contextmenu_openlink_newwindow_background |
| 1364 | : R.string.contextmenu_openlink_newwindow); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1365 | newTabItem.setVisible(showNewTab); |
| 1366 | if (showNewTab) { |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 1367 | if (WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE == type) { |
| 1368 | newTabItem.setOnMenuItemClickListener( |
| 1369 | new MenuItem.OnMenuItemClickListener() { |
| 1370 | @Override |
| 1371 | public boolean onMenuItemClick(MenuItem item) { |
| 1372 | final HashMap<String, WebView> hrefMap = |
| 1373 | new HashMap<String, WebView>(); |
| 1374 | hrefMap.put("webview", webview); |
| 1375 | final Message msg = mHandler.obtainMessage( |
| 1376 | FOCUS_NODE_HREF, |
| 1377 | R.id.open_newtab_context_menu_id, |
| 1378 | 0, hrefMap); |
| 1379 | webview.requestFocusNodeHref(msg); |
| 1380 | return true; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1381 | } |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 1382 | }); |
| 1383 | } else { |
| 1384 | newTabItem.setOnMenuItemClickListener( |
| 1385 | new MenuItem.OnMenuItemClickListener() { |
| 1386 | @Override |
| 1387 | public boolean onMenuItemClick(MenuItem item) { |
| 1388 | final Tab parent = mTabControl.getCurrentTab(); |
John Reck | 5949c66 | 2011-05-27 09:52:29 -0700 | [diff] [blame] | 1389 | openTab(extra, parent, |
| 1390 | !mSettings.openInBackground(), |
| 1391 | true); |
Leon Scroggins | 026f254 | 2010-11-22 13:26:12 -0500 | [diff] [blame] | 1392 | return true; |
| 1393 | } |
| 1394 | }); |
| 1395 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1396 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1397 | if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) { |
| 1398 | break; |
| 1399 | } |
| 1400 | // otherwise fall through to handle image part |
| 1401 | case WebView.HitTestResult.IMAGE_TYPE: |
| 1402 | if (type == WebView.HitTestResult.IMAGE_TYPE) { |
| 1403 | menu.setHeaderTitle(extra); |
| 1404 | } |
Michael Kolb | 3639c4c | 2011-09-28 15:36:40 -0700 | [diff] [blame] | 1405 | menu.findItem(R.id.view_image_context_menu_id) |
| 1406 | .setOnMenuItemClickListener(new OnMenuItemClickListener() { |
| 1407 | @Override |
| 1408 | public boolean onMenuItemClick(MenuItem item) { |
| 1409 | openTab(extra, mTabControl.getCurrentTab(), true, true); |
| 1410 | return false; |
| 1411 | } |
| 1412 | }); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1413 | menu.findItem(R.id.download_context_menu_id). |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 1414 | setOnMenuItemClickListener( |
| 1415 | new Download(mActivity, extra, webview.isPrivateBrowsingEnabled())); |
John Reck | 3527dd1 | 2011-02-22 10:35:29 -0800 | [diff] [blame] | 1416 | menu.findItem(R.id.set_wallpaper_context_menu_id). |
| 1417 | setOnMenuItemClickListener(new WallpaperHandler(mActivity, |
| 1418 | extra)); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | default: |
| 1422 | Log.w(LOGTAG, "We should not get here."); |
| 1423 | break; |
| 1424 | } |
| 1425 | //update the ui |
| 1426 | mUi.onContextMenuCreated(menu); |
| 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * As the menu can be open when loading state changes |
| 1431 | * we must manually update the state of the stop/reload menu |
| 1432 | * item |
| 1433 | */ |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1434 | private void updateInLoadMenuItems(Menu menu, Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1435 | if (menu == null) { |
| 1436 | return; |
| 1437 | } |
| 1438 | MenuItem dest = menu.findItem(R.id.stop_reload_menu_id); |
Michael Kolb | b833713 | 2011-11-28 15:07:39 -0800 | [diff] [blame] | 1439 | MenuItem src = ((tab != null) && tab.inPageLoad()) ? |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1440 | menu.findItem(R.id.stop_menu_id): |
| 1441 | menu.findItem(R.id.reload_menu_id); |
| 1442 | if (src != null) { |
| 1443 | dest.setIcon(src.getIcon()); |
| 1444 | dest.setTitle(src.getTitle()); |
| 1445 | } |
| 1446 | } |
| 1447 | |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 1448 | boolean onPrepareOptionsMenu(Menu menu) { |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1449 | updateInLoadMenuItems(menu, getCurrentTab()); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1450 | // hold on to the menu reference here; it is used by the page callbacks |
| 1451 | // to update the menu based on loading state |
| 1452 | mCachedMenu = menu; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1453 | // Note: setVisible will decide whether an item is visible; while |
| 1454 | // setEnabled() will decide whether an item is enabled, which also means |
| 1455 | // whether the matching shortcut key will function. |
| 1456 | switch (mMenuState) { |
| 1457 | case EMPTY_MENU: |
| 1458 | if (mCurrentMenuState != mMenuState) { |
| 1459 | menu.setGroupVisible(R.id.MAIN_MENU, false); |
| 1460 | menu.setGroupEnabled(R.id.MAIN_MENU, false); |
| 1461 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false); |
| 1462 | } |
| 1463 | break; |
| 1464 | default: |
| 1465 | if (mCurrentMenuState != mMenuState) { |
| 1466 | menu.setGroupVisible(R.id.MAIN_MENU, true); |
| 1467 | menu.setGroupEnabled(R.id.MAIN_MENU, true); |
| 1468 | menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true); |
| 1469 | } |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1470 | updateMenuState(getCurrentTab(), menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | } |
| 1473 | mCurrentMenuState = mMenuState; |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 1474 | return mUi.onPrepareOptionsMenu(menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1477 | @Override |
| 1478 | public void updateMenuState(Tab tab, Menu menu) { |
| 1479 | boolean canGoBack = false; |
| 1480 | boolean canGoForward = false; |
| 1481 | boolean isHome = false; |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 1482 | boolean isDesktopUa = false; |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1483 | boolean isLive = false; |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1484 | if (tab != null) { |
| 1485 | canGoBack = tab.canGoBack(); |
| 1486 | canGoForward = tab.canGoForward(); |
| 1487 | isHome = mSettings.getHomePage().equals(tab.getUrl()); |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 1488 | isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView()); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1489 | isLive = !tab.isSnapshot(); |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1490 | } |
| 1491 | final MenuItem back = menu.findItem(R.id.back_menu_id); |
| 1492 | back.setEnabled(canGoBack); |
| 1493 | |
| 1494 | final MenuItem home = menu.findItem(R.id.homepage_menu_id); |
| 1495 | home.setEnabled(!isHome); |
| 1496 | |
| 1497 | final MenuItem forward = menu.findItem(R.id.forward_menu_id); |
| 1498 | forward.setEnabled(canGoForward); |
| 1499 | |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1500 | final MenuItem source = menu.findItem(isInLoad() ? R.id.stop_menu_id |
| 1501 | : R.id.reload_menu_id); |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1502 | final MenuItem dest = menu.findItem(R.id.stop_reload_menu_id); |
Michael Kolb | 7ab75ee | 2011-07-14 16:36:38 -0700 | [diff] [blame] | 1503 | if (source != null && dest != null) { |
| 1504 | dest.setTitle(source.getTitle()); |
| 1505 | dest.setIcon(source.getIcon()); |
| 1506 | } |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1507 | menu.setGroupVisible(R.id.NAV_MENU, isLive); |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1508 | |
| 1509 | // decide whether to show the share link option |
| 1510 | PackageManager pm = mActivity.getPackageManager(); |
| 1511 | Intent send = new Intent(Intent.ACTION_SEND); |
| 1512 | send.setType("text/plain"); |
| 1513 | ResolveInfo ri = pm.resolveActivity(send, |
| 1514 | PackageManager.MATCH_DEFAULT_ONLY); |
| 1515 | menu.findItem(R.id.share_page_menu_id).setVisible(ri != null); |
| 1516 | |
| 1517 | boolean isNavDump = mSettings.enableNavDump(); |
| 1518 | final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id); |
| 1519 | nav.setVisible(isNavDump); |
| 1520 | nav.setEnabled(isNavDump); |
| 1521 | |
| 1522 | boolean showDebugSettings = mSettings.isDebugEnabled(); |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 1523 | final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id); |
| 1524 | uaSwitcher.setChecked(isDesktopUa); |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1525 | menu.setGroupVisible(R.id.LIVE_MENU, isLive); |
| 1526 | menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive); |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1527 | menu.setGroupVisible(R.id.COMBO_MENU, false); |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1528 | |
Michael Kolb | 7bdee0b | 2011-08-01 11:55:38 -0700 | [diff] [blame] | 1529 | mUi.updateMenuState(tab, menu); |
Michael Kolb | 4bf7971 | 2011-07-14 14:18:12 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1532 | public boolean onOptionsItemSelected(MenuItem item) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1533 | if (null == getCurrentTopWebView()) { |
| 1534 | return false; |
| 1535 | } |
| 1536 | if (mMenuIsDown) { |
| 1537 | // The shortcut action consumes the MENU. Even if it is still down, |
| 1538 | // it won't trigger the next shortcut action. In the case of the |
| 1539 | // shortcut action triggering a new activity, like Bookmarks, we |
| 1540 | // won't get onKeyUp for MENU. So it is important to reset it here. |
| 1541 | mMenuIsDown = false; |
| 1542 | } |
Michael Kolb | 3ca1275 | 2011-07-20 13:52:25 -0700 | [diff] [blame] | 1543 | if (mUi.onOptionsItemSelected(item)) { |
| 1544 | // ui callback handled it |
| 1545 | return true; |
| 1546 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1547 | switch (item.getItemId()) { |
| 1548 | // -- Main menu |
| 1549 | case R.id.new_tab_menu_id: |
| 1550 | openTabToHomePage(); |
| 1551 | break; |
| 1552 | |
| 1553 | case R.id.incognito_menu_id: |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 1554 | openIncognitoTab(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1555 | break; |
| 1556 | |
| 1557 | case R.id.goto_menu_id: |
| 1558 | editUrl(); |
| 1559 | break; |
| 1560 | |
| 1561 | case R.id.bookmarks_menu_id: |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1562 | bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
| 1563 | break; |
| 1564 | |
| 1565 | case R.id.history_menu_id: |
| 1566 | bookmarksOrHistoryPicker(ComboViews.History); |
| 1567 | break; |
| 1568 | |
| 1569 | case R.id.snapshots_menu_id: |
| 1570 | bookmarksOrHistoryPicker(ComboViews.Snapshots); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1571 | break; |
| 1572 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1573 | case R.id.add_bookmark_menu_id: |
John Reck | a60fffa | 2011-09-06 16:30:29 -0700 | [diff] [blame] | 1574 | Intent bookmarkIntent = createBookmarkCurrentPageIntent(false); |
| 1575 | if (bookmarkIntent != null) { |
| 1576 | mActivity.startActivity(bookmarkIntent); |
| 1577 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1578 | break; |
| 1579 | |
| 1580 | case R.id.stop_reload_menu_id: |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1581 | if (isInLoad()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1582 | stopLoading(); |
| 1583 | } else { |
| 1584 | getCurrentTopWebView().reload(); |
| 1585 | } |
| 1586 | break; |
| 1587 | |
| 1588 | case R.id.back_menu_id: |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 1589 | getCurrentTab().goBack(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | |
| 1592 | case R.id.forward_menu_id: |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 1593 | getCurrentTab().goForward(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1594 | break; |
| 1595 | |
| 1596 | case R.id.close_menu_id: |
| 1597 | // Close the subwindow if it exists. |
| 1598 | if (mTabControl.getCurrentSubWindow() != null) { |
| 1599 | dismissSubWindow(mTabControl.getCurrentTab()); |
| 1600 | break; |
| 1601 | } |
| 1602 | closeCurrentTab(); |
| 1603 | break; |
| 1604 | |
| 1605 | case R.id.homepage_menu_id: |
| 1606 | Tab current = mTabControl.getCurrentTab(); |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 1607 | loadUrl(current, mSettings.getHomePage()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1608 | break; |
| 1609 | |
| 1610 | case R.id.preferences_menu_id: |
| 1611 | Intent intent = new Intent(mActivity, BrowserPreferencesPage.class); |
| 1612 | intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE, |
| 1613 | getCurrentTopWebView().getUrl()); |
| 1614 | mActivity.startActivityForResult(intent, PREFERENCES_PAGE); |
| 1615 | break; |
| 1616 | |
| 1617 | case R.id.find_menu_id: |
Leon Scroggins | 1c00d5e | 2011-01-04 10:45:58 -0500 | [diff] [blame] | 1618 | getCurrentTopWebView().showFindDialog(null, true); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1619 | break; |
| 1620 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1621 | case R.id.save_snapshot_menu_id: |
| 1622 | final Tab source = getTabControl().getCurrentTab(); |
John Reck | f33b163 | 2011-06-04 20:00:23 -0700 | [diff] [blame] | 1623 | if (source == null) break; |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 1624 | final ContentResolver cr = mActivity.getContentResolver(); |
| 1625 | final ContentValues values = source.createSnapshotValues(); |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1626 | if (values != null) { |
| 1627 | new AsyncTask<Tab, Void, Long>() { |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 1628 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1629 | @Override |
| 1630 | protected Long doInBackground(Tab... params) { |
| 1631 | Uri result = cr.insert(Snapshots.CONTENT_URI, values); |
John Reck | 93384ff | 2011-11-10 11:29:18 -0800 | [diff] [blame] | 1632 | if (result == null) { |
| 1633 | return null; |
| 1634 | } |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1635 | long id = ContentUris.parseId(result); |
| 1636 | return id; |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 1637 | } |
John Reck | f33b163 | 2011-06-04 20:00:23 -0700 | [diff] [blame] | 1638 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1639 | @Override |
| 1640 | protected void onPostExecute(Long id) { |
John Reck | 93384ff | 2011-11-10 11:29:18 -0800 | [diff] [blame] | 1641 | if (id == null) { |
| 1642 | Toast.makeText(mActivity, R.string.snapshot_failed, |
| 1643 | Toast.LENGTH_SHORT).show(); |
| 1644 | return; |
| 1645 | } |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 1646 | Bundle b = new Bundle(); |
| 1647 | b.putLong(BrowserSnapshotPage.EXTRA_ANIMATE_ID, id); |
| 1648 | mUi.showComboView(ComboViews.Snapshots, b); |
| 1649 | }; |
| 1650 | }.execute(source); |
| 1651 | } else { |
| 1652 | Toast.makeText(mActivity, R.string.snapshot_failed, |
Leon Scroggins | ac99384 | 2011-02-02 12:54:07 -0500 | [diff] [blame] | 1653 | Toast.LENGTH_SHORT).show(); |
Leon Scroggins | ac99384 | 2011-02-02 12:54:07 -0500 | [diff] [blame] | 1654 | } |
Leon Scroggins | ac99384 | 2011-02-02 12:54:07 -0500 | [diff] [blame] | 1655 | break; |
| 1656 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1657 | case R.id.page_info_menu_id: |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1658 | showPageInfo(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1661 | case R.id.snapshot_go_live: |
| 1662 | goLive(); |
| 1663 | return true; |
| 1664 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1665 | case R.id.share_page_menu_id: |
| 1666 | Tab currentTab = mTabControl.getCurrentTab(); |
| 1667 | if (null == currentTab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1668 | return false; |
| 1669 | } |
Michael Kolb | ba99c5d | 2010-11-29 14:57:41 -0800 | [diff] [blame] | 1670 | shareCurrentPage(currentTab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1671 | break; |
| 1672 | |
| 1673 | case R.id.dump_nav_menu_id: |
| 1674 | getCurrentTopWebView().debugDump(); |
| 1675 | break; |
| 1676 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1677 | case R.id.zoom_in_menu_id: |
| 1678 | getCurrentTopWebView().zoomIn(); |
| 1679 | break; |
| 1680 | |
| 1681 | case R.id.zoom_out_menu_id: |
| 1682 | getCurrentTopWebView().zoomOut(); |
| 1683 | break; |
| 1684 | |
| 1685 | case R.id.view_downloads_menu_id: |
| 1686 | viewDownloads(); |
| 1687 | break; |
| 1688 | |
John Reck | 42229bc | 2011-08-19 13:26:43 -0700 | [diff] [blame] | 1689 | case R.id.ua_desktop_menu_id: |
| 1690 | WebView web = getCurrentWebView(); |
| 1691 | mSettings.toggleDesktopUseragent(web); |
| 1692 | web.loadUrl(web.getOriginalUrl()); |
| 1693 | break; |
| 1694 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1695 | case R.id.window_one_menu_id: |
| 1696 | case R.id.window_two_menu_id: |
| 1697 | case R.id.window_three_menu_id: |
| 1698 | case R.id.window_four_menu_id: |
| 1699 | case R.id.window_five_menu_id: |
| 1700 | case R.id.window_six_menu_id: |
| 1701 | case R.id.window_seven_menu_id: |
| 1702 | case R.id.window_eight_menu_id: |
| 1703 | { |
| 1704 | int menuid = item.getItemId(); |
| 1705 | for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) { |
| 1706 | if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) { |
| 1707 | Tab desiredTab = mTabControl.getTab(id); |
| 1708 | if (desiredTab != null && |
| 1709 | desiredTab != mTabControl.getCurrentTab()) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1710 | switchToTab(desiredTab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1711 | } |
| 1712 | break; |
| 1713 | } |
| 1714 | } |
| 1715 | } |
| 1716 | break; |
| 1717 | |
| 1718 | default: |
| 1719 | return false; |
| 1720 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1721 | return true; |
| 1722 | } |
| 1723 | |
John Reck | e1a03a3 | 2011-09-14 17:04:16 -0700 | [diff] [blame] | 1724 | private void goLive() { |
| 1725 | Tab t = getCurrentTab(); |
| 1726 | t.loadUrl(t.getUrl(), null); |
| 1727 | } |
| 1728 | |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 1729 | @Override |
| 1730 | public void showPageInfo() { |
| 1731 | mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null); |
| 1732 | } |
| 1733 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1734 | public boolean onContextItemSelected(MenuItem item) { |
John Reck | dbf57df | 2010-11-09 16:34:03 -0800 | [diff] [blame] | 1735 | // Let the History and Bookmark fragments handle menus they created. |
| 1736 | if (item.getGroupId() == R.id.CONTEXT_MENU) { |
| 1737 | return false; |
| 1738 | } |
| 1739 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1740 | int id = item.getItemId(); |
| 1741 | boolean result = true; |
| 1742 | switch (id) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1743 | // -- Browser context menu |
| 1744 | case R.id.open_context_menu_id: |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1745 | case R.id.save_link_context_menu_id: |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1746 | case R.id.copy_link_context_menu_id: |
| 1747 | final WebView webView = getCurrentTopWebView(); |
| 1748 | if (null == webView) { |
| 1749 | result = false; |
| 1750 | break; |
| 1751 | } |
| 1752 | final HashMap<String, WebView> hrefMap = |
| 1753 | new HashMap<String, WebView>(); |
| 1754 | hrefMap.put("webview", webView); |
| 1755 | final Message msg = mHandler.obtainMessage( |
| 1756 | FOCUS_NODE_HREF, id, 0, hrefMap); |
| 1757 | webView.requestFocusNodeHref(msg); |
| 1758 | break; |
| 1759 | |
| 1760 | default: |
| 1761 | // For other context menus |
| 1762 | result = onOptionsItemSelected(item); |
| 1763 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1764 | return result; |
| 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * support programmatically opening the context menu |
| 1769 | */ |
| 1770 | public void openContextMenu(View view) { |
| 1771 | mActivity.openContextMenu(view); |
| 1772 | } |
| 1773 | |
| 1774 | /** |
| 1775 | * programmatically open the options menu |
| 1776 | */ |
| 1777 | public void openOptionsMenu() { |
| 1778 | mActivity.openOptionsMenu(); |
| 1779 | } |
| 1780 | |
| 1781 | public boolean onMenuOpened(int featureId, Menu menu) { |
| 1782 | if (mOptionsMenuOpen) { |
| 1783 | if (mConfigChanged) { |
| 1784 | // We do not need to make any changes to the state of the |
| 1785 | // title bar, since the only thing that happened was a |
| 1786 | // change in orientation |
| 1787 | mConfigChanged = false; |
| 1788 | } else { |
| 1789 | if (!mExtendedMenuOpen) { |
| 1790 | mExtendedMenuOpen = true; |
| 1791 | mUi.onExtendedMenuOpened(); |
| 1792 | } else { |
| 1793 | // Switching the menu back to icon view, so show the |
| 1794 | // title bar once again. |
| 1795 | mExtendedMenuOpen = false; |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1796 | mUi.onExtendedMenuClosed(isInLoad()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1797 | } |
| 1798 | } |
| 1799 | } else { |
| 1800 | // The options menu is closed, so open it, and show the title |
| 1801 | mOptionsMenuOpen = true; |
| 1802 | mConfigChanged = false; |
| 1803 | mExtendedMenuOpen = false; |
| 1804 | mUi.onOptionsMenuOpened(); |
| 1805 | } |
| 1806 | return true; |
| 1807 | } |
| 1808 | |
| 1809 | public void onOptionsMenuClosed(Menu menu) { |
| 1810 | mOptionsMenuOpen = false; |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1811 | mUi.onOptionsMenuClosed(isInLoad()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | public void onContextMenuClosed(Menu menu) { |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1815 | mUi.onContextMenuClosed(menu, isInLoad()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | // Helper method for getting the top window. |
| 1819 | @Override |
| 1820 | public WebView getCurrentTopWebView() { |
| 1821 | return mTabControl.getCurrentTopWebView(); |
| 1822 | } |
| 1823 | |
| 1824 | @Override |
| 1825 | public WebView getCurrentWebView() { |
| 1826 | return mTabControl.getCurrentWebView(); |
| 1827 | } |
| 1828 | |
| 1829 | /* |
| 1830 | * This method is called as a result of the user selecting the options |
| 1831 | * menu to see the download window. It shows the download window on top of |
| 1832 | * the current window. |
| 1833 | */ |
| 1834 | void viewDownloads() { |
| 1835 | Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
| 1836 | mActivity.startActivity(intent); |
| 1837 | } |
| 1838 | |
John Reck | 30b065e | 2011-07-19 10:58:05 -0700 | [diff] [blame] | 1839 | int getActionModeHeight() { |
| 1840 | TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes( |
| 1841 | new int[] { android.R.attr.actionBarSize }); |
| 1842 | int size = (int) actionBarSizeTypedArray.getDimension(0, 0f); |
| 1843 | actionBarSizeTypedArray.recycle(); |
| 1844 | return size; |
| 1845 | } |
| 1846 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1847 | // action mode |
| 1848 | |
| 1849 | void onActionModeStarted(ActionMode mode) { |
| 1850 | mUi.onActionModeStarted(mode); |
| 1851 | mActionMode = mode; |
| 1852 | } |
| 1853 | |
| 1854 | /* |
| 1855 | * True if a custom ActionMode (i.e. find or select) is in use. |
| 1856 | */ |
| 1857 | @Override |
| 1858 | public boolean isInCustomActionMode() { |
| 1859 | return mActionMode != null; |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * End the current ActionMode. |
| 1864 | */ |
| 1865 | @Override |
| 1866 | public void endActionMode() { |
| 1867 | if (mActionMode != null) { |
| 1868 | mActionMode.finish(); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /* |
| 1873 | * Called by find and select when they are finished. Replace title bars |
| 1874 | * as necessary. |
| 1875 | */ |
| 1876 | public void onActionModeFinished(ActionMode mode) { |
| 1877 | if (!isInCustomActionMode()) return; |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1878 | mUi.onActionModeFinished(isInLoad()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1879 | mActionMode = null; |
| 1880 | } |
| 1881 | |
| 1882 | boolean isInLoad() { |
Michael Kolb | c5b0b2d | 2011-11-29 16:13:35 -0800 | [diff] [blame] | 1883 | final Tab tab = getCurrentTab(); |
| 1884 | return (tab != null) && tab.inPageLoad(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | // bookmark handling |
| 1888 | |
| 1889 | /** |
| 1890 | * add the current page as a bookmark to the given folder id |
| 1891 | * @param folderId use -1 for the default folder |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1892 | * @param editExisting If true, check to see whether the site is already |
Leon Scroggins | bdff8a7 | 2011-02-11 15:49:04 -0500 | [diff] [blame] | 1893 | * bookmarked, and if it is, edit that bookmark. If false, and |
| 1894 | * the site is already bookmarked, do not attempt to edit the |
| 1895 | * existing bookmark. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1896 | */ |
| 1897 | @Override |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1898 | public Intent createBookmarkCurrentPageIntent(boolean editExisting) { |
John Reck | a60fffa | 2011-09-06 16:30:29 -0700 | [diff] [blame] | 1899 | WebView w = getCurrentTopWebView(); |
| 1900 | if (w == null) { |
| 1901 | return null; |
| 1902 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1903 | Intent i = new Intent(mActivity, |
| 1904 | AddBookmarkPage.class); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1905 | i.putExtra(BrowserContract.Bookmarks.URL, w.getUrl()); |
| 1906 | i.putExtra(BrowserContract.Bookmarks.TITLE, w.getTitle()); |
| 1907 | String touchIconUrl = w.getTouchIconUrl(); |
| 1908 | if (touchIconUrl != null) { |
| 1909 | i.putExtra(AddBookmarkPage.TOUCH_ICON_URL, touchIconUrl); |
| 1910 | WebSettings settings = w.getSettings(); |
| 1911 | if (settings != null) { |
| 1912 | i.putExtra(AddBookmarkPage.USER_AGENT, |
| 1913 | settings.getUserAgentString()); |
| 1914 | } |
| 1915 | } |
| 1916 | i.putExtra(BrowserContract.Bookmarks.THUMBNAIL, |
| 1917 | createScreenshot(w, getDesiredThumbnailWidth(mActivity), |
| 1918 | getDesiredThumbnailHeight(mActivity))); |
| 1919 | i.putExtra(BrowserContract.Bookmarks.FAVICON, w.getFavicon()); |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1920 | if (editExisting) { |
Leon Scroggins | bdff8a7 | 2011-02-11 15:49:04 -0500 | [diff] [blame] | 1921 | i.putExtra(AddBookmarkPage.CHECK_FOR_DUPE, true); |
| 1922 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1923 | // Put the dialog at the upper right of the screen, covering the |
| 1924 | // star on the title bar. |
| 1925 | i.putExtra("gravity", Gravity.RIGHT | Gravity.TOP); |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 1926 | return i; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | // file chooser |
| 1930 | public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { |
| 1931 | mUploadHandler = new UploadHandler(this); |
| 1932 | mUploadHandler.openFileChooser(uploadMsg, acceptType); |
| 1933 | } |
| 1934 | |
| 1935 | // thumbnails |
| 1936 | |
| 1937 | /** |
| 1938 | * Return the desired width for thumbnail screenshots, which are stored in |
| 1939 | * the database, and used on the bookmarks screen. |
| 1940 | * @param context Context for finding out the density of the screen. |
| 1941 | * @return desired width for thumbnail screenshot. |
| 1942 | */ |
| 1943 | static int getDesiredThumbnailWidth(Context context) { |
| 1944 | return context.getResources().getDimensionPixelOffset( |
| 1945 | R.dimen.bookmarkThumbnailWidth); |
| 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * Return the desired height for thumbnail screenshots, which are stored in |
| 1950 | * the database, and used on the bookmarks screen. |
| 1951 | * @param context Context for finding out the density of the screen. |
| 1952 | * @return desired height for thumbnail screenshot. |
| 1953 | */ |
| 1954 | static int getDesiredThumbnailHeight(Context context) { |
| 1955 | return context.getResources().getDimensionPixelOffset( |
| 1956 | R.dimen.bookmarkThumbnailHeight); |
| 1957 | } |
| 1958 | |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 1959 | static Bitmap createScreenshot(WebView view, int width, int height) { |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 1960 | if (view == null || view.getContentHeight() == 0 |
| 1961 | || view.getContentWidth() == 0) { |
| 1962 | return null; |
| 1963 | } |
John Reck | 5c6ac2f | 2011-01-05 10:18:03 -0800 | [diff] [blame] | 1964 | // We render to a bitmap 2x the desired size so that we can then |
| 1965 | // re-scale it with filtering since canvas.scale doesn't filter |
| 1966 | // This helps reduce aliasing at the cost of being slightly blurry |
| 1967 | final int filter_scale = 2; |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 1968 | int scaledWidth = width * filter_scale; |
| 1969 | int scaledHeight = height * filter_scale; |
| 1970 | if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != scaledWidth |
| 1971 | || sThumbnailBitmap.getHeight() != scaledHeight) { |
| 1972 | if (sThumbnailBitmap != null) { |
| 1973 | sThumbnailBitmap.recycle(); |
| 1974 | sThumbnailBitmap = null; |
| 1975 | } |
| 1976 | sThumbnailBitmap = |
| 1977 | Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.RGB_565); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1978 | } |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 1979 | Canvas canvas = new Canvas(sThumbnailBitmap); |
| 1980 | int contentWidth = view.getContentWidth(); |
| 1981 | float overviewScale = scaledWidth / (view.getScale() * contentWidth); |
| 1982 | if (view instanceof BrowserWebView) { |
| 1983 | int dy = -((BrowserWebView)view).getTitleHeight(); |
| 1984 | canvas.translate(0, dy * overviewScale); |
| 1985 | } |
| 1986 | |
| 1987 | canvas.scale(overviewScale, overviewScale); |
| 1988 | |
| 1989 | if (view instanceof BrowserWebView) { |
| 1990 | ((BrowserWebView)view).drawContent(canvas); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1991 | } else { |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 1992 | view.draw(canvas); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1993 | } |
John Reck | d7dd9b2 | 2011-08-30 09:18:29 -0700 | [diff] [blame] | 1994 | Bitmap ret = Bitmap.createScaledBitmap(sThumbnailBitmap, |
| 1995 | width, height, true); |
Dianne Hackborn | 43cfe8a | 2011-08-02 16:59:35 -0700 | [diff] [blame] | 1996 | canvas.setBitmap(null); |
John Reck | 5c6ac2f | 2011-01-05 10:18:03 -0800 | [diff] [blame] | 1997 | return ret; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2000 | private void updateScreenshot(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2001 | // If this is a bookmarked site, add a screenshot to the database. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2002 | // FIXME: Would like to make sure there is actually something to |
| 2003 | // draw, but the API for that (WebViewCore.pictureReady()) is not |
| 2004 | // currently accessible here. |
| 2005 | |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2006 | WebView view = tab.getWebView(); |
John Reck | 7a59120 | 2011-02-16 15:44:01 -0800 | [diff] [blame] | 2007 | if (view == null) { |
| 2008 | // Tab was destroyed |
| 2009 | return; |
| 2010 | } |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2011 | final String url = tab.getUrl(); |
| 2012 | final String originalUrl = view.getOriginalUrl(); |
| 2013 | |
| 2014 | if (TextUtils.isEmpty(url)) { |
| 2015 | return; |
| 2016 | } |
| 2017 | |
| 2018 | // Only update thumbnails for web urls (http(s)://), not for |
| 2019 | // about:, javascript:, data:, etc... |
| 2020 | // Unless it is a bookmarked site, then always update |
| 2021 | if (!Patterns.WEB_URL.matcher(url).matches() && !tab.isBookmarkedSite()) { |
| 2022 | return; |
| 2023 | } |
| 2024 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2025 | final Bitmap bm = createScreenshot(view, getDesiredThumbnailWidth(mActivity), |
| 2026 | getDesiredThumbnailHeight(mActivity)); |
| 2027 | if (bm == null) { |
| 2028 | return; |
| 2029 | } |
| 2030 | |
| 2031 | final ContentResolver cr = mActivity.getContentResolver(); |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2032 | new AsyncTask<Void, Void, Void>() { |
| 2033 | @Override |
| 2034 | protected Void doInBackground(Void... unused) { |
| 2035 | Cursor cursor = null; |
| 2036 | try { |
| 2037 | // TODO: Clean this up |
| 2038 | cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url); |
| 2039 | if (cursor != null && cursor.moveToFirst()) { |
| 2040 | final ByteArrayOutputStream os = |
| 2041 | new ByteArrayOutputStream(); |
| 2042 | bm.compress(Bitmap.CompressFormat.PNG, 100, os); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2043 | |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2044 | ContentValues values = new ContentValues(); |
| 2045 | values.put(Images.THUMBNAIL, os.toByteArray()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2046 | |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2047 | do { |
John Reck | 617fd83 | 2011-02-16 14:35:59 -0800 | [diff] [blame] | 2048 | values.put(Images.URL, cursor.getString(0)); |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2049 | cr.update(Images.CONTENT_URI, values, null, null); |
| 2050 | } while (cursor.moveToNext()); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2051 | } |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2052 | } catch (IllegalStateException e) { |
| 2053 | // Ignore |
| 2054 | } finally { |
| 2055 | if (cursor != null) cursor.close(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2056 | } |
John Reck | 34ef267 | 2011-02-10 11:30:55 -0800 | [diff] [blame] | 2057 | return null; |
| 2058 | } |
| 2059 | }.execute(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | private class Copy implements OnMenuItemClickListener { |
| 2063 | private CharSequence mText; |
| 2064 | |
| 2065 | public boolean onMenuItemClick(MenuItem item) { |
| 2066 | copy(mText); |
| 2067 | return true; |
| 2068 | } |
| 2069 | |
| 2070 | public Copy(CharSequence toCopy) { |
| 2071 | mText = toCopy; |
| 2072 | } |
| 2073 | } |
| 2074 | |
Leon Scroggins | 63c0266 | 2010-11-18 15:16:27 -0500 | [diff] [blame] | 2075 | private static class Download implements OnMenuItemClickListener { |
| 2076 | private Activity mActivity; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2077 | private String mText; |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 2078 | private boolean mPrivateBrowsing; |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 2079 | private static final String FALLBACK_EXTENSION = "dat"; |
| 2080 | private static final String IMAGE_BASE_FORMAT = "yyyy-MM-dd-HH-mm-ss-"; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2081 | |
| 2082 | public boolean onMenuItemClick(MenuItem item) { |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 2083 | if (DataUri.isDataUri(mText)) { |
| 2084 | saveDataUri(); |
| 2085 | } else { |
| 2086 | DownloadHandler.onDownloadStartNoStream(mActivity, mText, null, |
| 2087 | null, null, mPrivateBrowsing); |
| 2088 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2089 | return true; |
| 2090 | } |
| 2091 | |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 2092 | public Download(Activity activity, String toDownload, boolean privateBrowsing) { |
Leon Scroggins | 63c0266 | 2010-11-18 15:16:27 -0500 | [diff] [blame] | 2093 | mActivity = activity; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2094 | mText = toDownload; |
Kristian Monsen | bc5cc75 | 2011-03-02 13:14:03 +0000 | [diff] [blame] | 2095 | mPrivateBrowsing = privateBrowsing; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2096 | } |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 2097 | |
| 2098 | /** |
| 2099 | * Treats mText as a data URI and writes its contents to a file |
| 2100 | * based on the current time. |
| 2101 | */ |
| 2102 | private void saveDataUri() { |
| 2103 | FileOutputStream outputStream = null; |
| 2104 | try { |
| 2105 | DataUri uri = new DataUri(mText); |
| 2106 | File target = getTarget(uri); |
| 2107 | outputStream = new FileOutputStream(target); |
| 2108 | outputStream.write(uri.getData()); |
| 2109 | final DownloadManager manager = |
| 2110 | (DownloadManager) mActivity.getSystemService(Context.DOWNLOAD_SERVICE); |
| 2111 | manager.addCompletedDownload(target.getName(), |
| 2112 | mActivity.getTitle().toString(), false, |
| 2113 | uri.getMimeType(), target.getAbsolutePath(), |
George Mount | 7501bf4 | 2011-11-17 11:17:03 -0800 | [diff] [blame] | 2114 | (long)uri.getData().length, true); |
George Mount | 387d45d | 2011-10-07 15:57:53 -0700 | [diff] [blame] | 2115 | } catch (IOException e) { |
| 2116 | Log.e(LOGTAG, "Could not save data URL"); |
| 2117 | } finally { |
| 2118 | if (outputStream != null) { |
| 2119 | try { |
| 2120 | outputStream.close(); |
| 2121 | } catch (IOException e) { |
| 2122 | // ignore close errors |
| 2123 | } |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | /** |
| 2129 | * Creates a File based on the current time stamp and uses |
| 2130 | * the mime type of the DataUri to get the extension. |
| 2131 | */ |
| 2132 | private File getTarget(DataUri uri) throws IOException { |
| 2133 | File dir = mActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); |
| 2134 | DateFormat format = new SimpleDateFormat(IMAGE_BASE_FORMAT); |
| 2135 | String nameBase = format.format(new Date()); |
| 2136 | String mimeType = uri.getMimeType(); |
| 2137 | MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); |
| 2138 | String extension = mimeTypeMap.getExtensionFromMimeType(mimeType); |
| 2139 | if (extension == null) { |
| 2140 | Log.w(LOGTAG, "Unknown mime type in data URI" + mimeType); |
| 2141 | extension = FALLBACK_EXTENSION; |
| 2142 | } |
| 2143 | extension = "." + extension; // createTempFile needs the '.' |
| 2144 | File targetFile = File.createTempFile(nameBase, extension, dir); |
| 2145 | return targetFile; |
| 2146 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2147 | } |
| 2148 | |
Cary Clark | 8974d28 | 2010-11-22 10:46:05 -0500 | [diff] [blame] | 2149 | private static class SelectText implements OnMenuItemClickListener { |
| 2150 | private WebView mWebView; |
| 2151 | |
| 2152 | public boolean onMenuItemClick(MenuItem item) { |
| 2153 | if (mWebView != null) { |
| 2154 | return mWebView.selectText(); |
| 2155 | } |
| 2156 | return false; |
| 2157 | } |
| 2158 | |
| 2159 | public SelectText(WebView webView) { |
| 2160 | mWebView = webView; |
| 2161 | } |
| 2162 | |
| 2163 | } |
| 2164 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2165 | /********************** TODO: UI stuff *****************************/ |
| 2166 | |
| 2167 | // these methods have been copied, they still need to be cleaned up |
| 2168 | |
| 2169 | /****************** tabs ***************************************************/ |
| 2170 | |
| 2171 | // basic tab interactions: |
| 2172 | |
| 2173 | // it is assumed that tabcontrol already knows about the tab |
| 2174 | protected void addTab(Tab tab) { |
| 2175 | mUi.addTab(tab); |
| 2176 | } |
| 2177 | |
| 2178 | protected void removeTab(Tab tab) { |
| 2179 | mUi.removeTab(tab); |
| 2180 | mTabControl.removeTab(tab); |
John Reck | 378a410 | 2011-06-09 16:23:01 -0700 | [diff] [blame] | 2181 | mCrashRecoveryHandler.backupState(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
Michael Kolb | f205560 | 2011-04-09 17:20:03 -0700 | [diff] [blame] | 2184 | @Override |
| 2185 | public void setActiveTab(Tab tab) { |
Michael Kolb | cd424e9 | 2011-02-24 10:26:26 -0800 | [diff] [blame] | 2186 | // monkey protection against delayed start |
| 2187 | if (tab != null) { |
| 2188 | mTabControl.setCurrentTab(tab); |
| 2189 | // the tab is guaranteed to have a webview after setCurrentTab |
| 2190 | mUi.setActiveTab(tab); |
| 2191 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
John Reck | 8bcafc1 | 2011-08-29 16:43:02 -0700 | [diff] [blame] | 2194 | protected void closeEmptyTab() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2195 | Tab current = mTabControl.getCurrentTab(); |
| 2196 | if (current != null |
| 2197 | && current.getWebView().copyBackForwardList().getSize() == 0) { |
John Reck | 8bcafc1 | 2011-08-29 16:43:02 -0700 | [diff] [blame] | 2198 | closeCurrentTab(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2202 | protected void reuseTab(Tab appTab, UrlData urlData) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2203 | // Dismiss the subwindow if applicable. |
| 2204 | dismissSubWindow(appTab); |
| 2205 | // Since we might kill the WebView, remove it from the |
| 2206 | // content view first. |
| 2207 | mUi.detachTab(appTab); |
| 2208 | // Recreate the main WebView after destroying the old one. |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2209 | mTabControl.recreateWebView(appTab); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2210 | // TODO: analyze why the remove and add are necessary |
| 2211 | mUi.attachTab(appTab); |
| 2212 | if (mTabControl.getCurrentTab() != appTab) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2213 | switchToTab(appTab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2214 | loadUrlDataIn(appTab, urlData); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2215 | } else { |
| 2216 | // If the tab was the current tab, we have to attach |
| 2217 | // it to the view system again. |
| 2218 | setActiveTab(appTab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2219 | loadUrlDataIn(appTab, urlData); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | // Remove the sub window if it exists. Also called by TabControl when the |
| 2224 | // user clicks the 'X' to dismiss a sub window. |
| 2225 | public void dismissSubWindow(Tab tab) { |
| 2226 | removeSubWindow(tab); |
| 2227 | // dismiss the subwindow. This will destroy the WebView. |
| 2228 | tab.dismissSubWindow(); |
Michael Kolb | e8c9757 | 2011-11-21 14:03:56 -0800 | [diff] [blame] | 2229 | WebView wv = getCurrentTopWebView(); |
| 2230 | if (wv != null) { |
| 2231 | wv.requestFocus(); |
| 2232 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | @Override |
| 2236 | public void removeSubWindow(Tab t) { |
| 2237 | if (t.getSubWebView() != null) { |
| 2238 | mUi.removeSubWindow(t.getSubViewContainer()); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | @Override |
| 2243 | public void attachSubWindow(Tab tab) { |
| 2244 | if (tab.getSubWebView() != null) { |
| 2245 | mUi.attachSubWindow(tab.getSubViewContainer()); |
| 2246 | getCurrentTopWebView().requestFocus(); |
| 2247 | } |
| 2248 | } |
| 2249 | |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2250 | private Tab showPreloadedTab(final UrlData urlData) { |
| 2251 | if (!urlData.isPreloaded()) { |
| 2252 | return null; |
| 2253 | } |
| 2254 | final PreloadedTabControl tabControl = urlData.getPreloadedTab(); |
| 2255 | final String sbQuery = urlData.getSearchBoxQueryToSubmit(); |
| 2256 | if (sbQuery != null) { |
Mathew Inwood | 9ad1eac | 2011-09-15 11:29:50 +0100 | [diff] [blame] | 2257 | if (!tabControl.searchBoxSubmit(sbQuery, urlData.mUrl, urlData.mHeaders)) { |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2258 | // Could not submit query. Fallback to regular tab creation |
| 2259 | tabControl.destroy(); |
| 2260 | return null; |
| 2261 | } |
| 2262 | } |
Michael Kolb | ff6a748 | 2011-07-26 16:37:15 -0700 | [diff] [blame] | 2263 | // check tab count and make room for new tab |
| 2264 | if (!mTabControl.canCreateNewTab()) { |
| 2265 | Tab leastUsed = mTabControl.getLeastUsedTab(getCurrentTab()); |
| 2266 | if (leastUsed != null) { |
| 2267 | closeTab(leastUsed); |
| 2268 | } |
| 2269 | } |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2270 | Tab t = tabControl.getTab(); |
Mathew Inwood | e09305e | 2011-09-02 12:03:26 +0100 | [diff] [blame] | 2271 | t.refreshIdAfterPreload(); |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2272 | mTabControl.addPreloadedTab(t); |
| 2273 | addTab(t); |
| 2274 | setActiveTab(t); |
| 2275 | return t; |
| 2276 | } |
| 2277 | |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2278 | // open a non inconito tab with the given url data |
| 2279 | // and set as active tab |
| 2280 | public Tab openTab(UrlData urlData) { |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2281 | Tab tab = showPreloadedTab(urlData); |
| 2282 | if (tab == null) { |
| 2283 | tab = createNewTab(false, true, true); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 2284 | if ((tab != null) && !urlData.isEmpty()) { |
| 2285 | loadUrlDataIn(tab, urlData); |
| 2286 | } |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2287 | } |
Mathew Inwood | 29721c2 | 2011-06-29 17:55:24 +0100 | [diff] [blame] | 2288 | return tab; |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
Michael Kolb | 843510f | 2010-12-09 10:51:49 -0800 | [diff] [blame] | 2291 | @Override |
| 2292 | public Tab openTabToHomePage() { |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2293 | return openTab(mSettings.getHomePage(), false, true, false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2296 | @Override |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 2297 | public Tab openIncognitoTab() { |
| 2298 | return openTab(INCOGNITO_URI, true, true, false); |
| 2299 | } |
| 2300 | |
| 2301 | @Override |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2302 | public Tab openTab(String url, boolean incognito, boolean setActive, |
| 2303 | boolean useCurrent) { |
John Reck | 5949c66 | 2011-05-27 09:52:29 -0700 | [diff] [blame] | 2304 | return openTab(url, incognito, setActive, useCurrent, null); |
| 2305 | } |
| 2306 | |
| 2307 | @Override |
| 2308 | public Tab openTab(String url, Tab parent, boolean setActive, |
| 2309 | boolean useCurrent) { |
| 2310 | return openTab(url, (parent != null) && parent.isPrivateBrowsingEnabled(), |
| 2311 | setActive, useCurrent, parent); |
| 2312 | } |
| 2313 | |
| 2314 | public Tab openTab(String url, boolean incognito, boolean setActive, |
| 2315 | boolean useCurrent, Tab parent) { |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2316 | Tab tab = createNewTab(incognito, setActive, useCurrent); |
| 2317 | if (tab != null) { |
John Reck | 5949c66 | 2011-05-27 09:52:29 -0700 | [diff] [blame] | 2318 | if (parent != null && parent != tab) { |
| 2319 | parent.addChildTab(tab); |
| 2320 | } |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 2321 | if (url != null) { |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2322 | loadUrl(tab, url); |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 2323 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2324 | } |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2325 | return tab; |
| 2326 | } |
| 2327 | |
| 2328 | // this method will attempt to create a new tab |
| 2329 | // incognito: private browsing tab |
| 2330 | // setActive: ste tab as current tab |
| 2331 | // useCurrent: if no new tab can be created, return current tab |
| 2332 | private Tab createNewTab(boolean incognito, boolean setActive, |
| 2333 | boolean useCurrent) { |
| 2334 | Tab tab = null; |
| 2335 | if (mTabControl.canCreateNewTab()) { |
| 2336 | tab = mTabControl.createNewTab(incognito); |
| 2337 | addTab(tab); |
| 2338 | if (setActive) { |
| 2339 | setActiveTab(tab); |
| 2340 | } |
| 2341 | } else { |
| 2342 | if (useCurrent) { |
| 2343 | tab = mTabControl.getCurrentTab(); |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2344 | reuseTab(tab, null); |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 2345 | } else { |
| 2346 | mUi.showMaxTabsWarning(); |
| 2347 | } |
| 2348 | } |
| 2349 | return tab; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
John Reck | 2bc8042 | 2011-06-30 15:11:49 -0700 | [diff] [blame] | 2352 | @Override |
| 2353 | public SnapshotTab createNewSnapshotTab(long snapshotId, boolean setActive) { |
| 2354 | SnapshotTab tab = null; |
| 2355 | if (mTabControl.canCreateNewTab()) { |
| 2356 | tab = mTabControl.createSnapshotTab(snapshotId); |
| 2357 | addTab(tab); |
| 2358 | if (setActive) { |
| 2359 | setActiveTab(tab); |
| 2360 | } |
| 2361 | } else { |
| 2362 | mUi.showMaxTabsWarning(); |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 2363 | } |
| 2364 | return tab; |
| 2365 | } |
| 2366 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2367 | /** |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2368 | * @param tab the tab to switch to |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2369 | * @return boolean True if we successfully switched to a different tab. If |
| 2370 | * the indexth tab is null, or if that tab is the same as |
| 2371 | * the current one, return false. |
| 2372 | */ |
| 2373 | @Override |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2374 | public boolean switchToTab(Tab tab) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2375 | Tab currentTab = mTabControl.getCurrentTab(); |
| 2376 | if (tab == null || tab == currentTab) { |
| 2377 | return false; |
| 2378 | } |
| 2379 | setActiveTab(tab); |
| 2380 | return true; |
| 2381 | } |
| 2382 | |
| 2383 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2384 | public void closeCurrentTab() { |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 2385 | closeCurrentTab(false); |
| 2386 | } |
| 2387 | |
| 2388 | protected void closeCurrentTab(boolean andQuit) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2389 | if (mTabControl.getTabCount() == 1) { |
John Reck | bc490d2 | 2011-07-22 15:04:59 -0700 | [diff] [blame] | 2390 | mCrashRecoveryHandler.clearState(); |
Michael Kolb | c1eeb12 | 2011-08-01 09:56:26 -0700 | [diff] [blame] | 2391 | mTabControl.removeTab(getCurrentTab()); |
John Reck | 958b242 | 2010-12-03 17:56:17 -0800 | [diff] [blame] | 2392 | mActivity.finish(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2393 | return; |
| 2394 | } |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2395 | final Tab current = mTabControl.getCurrentTab(); |
| 2396 | final int pos = mTabControl.getCurrentPosition(); |
| 2397 | Tab newTab = current.getParent(); |
| 2398 | if (newTab == null) { |
| 2399 | newTab = mTabControl.getTab(pos + 1); |
| 2400 | if (newTab == null) { |
| 2401 | newTab = mTabControl.getTab(pos - 1); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2402 | } |
| 2403 | } |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 2404 | if (andQuit) { |
| 2405 | mTabControl.setCurrentTab(newTab); |
| 2406 | closeTab(current); |
| 2407 | } else if (switchToTab(newTab)) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2408 | // Close window |
| 2409 | closeTab(current); |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | /** |
| 2414 | * Close the tab, remove its associated title bar, and adjust mTabControl's |
| 2415 | * current tab to a valid value. |
| 2416 | */ |
| 2417 | @Override |
| 2418 | public void closeTab(Tab tab) { |
John Reck | 2826377 | 2011-10-11 17:13:42 -0700 | [diff] [blame] | 2419 | if (tab == mTabControl.getCurrentTab()) { |
| 2420 | closeCurrentTab(); |
| 2421 | } else { |
| 2422 | removeTab(tab); |
| 2423 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2426 | // Called when loading from context menu or LOAD_URL message |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2427 | protected void loadUrlFromContext(String url) { |
| 2428 | Tab tab = getCurrentTab(); |
| 2429 | WebView view = tab != null ? tab.getWebView() : null; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2430 | // In case the user enters nothing. |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2431 | if (url != null && url.length() != 0 && tab != null && view != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2432 | url = UrlUtils.smartUrlFilter(url); |
| 2433 | if (!view.getWebViewClient().shouldOverrideUrlLoading(view, url)) { |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2434 | loadUrl(tab, url); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | /** |
| 2440 | * Load the URL into the given WebView and update the title bar |
| 2441 | * to reflect the new load. Call this instead of WebView.loadUrl |
| 2442 | * directly. |
| 2443 | * @param view The WebView used to load url. |
| 2444 | * @param url The URL to load. |
| 2445 | */ |
John Reck | 71e5142 | 2011-07-01 16:49:28 -0700 | [diff] [blame] | 2446 | @Override |
| 2447 | public void loadUrl(Tab tab, String url) { |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2448 | loadUrl(tab, url, null); |
| 2449 | } |
| 2450 | |
| 2451 | protected void loadUrl(Tab tab, String url, Map<String, String> headers) { |
| 2452 | if (tab != null) { |
| 2453 | dismissSubWindow(tab); |
| 2454 | tab.loadUrl(url, headers); |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 2455 | mUi.onProgressChanged(tab); |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2456 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * Load UrlData into a Tab and update the title bar to reflect the new |
| 2461 | * load. Call this instead of UrlData.loadIn directly. |
| 2462 | * @param t The Tab used to load. |
| 2463 | * @param data The UrlData being loaded. |
| 2464 | */ |
| 2465 | protected void loadUrlDataIn(Tab t, UrlData data) { |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2466 | if (data != null) { |
| 2467 | if (data.mVoiceIntent != null) { |
| 2468 | t.activateVoiceSearchMode(data.mVoiceIntent); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 2469 | } else if (data.isPreloaded()) { |
| 2470 | // this isn't called for preloaded tabs |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2471 | } else { |
| 2472 | loadUrl(t, data.mUrl, data.mHeaders); |
| 2473 | } |
| 2474 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2475 | } |
| 2476 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2477 | @Override |
| 2478 | public void onUserCanceledSsl(Tab tab) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2479 | // TODO: Figure out the "right" behavior |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2480 | if (tab.canGoBack()) { |
| 2481 | tab.goBack(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2482 | } else { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2483 | tab.loadUrl(mSettings.getHomePage(), null); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 2484 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | void goBackOnePageOrQuit() { |
| 2488 | Tab current = mTabControl.getCurrentTab(); |
| 2489 | if (current == null) { |
| 2490 | /* |
| 2491 | * Instead of finishing the activity, simply push this to the back |
| 2492 | * of the stack and let ActivityManager to choose the foreground |
| 2493 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2494 | * root of the task. So we can use either true or false for |
| 2495 | * moveTaskToBack(). |
| 2496 | */ |
| 2497 | mActivity.moveTaskToBack(true); |
| 2498 | return; |
| 2499 | } |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2500 | if (current.canGoBack()) { |
| 2501 | current.goBack(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2502 | } else { |
| 2503 | // Check to see if we are closing a window that was created by |
| 2504 | // another window. If so, we switch back to that window. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2505 | Tab parent = current.getParent(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2506 | if (parent != null) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2507 | switchToTab(parent); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2508 | // Now we close the other tab |
| 2509 | closeTab(current); |
| 2510 | } else { |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 2511 | if ((current.getAppId() != null) || current.closeOnBack()) { |
Michael Kolb | 2ae6ef7 | 2011-08-22 14:49:34 -0700 | [diff] [blame] | 2512 | closeCurrentTab(true); |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 2513 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2514 | /* |
| 2515 | * Instead of finishing the activity, simply push this to the back |
| 2516 | * of the stack and let ActivityManager to choose the foreground |
| 2517 | * activity. As BrowserActivity is singleTask, it will be always the |
| 2518 | * root of the task. So we can use either true or false for |
| 2519 | * moveTaskToBack(). |
| 2520 | */ |
| 2521 | mActivity.moveTaskToBack(true); |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * Feed the previously stored results strings to the BrowserProvider so that |
| 2528 | * the SearchDialog will show them instead of the standard searches. |
| 2529 | * @param result String to show on the editable line of the SearchDialog. |
| 2530 | */ |
| 2531 | @Override |
| 2532 | public void showVoiceSearchResults(String result) { |
| 2533 | ContentProviderClient client = mActivity.getContentResolver() |
| 2534 | .acquireContentProviderClient(Browser.BOOKMARKS_URI); |
| 2535 | ContentProvider prov = client.getLocalContentProvider(); |
| 2536 | BrowserProvider bp = (BrowserProvider) prov; |
| 2537 | bp.setQueryResults(mTabControl.getCurrentTab().getVoiceSearchResults()); |
| 2538 | client.release(); |
| 2539 | |
| 2540 | Bundle bundle = createGoogleSearchSourceBundle( |
| 2541 | GOOGLE_SEARCH_SOURCE_SEARCHKEY); |
| 2542 | bundle.putBoolean(SearchManager.CONTEXT_IS_VOICE, true); |
| 2543 | startSearch(result, false, bundle, false); |
| 2544 | } |
| 2545 | |
| 2546 | private void startSearch(String initialQuery, boolean selectInitialQuery, |
| 2547 | Bundle appSearchData, boolean globalSearch) { |
| 2548 | if (appSearchData == null) { |
| 2549 | appSearchData = createGoogleSearchSourceBundle( |
| 2550 | GOOGLE_SEARCH_SOURCE_TYPE); |
| 2551 | } |
| 2552 | |
| 2553 | SearchEngine searchEngine = mSettings.getSearchEngine(); |
| 2554 | if (searchEngine != null && !searchEngine.supportsVoiceSearch()) { |
| 2555 | appSearchData.putBoolean(SearchManager.DISABLE_VOICE_SEARCH, true); |
| 2556 | } |
| 2557 | mActivity.startSearch(initialQuery, selectInitialQuery, appSearchData, |
| 2558 | globalSearch); |
| 2559 | } |
| 2560 | |
| 2561 | private Bundle createGoogleSearchSourceBundle(String source) { |
| 2562 | Bundle bundle = new Bundle(); |
| 2563 | bundle.putString(Search.SOURCE, source); |
| 2564 | return bundle; |
| 2565 | } |
| 2566 | |
| 2567 | /** |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2568 | * helper method for key handler |
| 2569 | * returns the current tab if it can't advance |
| 2570 | */ |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2571 | private Tab getNextTab() { |
Michael Kolb | f5261da | 2011-12-15 15:07:35 -0800 | [diff] [blame] | 2572 | int pos = mTabControl.getCurrentPosition() + 1; |
| 2573 | if (pos >= mTabControl.getTabCount()) { |
| 2574 | pos = 0; |
| 2575 | } |
| 2576 | return mTabControl.getTab(pos); |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | /** |
| 2580 | * helper method for key handler |
| 2581 | * returns the current tab if it can't advance |
| 2582 | */ |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2583 | private Tab getPrevTab() { |
Michael Kolb | f5261da | 2011-12-15 15:07:35 -0800 | [diff] [blame] | 2584 | int pos = mTabControl.getCurrentPosition() - 1; |
| 2585 | if ( pos < 0) { |
| 2586 | pos = mTabControl.getTabCount() - 1; |
| 2587 | } |
| 2588 | return mTabControl.getTab(pos); |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | /** |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2592 | * handle key events in browser |
| 2593 | * |
| 2594 | * @param keyCode |
| 2595 | * @param event |
| 2596 | * @return true if handled, false to pass to super |
| 2597 | */ |
| 2598 | boolean onKeyDown(int keyCode, KeyEvent event) { |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2599 | boolean noModifiers = event.hasNoModifiers(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2600 | // Even if MENU is already held down, we need to call to super to open |
| 2601 | // the IME on long press. |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 2602 | if (!noModifiers |
| 2603 | && ((KeyEvent.KEYCODE_MENU == keyCode) |
| 2604 | || (KeyEvent.KEYCODE_CTRL_LEFT == keyCode) |
| 2605 | || (KeyEvent.KEYCODE_CTRL_RIGHT == keyCode))) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2606 | mMenuIsDown = true; |
| 2607 | return false; |
| 2608 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2609 | |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2610 | WebView webView = getCurrentTopWebView(); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2611 | Tab tab = getCurrentTab(); |
| 2612 | if (webView == null || tab == null) return false; |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2613 | |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2614 | boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 2615 | boolean shift = event.hasModifiers(KeyEvent.META_SHIFT_ON); |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2616 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2617 | switch(keyCode) { |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2618 | case KeyEvent.KEYCODE_TAB: |
| 2619 | if (event.isCtrlPressed()) { |
| 2620 | if (event.isShiftPressed()) { |
| 2621 | // prev tab |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2622 | switchToTab(getPrevTab()); |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2623 | } else { |
| 2624 | // next tab |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2625 | switchToTab(getNextTab()); |
Michael Kolb | 0035fad | 2011-03-14 13:25:28 -0700 | [diff] [blame] | 2626 | } |
| 2627 | return true; |
| 2628 | } |
| 2629 | break; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2630 | case KeyEvent.KEYCODE_SPACE: |
| 2631 | // WebView/WebTextView handle the keys in the KeyDown. As |
| 2632 | // the Activity's shortcut keys are only handled when WebView |
| 2633 | // doesn't, have to do it in onKeyDown instead of onKeyUp. |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2634 | if (shift) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2635 | pageUp(); |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2636 | } else if (noModifiers) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2637 | pageDown(); |
| 2638 | } |
| 2639 | return true; |
| 2640 | case KeyEvent.KEYCODE_BACK: |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2641 | if (!noModifiers) break; |
John Reck | e6bf4ab | 2011-02-24 15:48:05 -0800 | [diff] [blame] | 2642 | event.startTracking(); |
| 2643 | return true; |
Michael Kolb | e9e1d4a | 2011-07-14 15:02:17 -0700 | [diff] [blame] | 2644 | case KeyEvent.KEYCODE_FORWARD: |
| 2645 | if (!noModifiers) break; |
| 2646 | tab.goForward(); |
| 2647 | return true; |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2648 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 2649 | if (ctrl) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2650 | tab.goBack(); |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2651 | return true; |
| 2652 | } |
| 2653 | break; |
| 2654 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 2655 | if (ctrl) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2656 | tab.goForward(); |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2657 | return true; |
| 2658 | } |
| 2659 | break; |
| 2660 | case KeyEvent.KEYCODE_A: |
| 2661 | if (ctrl) { |
| 2662 | webView.selectAll(); |
| 2663 | return true; |
| 2664 | } |
| 2665 | break; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2666 | // case KeyEvent.KEYCODE_B: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2667 | case KeyEvent.KEYCODE_C: |
| 2668 | if (ctrl) { |
| 2669 | webView.copySelection(); |
| 2670 | return true; |
| 2671 | } |
| 2672 | break; |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2673 | // case KeyEvent.KEYCODE_D: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2674 | // case KeyEvent.KEYCODE_E: // in Chrome: puts '?' in URL bar |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2675 | // case KeyEvent.KEYCODE_F: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2676 | // case KeyEvent.KEYCODE_G: // in Chrome: finds next match |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2677 | // case KeyEvent.KEYCODE_H: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2678 | // case KeyEvent.KEYCODE_I: // unused |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2679 | // case KeyEvent.KEYCODE_J: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2680 | // case KeyEvent.KEYCODE_K: // in Chrome: puts '?' in URL bar |
Michael Kolb | a418306 | 2011-01-16 10:43:21 -0800 | [diff] [blame] | 2681 | // case KeyEvent.KEYCODE_L: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2682 | // case KeyEvent.KEYCODE_M: // unused |
| 2683 | // case KeyEvent.KEYCODE_N: // in Chrome: new window |
| 2684 | // case KeyEvent.KEYCODE_O: // in Chrome: open file |
| 2685 | // case KeyEvent.KEYCODE_P: // in Chrome: print page |
| 2686 | // case KeyEvent.KEYCODE_Q: // unused |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 2687 | // case KeyEvent.KEYCODE_R: |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2688 | // case KeyEvent.KEYCODE_S: // in Chrome: saves page |
| 2689 | case KeyEvent.KEYCODE_T: |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 2690 | // we can't use the ctrl/shift flags, they check for |
| 2691 | // exclusive use of a modifier |
| 2692 | if (event.isCtrlPressed()) { |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2693 | if (event.isShiftPressed()) { |
Michael Kolb | 519d228 | 2011-05-09 17:03:19 -0700 | [diff] [blame] | 2694 | openIncognitoTab(); |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2695 | } else { |
| 2696 | openTabToHomePage(); |
| 2697 | } |
| 2698 | return true; |
| 2699 | } |
| 2700 | break; |
| 2701 | // case KeyEvent.KEYCODE_U: // in Chrome: opens source of page |
| 2702 | // case KeyEvent.KEYCODE_V: // text view intercepts to paste |
Michael Kolb | 5ae15bd | 2011-08-16 17:09:27 -0700 | [diff] [blame] | 2703 | // case KeyEvent.KEYCODE_W: // menu |
Cary Clark | 8ff8c66 | 2010-12-29 15:03:05 -0500 | [diff] [blame] | 2704 | // case KeyEvent.KEYCODE_X: // text view intercepts to cut |
| 2705 | // case KeyEvent.KEYCODE_Y: // unused |
| 2706 | // case KeyEvent.KEYCODE_Z: // unused |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2707 | } |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 2708 | // it is a regular key and webview is not null |
| 2709 | return mUi.dispatchKey(keyCode, event); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
John Reck | e6bf4ab | 2011-02-24 15:48:05 -0800 | [diff] [blame] | 2712 | boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 2713 | switch(keyCode) { |
| 2714 | case KeyEvent.KEYCODE_BACK: |
John Reck | 3ba4553 | 2011-08-11 16:26:53 -0700 | [diff] [blame] | 2715 | if (mUi.isWebShowing()) { |
Michael Kolb | 315d502 | 2011-10-13 12:47:11 -0700 | [diff] [blame] | 2716 | bookmarksOrHistoryPicker(ComboViews.History); |
John Reck | e6bf4ab | 2011-02-24 15:48:05 -0800 | [diff] [blame] | 2717 | return true; |
| 2718 | } |
| 2719 | break; |
| 2720 | } |
| 2721 | return false; |
| 2722 | } |
| 2723 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2724 | boolean onKeyUp(int keyCode, KeyEvent event) { |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 2725 | if (KeyEvent.KEYCODE_MENU == keyCode) { |
| 2726 | mMenuIsDown = false; |
| 2727 | if (event.isTracking() && !event.isCanceled()) { |
Michael Kolb | 4bd767d | 2011-05-27 11:33:55 -0700 | [diff] [blame] | 2728 | return onMenuKey(); |
Michael Kolb | 2814a36 | 2011-05-19 15:49:41 -0700 | [diff] [blame] | 2729 | } |
| 2730 | } |
Cary Clark | 160bbb9 | 2011-01-10 11:17:07 -0500 | [diff] [blame] | 2731 | if (!event.hasNoModifiers()) return false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2732 | switch(keyCode) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2733 | case KeyEvent.KEYCODE_BACK: |
| 2734 | if (event.isTracking() && !event.isCanceled()) { |
| 2735 | onBackKey(); |
| 2736 | return true; |
| 2737 | } |
| 2738 | break; |
| 2739 | } |
| 2740 | return false; |
| 2741 | } |
| 2742 | |
| 2743 | public boolean isMenuDown() { |
| 2744 | return mMenuIsDown; |
| 2745 | } |
| 2746 | |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 2747 | public void setupAutoFill(Message message) { |
| 2748 | // Open the settings activity at the AutoFill profile fragment so that |
| 2749 | // the user can create a new profile. When they return, we will dispatch |
| 2750 | // the message so that we can autofill the form using their new profile. |
| 2751 | Intent intent = new Intent(mActivity, BrowserPreferencesPage.class); |
| 2752 | intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, |
| 2753 | AutoFillSettingsFragment.class.getName()); |
| 2754 | mAutoFillSetupMessage = message; |
| 2755 | mActivity.startActivityForResult(intent, AUTOFILL_SETUP); |
| 2756 | } |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 2757 | |
Michael Kolb | fbc579a | 2011-07-07 15:59:33 -0700 | [diff] [blame] | 2758 | public boolean onSearchRequested() { |
| 2759 | mUi.editUrl(false); |
| 2760 | return true; |
| 2761 | } |
| 2762 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2763 | @Override |
| 2764 | public boolean shouldCaptureThumbnails() { |
| 2765 | return mUi.shouldCaptureThumbnails(); |
| 2766 | } |
| 2767 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2768 | @Override |
| 2769 | public void setBlockEvents(boolean block) { |
| 2770 | mBlockEvents = block; |
| 2771 | } |
| 2772 | |
| 2773 | public boolean dispatchKeyEvent(KeyEvent event) { |
Michael Kolb | 8735764 | 2011-08-24 14:19:18 -0700 | [diff] [blame] | 2774 | return mBlockEvents; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
Michael Kolb | 8735764 | 2011-08-24 14:19:18 -0700 | [diff] [blame] | 2778 | return mBlockEvents; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | public boolean dispatchTouchEvent(MotionEvent ev) { |
Michael Kolb | 8735764 | 2011-08-24 14:19:18 -0700 | [diff] [blame] | 2782 | return mBlockEvents; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
Michael Kolb | 8735764 | 2011-08-24 14:19:18 -0700 | [diff] [blame] | 2786 | return mBlockEvents; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
| 2789 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
Michael Kolb | 8735764 | 2011-08-24 14:19:18 -0700 | [diff] [blame] | 2790 | return mBlockEvents; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 2793 | } |