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