Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.browser; |
| 18 | |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 19 | import com.android.browser.homepages.HomeProvider; |
Jeff Hamilton | 8ce956c | 2010-08-17 11:13:53 -0500 | [diff] [blame] | 20 | import com.android.common.speech.LoggingEvents; |
| 21 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 22 | import android.app.Activity; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 23 | import android.app.AlertDialog; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 24 | import android.app.SearchManager; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 25 | import android.content.ContentResolver; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 26 | import android.content.Context; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 27 | import android.content.DialogInterface; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 28 | import android.content.DialogInterface.OnCancelListener; |
Jeff Hamilton | 8ce956c | 2010-08-17 11:13:53 -0500 | [diff] [blame] | 29 | import android.content.Intent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 30 | import android.graphics.Bitmap; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 31 | import android.graphics.BitmapFactory; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 32 | import android.net.Uri; |
| 33 | import android.net.http.SslError; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 34 | import android.os.Bundle; |
| 35 | import android.os.Message; |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 36 | import android.os.SystemClock; |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 37 | import android.speech.RecognizerResultsIntent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | import android.view.KeyEvent; |
| 40 | import android.view.LayoutInflater; |
| 41 | import android.view.View; |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 42 | import android.view.ViewStub; |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 43 | import android.webkit.ConsoleMessage; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 44 | import android.webkit.DownloadListener; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 45 | import android.webkit.GeolocationPermissions; |
| 46 | import android.webkit.HttpAuthHandler; |
| 47 | import android.webkit.SslErrorHandler; |
| 48 | import android.webkit.URLUtil; |
| 49 | import android.webkit.ValueCallback; |
| 50 | import android.webkit.WebBackForwardList; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 51 | import android.webkit.WebBackForwardListClient; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 52 | import android.webkit.WebChromeClient; |
| 53 | import android.webkit.WebHistoryItem; |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 54 | import android.webkit.WebResourceResponse; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 55 | import android.webkit.WebStorage; |
| 56 | import android.webkit.WebView; |
| 57 | import android.webkit.WebViewClient; |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 58 | import android.widget.CheckBox; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 59 | import android.widget.LinearLayout; |
| 60 | import android.widget.TextView; |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 61 | import android.widget.Toast; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 62 | |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 63 | import java.util.ArrayList; |
| 64 | import java.util.HashMap; |
| 65 | import java.util.Iterator; |
| 66 | import java.util.LinkedList; |
| 67 | import java.util.Map; |
| 68 | import java.util.Vector; |
| 69 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Class for maintaining Tabs with a main WebView and a subwindow. |
| 72 | */ |
| 73 | class Tab { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 74 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 75 | // Log Tag |
| 76 | private static final String LOGTAG = "Tab"; |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 77 | // Special case the logtag for messages for the Console to make it easier to |
| 78 | // filter them and match the logtag used for these messages in older versions |
| 79 | // of the browser. |
| 80 | private static final String CONSOLE_LOGTAG = "browser"; |
| 81 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 82 | public enum LockIcon { |
| 83 | LOCK_ICON_UNSECURE, |
| 84 | LOCK_ICON_SECURE, |
| 85 | LOCK_ICON_MIXED, |
| 86 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 87 | |
| 88 | Activity mActivity; |
| 89 | private WebViewController mWebViewController; |
| 90 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 91 | // The tab ID |
| 92 | private long mId; |
| 93 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 94 | // The Geolocation permissions prompt |
| 95 | private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt; |
| 96 | // Main WebView wrapper |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 97 | private View mContainer; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 98 | // Main WebView |
| 99 | private WebView mMainView; |
| 100 | // Subwindow container |
| 101 | private View mSubViewContainer; |
| 102 | // Subwindow WebView |
| 103 | private WebView mSubView; |
| 104 | // Saved bundle for when we are running low on memory. It contains the |
| 105 | // information needed to restore the WebView if the user goes back to the |
| 106 | // tab. |
| 107 | private Bundle mSavedState; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 108 | // Parent Tab. This is the Tab that created this Tab, or null if the Tab was |
| 109 | // created by the UI |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 110 | private Tab mParent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 111 | // Tab that constructed by this Tab. This is used when this Tab is |
| 112 | // destroyed, it clears all mParentTab values in the children. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 113 | private Vector<Tab> mChildren; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 114 | // If true, the tab is in the foreground of the current activity. |
| 115 | private boolean mInForeground; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 116 | // If true, the tab is in page loading state (after onPageStarted, |
| 117 | // before onPageFinsihed) |
| 118 | private boolean mInPageLoad; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 119 | // The last reported progress of the current page |
| 120 | private int mPageLoadProgress; |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 121 | // The time the load started, used to find load page time |
| 122 | private long mLoadStartTime; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 123 | // Application identifier used to find tabs that another application wants |
| 124 | // to reuse. |
| 125 | private String mAppId; |
| 126 | // Keep the original url around to avoid killing the old WebView if the url |
| 127 | // has not changed. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 128 | // Error console for the tab |
| 129 | private ErrorConsoleView mErrorConsole; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 130 | // The listener that gets invoked when a download is started from the |
| 131 | // mMainView |
| 132 | private final DownloadListener mDownloadListener; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 133 | // Listener used to know when we move forward or back in the history list. |
| 134 | private final WebBackForwardListClient mWebBackForwardListClient; |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 135 | private DataController mDataController; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 136 | // State of the auto-login request. |
| 137 | private DeviceAccountLogin mDeviceAccountLogin; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 138 | |
| 139 | // AsyncTask for downloading touch icons |
| 140 | DownloadTouchIcon mTouchIconLoader; |
| 141 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 142 | private Bitmap mScreenshot; |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 143 | private BrowserSettings mSettings; |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 144 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 145 | // All the state needed for a page |
| 146 | private static class PageState { |
| 147 | String mUrl; |
| 148 | String mTitle; |
| 149 | LockIcon mLockIcon; |
| 150 | Bitmap mFavicon; |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 151 | Boolean mIsBookmarkedSite = false; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 152 | |
| 153 | PageState(Context c, boolean incognito) { |
| 154 | if (incognito) { |
| 155 | mUrl = "browser:incognito"; |
| 156 | mTitle = c.getString(R.string.new_incognito_tab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 157 | } else { |
| 158 | mUrl = ""; |
| 159 | mTitle = c.getString(R.string.new_tab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 160 | } |
Justin Ho | dc6cbb7 | 2011-01-24 15:14:54 -0800 | [diff] [blame] | 161 | mFavicon = BitmapFactory.decodeResource( |
| 162 | c.getResources(), R.drawable.app_web_browser_sm); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 163 | mLockIcon = LockIcon.LOCK_ICON_UNSECURE; |
| 164 | } |
| 165 | |
| 166 | PageState(Context c, boolean incognito, String url, Bitmap favicon) { |
| 167 | mUrl = url; |
| 168 | mTitle = null; |
| 169 | if (URLUtil.isHttpsUrl(url)) { |
| 170 | mLockIcon = LockIcon.LOCK_ICON_SECURE; |
| 171 | } else { |
| 172 | mLockIcon = LockIcon.LOCK_ICON_UNSECURE; |
| 173 | } |
| 174 | if (favicon != null) { |
| 175 | mFavicon = favicon; |
| 176 | } else { |
Justin Ho | dc6cbb7 | 2011-01-24 15:14:54 -0800 | [diff] [blame] | 177 | mFavicon = BitmapFactory.decodeResource( |
| 178 | c.getResources(), R.drawable.app_web_browser_sm); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 179 | } |
| 180 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 181 | } |
| 182 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 183 | // The current/loading page's state |
| 184 | private PageState mCurrentState; |
| 185 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 186 | // Used for saving and restoring each Tab |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 187 | static final String ID = "ID"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 188 | static final String CURRURL = "currentUrl"; |
| 189 | static final String CURRTITLE = "currentTitle"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 190 | static final String PARENTTAB = "parentTab"; |
| 191 | static final String APPID = "appid"; |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 192 | static final String INCOGNITO = "privateBrowsingEnabled"; |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 193 | static final String SCREENSHOT = "screenshot"; |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame^] | 194 | static final String USERAGENT = "useragent"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 195 | |
| 196 | // ------------------------------------------------------------------------- |
| 197 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 198 | /** |
| 199 | * Private information regarding the latest voice search. If the Tab is not |
| 200 | * in voice search mode, this will be null. |
| 201 | */ |
| 202 | private VoiceSearchData mVoiceSearchData; |
| 203 | /** |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 204 | * Remove voice search mode from this tab. |
| 205 | */ |
| 206 | public void revertVoiceSearchMode() { |
| 207 | if (mVoiceSearchData != null) { |
| 208 | mVoiceSearchData = null; |
| 209 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 210 | mWebViewController.revertVoiceSearchMode(this); |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 214 | |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 215 | /** |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 216 | * Return whether the tab is in voice search mode. |
| 217 | */ |
| 218 | public boolean isInVoiceSearchMode() { |
| 219 | return mVoiceSearchData != null; |
| 220 | } |
| 221 | /** |
Leon Scroggins III | c1f5ae2 | 2010-06-29 17:11:29 -0400 | [diff] [blame] | 222 | * Return true if the Tab is in voice search mode and the voice search |
| 223 | * Intent came with a String identifying that Google provided the Intent. |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 224 | */ |
| 225 | public boolean voiceSearchSourceIsGoogle() { |
| 226 | return mVoiceSearchData != null && mVoiceSearchData.mSourceIsGoogle; |
| 227 | } |
| 228 | /** |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 229 | * Get the title to display for the current voice search page. If the Tab |
| 230 | * is not in voice search mode, return null. |
| 231 | */ |
| 232 | public String getVoiceDisplayTitle() { |
| 233 | if (mVoiceSearchData == null) return null; |
| 234 | return mVoiceSearchData.mLastVoiceSearchTitle; |
| 235 | } |
| 236 | /** |
| 237 | * Get the latest array of voice search results, to be passed to the |
| 238 | * BrowserProvider. If the Tab is not in voice search mode, return null. |
| 239 | */ |
| 240 | public ArrayList<String> getVoiceSearchResults() { |
| 241 | if (mVoiceSearchData == null) return null; |
| 242 | return mVoiceSearchData.mVoiceSearchResults; |
| 243 | } |
| 244 | /** |
| 245 | * Activate voice search mode. |
| 246 | * @param intent Intent which has the results to use, or an index into the |
| 247 | * results when reusing the old results. |
| 248 | */ |
| 249 | /* package */ void activateVoiceSearchMode(Intent intent) { |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 250 | int index = 0; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 251 | ArrayList<String> results = intent.getStringArrayListExtra( |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 252 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 253 | if (results != null) { |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 254 | ArrayList<String> urls = intent.getStringArrayListExtra( |
| 255 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS); |
| 256 | ArrayList<String> htmls = intent.getStringArrayListExtra( |
| 257 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_HTML); |
| 258 | ArrayList<String> baseUrls = intent.getStringArrayListExtra( |
| 259 | RecognizerResultsIntent |
| 260 | .EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 261 | // This tab is now entering voice search mode for the first time, or |
| 262 | // a new voice search was done. |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 263 | int size = results.size(); |
| 264 | if (urls == null || size != urls.size()) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 265 | throw new AssertionError("improper extras passed in Intent"); |
| 266 | } |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 267 | if (htmls == null || htmls.size() != size || baseUrls == null || |
| 268 | (baseUrls.size() != size && baseUrls.size() != 1)) { |
| 269 | // If either of these arrays are empty/incorrectly sized, ignore |
| 270 | // them. |
| 271 | htmls = null; |
| 272 | baseUrls = null; |
| 273 | } |
| 274 | mVoiceSearchData = new VoiceSearchData(results, urls, htmls, |
| 275 | baseUrls); |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 276 | mVoiceSearchData.mHeaders = intent.getParcelableArrayListExtra( |
| 277 | RecognizerResultsIntent |
| 278 | .EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS); |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 279 | mVoiceSearchData.mSourceIsGoogle = intent.getBooleanExtra( |
| 280 | VoiceSearchData.SOURCE_IS_GOOGLE, false); |
Leon Scroggins | 2ee4a5a | 2010-03-15 16:56:57 -0400 | [diff] [blame] | 281 | mVoiceSearchData.mVoiceSearchIntent = new Intent(intent); |
Leon Scroggins | e10dde5 | 2010-03-08 19:53:03 -0500 | [diff] [blame] | 282 | } |
| 283 | String extraData = intent.getStringExtra( |
| 284 | SearchManager.EXTRA_DATA_KEY); |
| 285 | if (extraData != null) { |
| 286 | index = Integer.parseInt(extraData); |
| 287 | if (index >= mVoiceSearchData.mVoiceSearchResults.size()) { |
| 288 | throw new AssertionError("index must be less than " |
| 289 | + "size of mVoiceSearchResults"); |
| 290 | } |
| 291 | if (mVoiceSearchData.mSourceIsGoogle) { |
| 292 | Intent logIntent = new Intent( |
| 293 | LoggingEvents.ACTION_LOG_EVENT); |
| 294 | logIntent.putExtra(LoggingEvents.EXTRA_EVENT, |
| 295 | LoggingEvents.VoiceSearch.N_BEST_CHOOSE); |
| 296 | logIntent.putExtra( |
| 297 | LoggingEvents.VoiceSearch.EXTRA_N_BEST_CHOOSE_INDEX, |
| 298 | index); |
| 299 | mActivity.sendBroadcast(logIntent); |
| 300 | } |
| 301 | if (mVoiceSearchData.mVoiceSearchIntent != null) { |
Leon Scroggins | 2ee4a5a | 2010-03-15 16:56:57 -0400 | [diff] [blame] | 302 | // Copy the Intent, so that each history item will have its own |
| 303 | // Intent, with different (or none) extra data. |
| 304 | Intent latest = new Intent(mVoiceSearchData.mVoiceSearchIntent); |
| 305 | latest.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); |
| 306 | mVoiceSearchData.mVoiceSearchIntent = latest; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | mVoiceSearchData.mLastVoiceSearchTitle |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 310 | = mVoiceSearchData.mVoiceSearchResults.get(index); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 311 | if (mInForeground) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 312 | mWebViewController.activateVoiceSearchMode( |
| 313 | mVoiceSearchData.mLastVoiceSearchTitle, |
| 314 | mVoiceSearchData.mVoiceSearchResults); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 315 | } |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 316 | if (mVoiceSearchData.mVoiceSearchHtmls != null) { |
| 317 | // When index was found it was already ensured that it was valid |
| 318 | String uriString = mVoiceSearchData.mVoiceSearchHtmls.get(index); |
| 319 | if (uriString != null) { |
| 320 | Uri dataUri = Uri.parse(uriString); |
| 321 | if (RecognizerResultsIntent.URI_SCHEME_INLINE.equals( |
| 322 | dataUri.getScheme())) { |
| 323 | // If there is only one base URL, use it. If there are |
| 324 | // more, there will be one for each index, so use the base |
| 325 | // URL corresponding to the index. |
| 326 | String baseUrl = mVoiceSearchData.mVoiceSearchBaseUrls.get( |
| 327 | mVoiceSearchData.mVoiceSearchBaseUrls.size() > 1 ? |
| 328 | index : 0); |
| 329 | mVoiceSearchData.mLastVoiceSearchUrl = baseUrl; |
| 330 | mMainView.loadDataWithBaseURL(baseUrl, |
| 331 | uriString.substring(RecognizerResultsIntent |
| 332 | .URI_SCHEME_INLINE.length() + 1), "text/html", |
| 333 | "utf-8", baseUrl); |
| 334 | return; |
| 335 | } |
| 336 | } |
| 337 | } |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 338 | mVoiceSearchData.mLastVoiceSearchUrl |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 339 | = mVoiceSearchData.mVoiceSearchUrls.get(index); |
| 340 | if (null == mVoiceSearchData.mLastVoiceSearchUrl) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 341 | mVoiceSearchData.mLastVoiceSearchUrl = UrlUtils.smartUrlFilter( |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 342 | mVoiceSearchData.mLastVoiceSearchTitle); |
| 343 | } |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 344 | Map<String, String> headers = null; |
| 345 | if (mVoiceSearchData.mHeaders != null) { |
| 346 | int bundleIndex = mVoiceSearchData.mHeaders.size() == 1 ? 0 |
| 347 | : index; |
| 348 | Bundle bundle = mVoiceSearchData.mHeaders.get(bundleIndex); |
| 349 | if (bundle != null && !bundle.isEmpty()) { |
| 350 | Iterator<String> iter = bundle.keySet().iterator(); |
| 351 | headers = new HashMap<String, String>(); |
| 352 | while (iter.hasNext()) { |
| 353 | String key = iter.next(); |
| 354 | headers.put(key, bundle.getString(key)); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl, headers); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 359 | } |
| 360 | /* package */ static class VoiceSearchData { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 361 | public VoiceSearchData(ArrayList<String> results, |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 362 | ArrayList<String> urls, ArrayList<String> htmls, |
| 363 | ArrayList<String> baseUrls) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 364 | mVoiceSearchResults = results; |
| 365 | mVoiceSearchUrls = urls; |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 366 | mVoiceSearchHtmls = htmls; |
| 367 | mVoiceSearchBaseUrls = baseUrls; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 368 | } |
| 369 | /* |
| 370 | * ArrayList of suggestions to be displayed when opening the |
| 371 | * SearchManager |
| 372 | */ |
| 373 | public ArrayList<String> mVoiceSearchResults; |
| 374 | /* |
| 375 | * ArrayList of urls, associated with the suggestions in |
| 376 | * mVoiceSearchResults. |
| 377 | */ |
| 378 | public ArrayList<String> mVoiceSearchUrls; |
| 379 | /* |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 380 | * ArrayList holding content to load for each item in |
| 381 | * mVoiceSearchResults. |
| 382 | */ |
| 383 | public ArrayList<String> mVoiceSearchHtmls; |
| 384 | /* |
| 385 | * ArrayList holding base urls for the items in mVoiceSearchResults. |
| 386 | * If non null, this will either have the same size as |
| 387 | * mVoiceSearchResults or have a size of 1, in which case all will use |
| 388 | * the same base url |
| 389 | */ |
| 390 | public ArrayList<String> mVoiceSearchBaseUrls; |
| 391 | /* |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 392 | * The last url provided by voice search. Used for comparison to see if |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 393 | * we are going to a page by some method besides voice search. |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 394 | */ |
| 395 | public String mLastVoiceSearchUrl; |
| 396 | /** |
| 397 | * The last title used for voice search. Needed to update the title bar |
| 398 | * when switching tabs. |
| 399 | */ |
| 400 | public String mLastVoiceSearchTitle; |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 401 | /** |
| 402 | * Whether the Intent which turned on voice search mode contained the |
| 403 | * String signifying that Google was the source. |
| 404 | */ |
| 405 | public boolean mSourceIsGoogle; |
| 406 | /** |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 407 | * List of headers to be passed into the WebView containing location |
| 408 | * information |
| 409 | */ |
| 410 | public ArrayList<Bundle> mHeaders; |
| 411 | /** |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 412 | * The Intent used to invoke voice search. Placed on the |
| 413 | * WebHistoryItem so that when coming back to a previous voice search |
| 414 | * page we can again activate voice search. |
| 415 | */ |
Leon Scroggins | e10dde5 | 2010-03-08 19:53:03 -0500 | [diff] [blame] | 416 | public Intent mVoiceSearchIntent; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 417 | /** |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 418 | * String used to identify Google as the source of voice search. |
| 419 | */ |
| 420 | public static String SOURCE_IS_GOOGLE |
| 421 | = "android.speech.extras.SOURCE_IS_GOOGLE"; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 424 | // Container class for the next error dialog that needs to be displayed |
| 425 | private class ErrorDialog { |
| 426 | public final int mTitle; |
| 427 | public final String mDescription; |
| 428 | public final int mError; |
| 429 | ErrorDialog(int title, String desc, int error) { |
| 430 | mTitle = title; |
| 431 | mDescription = desc; |
| 432 | mError = error; |
| 433 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 434 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 435 | |
| 436 | private void processNextError() { |
| 437 | if (mQueuedErrors == null) { |
| 438 | return; |
| 439 | } |
| 440 | // The first one is currently displayed so just remove it. |
| 441 | mQueuedErrors.removeFirst(); |
| 442 | if (mQueuedErrors.size() == 0) { |
| 443 | mQueuedErrors = null; |
| 444 | return; |
| 445 | } |
| 446 | showError(mQueuedErrors.getFirst()); |
| 447 | } |
| 448 | |
| 449 | private DialogInterface.OnDismissListener mDialogListener = |
| 450 | new DialogInterface.OnDismissListener() { |
| 451 | public void onDismiss(DialogInterface d) { |
| 452 | processNextError(); |
| 453 | } |
| 454 | }; |
| 455 | private LinkedList<ErrorDialog> mQueuedErrors; |
| 456 | |
| 457 | private void queueError(int err, String desc) { |
| 458 | if (mQueuedErrors == null) { |
| 459 | mQueuedErrors = new LinkedList<ErrorDialog>(); |
| 460 | } |
| 461 | for (ErrorDialog d : mQueuedErrors) { |
| 462 | if (d.mError == err) { |
| 463 | // Already saw a similar error, ignore the new one. |
| 464 | return; |
| 465 | } |
| 466 | } |
| 467 | ErrorDialog errDialog = new ErrorDialog( |
| 468 | err == WebViewClient.ERROR_FILE_NOT_FOUND ? |
| 469 | R.string.browserFrameFileErrorLabel : |
| 470 | R.string.browserFrameNetworkErrorLabel, |
| 471 | desc, err); |
| 472 | mQueuedErrors.addLast(errDialog); |
| 473 | |
| 474 | // Show the dialog now if the queue was empty and it is in foreground |
| 475 | if (mQueuedErrors.size() == 1 && mInForeground) { |
| 476 | showError(errDialog); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | private void showError(ErrorDialog errDialog) { |
| 481 | if (mInForeground) { |
| 482 | AlertDialog d = new AlertDialog.Builder(mActivity) |
| 483 | .setTitle(errDialog.mTitle) |
| 484 | .setMessage(errDialog.mDescription) |
| 485 | .setPositiveButton(R.string.ok, null) |
| 486 | .create(); |
| 487 | d.setOnDismissListener(mDialogListener); |
| 488 | d.show(); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // ------------------------------------------------------------------------- |
| 493 | // WebViewClient implementation for the main WebView |
| 494 | // ------------------------------------------------------------------------- |
| 495 | |
| 496 | private final WebViewClient mWebViewClient = new WebViewClient() { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 497 | private Message mDontResend; |
| 498 | private Message mResend; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 499 | @Override |
| 500 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 501 | mInPageLoad = true; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 502 | mPageLoadProgress = 0; |
| 503 | mCurrentState = new PageState(mActivity, |
| 504 | view.isPrivateBrowsingEnabled(), url, favicon); |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 505 | mLoadStartTime = SystemClock.uptimeMillis(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 506 | if (mVoiceSearchData != null |
| 507 | && !url.equals(mVoiceSearchData.mLastVoiceSearchUrl)) { |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 508 | if (mVoiceSearchData.mSourceIsGoogle) { |
| 509 | Intent i = new Intent(LoggingEvents.ACTION_LOG_EVENT); |
| 510 | i.putExtra(LoggingEvents.EXTRA_FLUSH, true); |
| 511 | mActivity.sendBroadcast(i); |
| 512 | } |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 513 | revertVoiceSearchMode(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 514 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 515 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 516 | |
| 517 | // If we start a touch icon load and then load a new page, we don't |
| 518 | // want to cancel the current touch icon loader. But, we do want to |
| 519 | // create a new one when the touch icon url is known. |
| 520 | if (mTouchIconLoader != null) { |
| 521 | mTouchIconLoader.mTab = null; |
| 522 | mTouchIconLoader = null; |
| 523 | } |
| 524 | |
| 525 | // reset the error console |
| 526 | if (mErrorConsole != null) { |
| 527 | mErrorConsole.clearErrorMessages(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 528 | if (mWebViewController.shouldShowErrorConsole()) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 529 | mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 530 | } |
| 531 | } |
| 532 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 533 | // Cancel the auto-login process. |
| 534 | if (mDeviceAccountLogin != null) { |
| 535 | mDeviceAccountLogin.cancel(); |
| 536 | mDeviceAccountLogin = null; |
| 537 | mWebViewController.hideAutoLogin(Tab.this); |
| 538 | } |
| 539 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 540 | // finally update the UI in the activity if it is in the foreground |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 541 | mWebViewController.onPageStarted(Tab.this, view, favicon); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 542 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 543 | updateBookmarkedStatus(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public void onPageFinished(WebView view, String url) { |
John Reck | 5b69184 | 2010-11-29 11:21:13 -0800 | [diff] [blame] | 548 | if (!isPrivateBrowsingEnabled()) { |
| 549 | LogTag.logPageFinishedLoading( |
| 550 | url, SystemClock.uptimeMillis() - mLoadStartTime); |
| 551 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 552 | mInPageLoad = false; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 553 | // Sync state (in case of stop/timeout) |
| 554 | mCurrentState.mUrl = view.getUrl(); |
John Reck | 6c702ee | 2011-01-07 09:41:53 -0800 | [diff] [blame] | 555 | if (mCurrentState.mUrl == null) { |
| 556 | mCurrentState.mUrl = url != null ? url : ""; |
| 557 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 558 | mCurrentState.mTitle = view.getTitle(); |
| 559 | mCurrentState.mFavicon = view.getFavicon(); |
| 560 | if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) { |
| 561 | // In case we stop when loading an HTTPS page from an HTTP page |
| 562 | // but before a provisional load occurred |
| 563 | mCurrentState.mLockIcon = LockIcon.LOCK_ICON_UNSECURE; |
| 564 | } |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 565 | mWebViewController.onPageFinished(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | // return true if want to hijack the url to let another app to handle it |
| 569 | @Override |
| 570 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
Leon Scroggins III | c1f5ae2 | 2010-06-29 17:11:29 -0400 | [diff] [blame] | 571 | if (voiceSearchSourceIsGoogle()) { |
| 572 | // This method is called when the user clicks on a link. |
| 573 | // VoiceSearchMode is turned off when the user leaves the |
| 574 | // Google results page, so at this point the user must be on |
| 575 | // that page. If the user clicked a link on that page, assume |
| 576 | // that the voice search was effective, and broadcast an Intent |
| 577 | // so a receiver can take note of that fact. |
| 578 | Intent logIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT); |
| 579 | logIntent.putExtra(LoggingEvents.EXTRA_EVENT, |
| 580 | LoggingEvents.VoiceSearch.RESULT_CLICKED); |
| 581 | mActivity.sendBroadcast(logIntent); |
| 582 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 583 | if (mInForeground) { |
Michael Kolb | 18eb377 | 2010-12-10 14:29:51 -0800 | [diff] [blame] | 584 | return mWebViewController.shouldOverrideUrlLoading(Tab.this, |
| 585 | view, url); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 586 | } else { |
| 587 | return false; |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * Updates the lock icon. This method is called when we discover another |
| 593 | * resource to be loaded for this page (for example, javascript). While |
| 594 | * we update the icon type, we do not update the lock icon itself until |
| 595 | * we are done loading, it is slightly more secure this way. |
| 596 | */ |
| 597 | @Override |
| 598 | public void onLoadResource(WebView view, String url) { |
| 599 | if (url != null && url.length() > 0) { |
| 600 | // It is only if the page claims to be secure that we may have |
| 601 | // to update the lock: |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 602 | if (mCurrentState.mLockIcon == LockIcon.LOCK_ICON_SECURE) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 603 | // If NOT a 'safe' url, change the lock to mixed content! |
| 604 | if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url) |
| 605 | || URLUtil.isAboutUrl(url))) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 606 | mCurrentState.mLockIcon = LockIcon.LOCK_ICON_MIXED; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 613 | * Show a dialog informing the user of the network error reported by |
| 614 | * WebCore if it is in the foreground. |
| 615 | */ |
| 616 | @Override |
| 617 | public void onReceivedError(WebView view, int errorCode, |
| 618 | String description, String failingUrl) { |
| 619 | if (errorCode != WebViewClient.ERROR_HOST_LOOKUP && |
| 620 | errorCode != WebViewClient.ERROR_CONNECT && |
| 621 | errorCode != WebViewClient.ERROR_BAD_URL && |
| 622 | errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME && |
| 623 | errorCode != WebViewClient.ERROR_FILE) { |
| 624 | queueError(errorCode, description); |
| 625 | } |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 626 | |
| 627 | // Don't log URLs when in private browsing mode |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 628 | if (!isPrivateBrowsingEnabled()) { |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 629 | Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl |
| 630 | + " " + description); |
| 631 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Check with the user if it is ok to resend POST data as the page they |
| 636 | * are trying to navigate to is the result of a POST. |
| 637 | */ |
| 638 | @Override |
| 639 | public void onFormResubmission(WebView view, final Message dontResend, |
| 640 | final Message resend) { |
| 641 | if (!mInForeground) { |
| 642 | dontResend.sendToTarget(); |
| 643 | return; |
| 644 | } |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 645 | if (mDontResend != null) { |
| 646 | Log.w(LOGTAG, "onFormResubmission should not be called again " |
| 647 | + "while dialog is still up"); |
| 648 | dontResend.sendToTarget(); |
| 649 | return; |
| 650 | } |
| 651 | mDontResend = dontResend; |
| 652 | mResend = resend; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 653 | new AlertDialog.Builder(mActivity).setTitle( |
| 654 | R.string.browserFrameFormResubmitLabel).setMessage( |
| 655 | R.string.browserFrameFormResubmitMessage) |
| 656 | .setPositiveButton(R.string.ok, |
| 657 | new DialogInterface.OnClickListener() { |
| 658 | public void onClick(DialogInterface dialog, |
| 659 | int which) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 660 | if (mResend != null) { |
| 661 | mResend.sendToTarget(); |
| 662 | mResend = null; |
| 663 | mDontResend = null; |
| 664 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 665 | } |
| 666 | }).setNegativeButton(R.string.cancel, |
| 667 | new DialogInterface.OnClickListener() { |
| 668 | public void onClick(DialogInterface dialog, |
| 669 | int which) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 670 | if (mDontResend != null) { |
| 671 | mDontResend.sendToTarget(); |
| 672 | mResend = null; |
| 673 | mDontResend = null; |
| 674 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 675 | } |
| 676 | }).setOnCancelListener(new OnCancelListener() { |
| 677 | public void onCancel(DialogInterface dialog) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 678 | if (mDontResend != null) { |
| 679 | mDontResend.sendToTarget(); |
| 680 | mResend = null; |
| 681 | mDontResend = null; |
| 682 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 683 | } |
| 684 | }).show(); |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Insert the url into the visited history database. |
| 689 | * @param url The url to be inserted. |
| 690 | * @param isReload True if this url is being reloaded. |
| 691 | * FIXME: Not sure what to do when reloading the page. |
| 692 | */ |
| 693 | @Override |
| 694 | public void doUpdateVisitedHistory(WebView view, String url, |
| 695 | boolean isReload) { |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 696 | mWebViewController.doUpdateVisitedHistory(Tab.this, isReload); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
| 700 | * Displays SSL error(s) dialog to the user. |
| 701 | */ |
| 702 | @Override |
| 703 | public void onReceivedSslError(final WebView view, |
| 704 | final SslErrorHandler handler, final SslError error) { |
| 705 | if (!mInForeground) { |
| 706 | handler.cancel(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 707 | setLockIconType(LockIcon.LOCK_ICON_UNSECURE); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 708 | return; |
| 709 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 710 | if (mSettings.showSecurityWarnings()) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 711 | final LayoutInflater factory = |
| 712 | LayoutInflater.from(mActivity); |
| 713 | final View warningsView = |
| 714 | factory.inflate(R.layout.ssl_warnings, null); |
| 715 | final LinearLayout placeholder = |
| 716 | (LinearLayout)warningsView.findViewById(R.id.placeholder); |
| 717 | |
| 718 | if (error.hasError(SslError.SSL_UNTRUSTED)) { |
| 719 | LinearLayout ll = (LinearLayout)factory |
| 720 | .inflate(R.layout.ssl_warning, null); |
| 721 | ((TextView)ll.findViewById(R.id.warning)) |
| 722 | .setText(R.string.ssl_untrusted); |
| 723 | placeholder.addView(ll); |
| 724 | } |
| 725 | |
| 726 | if (error.hasError(SslError.SSL_IDMISMATCH)) { |
| 727 | LinearLayout ll = (LinearLayout)factory |
| 728 | .inflate(R.layout.ssl_warning, null); |
| 729 | ((TextView)ll.findViewById(R.id.warning)) |
| 730 | .setText(R.string.ssl_mismatch); |
| 731 | placeholder.addView(ll); |
| 732 | } |
| 733 | |
| 734 | if (error.hasError(SslError.SSL_EXPIRED)) { |
| 735 | LinearLayout ll = (LinearLayout)factory |
| 736 | .inflate(R.layout.ssl_warning, null); |
| 737 | ((TextView)ll.findViewById(R.id.warning)) |
| 738 | .setText(R.string.ssl_expired); |
| 739 | placeholder.addView(ll); |
| 740 | } |
| 741 | |
| 742 | if (error.hasError(SslError.SSL_NOTYETVALID)) { |
| 743 | LinearLayout ll = (LinearLayout)factory |
| 744 | .inflate(R.layout.ssl_warning, null); |
| 745 | ((TextView)ll.findViewById(R.id.warning)) |
| 746 | .setText(R.string.ssl_not_yet_valid); |
| 747 | placeholder.addView(ll); |
| 748 | } |
| 749 | |
| 750 | new AlertDialog.Builder(mActivity).setTitle( |
| 751 | R.string.security_warning).setIcon( |
| 752 | android.R.drawable.ic_dialog_alert).setView( |
| 753 | warningsView).setPositiveButton(R.string.ssl_continue, |
| 754 | new DialogInterface.OnClickListener() { |
| 755 | public void onClick(DialogInterface dialog, |
| 756 | int whichButton) { |
| 757 | handler.proceed(); |
| 758 | } |
| 759 | }).setNeutralButton(R.string.view_certificate, |
| 760 | new DialogInterface.OnClickListener() { |
| 761 | public void onClick(DialogInterface dialog, |
| 762 | int whichButton) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 763 | mWebViewController.showSslCertificateOnError(view, |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 764 | handler, error); |
| 765 | } |
Ben Murdoch | a49b829 | 2010-11-16 11:56:04 +0000 | [diff] [blame] | 766 | }).setNegativeButton(R.string.ssl_go_back, |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 767 | new DialogInterface.OnClickListener() { |
| 768 | public void onClick(DialogInterface dialog, |
| 769 | int whichButton) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 770 | dialog.cancel(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 771 | } |
| 772 | }).setOnCancelListener( |
| 773 | new DialogInterface.OnCancelListener() { |
| 774 | public void onCancel(DialogInterface dialog) { |
| 775 | handler.cancel(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 776 | setLockIconType(LockIcon.LOCK_ICON_UNSECURE); |
| 777 | mWebViewController.onUserCanceledSsl(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 778 | } |
| 779 | }).show(); |
| 780 | } else { |
| 781 | handler.proceed(); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * Handles an HTTP authentication request. |
| 787 | * |
| 788 | * @param handler The authentication handler |
| 789 | * @param host The host |
| 790 | * @param realm The realm |
| 791 | */ |
| 792 | @Override |
| 793 | public void onReceivedHttpAuthRequest(WebView view, |
| 794 | final HttpAuthHandler handler, final String host, |
| 795 | final String realm) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 796 | mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Override |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 800 | public WebResourceResponse shouldInterceptRequest(WebView view, |
| 801 | String url) { |
| 802 | WebResourceResponse res = HomeProvider.shouldInterceptRequest( |
| 803 | mActivity, url); |
| 804 | return res; |
| 805 | } |
| 806 | |
| 807 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 808 | public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { |
| 809 | if (!mInForeground) { |
| 810 | return false; |
| 811 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 812 | return mWebViewController.shouldOverrideKeyEvent(event); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | @Override |
| 816 | public void onUnhandledKeyEvent(WebView view, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 817 | if (!mInForeground) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 818 | return; |
| 819 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 820 | mWebViewController.onUnhandledKeyEvent(event); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 821 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 822 | |
| 823 | @Override |
| 824 | public void onReceivedLoginRequest(WebView view, String realm, |
| 825 | String account, String args) { |
| 826 | new DeviceAccountLogin(mActivity, view, Tab.this, mWebViewController) |
| 827 | .handleLogin(realm, account, args); |
| 828 | } |
| 829 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 830 | }; |
| 831 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 832 | // Called by DeviceAccountLogin when the Tab needs to have the auto-login UI |
| 833 | // displayed. |
| 834 | void setDeviceAccountLogin(DeviceAccountLogin login) { |
| 835 | mDeviceAccountLogin = login; |
| 836 | } |
| 837 | |
| 838 | // Returns non-null if the title bar should display the auto-login UI. |
| 839 | DeviceAccountLogin getDeviceAccountLogin() { |
| 840 | return mDeviceAccountLogin; |
| 841 | } |
| 842 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 843 | // ------------------------------------------------------------------------- |
| 844 | // WebChromeClient implementation for the main WebView |
| 845 | // ------------------------------------------------------------------------- |
| 846 | |
| 847 | private final WebChromeClient mWebChromeClient = new WebChromeClient() { |
| 848 | // Helper method to create a new tab or sub window. |
| 849 | private void createWindow(final boolean dialog, final Message msg) { |
| 850 | WebView.WebViewTransport transport = |
| 851 | (WebView.WebViewTransport) msg.obj; |
| 852 | if (dialog) { |
| 853 | createSubWindow(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 854 | mWebViewController.attachSubWindow(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 855 | transport.setWebView(mSubView); |
| 856 | } else { |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 857 | final Tab newTab = mWebViewController.openTab(null, |
| 858 | Tab.this.isPrivateBrowsingEnabled(), |
| 859 | true, true); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 860 | if (newTab != Tab.this) { |
| 861 | Tab.this.addChildTab(newTab); |
| 862 | } |
| 863 | transport.setWebView(newTab.getWebView()); |
| 864 | } |
| 865 | msg.sendToTarget(); |
| 866 | } |
| 867 | |
| 868 | @Override |
| 869 | public boolean onCreateWindow(WebView view, final boolean dialog, |
| 870 | final boolean userGesture, final Message resultMsg) { |
| 871 | // only allow new window or sub window for the foreground case |
| 872 | if (!mInForeground) { |
| 873 | return false; |
| 874 | } |
| 875 | // Short-circuit if we can't create any more tabs or sub windows. |
| 876 | if (dialog && mSubView != null) { |
| 877 | new AlertDialog.Builder(mActivity) |
| 878 | .setTitle(R.string.too_many_subwindows_dialog_title) |
| 879 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 880 | .setMessage(R.string.too_many_subwindows_dialog_message) |
| 881 | .setPositiveButton(R.string.ok, null) |
| 882 | .show(); |
| 883 | return false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 884 | } else if (!mWebViewController.getTabControl().canCreateNewTab()) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 885 | new AlertDialog.Builder(mActivity) |
| 886 | .setTitle(R.string.too_many_windows_dialog_title) |
| 887 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 888 | .setMessage(R.string.too_many_windows_dialog_message) |
| 889 | .setPositiveButton(R.string.ok, null) |
| 890 | .show(); |
| 891 | return false; |
| 892 | } |
| 893 | |
| 894 | // Short-circuit if this was a user gesture. |
| 895 | if (userGesture) { |
| 896 | createWindow(dialog, resultMsg); |
| 897 | return true; |
| 898 | } |
| 899 | |
| 900 | // Allow the popup and create the appropriate window. |
| 901 | final AlertDialog.OnClickListener allowListener = |
| 902 | new AlertDialog.OnClickListener() { |
| 903 | public void onClick(DialogInterface d, |
| 904 | int which) { |
| 905 | createWindow(dialog, resultMsg); |
| 906 | } |
| 907 | }; |
| 908 | |
| 909 | // Block the popup by returning a null WebView. |
| 910 | final AlertDialog.OnClickListener blockListener = |
| 911 | new AlertDialog.OnClickListener() { |
| 912 | public void onClick(DialogInterface d, int which) { |
| 913 | resultMsg.sendToTarget(); |
| 914 | } |
| 915 | }; |
| 916 | |
| 917 | // Build a confirmation dialog to display to the user. |
| 918 | final AlertDialog d = |
| 919 | new AlertDialog.Builder(mActivity) |
| 920 | .setTitle(R.string.attention) |
| 921 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 922 | .setMessage(R.string.popup_window_attempt) |
| 923 | .setPositiveButton(R.string.allow, allowListener) |
| 924 | .setNegativeButton(R.string.block, blockListener) |
| 925 | .setCancelable(false) |
| 926 | .create(); |
| 927 | |
| 928 | // Show the confirmation dialog. |
| 929 | d.show(); |
| 930 | return true; |
| 931 | } |
| 932 | |
| 933 | @Override |
Patrick Scott | eb5061b | 2009-11-18 15:00:30 -0500 | [diff] [blame] | 934 | public void onRequestFocus(WebView view) { |
| 935 | if (!mInForeground) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 936 | mWebViewController.switchToTab(Tab.this); |
Patrick Scott | eb5061b | 2009-11-18 15:00:30 -0500 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | |
| 940 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 941 | public void onCloseWindow(WebView window) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 942 | if (mParent != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 943 | // JavaScript can only close popup window. |
| 944 | if (mInForeground) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 945 | mWebViewController.switchToTab(mParent); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 946 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 947 | mWebViewController.closeTab(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public void onProgressChanged(WebView view, int newProgress) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 953 | mPageLoadProgress = newProgress; |
| 954 | mWebViewController.onProgressChanged(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | @Override |
Leon Scroggins | 21d9b90 | 2010-03-11 09:33:11 -0500 | [diff] [blame] | 958 | public void onReceivedTitle(WebView view, final String title) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 959 | mCurrentState.mTitle = title; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 960 | mWebViewController.onReceivedTitle(Tab.this, title); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | @Override |
| 964 | public void onReceivedIcon(WebView view, Bitmap icon) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 965 | mCurrentState.mFavicon = icon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 966 | mWebViewController.onFavicon(Tab.this, view, icon); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | @Override |
| 970 | public void onReceivedTouchIconUrl(WebView view, String url, |
| 971 | boolean precomposed) { |
| 972 | final ContentResolver cr = mActivity.getContentResolver(); |
Leon Scroggins | c8393d9 | 2010-04-23 14:58:16 -0400 | [diff] [blame] | 973 | // Let precomposed icons take precedence over non-composed |
| 974 | // icons. |
| 975 | if (precomposed && mTouchIconLoader != null) { |
| 976 | mTouchIconLoader.cancel(false); |
| 977 | mTouchIconLoader = null; |
| 978 | } |
| 979 | // Have only one async task at a time. |
| 980 | if (mTouchIconLoader == null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 981 | mTouchIconLoader = new DownloadTouchIcon(Tab.this, |
| 982 | mActivity, cr, view); |
Leon Scroggins | c8393d9 | 2010-04-23 14:58:16 -0400 | [diff] [blame] | 983 | mTouchIconLoader.execute(url); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | |
| 987 | @Override |
| 988 | public void onShowCustomView(View view, |
| 989 | WebChromeClient.CustomViewCallback callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 990 | if (mInForeground) mWebViewController.showCustomView(Tab.this, view, |
| 991 | callback); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | @Override |
| 995 | public void onHideCustomView() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 996 | if (mInForeground) mWebViewController.hideCustomView(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * The origin has exceeded its database quota. |
| 1001 | * @param url the URL that exceeded the quota |
| 1002 | * @param databaseIdentifier the identifier of the database on which the |
| 1003 | * transaction that caused the quota overflow was run |
| 1004 | * @param currentQuota the current quota for the origin. |
| 1005 | * @param estimatedSize the estimated size of the database. |
| 1006 | * @param totalUsedQuota is the sum of all origins' quota. |
| 1007 | * @param quotaUpdater The callback to run when a decision to allow or |
| 1008 | * deny quota has been made. Don't forget to call this! |
| 1009 | */ |
| 1010 | @Override |
| 1011 | public void onExceededDatabaseQuota(String url, |
| 1012 | String databaseIdentifier, long currentQuota, long estimatedSize, |
| 1013 | long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1014 | mSettings.getWebStorageSizeManager() |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1015 | .onExceededDatabaseQuota(url, databaseIdentifier, |
| 1016 | currentQuota, estimatedSize, totalUsedQuota, |
| 1017 | quotaUpdater); |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * The Application Cache has exceeded its max size. |
| 1022 | * @param spaceNeeded is the amount of disk space that would be needed |
| 1023 | * in order for the last appcache operation to succeed. |
| 1024 | * @param totalUsedQuota is the sum of all origins' quota. |
| 1025 | * @param quotaUpdater A callback to inform the WebCore thread that a |
| 1026 | * new app cache size is available. This callback must always |
| 1027 | * be executed at some point to ensure that the sleeping |
| 1028 | * WebCore thread is woken up. |
| 1029 | */ |
| 1030 | @Override |
| 1031 | public void onReachedMaxAppCacheSize(long spaceNeeded, |
| 1032 | long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1033 | mSettings.getWebStorageSizeManager() |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1034 | .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota, |
| 1035 | quotaUpdater); |
| 1036 | } |
| 1037 | |
| 1038 | /** |
| 1039 | * Instructs the browser to show a prompt to ask the user to set the |
| 1040 | * Geolocation permission state for the specified origin. |
| 1041 | * @param origin The origin for which Geolocation permissions are |
| 1042 | * requested. |
| 1043 | * @param callback The callback to call once the user has set the |
| 1044 | * Geolocation permission state. |
| 1045 | */ |
| 1046 | @Override |
| 1047 | public void onGeolocationPermissionsShowPrompt(String origin, |
| 1048 | GeolocationPermissions.Callback callback) { |
| 1049 | if (mInForeground) { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1050 | getGeolocationPermissionsPrompt().show(origin, callback); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | /** |
| 1055 | * Instructs the browser to hide the Geolocation permissions prompt. |
| 1056 | */ |
| 1057 | @Override |
| 1058 | public void onGeolocationPermissionsHidePrompt() { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1059 | if (mInForeground && mGeolocationPermissionsPrompt != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1060 | mGeolocationPermissionsPrompt.hide(); |
| 1061 | } |
| 1062 | } |
| 1063 | |
Ben Murdoch | 65acc35 | 2009-11-19 18:16:04 +0000 | [diff] [blame] | 1064 | /* Adds a JavaScript error message to the system log and if the JS |
| 1065 | * console is enabled in the about:debug options, to that console |
| 1066 | * also. |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1067 | * @param consoleMessage the message object. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1068 | */ |
| 1069 | @Override |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1070 | public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1071 | if (mInForeground) { |
| 1072 | // call getErrorConsole(true) so it will create one if needed |
| 1073 | ErrorConsoleView errorConsole = getErrorConsole(true); |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1074 | errorConsole.addErrorMessage(consoleMessage); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1075 | if (mWebViewController.shouldShowErrorConsole() |
| 1076 | && errorConsole.getShowState() != |
| 1077 | ErrorConsoleView.SHOW_MAXIMIZED) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1078 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 1079 | } |
| 1080 | } |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1081 | |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 1082 | // Don't log console messages in private browsing mode |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1083 | if (isPrivateBrowsingEnabled()) return true; |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 1084 | |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1085 | String message = "Console: " + consoleMessage.message() + " " |
| 1086 | + consoleMessage.sourceId() + ":" |
| 1087 | + consoleMessage.lineNumber(); |
| 1088 | |
| 1089 | switch (consoleMessage.messageLevel()) { |
| 1090 | case TIP: |
| 1091 | Log.v(CONSOLE_LOGTAG, message); |
| 1092 | break; |
| 1093 | case LOG: |
| 1094 | Log.i(CONSOLE_LOGTAG, message); |
| 1095 | break; |
| 1096 | case WARNING: |
| 1097 | Log.w(CONSOLE_LOGTAG, message); |
| 1098 | break; |
| 1099 | case ERROR: |
| 1100 | Log.e(CONSOLE_LOGTAG, message); |
| 1101 | break; |
| 1102 | case DEBUG: |
| 1103 | Log.d(CONSOLE_LOGTAG, message); |
| 1104 | break; |
| 1105 | } |
| 1106 | |
| 1107 | return true; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * Ask the browser for an icon to represent a <video> element. |
| 1112 | * This icon will be used if the Web page did not specify a poster attribute. |
| 1113 | * @return Bitmap The icon or null if no such icon is available. |
| 1114 | */ |
| 1115 | @Override |
| 1116 | public Bitmap getDefaultVideoPoster() { |
| 1117 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1118 | return mWebViewController.getDefaultVideoPoster(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1119 | } |
| 1120 | return null; |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Ask the host application for a custom progress view to show while |
| 1125 | * a <video> is loading. |
| 1126 | * @return View The progress view. |
| 1127 | */ |
| 1128 | @Override |
| 1129 | public View getVideoLoadingProgressView() { |
| 1130 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1131 | return mWebViewController.getVideoLoadingProgressView(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1132 | } |
| 1133 | return null; |
| 1134 | } |
| 1135 | |
| 1136 | @Override |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 1137 | public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1138 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1139 | mWebViewController.openFileChooser(uploadMsg, acceptType); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1140 | } else { |
| 1141 | uploadMsg.onReceiveValue(null); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Deliver a list of already-visited URLs |
| 1147 | */ |
| 1148 | @Override |
| 1149 | public void getVisitedHistory(final ValueCallback<String[]> callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1150 | mWebViewController.getVisitedHistory(callback); |
| 1151 | } |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 1152 | |
| 1153 | @Override |
| 1154 | public void setupAutoFill(Message message) { |
| 1155 | // Prompt the user to set up their profile. |
| 1156 | final Message msg = message; |
| 1157 | AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 1158 | LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService( |
| 1159 | Context.LAYOUT_INFLATER_SERVICE); |
| 1160 | final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null); |
| 1161 | |
| 1162 | builder.setView(layout) |
| 1163 | .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 1164 | @Override |
| 1165 | public void onClick(DialogInterface dialog, int id) { |
| 1166 | CheckBox disableAutoFill = (CheckBox) layout.findViewById( |
| 1167 | R.id.setup_autofill_dialog_disable_autofill); |
| 1168 | |
| 1169 | if (disableAutoFill.isChecked()) { |
| 1170 | // Disable autofill and show a toast with how to turn it on again. |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1171 | mSettings.setAutofillEnabled(false); |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 1172 | Toast.makeText(mActivity, |
| 1173 | R.string.autofill_setup_dialog_negative_toast, |
| 1174 | Toast.LENGTH_LONG).show(); |
| 1175 | } else { |
| 1176 | // Take user to the AutoFill profile editor. When they return, |
| 1177 | // we will send the message that we pass here which will trigger |
| 1178 | // the form to get filled out with their new profile. |
| 1179 | mWebViewController.setupAutoFill(msg); |
| 1180 | } |
| 1181 | } |
| 1182 | }) |
| 1183 | .setNegativeButton(R.string.cancel, null) |
| 1184 | .show(); |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 1185 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1186 | }; |
| 1187 | |
| 1188 | // ------------------------------------------------------------------------- |
| 1189 | // WebViewClient implementation for the sub window |
| 1190 | // ------------------------------------------------------------------------- |
| 1191 | |
| 1192 | // Subclass of WebViewClient used in subwindows to notify the main |
| 1193 | // WebViewClient of certain WebView activities. |
| 1194 | private static class SubWindowClient extends WebViewClient { |
| 1195 | // The main WebViewClient. |
| 1196 | private final WebViewClient mClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1197 | private final WebViewController mController; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1198 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1199 | SubWindowClient(WebViewClient client, WebViewController controller) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1200 | mClient = client; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1201 | mController = controller; |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 1202 | } |
| 1203 | @Override |
| 1204 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 1205 | // Unlike the others, do not call mClient's version, which would |
| 1206 | // change the progress bar. However, we do want to remove the |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1207 | // find or select dialog. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1208 | mController.endActionMode(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1209 | } |
| 1210 | @Override |
| 1211 | public void doUpdateVisitedHistory(WebView view, String url, |
| 1212 | boolean isReload) { |
| 1213 | mClient.doUpdateVisitedHistory(view, url, isReload); |
| 1214 | } |
| 1215 | @Override |
| 1216 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
| 1217 | return mClient.shouldOverrideUrlLoading(view, url); |
| 1218 | } |
| 1219 | @Override |
| 1220 | public void onReceivedSslError(WebView view, SslErrorHandler handler, |
| 1221 | SslError error) { |
| 1222 | mClient.onReceivedSslError(view, handler, error); |
| 1223 | } |
| 1224 | @Override |
| 1225 | public void onReceivedHttpAuthRequest(WebView view, |
| 1226 | HttpAuthHandler handler, String host, String realm) { |
| 1227 | mClient.onReceivedHttpAuthRequest(view, handler, host, realm); |
| 1228 | } |
| 1229 | @Override |
| 1230 | public void onFormResubmission(WebView view, Message dontResend, |
| 1231 | Message resend) { |
| 1232 | mClient.onFormResubmission(view, dontResend, resend); |
| 1233 | } |
| 1234 | @Override |
| 1235 | public void onReceivedError(WebView view, int errorCode, |
| 1236 | String description, String failingUrl) { |
| 1237 | mClient.onReceivedError(view, errorCode, description, failingUrl); |
| 1238 | } |
| 1239 | @Override |
| 1240 | public boolean shouldOverrideKeyEvent(WebView view, |
| 1241 | android.view.KeyEvent event) { |
| 1242 | return mClient.shouldOverrideKeyEvent(view, event); |
| 1243 | } |
| 1244 | @Override |
| 1245 | public void onUnhandledKeyEvent(WebView view, |
| 1246 | android.view.KeyEvent event) { |
| 1247 | mClient.onUnhandledKeyEvent(view, event); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | // ------------------------------------------------------------------------- |
| 1252 | // WebChromeClient implementation for the sub window |
| 1253 | // ------------------------------------------------------------------------- |
| 1254 | |
| 1255 | private class SubWindowChromeClient extends WebChromeClient { |
| 1256 | // The main WebChromeClient. |
| 1257 | private final WebChromeClient mClient; |
| 1258 | |
| 1259 | SubWindowChromeClient(WebChromeClient client) { |
| 1260 | mClient = client; |
| 1261 | } |
| 1262 | @Override |
| 1263 | public void onProgressChanged(WebView view, int newProgress) { |
| 1264 | mClient.onProgressChanged(view, newProgress); |
| 1265 | } |
| 1266 | @Override |
| 1267 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 1268 | boolean userGesture, android.os.Message resultMsg) { |
| 1269 | return mClient.onCreateWindow(view, dialog, userGesture, resultMsg); |
| 1270 | } |
| 1271 | @Override |
| 1272 | public void onCloseWindow(WebView window) { |
| 1273 | if (window != mSubView) { |
| 1274 | Log.e(LOGTAG, "Can't close the window"); |
| 1275 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1276 | mWebViewController.dismissSubWindow(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | // ------------------------------------------------------------------------- |
| 1281 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1282 | // TODO temporarily use activity here |
| 1283 | // remove later |
| 1284 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1285 | // Construct a new tab |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 1286 | Tab(WebViewController wvcontroller, WebView w) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1287 | mWebViewController = wvcontroller; |
| 1288 | mActivity = mWebViewController.getActivity(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1289 | mSettings = BrowserSettings.getInstance(); |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1290 | mDataController = DataController.getInstance(mActivity); |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 1291 | mCurrentState = new PageState(mActivity, w != null |
| 1292 | ? w.isPrivateBrowsingEnabled() : false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1293 | mInPageLoad = false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1294 | mInForeground = false; |
| 1295 | |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1296 | mDownloadListener = new DownloadListener() { |
| 1297 | public void onDownloadStart(String url, String userAgent, |
| 1298 | String contentDisposition, String mimetype, |
| 1299 | long contentLength) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1300 | mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition, |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1301 | mimetype, contentLength); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1302 | } |
| 1303 | }; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 1304 | mWebBackForwardListClient = new WebBackForwardListClient() { |
| 1305 | @Override |
| 1306 | public void onNewHistoryItem(WebHistoryItem item) { |
| 1307 | if (isInVoiceSearchMode()) { |
| 1308 | item.setCustomData(mVoiceSearchData.mVoiceSearchIntent); |
| 1309 | } |
| 1310 | } |
| 1311 | @Override |
| 1312 | public void onIndexChanged(WebHistoryItem item, int index) { |
| 1313 | Object data = item.getCustomData(); |
| 1314 | if (data != null && data instanceof Intent) { |
| 1315 | activateVoiceSearchMode((Intent) data); |
| 1316 | } |
| 1317 | } |
| 1318 | }; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1319 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1320 | setWebView(w); |
| 1321 | } |
| 1322 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1323 | public void setId(long id) { |
| 1324 | mId = id; |
| 1325 | } |
| 1326 | |
| 1327 | public long getId() { |
| 1328 | return mId; |
| 1329 | } |
| 1330 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1331 | /** |
| 1332 | * Sets the WebView for this tab, correctly removing the old WebView from |
| 1333 | * the container view. |
| 1334 | */ |
| 1335 | void setWebView(WebView w) { |
| 1336 | if (mMainView == w) { |
| 1337 | return; |
| 1338 | } |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1339 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1340 | // If the WebView is changing, the page will be reloaded, so any ongoing |
| 1341 | // Geolocation permission requests are void. |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1342 | if (mGeolocationPermissionsPrompt != null) { |
| 1343 | mGeolocationPermissionsPrompt.hide(); |
| 1344 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1345 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1346 | mWebViewController.onSetWebView(this, w); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1347 | |
| 1348 | // set the new one |
| 1349 | mMainView = w; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1350 | // attach the WebViewClient, WebChromeClient and DownloadListener |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1351 | if (mMainView != null) { |
| 1352 | mMainView.setWebViewClient(mWebViewClient); |
| 1353 | mMainView.setWebChromeClient(mWebChromeClient); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1354 | // Attach DownloadManager so that downloads can start in an active |
| 1355 | // or a non-active window. This can happen when going to a site that |
| 1356 | // does a redirect after a period of time. The user could have |
| 1357 | // switched to another tab while waiting for the download to start. |
| 1358 | mMainView.setDownloadListener(mDownloadListener); |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 1359 | mMainView.setWebBackForwardListClient(mWebBackForwardListClient); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | /** |
| 1364 | * Destroy the tab's main WebView and subWindow if any |
| 1365 | */ |
| 1366 | void destroy() { |
| 1367 | if (mMainView != null) { |
| 1368 | dismissSubWindow(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1369 | // save the WebView to call destroy() after detach it from the tab |
| 1370 | WebView webView = mMainView; |
| 1371 | setWebView(null); |
| 1372 | webView.destroy(); |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Remove the tab from the parent |
| 1378 | */ |
| 1379 | void removeFromTree() { |
| 1380 | // detach the children |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1381 | if (mChildren != null) { |
| 1382 | for(Tab t : mChildren) { |
| 1383 | t.setParent(null); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | // remove itself from the parent list |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1387 | if (mParent != null) { |
| 1388 | mParent.mChildren.remove(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * Create a new subwindow unless a subwindow already exists. |
| 1394 | * @return True if a new subwindow was created. False if one already exists. |
| 1395 | */ |
| 1396 | boolean createSubWindow() { |
| 1397 | if (mSubView == null) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1398 | mWebViewController.createSubWindow(this); |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 1399 | mSubView.setWebViewClient(new SubWindowClient(mWebViewClient, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1400 | mWebViewController)); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1401 | mSubView.setWebChromeClient(new SubWindowChromeClient( |
| 1402 | mWebChromeClient)); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1403 | // Set a different DownloadListener for the mSubView, since it will |
| 1404 | // just need to dismiss the mSubView, rather than close the Tab |
| 1405 | mSubView.setDownloadListener(new DownloadListener() { |
| 1406 | public void onDownloadStart(String url, String userAgent, |
| 1407 | String contentDisposition, String mimetype, |
| 1408 | long contentLength) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1409 | mWebViewController.onDownloadStart(Tab.this, url, userAgent, |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1410 | contentDisposition, mimetype, contentLength); |
| 1411 | if (mSubView.copyBackForwardList().getSize() == 0) { |
| 1412 | // This subwindow was opened for the sole purpose of |
| 1413 | // downloading a file. Remove it. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1414 | mWebViewController.dismissSubWindow(Tab.this); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | }); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1418 | mSubView.setOnCreateContextMenuListener(mActivity); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1419 | return true; |
| 1420 | } |
| 1421 | return false; |
| 1422 | } |
| 1423 | |
| 1424 | /** |
| 1425 | * Dismiss the subWindow for the tab. |
| 1426 | */ |
| 1427 | void dismissSubWindow() { |
| 1428 | if (mSubView != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1429 | mWebViewController.endActionMode(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1430 | mSubView.destroy(); |
| 1431 | mSubView = null; |
| 1432 | mSubViewContainer = null; |
| 1433 | } |
| 1434 | } |
| 1435 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1436 | |
| 1437 | /** |
| 1438 | * Set the parent tab of this tab. |
| 1439 | */ |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1440 | void setParent(Tab parent) { |
| 1441 | mParent = parent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1442 | // This tab may have been freed due to low memory. If that is the case, |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1443 | // the parent tab id is already saved. If we are changing that id |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1444 | // (most likely due to removing the parent tab) we must update the |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1445 | // parent tab id in the saved Bundle. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1446 | if (mSavedState != null) { |
| 1447 | if (parent == null) { |
| 1448 | mSavedState.remove(PARENTTAB); |
| 1449 | } else { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1450 | mSavedState.putLong(PARENTTAB, parent.getId()); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame^] | 1453 | |
| 1454 | // Sync the WebView useragent with the parent |
| 1455 | if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView()) |
| 1456 | != mSettings.hasDesktopUseragent(getWebView())) { |
| 1457 | mSettings.toggleDesktopUseragent(getWebView()); |
| 1458 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /** |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1462 | * If this Tab was created through another Tab, then this method returns |
| 1463 | * that Tab. |
| 1464 | * @return the Tab parent or null |
| 1465 | */ |
| 1466 | public Tab getParent() { |
| 1467 | return mParent; |
| 1468 | } |
| 1469 | |
| 1470 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1471 | * When a Tab is created through the content of another Tab, then we |
| 1472 | * associate the Tabs. |
| 1473 | * @param child the Tab that was created from this Tab |
| 1474 | */ |
| 1475 | void addChildTab(Tab child) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1476 | if (mChildren == null) { |
| 1477 | mChildren = new Vector<Tab>(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1478 | } |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1479 | mChildren.add(child); |
| 1480 | child.setParent(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1483 | Vector<Tab> getChildren() { |
| 1484 | return mChildren; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | void resume() { |
| 1488 | if (mMainView != null) { |
| 1489 | mMainView.onResume(); |
| 1490 | if (mSubView != null) { |
| 1491 | mSubView.onResume(); |
| 1492 | } |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | void pause() { |
| 1497 | if (mMainView != null) { |
| 1498 | mMainView.onPause(); |
| 1499 | if (mSubView != null) { |
| 1500 | mSubView.onPause(); |
| 1501 | } |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | void putInForeground() { |
| 1506 | mInForeground = true; |
| 1507 | resume(); |
| 1508 | mMainView.setOnCreateContextMenuListener(mActivity); |
| 1509 | if (mSubView != null) { |
| 1510 | mSubView.setOnCreateContextMenuListener(mActivity); |
| 1511 | } |
| 1512 | // Show the pending error dialog if the queue is not empty |
| 1513 | if (mQueuedErrors != null && mQueuedErrors.size() > 0) { |
| 1514 | showError(mQueuedErrors.getFirst()); |
| 1515 | } |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 1516 | mWebViewController.bookmarkedStatusHasChanged(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | void putInBackground() { |
| 1520 | mInForeground = false; |
| 1521 | pause(); |
| 1522 | mMainView.setOnCreateContextMenuListener(null); |
| 1523 | if (mSubView != null) { |
| 1524 | mSubView.setOnCreateContextMenuListener(null); |
| 1525 | } |
| 1526 | } |
| 1527 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1528 | boolean inForeground() { |
| 1529 | return mInForeground; |
| 1530 | } |
| 1531 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1532 | /** |
| 1533 | * Return the top window of this tab; either the subwindow if it is not |
| 1534 | * null or the main window. |
| 1535 | * @return The top window of this tab. |
| 1536 | */ |
| 1537 | WebView getTopWindow() { |
| 1538 | if (mSubView != null) { |
| 1539 | return mSubView; |
| 1540 | } |
| 1541 | return mMainView; |
| 1542 | } |
| 1543 | |
| 1544 | /** |
| 1545 | * Return the main window of this tab. Note: if a tab is freed in the |
| 1546 | * background, this can return null. It is only guaranteed to be |
| 1547 | * non-null for the current tab. |
| 1548 | * @return The main WebView of this tab. |
| 1549 | */ |
| 1550 | WebView getWebView() { |
| 1551 | return mMainView; |
| 1552 | } |
| 1553 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1554 | void setViewContainer(View container) { |
| 1555 | mContainer = container; |
| 1556 | } |
| 1557 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1558 | View getViewContainer() { |
| 1559 | return mContainer; |
| 1560 | } |
| 1561 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1562 | /** |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1563 | * Return whether private browsing is enabled for the main window of |
| 1564 | * this tab. |
| 1565 | * @return True if private browsing is enabled. |
| 1566 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1567 | boolean isPrivateBrowsingEnabled() { |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1568 | WebView webView = getWebView(); |
| 1569 | if (webView == null) { |
| 1570 | return false; |
| 1571 | } |
| 1572 | return webView.isPrivateBrowsingEnabled(); |
| 1573 | } |
| 1574 | |
| 1575 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1576 | * Return the subwindow of this tab or null if there is no subwindow. |
| 1577 | * @return The subwindow of this tab or null. |
| 1578 | */ |
| 1579 | WebView getSubWebView() { |
| 1580 | return mSubView; |
| 1581 | } |
| 1582 | |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1583 | void setSubWebView(WebView subView) { |
| 1584 | mSubView = subView; |
| 1585 | } |
| 1586 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1587 | View getSubViewContainer() { |
| 1588 | return mSubViewContainer; |
| 1589 | } |
| 1590 | |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1591 | void setSubViewContainer(View subViewContainer) { |
| 1592 | mSubViewContainer = subViewContainer; |
| 1593 | } |
| 1594 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1595 | /** |
| 1596 | * @return The geolocation permissions prompt for this tab. |
| 1597 | */ |
| 1598 | GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1599 | if (mGeolocationPermissionsPrompt == null) { |
| 1600 | ViewStub stub = (ViewStub) mContainer |
| 1601 | .findViewById(R.id.geolocation_permissions_prompt); |
| 1602 | mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub |
| 1603 | .inflate(); |
| 1604 | mGeolocationPermissionsPrompt.init(); |
| 1605 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1606 | return mGeolocationPermissionsPrompt; |
| 1607 | } |
| 1608 | |
| 1609 | /** |
| 1610 | * @return The application id string |
| 1611 | */ |
| 1612 | String getAppId() { |
| 1613 | return mAppId; |
| 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * Set the application id string |
| 1618 | * @param id |
| 1619 | */ |
| 1620 | void setAppId(String id) { |
| 1621 | mAppId = id; |
| 1622 | } |
| 1623 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1624 | String getUrl() { |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 1625 | return UrlUtils.filteredUrl(mCurrentState.mUrl); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 1628 | String getOriginalUrl() { |
| 1629 | if (mMainView == null) { |
| 1630 | return ""; |
| 1631 | } |
| 1632 | return UrlUtils.filteredUrl(mMainView.getOriginalUrl()); |
| 1633 | } |
| 1634 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1635 | /** |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1636 | * Get the title of this tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1637 | */ |
| 1638 | String getTitle() { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1639 | if (mCurrentState.mTitle == null && mInPageLoad) { |
| 1640 | return mActivity.getString(R.string.title_bar_loading); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1641 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1642 | return mCurrentState.mTitle; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /** |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1646 | * Get the favicon of this tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1647 | */ |
| 1648 | Bitmap getFavicon() { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1649 | return mCurrentState.mFavicon; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1650 | } |
| 1651 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1652 | public boolean isBookmarkedSite() { |
| 1653 | return mCurrentState.mIsBookmarkedSite; |
| 1654 | } |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1655 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1656 | /** |
| 1657 | * Return the tab's error console. Creates the console if createIfNEcessary |
| 1658 | * is true and we haven't already created the console. |
| 1659 | * @param createIfNecessary Flag to indicate if the console should be |
| 1660 | * created if it has not been already. |
| 1661 | * @return The tab's error console, or null if one has not been created and |
| 1662 | * createIfNecessary is false. |
| 1663 | */ |
| 1664 | ErrorConsoleView getErrorConsole(boolean createIfNecessary) { |
| 1665 | if (createIfNecessary && mErrorConsole == null) { |
| 1666 | mErrorConsole = new ErrorConsoleView(mActivity); |
| 1667 | mErrorConsole.setWebView(mMainView); |
| 1668 | } |
| 1669 | return mErrorConsole; |
| 1670 | } |
| 1671 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1672 | private void setLockIconType(LockIcon icon) { |
| 1673 | mCurrentState.mLockIcon = icon; |
| 1674 | mWebViewController.onUpdatedLockIcon(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * @return The tab's lock icon type. |
| 1679 | */ |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1680 | LockIcon getLockIconType() { |
| 1681 | return mCurrentState.mLockIcon; |
| 1682 | } |
| 1683 | |
| 1684 | int getLoadProgress() { |
| 1685 | if (mInPageLoad) { |
| 1686 | return mPageLoadProgress; |
| 1687 | } |
| 1688 | return 100; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | /** |
| 1692 | * @return TRUE if onPageStarted is called while onPageFinished is not |
| 1693 | * called yet. |
| 1694 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1695 | boolean inPageLoad() { |
| 1696 | return mInPageLoad; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | // force mInLoad to be false. This should only be called before closing the |
| 1700 | // tab to ensure BrowserActivity's pauseWebViewTimers() is called correctly. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1701 | void clearInPageLoad() { |
| 1702 | mInPageLoad = false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1705 | /** |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1706 | * Get the cached saved state bundle. |
| 1707 | * @return cached state bundle |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1708 | */ |
| 1709 | Bundle getSavedState() { |
| 1710 | return mSavedState; |
| 1711 | } |
| 1712 | |
| 1713 | /** |
| 1714 | * Set the saved state. |
| 1715 | */ |
| 1716 | void setSavedState(Bundle state) { |
| 1717 | mSavedState = state; |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * @return TRUE if succeed in saving the state. |
| 1722 | */ |
| 1723 | boolean saveState() { |
| 1724 | // If the WebView is null it means we ran low on memory and we already |
| 1725 | // stored the saved state in mSavedState. |
| 1726 | if (mMainView == null) { |
| 1727 | return mSavedState != null; |
| 1728 | } |
| 1729 | |
| 1730 | mSavedState = new Bundle(); |
| 1731 | final WebBackForwardList list = mMainView.saveState(mSavedState); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1732 | |
| 1733 | // Store some extra info for displaying the tab in the picker. |
| 1734 | final WebHistoryItem item = list != null ? list.getCurrentItem() : null; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1735 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1736 | mSavedState.putLong(ID, mId); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1737 | mSavedState.putString(CURRURL, mCurrentState.mUrl); |
| 1738 | mSavedState.putString(CURRTITLE, mCurrentState.mTitle); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1739 | if (mAppId != null) { |
| 1740 | mSavedState.putString(APPID, mAppId); |
| 1741 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1742 | // Remember the parent tab so the relationship can be restored. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1743 | if (mParent != null) { |
| 1744 | mSavedState.putLong(PARENTTAB, mParent.mId); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1745 | } |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 1746 | if (mScreenshot != null) { |
| 1747 | mSavedState.putParcelable(SCREENSHOT, mScreenshot); |
| 1748 | } |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame^] | 1749 | mSavedState.putBoolean(USERAGENT, |
| 1750 | mSettings.hasDesktopUseragent(getWebView())); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1751 | return true; |
| 1752 | } |
| 1753 | |
| 1754 | /* |
| 1755 | * Restore the state of the tab. |
| 1756 | */ |
| 1757 | boolean restoreState(Bundle b) { |
| 1758 | if (b == null) { |
| 1759 | return false; |
| 1760 | } |
| 1761 | // Restore the internal state even if the WebView fails to restore. |
| 1762 | // This will maintain the app id, original url and close-on-exit values. |
| 1763 | mSavedState = null; |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1764 | mId = b.getLong(ID); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1765 | mAppId = b.getString(APPID); |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 1766 | mScreenshot = b.getParcelable(SCREENSHOT); |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame^] | 1767 | if (b.getBoolean(USERAGENT) |
| 1768 | != mSettings.hasDesktopUseragent(getWebView())) { |
| 1769 | mSettings.toggleDesktopUseragent(getWebView()); |
| 1770 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1771 | |
| 1772 | final WebBackForwardList list = mMainView.restoreState(b); |
| 1773 | if (list == null) { |
| 1774 | return false; |
| 1775 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1776 | return true; |
| 1777 | } |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 1778 | |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 1779 | public void updateBookmarkedStatus() { |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1780 | mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback); |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 1781 | } |
| 1782 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1783 | private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback |
| 1784 | = new DataController.OnQueryUrlIsBookmark() { |
| 1785 | @Override |
| 1786 | public void onQueryUrlIsBookmark(String url, boolean isBookmark) { |
| 1787 | if (mCurrentState.mUrl.equals(url)) { |
| 1788 | mCurrentState.mIsBookmarkedSite = isBookmark; |
| 1789 | mWebViewController.bookmarkedStatusHasChanged(Tab.this); |
| 1790 | } |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 1791 | } |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1792 | }; |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 1793 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 1794 | public void setScreenshot(Bitmap screenshot) { |
| 1795 | mScreenshot = screenshot; |
| 1796 | } |
| 1797 | |
| 1798 | public Bitmap getScreenshot() { |
| 1799 | return mScreenshot; |
| 1800 | } |
| 1801 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1802 | } |