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