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