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 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 19 | import android.app.Activity; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 20 | import android.app.AlertDialog; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 21 | import android.app.SearchManager; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 22 | import android.content.ContentResolver; |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 23 | import android.content.ContentValues; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 25 | import android.content.DialogInterface; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 26 | import android.content.DialogInterface.OnCancelListener; |
Jeff Hamilton | 8ce956c | 2010-08-17 11:13:53 -0500 | [diff] [blame] | 27 | import android.content.Intent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 28 | import android.graphics.Bitmap; |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 29 | import android.graphics.Bitmap.CompressFormat; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 30 | import android.graphics.BitmapFactory; |
| 31 | import android.graphics.Canvas; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 32 | import android.graphics.Color; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 33 | import android.graphics.Paint; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 34 | import android.graphics.Picture; |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 35 | import android.graphics.PorterDuff; |
| 36 | import android.graphics.PorterDuffXfermode; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.net.http.SslError; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 39 | import android.os.Bundle; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 40 | import android.os.Handler; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 41 | import android.os.Message; |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 42 | import android.os.SystemClock; |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 43 | import android.security.KeyChain; |
Brian Carlstrom | aa09cd8 | 2011-06-09 16:04:40 -0700 | [diff] [blame] | 44 | import android.security.KeyChainAliasCallback; |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 45 | import android.speech.RecognizerResultsIntent; |
John Reck | 24f1826 | 2011-06-17 14:47:20 -0700 | [diff] [blame] | 46 | import android.text.TextUtils; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | import android.view.KeyEvent; |
| 49 | import android.view.LayoutInflater; |
| 50 | import android.view.View; |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 51 | import android.view.ViewStub; |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 52 | import android.webkit.ClientCertRequestHandler; |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 53 | import android.webkit.ConsoleMessage; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 54 | import android.webkit.DownloadListener; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 55 | import android.webkit.GeolocationPermissions; |
| 56 | import android.webkit.HttpAuthHandler; |
| 57 | import android.webkit.SslErrorHandler; |
| 58 | import android.webkit.URLUtil; |
| 59 | import android.webkit.ValueCallback; |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 60 | import android.webkit.WebBackForwardList; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 61 | import android.webkit.WebBackForwardListClient; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 62 | import android.webkit.WebChromeClient; |
| 63 | import android.webkit.WebHistoryItem; |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 64 | import android.webkit.WebResourceResponse; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 65 | import android.webkit.WebStorage; |
| 66 | import android.webkit.WebView; |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 67 | import android.webkit.WebViewClassic; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 68 | import android.webkit.WebView.PictureListener; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 69 | import android.webkit.WebViewClient; |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 70 | import android.widget.CheckBox; |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 71 | import android.widget.Toast; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 72 | |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 73 | import com.android.browser.TabControl.OnThumbnailUpdatedListener; |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 74 | import com.android.browser.homepages.HomeProvider; |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 75 | import com.android.browser.provider.SnapshotProvider.Snapshots; |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 76 | import com.android.common.speech.LoggingEvents; |
| 77 | |
| 78 | import java.io.ByteArrayOutputStream; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 79 | import java.nio.ByteBuffer; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 80 | import java.util.ArrayList; |
| 81 | import java.util.HashMap; |
| 82 | import java.util.Iterator; |
| 83 | import java.util.LinkedList; |
| 84 | import java.util.Map; |
| 85 | import java.util.Vector; |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 86 | import java.util.regex.Pattern; |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 87 | import java.util.zip.GZIPOutputStream; |
Michael Kolb | fe25199 | 2010-07-08 15:41:55 -0700 | [diff] [blame] | 88 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Class for maintaining Tabs with a main WebView and a subwindow. |
| 91 | */ |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 92 | class Tab implements PictureListener { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 93 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 94 | // Log Tag |
| 95 | private static final String LOGTAG = "Tab"; |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 96 | private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED; |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 97 | // Special case the logtag for messages for the Console to make it easier to |
| 98 | // filter them and match the logtag used for these messages in older versions |
| 99 | // of the browser. |
| 100 | private static final String CONSOLE_LOGTAG = "browser"; |
| 101 | |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 102 | private static final int MSG_CAPTURE = 42; |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 103 | private static final int CAPTURE_DELAY = 100; |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 104 | private static final int INITIAL_PROGRESS = 5; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 105 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 106 | private static Bitmap sDefaultFavicon; |
| 107 | |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 108 | private static Paint sAlphaPaint = new Paint(); |
| 109 | static { |
| 110 | sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); |
| 111 | sAlphaPaint.setColor(Color.TRANSPARENT); |
| 112 | } |
| 113 | |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 114 | public enum SecurityState { |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 115 | // The page's main resource does not use SSL. Note that we use this |
| 116 | // state irrespective of the SSL authentication state of sub-resources. |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 117 | SECURITY_STATE_NOT_SECURE, |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 118 | // The page's main resource uses SSL and the certificate is good. The |
| 119 | // same is true of all sub-resources. |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 120 | SECURITY_STATE_SECURE, |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 121 | // The page's main resource uses SSL and the certificate is good, but |
| 122 | // some sub-resources either do not use SSL or have problems with their |
| 123 | // certificates. |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 124 | SECURITY_STATE_MIXED, |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 125 | // The page's main resource uses SSL but there is a problem with its |
| 126 | // certificate. |
| 127 | SECURITY_STATE_BAD_CERTIFICATE, |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 128 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 129 | |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 130 | Context mContext; |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 131 | protected WebViewController mWebViewController; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 132 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 133 | // The tab ID |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 134 | private long mId = -1; |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 135 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 136 | // The Geolocation permissions prompt |
| 137 | private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt; |
| 138 | // Main WebView wrapper |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 139 | private View mContainer; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 140 | // Main WebView |
| 141 | private WebView mMainView; |
| 142 | // Subwindow container |
| 143 | private View mSubViewContainer; |
| 144 | // Subwindow WebView |
| 145 | private WebView mSubView; |
| 146 | // Saved bundle for when we are running low on memory. It contains the |
| 147 | // information needed to restore the WebView if the user goes back to the |
| 148 | // tab. |
| 149 | private Bundle mSavedState; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 150 | // Parent Tab. This is the Tab that created this Tab, or null if the Tab was |
| 151 | // created by the UI |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 152 | private Tab mParent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 153 | // Tab that constructed by this Tab. This is used when this Tab is |
| 154 | // destroyed, it clears all mParentTab values in the children. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 155 | private Vector<Tab> mChildren; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 156 | // If true, the tab is in the foreground of the current activity. |
| 157 | private boolean mInForeground; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 158 | // If true, the tab is in page loading state (after onPageStarted, |
| 159 | // before onPageFinsihed) |
| 160 | private boolean mInPageLoad; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 161 | // The last reported progress of the current page |
| 162 | private int mPageLoadProgress; |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 163 | // The time the load started, used to find load page time |
| 164 | private long mLoadStartTime; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 165 | // Application identifier used to find tabs that another application wants |
| 166 | // to reuse. |
| 167 | private String mAppId; |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 168 | // flag to indicate if tab should be closed on back |
| 169 | private boolean mCloseOnBack; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 170 | // Keep the original url around to avoid killing the old WebView if the url |
| 171 | // has not changed. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 172 | // Error console for the tab |
| 173 | private ErrorConsoleView mErrorConsole; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 174 | // The listener that gets invoked when a download is started from the |
| 175 | // mMainView |
| 176 | private final DownloadListener mDownloadListener; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 177 | // Listener used to know when we move forward or back in the history list. |
| 178 | private final WebBackForwardListClient mWebBackForwardListClient; |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 179 | private DataController mDataController; |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 180 | // State of the auto-login request. |
| 181 | private DeviceAccountLogin mDeviceAccountLogin; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 182 | |
| 183 | // AsyncTask for downloading touch icons |
| 184 | DownloadTouchIcon mTouchIconLoader; |
| 185 | |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 186 | private BrowserSettings mSettings; |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 187 | private int mCaptureWidth; |
| 188 | private int mCaptureHeight; |
| 189 | private Bitmap mCapture; |
| 190 | private Handler mHandler; |
| 191 | |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 192 | /** |
Mathew Inwood | 9ad1eac | 2011-09-15 11:29:50 +0100 | [diff] [blame] | 193 | * See {@link #clearBackStackWhenItemAdded(String)}. |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 194 | */ |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 195 | private Pattern mClearHistoryUrlPattern; |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 196 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 197 | private static synchronized Bitmap getDefaultFavicon(Context context) { |
| 198 | if (sDefaultFavicon == null) { |
| 199 | sDefaultFavicon = BitmapFactory.decodeResource( |
| 200 | context.getResources(), R.drawable.app_web_browser_sm); |
| 201 | } |
| 202 | return sDefaultFavicon; |
| 203 | } |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 204 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 205 | // All the state needed for a page |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 206 | protected static class PageState { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 207 | String mUrl; |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 208 | String mOriginalUrl; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 209 | String mTitle; |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 210 | SecurityState mSecurityState; |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 211 | // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE. |
| 212 | SslError mSslCertificateError; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 213 | Bitmap mFavicon; |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 214 | boolean mIsBookmarkedSite; |
| 215 | boolean mIncognito; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 216 | |
| 217 | PageState(Context c, boolean incognito) { |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 218 | mIncognito = incognito; |
| 219 | if (mIncognito) { |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 220 | mOriginalUrl = mUrl = "browser:incognito"; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 221 | mTitle = c.getString(R.string.new_incognito_tab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 222 | } else { |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 223 | mOriginalUrl = mUrl = ""; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 224 | mTitle = c.getString(R.string.new_tab); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 225 | } |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 226 | mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | PageState(Context c, boolean incognito, String url, Bitmap favicon) { |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 230 | mIncognito = incognito; |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 231 | mOriginalUrl = mUrl = url; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 232 | if (URLUtil.isHttpsUrl(url)) { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 233 | mSecurityState = SecurityState.SECURITY_STATE_SECURE; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 234 | } else { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 235 | mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 236 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 237 | mFavicon = favicon; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 238 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 239 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 240 | } |
| 241 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 242 | // The current/loading page's state |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 243 | protected PageState mCurrentState; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 244 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 245 | // Used for saving and restoring each Tab |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 246 | static final String ID = "ID"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 247 | static final String CURRURL = "currentUrl"; |
| 248 | static final String CURRTITLE = "currentTitle"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 249 | static final String PARENTTAB = "parentTab"; |
| 250 | static final String APPID = "appid"; |
Elliott Slaughter | 3d6df16 | 2010-08-25 13:17:44 -0700 | [diff] [blame] | 251 | static final String INCOGNITO = "privateBrowsingEnabled"; |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 252 | static final String USERAGENT = "useragent"; |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 253 | static final String CLOSEFLAG = "closeOnBack"; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 254 | |
| 255 | // ------------------------------------------------------------------------- |
| 256 | |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 257 | /** |
| 258 | * Private information regarding the latest voice search. If the Tab is not |
| 259 | * in voice search mode, this will be null. |
| 260 | */ |
| 261 | private VoiceSearchData mVoiceSearchData; |
| 262 | /** |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 263 | * Remove voice search mode from this tab. |
| 264 | */ |
| 265 | public void revertVoiceSearchMode() { |
| 266 | if (mVoiceSearchData != null) { |
| 267 | mVoiceSearchData = null; |
| 268 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 269 | mWebViewController.revertVoiceSearchMode(this); |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 273 | |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 274 | /** |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 275 | * Return whether the tab is in voice search mode. |
| 276 | */ |
| 277 | public boolean isInVoiceSearchMode() { |
| 278 | return mVoiceSearchData != null; |
| 279 | } |
| 280 | /** |
Leon Scroggins III | c1f5ae2 | 2010-06-29 17:11:29 -0400 | [diff] [blame] | 281 | * Return true if the Tab is in voice search mode and the voice search |
| 282 | * Intent came with a String identifying that Google provided the Intent. |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 283 | */ |
| 284 | public boolean voiceSearchSourceIsGoogle() { |
| 285 | return mVoiceSearchData != null && mVoiceSearchData.mSourceIsGoogle; |
| 286 | } |
| 287 | /** |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 288 | * Get the title to display for the current voice search page. If the Tab |
| 289 | * is not in voice search mode, return null. |
| 290 | */ |
| 291 | public String getVoiceDisplayTitle() { |
| 292 | if (mVoiceSearchData == null) return null; |
| 293 | return mVoiceSearchData.mLastVoiceSearchTitle; |
| 294 | } |
| 295 | /** |
| 296 | * Get the latest array of voice search results, to be passed to the |
| 297 | * BrowserProvider. If the Tab is not in voice search mode, return null. |
| 298 | */ |
| 299 | public ArrayList<String> getVoiceSearchResults() { |
| 300 | if (mVoiceSearchData == null) return null; |
| 301 | return mVoiceSearchData.mVoiceSearchResults; |
| 302 | } |
| 303 | /** |
| 304 | * Activate voice search mode. |
| 305 | * @param intent Intent which has the results to use, or an index into the |
| 306 | * results when reusing the old results. |
| 307 | */ |
| 308 | /* package */ void activateVoiceSearchMode(Intent intent) { |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 309 | int index = 0; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 310 | ArrayList<String> results = intent.getStringArrayListExtra( |
Leon Scroggins | a1cc3fd | 2010-02-01 16:14:11 -0500 | [diff] [blame] | 311 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 312 | if (results != null) { |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 313 | ArrayList<String> urls = intent.getStringArrayListExtra( |
| 314 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS); |
| 315 | ArrayList<String> htmls = intent.getStringArrayListExtra( |
| 316 | RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_HTML); |
| 317 | ArrayList<String> baseUrls = intent.getStringArrayListExtra( |
| 318 | RecognizerResultsIntent |
| 319 | .EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 320 | // This tab is now entering voice search mode for the first time, or |
| 321 | // a new voice search was done. |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 322 | int size = results.size(); |
| 323 | if (urls == null || size != urls.size()) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 324 | throw new AssertionError("improper extras passed in Intent"); |
| 325 | } |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 326 | if (htmls == null || htmls.size() != size || baseUrls == null || |
| 327 | (baseUrls.size() != size && baseUrls.size() != 1)) { |
| 328 | // If either of these arrays are empty/incorrectly sized, ignore |
| 329 | // them. |
| 330 | htmls = null; |
| 331 | baseUrls = null; |
| 332 | } |
| 333 | mVoiceSearchData = new VoiceSearchData(results, urls, htmls, |
| 334 | baseUrls); |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 335 | mVoiceSearchData.mHeaders = intent.getParcelableArrayListExtra( |
| 336 | RecognizerResultsIntent |
| 337 | .EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS); |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 338 | mVoiceSearchData.mSourceIsGoogle = intent.getBooleanExtra( |
| 339 | VoiceSearchData.SOURCE_IS_GOOGLE, false); |
Leon Scroggins | 2ee4a5a | 2010-03-15 16:56:57 -0400 | [diff] [blame] | 340 | mVoiceSearchData.mVoiceSearchIntent = new Intent(intent); |
Leon Scroggins | e10dde5 | 2010-03-08 19:53:03 -0500 | [diff] [blame] | 341 | } |
| 342 | String extraData = intent.getStringExtra( |
| 343 | SearchManager.EXTRA_DATA_KEY); |
| 344 | if (extraData != null) { |
| 345 | index = Integer.parseInt(extraData); |
| 346 | if (index >= mVoiceSearchData.mVoiceSearchResults.size()) { |
| 347 | throw new AssertionError("index must be less than " |
| 348 | + "size of mVoiceSearchResults"); |
| 349 | } |
| 350 | if (mVoiceSearchData.mSourceIsGoogle) { |
| 351 | Intent logIntent = new Intent( |
| 352 | LoggingEvents.ACTION_LOG_EVENT); |
| 353 | logIntent.putExtra(LoggingEvents.EXTRA_EVENT, |
| 354 | LoggingEvents.VoiceSearch.N_BEST_CHOOSE); |
| 355 | logIntent.putExtra( |
| 356 | LoggingEvents.VoiceSearch.EXTRA_N_BEST_CHOOSE_INDEX, |
| 357 | index); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 358 | mContext.sendBroadcast(logIntent); |
Leon Scroggins | e10dde5 | 2010-03-08 19:53:03 -0500 | [diff] [blame] | 359 | } |
| 360 | if (mVoiceSearchData.mVoiceSearchIntent != null) { |
Leon Scroggins | 2ee4a5a | 2010-03-15 16:56:57 -0400 | [diff] [blame] | 361 | // Copy the Intent, so that each history item will have its own |
| 362 | // Intent, with different (or none) extra data. |
| 363 | Intent latest = new Intent(mVoiceSearchData.mVoiceSearchIntent); |
| 364 | latest.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); |
| 365 | mVoiceSearchData.mVoiceSearchIntent = latest; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | mVoiceSearchData.mLastVoiceSearchTitle |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 369 | = mVoiceSearchData.mVoiceSearchResults.get(index); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 370 | if (mInForeground) { |
Michael Kolb | 11d1978 | 2011-03-20 10:17:40 -0700 | [diff] [blame] | 371 | mWebViewController.activateVoiceSearchMode( |
| 372 | mVoiceSearchData.mLastVoiceSearchTitle, |
| 373 | mVoiceSearchData.mVoiceSearchResults); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 374 | } |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 375 | if (mVoiceSearchData.mVoiceSearchHtmls != null) { |
| 376 | // When index was found it was already ensured that it was valid |
| 377 | String uriString = mVoiceSearchData.mVoiceSearchHtmls.get(index); |
| 378 | if (uriString != null) { |
| 379 | Uri dataUri = Uri.parse(uriString); |
| 380 | if (RecognizerResultsIntent.URI_SCHEME_INLINE.equals( |
| 381 | dataUri.getScheme())) { |
| 382 | // If there is only one base URL, use it. If there are |
| 383 | // more, there will be one for each index, so use the base |
| 384 | // URL corresponding to the index. |
| 385 | String baseUrl = mVoiceSearchData.mVoiceSearchBaseUrls.get( |
| 386 | mVoiceSearchData.mVoiceSearchBaseUrls.size() > 1 ? |
| 387 | index : 0); |
| 388 | mVoiceSearchData.mLastVoiceSearchUrl = baseUrl; |
| 389 | mMainView.loadDataWithBaseURL(baseUrl, |
| 390 | uriString.substring(RecognizerResultsIntent |
| 391 | .URI_SCHEME_INLINE.length() + 1), "text/html", |
| 392 | "utf-8", baseUrl); |
| 393 | return; |
| 394 | } |
| 395 | } |
| 396 | } |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 397 | mVoiceSearchData.mLastVoiceSearchUrl |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 398 | = mVoiceSearchData.mVoiceSearchUrls.get(index); |
| 399 | if (null == mVoiceSearchData.mLastVoiceSearchUrl) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 400 | mVoiceSearchData.mLastVoiceSearchUrl = UrlUtils.smartUrlFilter( |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 401 | mVoiceSearchData.mLastVoiceSearchTitle); |
| 402 | } |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 403 | Map<String, String> headers = null; |
| 404 | if (mVoiceSearchData.mHeaders != null) { |
| 405 | int bundleIndex = mVoiceSearchData.mHeaders.size() == 1 ? 0 |
| 406 | : index; |
| 407 | Bundle bundle = mVoiceSearchData.mHeaders.get(bundleIndex); |
| 408 | if (bundle != null && !bundle.isEmpty()) { |
| 409 | Iterator<String> iter = bundle.keySet().iterator(); |
| 410 | headers = new HashMap<String, String>(); |
| 411 | while (iter.hasNext()) { |
| 412 | String key = iter.next(); |
| 413 | headers.put(key, bundle.getString(key)); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl, headers); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 418 | } |
| 419 | /* package */ static class VoiceSearchData { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 420 | public VoiceSearchData(ArrayList<String> results, |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 421 | ArrayList<String> urls, ArrayList<String> htmls, |
| 422 | ArrayList<String> baseUrls) { |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 423 | mVoiceSearchResults = results; |
| 424 | mVoiceSearchUrls = urls; |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 425 | mVoiceSearchHtmls = htmls; |
| 426 | mVoiceSearchBaseUrls = baseUrls; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 427 | } |
| 428 | /* |
| 429 | * ArrayList of suggestions to be displayed when opening the |
| 430 | * SearchManager |
| 431 | */ |
| 432 | public ArrayList<String> mVoiceSearchResults; |
| 433 | /* |
| 434 | * ArrayList of urls, associated with the suggestions in |
| 435 | * mVoiceSearchResults. |
| 436 | */ |
| 437 | public ArrayList<String> mVoiceSearchUrls; |
| 438 | /* |
Leon Scroggins | 82c1baa | 2010-02-02 16:10:57 -0500 | [diff] [blame] | 439 | * ArrayList holding content to load for each item in |
| 440 | * mVoiceSearchResults. |
| 441 | */ |
| 442 | public ArrayList<String> mVoiceSearchHtmls; |
| 443 | /* |
| 444 | * ArrayList holding base urls for the items in mVoiceSearchResults. |
| 445 | * If non null, this will either have the same size as |
| 446 | * mVoiceSearchResults or have a size of 1, in which case all will use |
| 447 | * the same base url |
| 448 | */ |
| 449 | public ArrayList<String> mVoiceSearchBaseUrls; |
| 450 | /* |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 451 | * 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] | 452 | * we are going to a page by some method besides voice search. |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 453 | */ |
| 454 | public String mLastVoiceSearchUrl; |
| 455 | /** |
| 456 | * The last title used for voice search. Needed to update the title bar |
| 457 | * when switching tabs. |
| 458 | */ |
| 459 | public String mLastVoiceSearchTitle; |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 460 | /** |
| 461 | * Whether the Intent which turned on voice search mode contained the |
| 462 | * String signifying that Google was the source. |
| 463 | */ |
| 464 | public boolean mSourceIsGoogle; |
| 465 | /** |
Leon Scroggins | 9df9497 | 2010-03-08 18:20:35 -0500 | [diff] [blame] | 466 | * List of headers to be passed into the WebView containing location |
| 467 | * information |
| 468 | */ |
| 469 | public ArrayList<Bundle> mHeaders; |
| 470 | /** |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 471 | * The Intent used to invoke voice search. Placed on the |
| 472 | * WebHistoryItem so that when coming back to a previous voice search |
| 473 | * page we can again activate voice search. |
| 474 | */ |
Leon Scroggins | e10dde5 | 2010-03-08 19:53:03 -0500 | [diff] [blame] | 475 | public Intent mVoiceSearchIntent; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 476 | /** |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 477 | * String used to identify Google as the source of voice search. |
| 478 | */ |
| 479 | public static String SOURCE_IS_GOOGLE |
| 480 | = "android.speech.extras.SOURCE_IS_GOOGLE"; |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 481 | } |
| 482 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 483 | // Container class for the next error dialog that needs to be displayed |
| 484 | private class ErrorDialog { |
| 485 | public final int mTitle; |
| 486 | public final String mDescription; |
| 487 | public final int mError; |
| 488 | ErrorDialog(int title, String desc, int error) { |
| 489 | mTitle = title; |
| 490 | mDescription = desc; |
| 491 | mError = error; |
| 492 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 493 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 494 | |
| 495 | private void processNextError() { |
| 496 | if (mQueuedErrors == null) { |
| 497 | return; |
| 498 | } |
| 499 | // The first one is currently displayed so just remove it. |
| 500 | mQueuedErrors.removeFirst(); |
| 501 | if (mQueuedErrors.size() == 0) { |
| 502 | mQueuedErrors = null; |
| 503 | return; |
| 504 | } |
| 505 | showError(mQueuedErrors.getFirst()); |
| 506 | } |
| 507 | |
| 508 | private DialogInterface.OnDismissListener mDialogListener = |
| 509 | new DialogInterface.OnDismissListener() { |
| 510 | public void onDismiss(DialogInterface d) { |
| 511 | processNextError(); |
| 512 | } |
| 513 | }; |
| 514 | private LinkedList<ErrorDialog> mQueuedErrors; |
| 515 | |
| 516 | private void queueError(int err, String desc) { |
| 517 | if (mQueuedErrors == null) { |
| 518 | mQueuedErrors = new LinkedList<ErrorDialog>(); |
| 519 | } |
| 520 | for (ErrorDialog d : mQueuedErrors) { |
| 521 | if (d.mError == err) { |
| 522 | // Already saw a similar error, ignore the new one. |
| 523 | return; |
| 524 | } |
| 525 | } |
| 526 | ErrorDialog errDialog = new ErrorDialog( |
| 527 | err == WebViewClient.ERROR_FILE_NOT_FOUND ? |
| 528 | R.string.browserFrameFileErrorLabel : |
| 529 | R.string.browserFrameNetworkErrorLabel, |
| 530 | desc, err); |
| 531 | mQueuedErrors.addLast(errDialog); |
| 532 | |
| 533 | // Show the dialog now if the queue was empty and it is in foreground |
| 534 | if (mQueuedErrors.size() == 1 && mInForeground) { |
| 535 | showError(errDialog); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | private void showError(ErrorDialog errDialog) { |
| 540 | if (mInForeground) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 541 | AlertDialog d = new AlertDialog.Builder(mContext) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 542 | .setTitle(errDialog.mTitle) |
| 543 | .setMessage(errDialog.mDescription) |
| 544 | .setPositiveButton(R.string.ok, null) |
| 545 | .create(); |
| 546 | d.setOnDismissListener(mDialogListener); |
| 547 | d.show(); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | // ------------------------------------------------------------------------- |
| 552 | // WebViewClient implementation for the main WebView |
| 553 | // ------------------------------------------------------------------------- |
| 554 | |
| 555 | private final WebViewClient mWebViewClient = new WebViewClient() { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 556 | private Message mDontResend; |
| 557 | private Message mResend; |
Michael Kolb | 47bd1e4 | 2011-09-01 15:25:00 -0700 | [diff] [blame] | 558 | |
| 559 | private boolean providersDiffer(String url, String otherUrl) { |
| 560 | Uri uri1 = Uri.parse(url); |
| 561 | Uri uri2 = Uri.parse(otherUrl); |
| 562 | return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority()); |
| 563 | } |
| 564 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 565 | @Override |
| 566 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 567 | mInPageLoad = true; |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 568 | mPageLoadProgress = INITIAL_PROGRESS; |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 569 | mCurrentState = new PageState(mContext, |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 570 | view.isPrivateBrowsingEnabled(), url, favicon); |
Kristian Monsen | 4dce3bf | 2010-02-02 13:37:09 +0000 | [diff] [blame] | 571 | mLoadStartTime = SystemClock.uptimeMillis(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 572 | if (mVoiceSearchData != null |
Michael Kolb | 47bd1e4 | 2011-09-01 15:25:00 -0700 | [diff] [blame] | 573 | && providersDiffer(url, mVoiceSearchData.mLastVoiceSearchUrl)) { |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 574 | if (mVoiceSearchData.mSourceIsGoogle) { |
| 575 | Intent i = new Intent(LoggingEvents.ACTION_LOG_EVENT); |
| 576 | i.putExtra(LoggingEvents.EXTRA_FLUSH, true); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 577 | mContext.sendBroadcast(i); |
Leon Scroggins | 1fe13a5 | 2010-02-09 15:31:26 -0500 | [diff] [blame] | 578 | } |
Leon Scroggins III | 95d9bfd | 2010-09-14 14:02:36 -0400 | [diff] [blame] | 579 | revertVoiceSearchMode(); |
Leon Scroggins | 58d56c6 | 2010-01-28 15:12:40 -0500 | [diff] [blame] | 580 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 581 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 582 | |
| 583 | // If we start a touch icon load and then load a new page, we don't |
| 584 | // want to cancel the current touch icon loader. But, we do want to |
| 585 | // create a new one when the touch icon url is known. |
| 586 | if (mTouchIconLoader != null) { |
| 587 | mTouchIconLoader.mTab = null; |
| 588 | mTouchIconLoader = null; |
| 589 | } |
| 590 | |
| 591 | // reset the error console |
| 592 | if (mErrorConsole != null) { |
| 593 | mErrorConsole.clearErrorMessages(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 594 | if (mWebViewController.shouldShowErrorConsole()) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 595 | mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE); |
| 596 | } |
| 597 | } |
| 598 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 599 | // Cancel the auto-login process. |
| 600 | if (mDeviceAccountLogin != null) { |
| 601 | mDeviceAccountLogin.cancel(); |
| 602 | mDeviceAccountLogin = null; |
| 603 | mWebViewController.hideAutoLogin(Tab.this); |
| 604 | } |
| 605 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 606 | // 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] | 607 | mWebViewController.onPageStarted(Tab.this, view, favicon); |
Leon Scroggins | 4cd9779 | 2010-12-03 15:31:56 -0500 | [diff] [blame] | 608 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 609 | updateBookmarkedStatus(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | @Override |
| 613 | public void onPageFinished(WebView view, String url) { |
John Reck | 5b69184 | 2010-11-29 11:21:13 -0800 | [diff] [blame] | 614 | if (!isPrivateBrowsingEnabled()) { |
| 615 | LogTag.logPageFinishedLoading( |
| 616 | url, SystemClock.uptimeMillis() - mLoadStartTime); |
| 617 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 618 | syncCurrentState(view, url); |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 619 | mWebViewController.onPageFinished(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | // return true if want to hijack the url to let another app to handle it |
| 623 | @Override |
| 624 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
Leon Scroggins III | c1f5ae2 | 2010-06-29 17:11:29 -0400 | [diff] [blame] | 625 | if (voiceSearchSourceIsGoogle()) { |
| 626 | // This method is called when the user clicks on a link. |
| 627 | // VoiceSearchMode is turned off when the user leaves the |
| 628 | // Google results page, so at this point the user must be on |
| 629 | // that page. If the user clicked a link on that page, assume |
| 630 | // that the voice search was effective, and broadcast an Intent |
| 631 | // so a receiver can take note of that fact. |
| 632 | Intent logIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT); |
| 633 | logIntent.putExtra(LoggingEvents.EXTRA_EVENT, |
| 634 | LoggingEvents.VoiceSearch.RESULT_CLICKED); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 635 | mContext.sendBroadcast(logIntent); |
Leon Scroggins III | c1f5ae2 | 2010-06-29 17:11:29 -0400 | [diff] [blame] | 636 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 637 | if (mInForeground) { |
Michael Kolb | 18eb377 | 2010-12-10 14:29:51 -0800 | [diff] [blame] | 638 | return mWebViewController.shouldOverrideUrlLoading(Tab.this, |
| 639 | view, url); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 640 | } else { |
| 641 | return false; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /** |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 646 | * Updates the security state. This method is called when we discover |
| 647 | * another resource to be loaded for this page (for example, |
| 648 | * javascript). While we update the security state, we do not update |
| 649 | * the lock icon until we are done loading, as it is slightly more |
| 650 | * secure this way. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 651 | */ |
| 652 | @Override |
| 653 | public void onLoadResource(WebView view, String url) { |
| 654 | if (url != null && url.length() > 0) { |
| 655 | // It is only if the page claims to be secure that we may have |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 656 | // to update the security state: |
| 657 | if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) { |
| 658 | // If NOT a 'safe' url, change the state to mixed content! |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 659 | if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url) |
| 660 | || URLUtil.isAboutUrl(url))) { |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 661 | mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 668 | * Show a dialog informing the user of the network error reported by |
| 669 | * WebCore if it is in the foreground. |
| 670 | */ |
| 671 | @Override |
| 672 | public void onReceivedError(WebView view, int errorCode, |
| 673 | String description, String failingUrl) { |
| 674 | if (errorCode != WebViewClient.ERROR_HOST_LOOKUP && |
| 675 | errorCode != WebViewClient.ERROR_CONNECT && |
| 676 | errorCode != WebViewClient.ERROR_BAD_URL && |
| 677 | errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME && |
| 678 | errorCode != WebViewClient.ERROR_FILE) { |
| 679 | queueError(errorCode, description); |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 680 | |
Selim Gurun | 3da06b8 | 2011-10-10 13:58:12 -0700 | [diff] [blame] | 681 | // Don't log URLs when in private browsing mode |
| 682 | if (!isPrivateBrowsingEnabled()) { |
| 683 | Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 684 | + " " + description); |
Selim Gurun | 3da06b8 | 2011-10-10 13:58:12 -0700 | [diff] [blame] | 685 | } |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 686 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Check with the user if it is ok to resend POST data as the page they |
| 691 | * are trying to navigate to is the result of a POST. |
| 692 | */ |
| 693 | @Override |
| 694 | public void onFormResubmission(WebView view, final Message dontResend, |
| 695 | final Message resend) { |
| 696 | if (!mInForeground) { |
| 697 | dontResend.sendToTarget(); |
| 698 | return; |
| 699 | } |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 700 | if (mDontResend != null) { |
| 701 | Log.w(LOGTAG, "onFormResubmission should not be called again " |
| 702 | + "while dialog is still up"); |
| 703 | dontResend.sendToTarget(); |
| 704 | return; |
| 705 | } |
| 706 | mDontResend = dontResend; |
| 707 | mResend = resend; |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 708 | new AlertDialog.Builder(mContext).setTitle( |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 709 | R.string.browserFrameFormResubmitLabel).setMessage( |
| 710 | R.string.browserFrameFormResubmitMessage) |
| 711 | .setPositiveButton(R.string.ok, |
| 712 | new DialogInterface.OnClickListener() { |
| 713 | public void onClick(DialogInterface dialog, |
| 714 | int which) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 715 | if (mResend != null) { |
| 716 | mResend.sendToTarget(); |
| 717 | mResend = null; |
| 718 | mDontResend = null; |
| 719 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 720 | } |
| 721 | }).setNegativeButton(R.string.cancel, |
| 722 | new DialogInterface.OnClickListener() { |
| 723 | public void onClick(DialogInterface dialog, |
| 724 | int which) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 725 | if (mDontResend != null) { |
| 726 | mDontResend.sendToTarget(); |
| 727 | mResend = null; |
| 728 | mDontResend = null; |
| 729 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 730 | } |
| 731 | }).setOnCancelListener(new OnCancelListener() { |
| 732 | public void onCancel(DialogInterface dialog) { |
Leon Scroggins | 4a64a8a | 2010-03-02 17:57:40 -0500 | [diff] [blame] | 733 | if (mDontResend != null) { |
| 734 | mDontResend.sendToTarget(); |
| 735 | mResend = null; |
| 736 | mDontResend = null; |
| 737 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 738 | } |
| 739 | }).show(); |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * Insert the url into the visited history database. |
| 744 | * @param url The url to be inserted. |
| 745 | * @param isReload True if this url is being reloaded. |
| 746 | * FIXME: Not sure what to do when reloading the page. |
| 747 | */ |
| 748 | @Override |
| 749 | public void doUpdateVisitedHistory(WebView view, String url, |
| 750 | boolean isReload) { |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 751 | mWebViewController.doUpdateVisitedHistory(Tab.this, isReload); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Displays SSL error(s) dialog to the user. |
| 756 | */ |
| 757 | @Override |
| 758 | public void onReceivedSslError(final WebView view, |
| 759 | final SslErrorHandler handler, final SslError error) { |
| 760 | if (!mInForeground) { |
| 761 | handler.cancel(); |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 762 | setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 763 | return; |
| 764 | } |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 765 | if (mSettings.showSecurityWarnings()) { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 766 | new AlertDialog.Builder(mContext) |
| 767 | .setTitle(R.string.security_warning) |
| 768 | .setMessage(R.string.ssl_warnings_header) |
| 769 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 770 | .setPositiveButton(R.string.ssl_continue, |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 771 | new DialogInterface.OnClickListener() { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 772 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 773 | public void onClick(DialogInterface dialog, |
| 774 | int whichButton) { |
| 775 | handler.proceed(); |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 776 | handleProceededAfterSslError(error); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 777 | } |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 778 | }) |
| 779 | .setNeutralButton(R.string.view_certificate, |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 780 | new DialogInterface.OnClickListener() { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 781 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 782 | public void onClick(DialogInterface dialog, |
| 783 | int whichButton) { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 784 | mWebViewController.showSslCertificateOnError( |
| 785 | view, handler, error); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 786 | } |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 787 | }) |
| 788 | .setNegativeButton(R.string.ssl_go_back, |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 789 | new DialogInterface.OnClickListener() { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 790 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 791 | public void onClick(DialogInterface dialog, |
| 792 | int whichButton) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 793 | dialog.cancel(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 794 | } |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 795 | }) |
| 796 | .setOnCancelListener( |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 797 | new DialogInterface.OnCancelListener() { |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 798 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 799 | public void onCancel(DialogInterface dialog) { |
| 800 | handler.cancel(); |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 801 | setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 802 | mWebViewController.onUserCanceledSsl(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 803 | } |
John Reck | cb28b2c | 2011-08-26 17:39:44 -0700 | [diff] [blame] | 804 | }) |
| 805 | .show(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 806 | } else { |
| 807 | handler.proceed(); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /** |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 812 | * Called when an SSL error occurred while loading a resource, but the |
| 813 | * WebView but chose to proceed anyway based on a decision retained |
| 814 | * from a previous response to onReceivedSslError(). We update our |
| 815 | * security state to reflect this. |
| 816 | */ |
| 817 | @Override |
| 818 | public void onProceededAfterSslError(WebView view, SslError error) { |
| 819 | handleProceededAfterSslError(error); |
| 820 | } |
| 821 | |
| 822 | /** |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 823 | * Displays client certificate request to the user. |
| 824 | */ |
| 825 | @Override |
| 826 | public void onReceivedClientCertRequest(final WebView view, |
| 827 | final ClientCertRequestHandler handler, final String host_and_port) { |
| 828 | if (!mInForeground) { |
| 829 | handler.ignore(); |
| 830 | return; |
| 831 | } |
Brian Carlstrom | 6d85fab | 2011-06-24 14:26:46 -0700 | [diff] [blame] | 832 | int colon = host_and_port.lastIndexOf(':'); |
| 833 | String host; |
| 834 | int port; |
| 835 | if (colon == -1) { |
| 836 | host = host_and_port; |
| 837 | port = -1; |
| 838 | } else { |
| 839 | String portString = host_and_port.substring(colon + 1); |
| 840 | try { |
| 841 | port = Integer.parseInt(portString); |
| 842 | host = host_and_port.substring(0, colon); |
| 843 | } catch (NumberFormatException e) { |
| 844 | host = host_and_port; |
| 845 | port = -1; |
| 846 | } |
| 847 | } |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 848 | KeyChain.choosePrivateKeyAlias( |
| 849 | mWebViewController.getActivity(), new KeyChainAliasCallback() { |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 850 | @Override public void alias(String alias) { |
| 851 | if (alias == null) { |
| 852 | handler.cancel(); |
| 853 | return; |
| 854 | } |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 855 | new KeyChainLookup(mContext, handler, alias).execute(); |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 856 | } |
Brian Carlstrom | 6d85fab | 2011-06-24 14:26:46 -0700 | [diff] [blame] | 857 | }, null, null, host, port, null); |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 861 | * Handles an HTTP authentication request. |
| 862 | * |
| 863 | * @param handler The authentication handler |
| 864 | * @param host The host |
| 865 | * @param realm The realm |
| 866 | */ |
| 867 | @Override |
| 868 | public void onReceivedHttpAuthRequest(WebView view, |
| 869 | final HttpAuthHandler handler, final String host, |
| 870 | final String realm) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 871 | mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | @Override |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 875 | public WebResourceResponse shouldInterceptRequest(WebView view, |
| 876 | String url) { |
| 877 | WebResourceResponse res = HomeProvider.shouldInterceptRequest( |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 878 | mContext, url); |
John Reck | 438bf46 | 2011-01-12 18:11:46 -0800 | [diff] [blame] | 879 | return res; |
| 880 | } |
| 881 | |
| 882 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 883 | public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { |
| 884 | if (!mInForeground) { |
| 885 | return false; |
| 886 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 887 | return mWebViewController.shouldOverrideKeyEvent(event); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | @Override |
| 891 | public void onUnhandledKeyEvent(WebView view, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 892 | if (!mInForeground) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 893 | return; |
| 894 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 895 | mWebViewController.onUnhandledKeyEvent(event); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 896 | } |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 897 | |
| 898 | @Override |
| 899 | public void onReceivedLoginRequest(WebView view, String realm, |
| 900 | String account, String args) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 901 | new DeviceAccountLogin(mWebViewController.getActivity(), view, Tab.this, mWebViewController) |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 902 | .handleLogin(realm, account, args); |
| 903 | } |
| 904 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 905 | }; |
| 906 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 907 | private void syncCurrentState(WebView view, String url) { |
| 908 | // Sync state (in case of stop/timeout) |
| 909 | mCurrentState.mUrl = view.getUrl(); |
| 910 | if (mCurrentState.mUrl == null) { |
John Reck | 8bcafc1 | 2011-08-29 16:43:02 -0700 | [diff] [blame] | 911 | mCurrentState.mUrl = ""; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 912 | } |
| 913 | mCurrentState.mOriginalUrl = view.getOriginalUrl(); |
| 914 | mCurrentState.mTitle = view.getTitle(); |
| 915 | mCurrentState.mFavicon = view.getFavicon(); |
| 916 | if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) { |
| 917 | // In case we stop when loading an HTTPS page from an HTTP page |
| 918 | // but before a provisional load occurred |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 919 | mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE; |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 920 | mCurrentState.mSslCertificateError = null; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 921 | } |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 922 | mCurrentState.mIncognito = view.isPrivateBrowsingEnabled(); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Patrick Scott | 9206677 | 2011-03-10 08:46:27 -0500 | [diff] [blame] | 925 | // Called by DeviceAccountLogin when the Tab needs to have the auto-login UI |
| 926 | // displayed. |
| 927 | void setDeviceAccountLogin(DeviceAccountLogin login) { |
| 928 | mDeviceAccountLogin = login; |
| 929 | } |
| 930 | |
| 931 | // Returns non-null if the title bar should display the auto-login UI. |
| 932 | DeviceAccountLogin getDeviceAccountLogin() { |
| 933 | return mDeviceAccountLogin; |
| 934 | } |
| 935 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 936 | // ------------------------------------------------------------------------- |
| 937 | // WebChromeClient implementation for the main WebView |
| 938 | // ------------------------------------------------------------------------- |
| 939 | |
| 940 | private final WebChromeClient mWebChromeClient = new WebChromeClient() { |
| 941 | // Helper method to create a new tab or sub window. |
| 942 | private void createWindow(final boolean dialog, final Message msg) { |
| 943 | WebView.WebViewTransport transport = |
| 944 | (WebView.WebViewTransport) msg.obj; |
| 945 | if (dialog) { |
| 946 | createSubWindow(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 947 | mWebViewController.attachSubWindow(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 948 | transport.setWebView(mSubView); |
| 949 | } else { |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 950 | final Tab newTab = mWebViewController.openTab(null, |
John Reck | 5949c66 | 2011-05-27 09:52:29 -0700 | [diff] [blame] | 951 | Tab.this, true, true); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 952 | transport.setWebView(newTab.getWebView()); |
| 953 | } |
| 954 | msg.sendToTarget(); |
| 955 | } |
| 956 | |
| 957 | @Override |
| 958 | public boolean onCreateWindow(WebView view, final boolean dialog, |
| 959 | final boolean userGesture, final Message resultMsg) { |
| 960 | // only allow new window or sub window for the foreground case |
| 961 | if (!mInForeground) { |
| 962 | return false; |
| 963 | } |
| 964 | // Short-circuit if we can't create any more tabs or sub windows. |
| 965 | if (dialog && mSubView != null) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 966 | new AlertDialog.Builder(mContext) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 967 | .setTitle(R.string.too_many_subwindows_dialog_title) |
| 968 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 969 | .setMessage(R.string.too_many_subwindows_dialog_message) |
| 970 | .setPositiveButton(R.string.ok, null) |
| 971 | .show(); |
| 972 | return false; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 973 | } else if (!mWebViewController.getTabControl().canCreateNewTab()) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 974 | new AlertDialog.Builder(mContext) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 975 | .setTitle(R.string.too_many_windows_dialog_title) |
| 976 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 977 | .setMessage(R.string.too_many_windows_dialog_message) |
| 978 | .setPositiveButton(R.string.ok, null) |
| 979 | .show(); |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | // Short-circuit if this was a user gesture. |
| 984 | if (userGesture) { |
| 985 | createWindow(dialog, resultMsg); |
| 986 | return true; |
| 987 | } |
| 988 | |
| 989 | // Allow the popup and create the appropriate window. |
| 990 | final AlertDialog.OnClickListener allowListener = |
| 991 | new AlertDialog.OnClickListener() { |
| 992 | public void onClick(DialogInterface d, |
| 993 | int which) { |
| 994 | createWindow(dialog, resultMsg); |
| 995 | } |
| 996 | }; |
| 997 | |
| 998 | // Block the popup by returning a null WebView. |
| 999 | final AlertDialog.OnClickListener blockListener = |
| 1000 | new AlertDialog.OnClickListener() { |
| 1001 | public void onClick(DialogInterface d, int which) { |
| 1002 | resultMsg.sendToTarget(); |
| 1003 | } |
| 1004 | }; |
| 1005 | |
| 1006 | // Build a confirmation dialog to display to the user. |
| 1007 | final AlertDialog d = |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1008 | new AlertDialog.Builder(mContext) |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1009 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 1010 | .setMessage(R.string.popup_window_attempt) |
| 1011 | .setPositiveButton(R.string.allow, allowListener) |
| 1012 | .setNegativeButton(R.string.block, blockListener) |
| 1013 | .setCancelable(false) |
| 1014 | .create(); |
| 1015 | |
| 1016 | // Show the confirmation dialog. |
| 1017 | d.show(); |
| 1018 | return true; |
| 1019 | } |
| 1020 | |
| 1021 | @Override |
Patrick Scott | eb5061b | 2009-11-18 15:00:30 -0500 | [diff] [blame] | 1022 | public void onRequestFocus(WebView view) { |
| 1023 | if (!mInForeground) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1024 | mWebViewController.switchToTab(Tab.this); |
Patrick Scott | eb5061b | 2009-11-18 15:00:30 -0500 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1029 | public void onCloseWindow(WebView window) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1030 | if (mParent != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1031 | // JavaScript can only close popup window. |
| 1032 | if (mInForeground) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1033 | mWebViewController.switchToTab(mParent); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1034 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1035 | mWebViewController.closeTab(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | @Override |
| 1040 | public void onProgressChanged(WebView view, int newProgress) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1041 | mPageLoadProgress = newProgress; |
Michael Kolb | b1fb70c | 2011-11-21 12:38:14 -0800 | [diff] [blame] | 1042 | if (newProgress == 100) { |
| 1043 | mInPageLoad = false; |
| 1044 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1045 | mWebViewController.onProgressChanged(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | @Override |
Leon Scroggins | 21d9b90 | 2010-03-11 09:33:11 -0500 | [diff] [blame] | 1049 | public void onReceivedTitle(WebView view, final String title) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1050 | mCurrentState.mTitle = title; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1051 | mWebViewController.onReceivedTitle(Tab.this, title); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | @Override |
| 1055 | public void onReceivedIcon(WebView view, Bitmap icon) { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1056 | mCurrentState.mFavicon = icon; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1057 | mWebViewController.onFavicon(Tab.this, view, icon); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | @Override |
| 1061 | public void onReceivedTouchIconUrl(WebView view, String url, |
| 1062 | boolean precomposed) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1063 | final ContentResolver cr = mContext.getContentResolver(); |
Leon Scroggins | c8393d9 | 2010-04-23 14:58:16 -0400 | [diff] [blame] | 1064 | // Let precomposed icons take precedence over non-composed |
| 1065 | // icons. |
| 1066 | if (precomposed && mTouchIconLoader != null) { |
| 1067 | mTouchIconLoader.cancel(false); |
| 1068 | mTouchIconLoader = null; |
| 1069 | } |
| 1070 | // Have only one async task at a time. |
| 1071 | if (mTouchIconLoader == null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1072 | mTouchIconLoader = new DownloadTouchIcon(Tab.this, |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1073 | mContext, cr, view); |
Leon Scroggins | c8393d9 | 2010-04-23 14:58:16 -0400 | [diff] [blame] | 1074 | mTouchIconLoader.execute(url); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | @Override |
| 1079 | public void onShowCustomView(View view, |
| 1080 | WebChromeClient.CustomViewCallback callback) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1081 | Activity activity = mWebViewController.getActivity(); |
| 1082 | if (activity != null) { |
| 1083 | onShowCustomView(view, activity.getRequestedOrientation(), callback); |
| 1084 | } |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | @Override |
| 1088 | public void onShowCustomView(View view, int requestedOrientation, |
| 1089 | WebChromeClient.CustomViewCallback callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1090 | if (mInForeground) mWebViewController.showCustomView(Tab.this, view, |
Derek Sollenberger | 2d4f1e2 | 2011-06-01 14:50:42 -0400 | [diff] [blame] | 1091 | requestedOrientation, callback); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | @Override |
| 1095 | public void onHideCustomView() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1096 | if (mInForeground) mWebViewController.hideCustomView(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * The origin has exceeded its database quota. |
| 1101 | * @param url the URL that exceeded the quota |
| 1102 | * @param databaseIdentifier the identifier of the database on which the |
| 1103 | * transaction that caused the quota overflow was run |
| 1104 | * @param currentQuota the current quota for the origin. |
| 1105 | * @param estimatedSize the estimated size of the database. |
| 1106 | * @param totalUsedQuota is the sum of all origins' quota. |
| 1107 | * @param quotaUpdater The callback to run when a decision to allow or |
| 1108 | * deny quota has been made. Don't forget to call this! |
| 1109 | */ |
| 1110 | @Override |
| 1111 | public void onExceededDatabaseQuota(String url, |
| 1112 | String databaseIdentifier, long currentQuota, long estimatedSize, |
| 1113 | long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1114 | mSettings.getWebStorageSizeManager() |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1115 | .onExceededDatabaseQuota(url, databaseIdentifier, |
| 1116 | currentQuota, estimatedSize, totalUsedQuota, |
| 1117 | quotaUpdater); |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * The Application Cache has exceeded its max size. |
| 1122 | * @param spaceNeeded is the amount of disk space that would be needed |
| 1123 | * in order for the last appcache operation to succeed. |
| 1124 | * @param totalUsedQuota is the sum of all origins' quota. |
| 1125 | * @param quotaUpdater A callback to inform the WebCore thread that a |
| 1126 | * new app cache size is available. This callback must always |
| 1127 | * be executed at some point to ensure that the sleeping |
| 1128 | * WebCore thread is woken up. |
| 1129 | */ |
| 1130 | @Override |
| 1131 | public void onReachedMaxAppCacheSize(long spaceNeeded, |
| 1132 | long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) { |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1133 | mSettings.getWebStorageSizeManager() |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1134 | .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota, |
| 1135 | quotaUpdater); |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * Instructs the browser to show a prompt to ask the user to set the |
| 1140 | * Geolocation permission state for the specified origin. |
| 1141 | * @param origin The origin for which Geolocation permissions are |
| 1142 | * requested. |
| 1143 | * @param callback The callback to call once the user has set the |
| 1144 | * Geolocation permission state. |
| 1145 | */ |
| 1146 | @Override |
| 1147 | public void onGeolocationPermissionsShowPrompt(String origin, |
| 1148 | GeolocationPermissions.Callback callback) { |
| 1149 | if (mInForeground) { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1150 | getGeolocationPermissionsPrompt().show(origin, callback); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | /** |
| 1155 | * Instructs the browser to hide the Geolocation permissions prompt. |
| 1156 | */ |
| 1157 | @Override |
| 1158 | public void onGeolocationPermissionsHidePrompt() { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1159 | if (mInForeground && mGeolocationPermissionsPrompt != null) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1160 | mGeolocationPermissionsPrompt.hide(); |
| 1161 | } |
| 1162 | } |
| 1163 | |
Ben Murdoch | 65acc35 | 2009-11-19 18:16:04 +0000 | [diff] [blame] | 1164 | /* Adds a JavaScript error message to the system log and if the JS |
| 1165 | * console is enabled in the about:debug options, to that console |
| 1166 | * also. |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1167 | * @param consoleMessage the message object. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1168 | */ |
| 1169 | @Override |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1170 | public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1171 | if (mInForeground) { |
| 1172 | // call getErrorConsole(true) so it will create one if needed |
| 1173 | ErrorConsoleView errorConsole = getErrorConsole(true); |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1174 | errorConsole.addErrorMessage(consoleMessage); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1175 | if (mWebViewController.shouldShowErrorConsole() |
| 1176 | && errorConsole.getShowState() != |
| 1177 | ErrorConsoleView.SHOW_MAXIMIZED) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1178 | errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED); |
| 1179 | } |
| 1180 | } |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1181 | |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 1182 | // Don't log console messages in private browsing mode |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1183 | if (isPrivateBrowsingEnabled()) return true; |
Jeff Hamilton | 47654f4 | 2010-09-07 09:57:51 -0500 | [diff] [blame] | 1184 | |
Ben Murdoch | c42addf | 2010-01-28 15:19:59 +0000 | [diff] [blame] | 1185 | String message = "Console: " + consoleMessage.message() + " " |
| 1186 | + consoleMessage.sourceId() + ":" |
| 1187 | + consoleMessage.lineNumber(); |
| 1188 | |
| 1189 | switch (consoleMessage.messageLevel()) { |
| 1190 | case TIP: |
| 1191 | Log.v(CONSOLE_LOGTAG, message); |
| 1192 | break; |
| 1193 | case LOG: |
| 1194 | Log.i(CONSOLE_LOGTAG, message); |
| 1195 | break; |
| 1196 | case WARNING: |
| 1197 | Log.w(CONSOLE_LOGTAG, message); |
| 1198 | break; |
| 1199 | case ERROR: |
| 1200 | Log.e(CONSOLE_LOGTAG, message); |
| 1201 | break; |
| 1202 | case DEBUG: |
| 1203 | Log.d(CONSOLE_LOGTAG, message); |
| 1204 | break; |
| 1205 | } |
| 1206 | |
| 1207 | return true; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Ask the browser for an icon to represent a <video> element. |
| 1212 | * This icon will be used if the Web page did not specify a poster attribute. |
| 1213 | * @return Bitmap The icon or null if no such icon is available. |
| 1214 | */ |
| 1215 | @Override |
| 1216 | public Bitmap getDefaultVideoPoster() { |
| 1217 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1218 | return mWebViewController.getDefaultVideoPoster(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1219 | } |
| 1220 | return null; |
| 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * Ask the host application for a custom progress view to show while |
| 1225 | * a <video> is loading. |
| 1226 | * @return View The progress view. |
| 1227 | */ |
| 1228 | @Override |
| 1229 | public View getVideoLoadingProgressView() { |
| 1230 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1231 | return mWebViewController.getVideoLoadingProgressView(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1232 | } |
| 1233 | return null; |
| 1234 | } |
| 1235 | |
| 1236 | @Override |
Ben Murdoch | 62b1b7e | 2010-05-19 20:38:56 +0100 | [diff] [blame] | 1237 | public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1238 | if (mInForeground) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1239 | mWebViewController.openFileChooser(uploadMsg, acceptType); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1240 | } else { |
| 1241 | uploadMsg.onReceiveValue(null); |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * Deliver a list of already-visited URLs |
| 1247 | */ |
| 1248 | @Override |
| 1249 | public void getVisitedHistory(final ValueCallback<String[]> callback) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1250 | mWebViewController.getVisitedHistory(callback); |
| 1251 | } |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 1252 | |
| 1253 | @Override |
| 1254 | public void setupAutoFill(Message message) { |
| 1255 | // Prompt the user to set up their profile. |
| 1256 | final Message msg = message; |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1257 | AlertDialog.Builder builder = new AlertDialog.Builder(mContext); |
| 1258 | LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 1259 | Context.LAYOUT_INFLATER_SERVICE); |
| 1260 | final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null); |
| 1261 | |
| 1262 | builder.setView(layout) |
| 1263 | .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { |
| 1264 | @Override |
| 1265 | public void onClick(DialogInterface dialog, int id) { |
| 1266 | CheckBox disableAutoFill = (CheckBox) layout.findViewById( |
| 1267 | R.id.setup_autofill_dialog_disable_autofill); |
| 1268 | |
| 1269 | if (disableAutoFill.isChecked()) { |
| 1270 | // 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] | 1271 | mSettings.setAutofillEnabled(false); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1272 | Toast.makeText(mContext, |
Ben Murdoch | 1d676b6 | 2011-01-17 12:54:24 +0000 | [diff] [blame] | 1273 | R.string.autofill_setup_dialog_negative_toast, |
| 1274 | Toast.LENGTH_LONG).show(); |
| 1275 | } else { |
| 1276 | // Take user to the AutoFill profile editor. When they return, |
| 1277 | // we will send the message that we pass here which will trigger |
| 1278 | // the form to get filled out with their new profile. |
| 1279 | mWebViewController.setupAutoFill(msg); |
| 1280 | } |
| 1281 | } |
| 1282 | }) |
| 1283 | .setNegativeButton(R.string.cancel, null) |
| 1284 | .show(); |
Ben Murdoch | 8029a77 | 2010-11-16 11:58:21 +0000 | [diff] [blame] | 1285 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1286 | }; |
| 1287 | |
| 1288 | // ------------------------------------------------------------------------- |
| 1289 | // WebViewClient implementation for the sub window |
| 1290 | // ------------------------------------------------------------------------- |
| 1291 | |
| 1292 | // Subclass of WebViewClient used in subwindows to notify the main |
| 1293 | // WebViewClient of certain WebView activities. |
| 1294 | private static class SubWindowClient extends WebViewClient { |
| 1295 | // The main WebViewClient. |
| 1296 | private final WebViewClient mClient; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1297 | private final WebViewController mController; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1298 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1299 | SubWindowClient(WebViewClient client, WebViewController controller) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1300 | mClient = client; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1301 | mController = controller; |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 1302 | } |
| 1303 | @Override |
| 1304 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 1305 | // Unlike the others, do not call mClient's version, which would |
| 1306 | // change the progress bar. However, we do want to remove the |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 1307 | // find or select dialog. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1308 | mController.endActionMode(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1309 | } |
| 1310 | @Override |
| 1311 | public void doUpdateVisitedHistory(WebView view, String url, |
| 1312 | boolean isReload) { |
| 1313 | mClient.doUpdateVisitedHistory(view, url, isReload); |
| 1314 | } |
| 1315 | @Override |
| 1316 | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
| 1317 | return mClient.shouldOverrideUrlLoading(view, url); |
| 1318 | } |
| 1319 | @Override |
| 1320 | public void onReceivedSslError(WebView view, SslErrorHandler handler, |
| 1321 | SslError error) { |
| 1322 | mClient.onReceivedSslError(view, handler, error); |
| 1323 | } |
| 1324 | @Override |
Brian Carlstrom | 8862c1d | 2011-06-02 01:05:55 -0700 | [diff] [blame] | 1325 | public void onReceivedClientCertRequest(WebView view, |
| 1326 | ClientCertRequestHandler handler, String host_and_port) { |
| 1327 | mClient.onReceivedClientCertRequest(view, handler, host_and_port); |
| 1328 | } |
| 1329 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1330 | public void onReceivedHttpAuthRequest(WebView view, |
| 1331 | HttpAuthHandler handler, String host, String realm) { |
| 1332 | mClient.onReceivedHttpAuthRequest(view, handler, host, realm); |
| 1333 | } |
| 1334 | @Override |
| 1335 | public void onFormResubmission(WebView view, Message dontResend, |
| 1336 | Message resend) { |
| 1337 | mClient.onFormResubmission(view, dontResend, resend); |
| 1338 | } |
| 1339 | @Override |
| 1340 | public void onReceivedError(WebView view, int errorCode, |
| 1341 | String description, String failingUrl) { |
| 1342 | mClient.onReceivedError(view, errorCode, description, failingUrl); |
| 1343 | } |
| 1344 | @Override |
| 1345 | public boolean shouldOverrideKeyEvent(WebView view, |
| 1346 | android.view.KeyEvent event) { |
| 1347 | return mClient.shouldOverrideKeyEvent(view, event); |
| 1348 | } |
| 1349 | @Override |
| 1350 | public void onUnhandledKeyEvent(WebView view, |
| 1351 | android.view.KeyEvent event) { |
| 1352 | mClient.onUnhandledKeyEvent(view, event); |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | // ------------------------------------------------------------------------- |
| 1357 | // WebChromeClient implementation for the sub window |
| 1358 | // ------------------------------------------------------------------------- |
| 1359 | |
| 1360 | private class SubWindowChromeClient extends WebChromeClient { |
| 1361 | // The main WebChromeClient. |
| 1362 | private final WebChromeClient mClient; |
| 1363 | |
| 1364 | SubWindowChromeClient(WebChromeClient client) { |
| 1365 | mClient = client; |
| 1366 | } |
| 1367 | @Override |
| 1368 | public void onProgressChanged(WebView view, int newProgress) { |
| 1369 | mClient.onProgressChanged(view, newProgress); |
| 1370 | } |
| 1371 | @Override |
| 1372 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 1373 | boolean userGesture, android.os.Message resultMsg) { |
| 1374 | return mClient.onCreateWindow(view, dialog, userGesture, resultMsg); |
| 1375 | } |
| 1376 | @Override |
| 1377 | public void onCloseWindow(WebView window) { |
| 1378 | if (window != mSubView) { |
| 1379 | Log.e(LOGTAG, "Can't close the window"); |
| 1380 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1381 | mWebViewController.dismissSubWindow(Tab.this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | // ------------------------------------------------------------------------- |
| 1386 | |
| 1387 | // Construct a new tab |
Michael Kolb | 7bcafde | 2011-05-09 13:55:59 -0700 | [diff] [blame] | 1388 | Tab(WebViewController wvcontroller, WebView w) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1389 | this(wvcontroller, w, null); |
| 1390 | } |
| 1391 | |
| 1392 | Tab(WebViewController wvcontroller, Bundle state) { |
| 1393 | this(wvcontroller, null, state); |
| 1394 | } |
| 1395 | |
| 1396 | Tab(WebViewController wvcontroller, WebView w, Bundle state) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1397 | mWebViewController = wvcontroller; |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1398 | mContext = mWebViewController.getContext(); |
John Reck | 35e9dd6 | 2011-04-25 09:01:54 -0700 | [diff] [blame] | 1399 | mSettings = BrowserSettings.getInstance(); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1400 | mDataController = DataController.getInstance(mContext); |
| 1401 | mCurrentState = new PageState(mContext, w != null |
John Reck | 847b532 | 2011-04-14 17:02:18 -0700 | [diff] [blame] | 1402 | ? w.isPrivateBrowsingEnabled() : false); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1403 | mInPageLoad = false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1404 | mInForeground = false; |
| 1405 | |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1406 | mDownloadListener = new DownloadListener() { |
| 1407 | public void onDownloadStart(String url, String userAgent, |
| 1408 | String contentDisposition, String mimetype, |
| 1409 | long contentLength) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1410 | mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition, |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1411 | mimetype, contentLength); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1412 | } |
| 1413 | }; |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 1414 | mWebBackForwardListClient = new WebBackForwardListClient() { |
| 1415 | @Override |
| 1416 | public void onNewHistoryItem(WebHistoryItem item) { |
| 1417 | if (isInVoiceSearchMode()) { |
| 1418 | item.setCustomData(mVoiceSearchData.mVoiceSearchIntent); |
| 1419 | } |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 1420 | if (mClearHistoryUrlPattern != null) { |
| 1421 | boolean match = |
| 1422 | mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches(); |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 1423 | if (LOGD_ENABLED) { |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 1424 | Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t" |
| 1425 | + item.getUrl() + "\n\t" |
| 1426 | + mClearHistoryUrlPattern); |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 1427 | } |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 1428 | if (match) { |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 1429 | if (mMainView != null) { |
| 1430 | mMainView.clearHistory(); |
| 1431 | } |
| 1432 | } |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 1433 | mClearHistoryUrlPattern = null; |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 1434 | } |
Leon Scroggins | 0c75a8e | 2010-03-03 16:40:58 -0500 | [diff] [blame] | 1435 | } |
| 1436 | @Override |
| 1437 | public void onIndexChanged(WebHistoryItem item, int index) { |
| 1438 | Object data = item.getCustomData(); |
| 1439 | if (data != null && data instanceof Intent) { |
| 1440 | activateVoiceSearchMode((Intent) data); |
| 1441 | } |
| 1442 | } |
| 1443 | }; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1444 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1445 | mCaptureWidth = mContext.getResources().getDimensionPixelSize( |
| 1446 | R.dimen.tab_thumbnail_width); |
| 1447 | mCaptureHeight = mContext.getResources().getDimensionPixelSize( |
| 1448 | R.dimen.tab_thumbnail_height); |
| 1449 | updateShouldCaptureThumbnails(); |
| 1450 | restoreState(state); |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 1451 | if (getId() == -1) { |
| 1452 | mId = TabControl.getNextId(); |
| 1453 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1454 | setWebView(w); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 1455 | mHandler = new Handler() { |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 1456 | @Override |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 1457 | public void handleMessage(Message m) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1458 | switch (m.what) { |
| 1459 | case MSG_CAPTURE: |
| 1460 | capture(); |
| 1461 | break; |
| 1462 | } |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 1463 | } |
| 1464 | }; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1465 | } |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 1466 | |
Mathew Inwood | e09305e | 2011-09-02 12:03:26 +0100 | [diff] [blame] | 1467 | /** |
| 1468 | * This is used to get a new ID when the tab has been preloaded, before it is displayed and |
| 1469 | * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading |
| 1470 | * to overlapping IDs between the preloaded and restored tabs. |
| 1471 | */ |
| 1472 | public void refreshIdAfterPreload() { |
| 1473 | mId = TabControl.getNextId(); |
| 1474 | } |
| 1475 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1476 | public void updateShouldCaptureThumbnails() { |
| 1477 | if (mWebViewController.shouldCaptureThumbnails()) { |
| 1478 | synchronized (Tab.this) { |
| 1479 | if (mCapture == null) { |
| 1480 | mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight, |
| 1481 | Bitmap.Config.RGB_565); |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 1482 | mCapture.eraseColor(Color.WHITE); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1483 | if (mInForeground) { |
| 1484 | postCapture(); |
| 1485 | } |
| 1486 | } |
| 1487 | } |
| 1488 | } else { |
| 1489 | synchronized (Tab.this) { |
| 1490 | mCapture = null; |
| 1491 | deleteThumbnail(); |
| 1492 | } |
| 1493 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1496 | public void setController(WebViewController ctl) { |
| 1497 | mWebViewController = ctl; |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1498 | updateShouldCaptureThumbnails(); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1501 | public long getId() { |
| 1502 | return mId; |
| 1503 | } |
| 1504 | |
Michael Kolb | 91911a2 | 2012-01-17 11:21:25 -0800 | [diff] [blame] | 1505 | void setWebView(WebView w) { |
| 1506 | setWebView(w, true); |
| 1507 | } |
| 1508 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1509 | /** |
| 1510 | * Sets the WebView for this tab, correctly removing the old WebView from |
| 1511 | * the container view. |
| 1512 | */ |
Michael Kolb | 91911a2 | 2012-01-17 11:21:25 -0800 | [diff] [blame] | 1513 | void setWebView(WebView w, boolean restore) { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1514 | if (mMainView == w) { |
| 1515 | return; |
| 1516 | } |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1517 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1518 | // If the WebView is changing, the page will be reloaded, so any ongoing |
| 1519 | // Geolocation permission requests are void. |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1520 | if (mGeolocationPermissionsPrompt != null) { |
| 1521 | mGeolocationPermissionsPrompt.hide(); |
| 1522 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1523 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1524 | mWebViewController.onSetWebView(this, w); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1525 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1526 | if (mMainView != null) { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 1527 | mMainView.setPictureListener(null); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1528 | if (w != null) { |
| 1529 | syncCurrentState(w, null); |
| 1530 | } else { |
| 1531 | mCurrentState = new PageState(mContext, false); |
| 1532 | } |
| 1533 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1534 | // set the new one |
| 1535 | mMainView = w; |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1536 | // attach the WebViewClient, WebChromeClient and DownloadListener |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1537 | if (mMainView != null) { |
| 1538 | mMainView.setWebViewClient(mWebViewClient); |
| 1539 | mMainView.setWebChromeClient(mWebChromeClient); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1540 | // Attach DownloadManager so that downloads can start in an active |
| 1541 | // or a non-active window. This can happen when going to a site that |
| 1542 | // does a redirect after a period of time. The user could have |
| 1543 | // switched to another tab while waiting for the download to start. |
| 1544 | mMainView.setDownloadListener(mDownloadListener); |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 1545 | getWebViewClassic().setWebBackForwardListClient(mWebBackForwardListClient); |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 1546 | TabControl tc = mWebViewController.getTabControl(); |
| 1547 | if (tc != null && tc.getOnThumbnailUpdatedListener() != null) { |
| 1548 | mMainView.setPictureListener(this); |
| 1549 | } |
Michael Kolb | 91911a2 | 2012-01-17 11:21:25 -0800 | [diff] [blame] | 1550 | if (restore && (mSavedState != null)) { |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 1551 | WebBackForwardList restoredState |
| 1552 | = mMainView.restoreState(mSavedState); |
| 1553 | if (restoredState == null || restoredState.getSize() == 0) { |
| 1554 | Log.w(LOGTAG, "Failed to restore WebView state!"); |
| 1555 | loadUrl(mCurrentState.mOriginalUrl, null); |
| 1556 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1557 | mSavedState = null; |
| 1558 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | /** |
| 1563 | * Destroy the tab's main WebView and subWindow if any |
| 1564 | */ |
| 1565 | void destroy() { |
| 1566 | if (mMainView != null) { |
| 1567 | dismissSubWindow(); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 1568 | // Make sure the embedded title bar isn't still attached |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 1569 | getWebViewClassic().setEmbeddedTitleBar(null); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1570 | // save the WebView to call destroy() after detach it from the tab |
| 1571 | WebView webView = mMainView; |
| 1572 | setWebView(null); |
| 1573 | webView.destroy(); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * Remove the tab from the parent |
| 1579 | */ |
| 1580 | void removeFromTree() { |
| 1581 | // detach the children |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1582 | if (mChildren != null) { |
| 1583 | for(Tab t : mChildren) { |
| 1584 | t.setParent(null); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1585 | } |
| 1586 | } |
| 1587 | // remove itself from the parent list |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1588 | if (mParent != null) { |
| 1589 | mParent.mChildren.remove(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1590 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1591 | deleteThumbnail(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | /** |
| 1595 | * Create a new subwindow unless a subwindow already exists. |
| 1596 | * @return True if a new subwindow was created. False if one already exists. |
| 1597 | */ |
| 1598 | boolean createSubWindow() { |
| 1599 | if (mSubView == null) { |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1600 | mWebViewController.createSubWindow(this); |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 1601 | mSubView.setWebViewClient(new SubWindowClient(mWebViewClient, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1602 | mWebViewController)); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1603 | mSubView.setWebChromeClient(new SubWindowChromeClient( |
| 1604 | mWebChromeClient)); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1605 | // Set a different DownloadListener for the mSubView, since it will |
| 1606 | // just need to dismiss the mSubView, rather than close the Tab |
| 1607 | mSubView.setDownloadListener(new DownloadListener() { |
| 1608 | public void onDownloadStart(String url, String userAgent, |
| 1609 | String contentDisposition, String mimetype, |
| 1610 | long contentLength) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1611 | mWebViewController.onDownloadStart(Tab.this, url, userAgent, |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1612 | contentDisposition, mimetype, contentLength); |
| 1613 | if (mSubView.copyBackForwardList().getSize() == 0) { |
| 1614 | // This subwindow was opened for the sole purpose of |
| 1615 | // downloading a file. Remove it. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1616 | mWebViewController.dismissSubWindow(Tab.this); |
Leon Scroggins | dcc5eeb | 2010-02-23 17:26:37 -0500 | [diff] [blame] | 1617 | } |
| 1618 | } |
| 1619 | }); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1620 | mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity()); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1621 | return true; |
| 1622 | } |
| 1623 | return false; |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * Dismiss the subWindow for the tab. |
| 1628 | */ |
| 1629 | void dismissSubWindow() { |
| 1630 | if (mSubView != null) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1631 | mWebViewController.endActionMode(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1632 | mSubView.destroy(); |
| 1633 | mSubView = null; |
| 1634 | mSubViewContainer = null; |
| 1635 | } |
| 1636 | } |
| 1637 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1638 | |
| 1639 | /** |
| 1640 | * Set the parent tab of this tab. |
| 1641 | */ |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1642 | void setParent(Tab parent) { |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 1643 | if (parent == this) { |
| 1644 | throw new IllegalStateException("Cannot set parent to self!"); |
| 1645 | } |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1646 | mParent = parent; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1647 | // 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] | 1648 | // 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] | 1649 | // (most likely due to removing the parent tab) we must update the |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1650 | // parent tab id in the saved Bundle. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1651 | if (mSavedState != null) { |
| 1652 | if (parent == null) { |
| 1653 | mSavedState.remove(PARENTTAB); |
| 1654 | } else { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1655 | mSavedState.putLong(PARENTTAB, parent.getId()); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1656 | } |
| 1657 | } |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 1658 | |
| 1659 | // Sync the WebView useragent with the parent |
| 1660 | if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView()) |
| 1661 | != mSettings.hasDesktopUseragent(getWebView())) { |
| 1662 | mSettings.toggleDesktopUseragent(getWebView()); |
| 1663 | } |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 1664 | |
| 1665 | if (parent != null && parent.getId() == getId()) { |
| 1666 | throw new IllegalStateException("Parent has same ID as child!"); |
| 1667 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | /** |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1671 | * If this Tab was created through another Tab, then this method returns |
| 1672 | * that Tab. |
| 1673 | * @return the Tab parent or null |
| 1674 | */ |
| 1675 | public Tab getParent() { |
| 1676 | return mParent; |
| 1677 | } |
| 1678 | |
| 1679 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1680 | * When a Tab is created through the content of another Tab, then we |
| 1681 | * associate the Tabs. |
| 1682 | * @param child the Tab that was created from this Tab |
| 1683 | */ |
| 1684 | void addChildTab(Tab child) { |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1685 | if (mChildren == null) { |
| 1686 | mChildren = new Vector<Tab>(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1687 | } |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1688 | mChildren.add(child); |
| 1689 | child.setParent(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1692 | Vector<Tab> getChildren() { |
| 1693 | return mChildren; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | void resume() { |
| 1697 | if (mMainView != null) { |
John Reck | 56c1fcf | 2011-08-17 10:15:16 -0700 | [diff] [blame] | 1698 | setupHwAcceleration(mMainView); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1699 | mMainView.onResume(); |
| 1700 | if (mSubView != null) { |
| 1701 | mSubView.onResume(); |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | |
John Reck | 56c1fcf | 2011-08-17 10:15:16 -0700 | [diff] [blame] | 1706 | private void setupHwAcceleration(View web) { |
| 1707 | if (web == null) return; |
| 1708 | BrowserSettings settings = BrowserSettings.getInstance(); |
| 1709 | if (settings.isHardwareAccelerated()) { |
| 1710 | web.setLayerType(View.LAYER_TYPE_NONE, null); |
| 1711 | } else { |
| 1712 | web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); |
| 1713 | } |
| 1714 | } |
| 1715 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1716 | void pause() { |
| 1717 | if (mMainView != null) { |
| 1718 | mMainView.onPause(); |
| 1719 | if (mSubView != null) { |
| 1720 | mSubView.onPause(); |
| 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | |
| 1725 | void putInForeground() { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 1726 | if (mInForeground) { |
| 1727 | return; |
| 1728 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1729 | mInForeground = true; |
| 1730 | resume(); |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1731 | Activity activity = mWebViewController.getActivity(); |
| 1732 | mMainView.setOnCreateContextMenuListener(activity); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1733 | if (mSubView != null) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1734 | mSubView.setOnCreateContextMenuListener(activity); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1735 | } |
| 1736 | // Show the pending error dialog if the queue is not empty |
| 1737 | if (mQueuedErrors != null && mQueuedErrors.size() > 0) { |
| 1738 | showError(mQueuedErrors.getFirst()); |
| 1739 | } |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 1740 | mWebViewController.bookmarkedStatusHasChanged(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | void putInBackground() { |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 1744 | if (!mInForeground) { |
| 1745 | return; |
| 1746 | } |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 1747 | capture(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1748 | mInForeground = false; |
| 1749 | pause(); |
| 1750 | mMainView.setOnCreateContextMenuListener(null); |
| 1751 | if (mSubView != null) { |
| 1752 | mSubView.setOnCreateContextMenuListener(null); |
| 1753 | } |
| 1754 | } |
| 1755 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1756 | boolean inForeground() { |
| 1757 | return mInForeground; |
| 1758 | } |
| 1759 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1760 | /** |
| 1761 | * Return the top window of this tab; either the subwindow if it is not |
| 1762 | * null or the main window. |
| 1763 | * @return The top window of this tab. |
| 1764 | */ |
| 1765 | WebView getTopWindow() { |
| 1766 | if (mSubView != null) { |
| 1767 | return mSubView; |
| 1768 | } |
| 1769 | return mMainView; |
| 1770 | } |
| 1771 | |
| 1772 | /** |
| 1773 | * Return the main window of this tab. Note: if a tab is freed in the |
| 1774 | * background, this can return null. It is only guaranteed to be |
| 1775 | * non-null for the current tab. |
| 1776 | * @return The main WebView of this tab. |
| 1777 | */ |
| 1778 | WebView getWebView() { |
| 1779 | return mMainView; |
| 1780 | } |
| 1781 | |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 1782 | /** |
| 1783 | * Return the underlying WebViewClassic implementation. As with getWebView, |
| 1784 | * this maybe null for background tabs. |
| 1785 | * @return The main WebView of this tab. |
| 1786 | */ |
| 1787 | WebViewClassic getWebViewClassic() { |
| 1788 | return WebViewClassic.fromWebView(mMainView); |
| 1789 | } |
| 1790 | |
Michael Kolb | a713ec8 | 2010-11-29 17:27:06 -0800 | [diff] [blame] | 1791 | void setViewContainer(View container) { |
| 1792 | mContainer = container; |
| 1793 | } |
| 1794 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1795 | View getViewContainer() { |
| 1796 | return mContainer; |
| 1797 | } |
| 1798 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1799 | /** |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1800 | * Return whether private browsing is enabled for the main window of |
| 1801 | * this tab. |
| 1802 | * @return True if private browsing is enabled. |
| 1803 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1804 | boolean isPrivateBrowsingEnabled() { |
John Reck | 502a353 | 2011-08-16 14:21:46 -0700 | [diff] [blame] | 1805 | return mCurrentState.mIncognito; |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | /** |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1809 | * Return the subwindow of this tab or null if there is no subwindow. |
| 1810 | * @return The subwindow of this tab or null. |
| 1811 | */ |
| 1812 | WebView getSubWebView() { |
| 1813 | return mSubView; |
| 1814 | } |
| 1815 | |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1816 | void setSubWebView(WebView subView) { |
| 1817 | mSubView = subView; |
| 1818 | } |
| 1819 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1820 | View getSubViewContainer() { |
| 1821 | return mSubViewContainer; |
| 1822 | } |
| 1823 | |
Michael Kolb | 1514bb7 | 2010-11-22 09:11:48 -0800 | [diff] [blame] | 1824 | void setSubViewContainer(View subViewContainer) { |
| 1825 | mSubViewContainer = subViewContainer; |
| 1826 | } |
| 1827 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1828 | /** |
| 1829 | * @return The geolocation permissions prompt for this tab. |
| 1830 | */ |
| 1831 | GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() { |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1832 | if (mGeolocationPermissionsPrompt == null) { |
| 1833 | ViewStub stub = (ViewStub) mContainer |
| 1834 | .findViewById(R.id.geolocation_permissions_prompt); |
| 1835 | mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub |
| 1836 | .inflate(); |
Grace Kloba | 50c241e | 2010-04-20 11:07:50 -0700 | [diff] [blame] | 1837 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1838 | return mGeolocationPermissionsPrompt; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * @return The application id string |
| 1843 | */ |
| 1844 | String getAppId() { |
| 1845 | return mAppId; |
| 1846 | } |
| 1847 | |
| 1848 | /** |
| 1849 | * Set the application id string |
| 1850 | * @param id |
| 1851 | */ |
| 1852 | void setAppId(String id) { |
| 1853 | mAppId = id; |
| 1854 | } |
| 1855 | |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 1856 | boolean closeOnBack() { |
| 1857 | return mCloseOnBack; |
| 1858 | } |
| 1859 | |
| 1860 | void setCloseOnBack(boolean close) { |
| 1861 | mCloseOnBack = close; |
| 1862 | } |
| 1863 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1864 | String getUrl() { |
John Reck | 324d440 | 2011-01-11 16:56:42 -0800 | [diff] [blame] | 1865 | return UrlUtils.filteredUrl(mCurrentState.mUrl); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 1868 | String getOriginalUrl() { |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 1869 | if (mCurrentState.mOriginalUrl == null) { |
| 1870 | return getUrl(); |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 1871 | } |
John Reck | db22ec4 | 2011-06-29 11:31:24 -0700 | [diff] [blame] | 1872 | return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl); |
John Reck | 49a603c | 2011-03-03 09:33:05 -0800 | [diff] [blame] | 1873 | } |
| 1874 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1875 | /** |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1876 | * Get the title of this tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1877 | */ |
| 1878 | String getTitle() { |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1879 | if (mCurrentState.mTitle == null && mInPageLoad) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1880 | return mContext.getString(R.string.title_bar_loading); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1881 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1882 | return mCurrentState.mTitle; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /** |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1886 | * Get the favicon of this tab. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1887 | */ |
| 1888 | Bitmap getFavicon() { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1889 | if (mCurrentState.mFavicon != null) { |
| 1890 | return mCurrentState.mFavicon; |
| 1891 | } |
| 1892 | return getDefaultFavicon(mContext); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 1895 | public boolean isBookmarkedSite() { |
| 1896 | return mCurrentState.mIsBookmarkedSite; |
| 1897 | } |
Rob Tsuk | f8bdfce | 2010-10-07 15:41:16 -0700 | [diff] [blame] | 1898 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1899 | /** |
| 1900 | * Return the tab's error console. Creates the console if createIfNEcessary |
| 1901 | * is true and we haven't already created the console. |
| 1902 | * @param createIfNecessary Flag to indicate if the console should be |
| 1903 | * created if it has not been already. |
| 1904 | * @return The tab's error console, or null if one has not been created and |
| 1905 | * createIfNecessary is false. |
| 1906 | */ |
| 1907 | ErrorConsoleView getErrorConsole(boolean createIfNecessary) { |
| 1908 | if (createIfNecessary && mErrorConsole == null) { |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 1909 | mErrorConsole = new ErrorConsoleView(mContext); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1910 | mErrorConsole.setWebView(mMainView); |
| 1911 | } |
| 1912 | return mErrorConsole; |
| 1913 | } |
| 1914 | |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 1915 | /** |
| 1916 | * Sets the security state, clears the SSL certificate error and informs |
| 1917 | * the controller. |
| 1918 | */ |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 1919 | private void setSecurityState(SecurityState securityState) { |
| 1920 | mCurrentState.mSecurityState = securityState; |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 1921 | mCurrentState.mSslCertificateError = null; |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 1922 | mWebViewController.onUpdatedSecurityState(this); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | /** |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 1926 | * @return The tab's security state. |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1927 | */ |
Steve Block | 2466eff | 2011-10-03 15:33:09 +0100 | [diff] [blame] | 1928 | SecurityState getSecurityState() { |
| 1929 | return mCurrentState.mSecurityState; |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1930 | } |
| 1931 | |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 1932 | /** |
| 1933 | * Gets the SSL certificate error, if any, for the page's main resource. |
| 1934 | * This is only non-null when the security state is |
| 1935 | * SECURITY_STATE_BAD_CERTIFICATE. |
| 1936 | */ |
| 1937 | SslError getSslCertificateError() { |
| 1938 | return mCurrentState.mSslCertificateError; |
| 1939 | } |
| 1940 | |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1941 | int getLoadProgress() { |
| 1942 | if (mInPageLoad) { |
| 1943 | return mPageLoadProgress; |
| 1944 | } |
| 1945 | return 100; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * @return TRUE if onPageStarted is called while onPageFinished is not |
| 1950 | * called yet. |
| 1951 | */ |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1952 | boolean inPageLoad() { |
| 1953 | return mInPageLoad; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | // force mInLoad to be false. This should only be called before closing the |
| 1957 | // tab to ensure BrowserActivity's pauseWebViewTimers() is called correctly. |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 1958 | void clearInPageLoad() { |
| 1959 | mInPageLoad = false; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1962 | /** |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1963 | * @return The Bundle with the tab's state if it can be saved, otherwise null |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1964 | */ |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1965 | public Bundle saveState() { |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1966 | // If the WebView is null it means we ran low on memory and we already |
| 1967 | // stored the saved state in mSavedState. |
| 1968 | if (mMainView == null) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1969 | return mSavedState; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1970 | } |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 1971 | |
| 1972 | if (TextUtils.isEmpty(mCurrentState.mUrl)) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1973 | return null; |
John Reck | 24f1826 | 2011-06-17 14:47:20 -0700 | [diff] [blame] | 1974 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1975 | |
| 1976 | mSavedState = new Bundle(); |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 1977 | WebBackForwardList savedList = mMainView.saveState(mSavedState); |
| 1978 | if (savedList == null || savedList.getSize() == 0) { |
| 1979 | Log.w(LOGTAG, "Failed to save back/forward list for " |
| 1980 | + mCurrentState.mUrl); |
| 1981 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1982 | |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1983 | mSavedState.putLong(ID, mId); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 1984 | mSavedState.putString(CURRURL, mCurrentState.mUrl); |
| 1985 | mSavedState.putString(CURRTITLE, mCurrentState.mTitle); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1986 | mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled()); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1987 | if (mAppId != null) { |
| 1988 | mSavedState.putString(APPID, mAppId); |
| 1989 | } |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 1990 | mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1991 | // Remember the parent tab so the relationship can be restored. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 1992 | if (mParent != null) { |
| 1993 | mSavedState.putLong(PARENTTAB, mParent.mId); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1994 | } |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 1995 | mSavedState.putBoolean(USERAGENT, |
| 1996 | mSettings.hasDesktopUseragent(getWebView())); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 1997 | return mSavedState; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /* |
| 2001 | * Restore the state of the tab. |
| 2002 | */ |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2003 | private void restoreState(Bundle b) { |
| 2004 | mSavedState = b; |
| 2005 | if (mSavedState == null) { |
| 2006 | return; |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2007 | } |
| 2008 | // Restore the internal state even if the WebView fails to restore. |
| 2009 | // This will maintain the app id, original url and close-on-exit values. |
Michael Kolb | c831b63 | 2011-05-11 09:30:34 -0700 | [diff] [blame] | 2010 | mId = b.getLong(ID); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2011 | mAppId = b.getString(APPID); |
Michael Kolb | e28b347 | 2011-08-04 16:54:31 -0700 | [diff] [blame] | 2012 | mCloseOnBack = b.getBoolean(CLOSEFLAG); |
John Reck | b0a86db | 2011-05-24 14:05:58 -0700 | [diff] [blame] | 2013 | if (b.getBoolean(USERAGENT) |
| 2014 | != mSettings.hasDesktopUseragent(getWebView())) { |
| 2015 | mSettings.toggleDesktopUseragent(getWebView()); |
| 2016 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2017 | String url = b.getString(CURRURL); |
| 2018 | String title = b.getString(CURRTITLE); |
| 2019 | boolean incognito = b.getBoolean(INCOGNITO); |
| 2020 | mCurrentState = new PageState(mContext, incognito, url, null); |
| 2021 | mCurrentState.mTitle = title; |
| 2022 | synchronized (Tab.this) { |
| 2023 | if (mCapture != null) { |
John Reck | 4eadc34 | 2011-10-31 14:04:10 -0700 | [diff] [blame] | 2024 | DataController.getInstance(mContext).loadThumbnail(this); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2025 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2026 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2027 | } |
Leon Scroggins III | 211ba54 | 2010-04-19 13:21:13 -0400 | [diff] [blame] | 2028 | |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 2029 | public void updateBookmarkedStatus() { |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 2030 | mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback); |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 2031 | } |
| 2032 | |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 2033 | private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback |
| 2034 | = new DataController.OnQueryUrlIsBookmark() { |
| 2035 | @Override |
| 2036 | public void onQueryUrlIsBookmark(String url, boolean isBookmark) { |
| 2037 | if (mCurrentState.mUrl.equals(url)) { |
| 2038 | mCurrentState.mIsBookmarkedSite = isBookmark; |
| 2039 | mWebViewController.bookmarkedStatusHasChanged(Tab.this); |
| 2040 | } |
Leon Scroggins | 1961ed2 | 2010-12-07 15:22:21 -0500 | [diff] [blame] | 2041 | } |
John Reck | e969cc5 | 2010-12-21 17:24:43 -0800 | [diff] [blame] | 2042 | }; |
Michael Kolb | 1acef69 | 2011-03-08 14:12:06 -0800 | [diff] [blame] | 2043 | |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 2044 | public Bitmap getScreenshot() { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2045 | synchronized (Tab.this) { |
| 2046 | return mCapture; |
| 2047 | } |
Michael Kolb | eb95db4 | 2011-03-03 10:38:40 -0800 | [diff] [blame] | 2048 | } |
| 2049 | |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 2050 | public boolean isSnapshot() { |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 2051 | return false; |
| 2052 | } |
| 2053 | |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 2054 | public ContentValues createSnapshotValues() { |
| 2055 | if (mMainView == null) return null; |
John Reck | 9d2718e | 2011-10-05 17:10:17 -0700 | [diff] [blame] | 2056 | SnapshotByteArrayOutputStream bos = new SnapshotByteArrayOutputStream(); |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 2057 | try { |
| 2058 | GZIPOutputStream stream = new GZIPOutputStream(bos); |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 2059 | if (!getWebViewClassic().saveViewState(stream)) { |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 2060 | return null; |
| 2061 | } |
| 2062 | stream.flush(); |
| 2063 | stream.close(); |
| 2064 | } catch (Exception e) { |
| 2065 | Log.w(LOGTAG, "Failed to save view state", e); |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 2066 | return null; |
| 2067 | } |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 2068 | byte[] data = bos.toByteArray(); |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 2069 | ContentValues values = new ContentValues(); |
| 2070 | values.put(Snapshots.TITLE, mCurrentState.mTitle); |
| 2071 | values.put(Snapshots.URL, mCurrentState.mUrl); |
| 2072 | values.put(Snapshots.VIEWSTATE, data); |
Jonathan Dixon | 4d2fcab | 2012-02-24 00:13:06 +0000 | [diff] [blame^] | 2073 | values.put(Snapshots.BACKGROUND, getWebViewClassic().getPageBackgroundColor()); |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 2074 | values.put(Snapshots.DATE_CREATED, System.currentTimeMillis()); |
| 2075 | values.put(Snapshots.FAVICON, compressBitmap(getFavicon())); |
| 2076 | Bitmap screenshot = Controller.createScreenshot(mMainView, |
| 2077 | Controller.getDesiredThumbnailWidth(mContext), |
| 2078 | Controller.getDesiredThumbnailHeight(mContext)); |
| 2079 | values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot)); |
John Reck | d8c7452 | 2011-06-14 08:45:00 -0700 | [diff] [blame] | 2080 | return values; |
John Reck | 541f55a | 2011-06-07 16:34:43 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
John Reck | 8cc9235 | 2011-07-06 17:41:52 -0700 | [diff] [blame] | 2083 | public byte[] compressBitmap(Bitmap bitmap) { |
| 2084 | if (bitmap == null) { |
| 2085 | return null; |
| 2086 | } |
| 2087 | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| 2088 | bitmap.compress(CompressFormat.PNG, 100, stream); |
| 2089 | return stream.toByteArray(); |
| 2090 | } |
| 2091 | |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2092 | public void loadUrl(String url, Map<String, String> headers) { |
| 2093 | if (mMainView != null) { |
Michael Kolb | a53c989 | 2011-10-05 13:31:40 -0700 | [diff] [blame] | 2094 | mPageLoadProgress = INITIAL_PROGRESS; |
| 2095 | mInPageLoad = true; |
Michael Kolb | 1461244 | 2011-06-24 13:06:29 -0700 | [diff] [blame] | 2096 | mCurrentState = new PageState(mContext, false, url, null); |
John Reck | 26b1832 | 2011-06-21 13:08:58 -0700 | [diff] [blame] | 2097 | mWebViewController.onPageStarted(this, mMainView, null); |
| 2098 | mMainView.loadUrl(url, headers); |
| 2099 | } |
| 2100 | } |
| 2101 | |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 2102 | protected void capture() { |
| 2103 | if (mMainView == null || mCapture == null) return; |
John Reck | 4eadc34 | 2011-10-31 14:04:10 -0700 | [diff] [blame] | 2104 | if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) { |
| 2105 | return; |
| 2106 | } |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 2107 | Canvas c = new Canvas(mCapture); |
| 2108 | final int left = mMainView.getScrollX(); |
| 2109 | final int top = mMainView.getScrollY() + mMainView.getVisibleTitleHeight(); |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 2110 | int state = c.save(); |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 2111 | c.translate(-left, -top); |
| 2112 | float scale = mCaptureWidth / (float) mMainView.getWidth(); |
| 2113 | c.scale(scale, scale, left, top); |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 2114 | if (mMainView instanceof BrowserWebView) { |
| 2115 | ((BrowserWebView)mMainView).drawContent(c); |
| 2116 | } else { |
| 2117 | mMainView.draw(c); |
| 2118 | } |
Michael Kolb | a3194d0 | 2011-09-07 11:23:51 -0700 | [diff] [blame] | 2119 | c.restoreToCount(state); |
| 2120 | // manually anti-alias the edges for the tilt |
| 2121 | c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint); |
| 2122 | c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(), |
| 2123 | mCapture.getHeight(), sAlphaPaint); |
| 2124 | c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint); |
| 2125 | c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(), |
| 2126 | mCapture.getHeight(), sAlphaPaint); |
Dianne Hackborn | 43cfe8a | 2011-08-02 16:59:35 -0700 | [diff] [blame] | 2127 | c.setBitmap(null); |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 2128 | mHandler.removeMessages(MSG_CAPTURE); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2129 | persistThumbnail(); |
John Reck | 8ee633f | 2011-08-09 16:00:35 -0700 | [diff] [blame] | 2130 | TabControl tc = mWebViewController.getTabControl(); |
| 2131 | if (tc != null) { |
| 2132 | OnThumbnailUpdatedListener updateListener |
| 2133 | = tc.getOnThumbnailUpdatedListener(); |
| 2134 | if (updateListener != null) { |
| 2135 | updateListener.onThumbnailUpdated(this); |
| 2136 | } |
| 2137 | } |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | @Override |
| 2141 | public void onNewPicture(WebView view, Picture picture) { |
| 2142 | //update screenshot |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2143 | postCapture(); |
| 2144 | } |
| 2145 | |
| 2146 | private void postCapture() { |
Michael Kolb | 9ef259a | 2011-07-12 15:33:08 -0700 | [diff] [blame] | 2147 | if (!mHandler.hasMessages(MSG_CAPTURE)) { |
| 2148 | mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY); |
| 2149 | } |
| 2150 | } |
| 2151 | |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 2152 | public boolean canGoBack() { |
| 2153 | return mMainView != null ? mMainView.canGoBack() : false; |
| 2154 | } |
| 2155 | |
| 2156 | public boolean canGoForward() { |
| 2157 | return mMainView != null ? mMainView.canGoForward() : false; |
| 2158 | } |
| 2159 | |
| 2160 | public void goBack() { |
| 2161 | if (mMainView != null) { |
| 2162 | mMainView.goBack(); |
| 2163 | } |
| 2164 | } |
| 2165 | |
| 2166 | public void goForward() { |
| 2167 | if (mMainView != null) { |
| 2168 | mMainView.goForward(); |
| 2169 | } |
| 2170 | } |
| 2171 | |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 2172 | /** |
| 2173 | * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL |
| 2174 | * to be added to the stack. |
| 2175 | * |
| 2176 | * This is used to ensure that preloaded URLs that are not subsequently seen by the user do |
| 2177 | * not appear in the back stack. |
| 2178 | */ |
Mathew Inwood | a829d55 | 2011-09-02 14:16:25 +0100 | [diff] [blame] | 2179 | public void clearBackStackWhenItemAdded(Pattern urlPattern) { |
| 2180 | mClearHistoryUrlPattern = urlPattern; |
Mathew Inwood | 1dd8e82 | 2011-08-03 14:34:29 +0100 | [diff] [blame] | 2181 | } |
| 2182 | |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2183 | protected void persistThumbnail() { |
John Reck | 4eadc34 | 2011-10-31 14:04:10 -0700 | [diff] [blame] | 2184 | DataController.getInstance(mContext).saveThumbnail(this); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | protected void deleteThumbnail() { |
John Reck | 4eadc34 | 2011-10-31 14:04:10 -0700 | [diff] [blame] | 2188 | DataController.getInstance(mContext).deleteThumbnail(this); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
John Reck | 4eadc34 | 2011-10-31 14:04:10 -0700 | [diff] [blame] | 2191 | void updateCaptureFromBlob(byte[] blob) { |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2192 | synchronized (Tab.this) { |
| 2193 | if (mCapture == null) { |
| 2194 | return; |
| 2195 | } |
Michael Kolb | bd4c00a | 2011-08-02 11:27:12 -0700 | [diff] [blame] | 2196 | ByteBuffer buffer = ByteBuffer.wrap(blob); |
Michael Kolb | d837a11 | 2011-08-09 14:00:18 -0700 | [diff] [blame] | 2197 | try { |
| 2198 | mCapture.copyPixelsFromBuffer(buffer); |
| 2199 | } catch (RuntimeException rex) { |
| 2200 | Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: " |
| 2201 | + buffer.capacity() + " blob: " + blob.length |
| 2202 | + "capture: " + mCapture.getByteCount()); |
| 2203 | throw rex; |
Michael Kolb | bd4c00a | 2011-08-02 11:27:12 -0700 | [diff] [blame] | 2204 | } |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 2205 | } |
| 2206 | } |
| 2207 | |
John Reck | 52be478 | 2011-08-26 15:37:29 -0700 | [diff] [blame] | 2208 | @Override |
| 2209 | public String toString() { |
| 2210 | StringBuilder builder = new StringBuilder(100); |
| 2211 | builder.append(mId); |
| 2212 | builder.append(") has parent: "); |
| 2213 | if (getParent() != null) { |
| 2214 | builder.append("true["); |
| 2215 | builder.append(getParent().getId()); |
| 2216 | builder.append("]"); |
| 2217 | } else { |
| 2218 | builder.append("false"); |
| 2219 | } |
| 2220 | builder.append(", incog: "); |
| 2221 | builder.append(isPrivateBrowsingEnabled()); |
| 2222 | if (!isPrivateBrowsingEnabled()) { |
| 2223 | builder.append(", title: "); |
| 2224 | builder.append(getTitle()); |
| 2225 | builder.append(", url: "); |
| 2226 | builder.append(getUrl()); |
| 2227 | } |
| 2228 | return builder.toString(); |
| 2229 | } |
| 2230 | |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 2231 | private void handleProceededAfterSslError(SslError error) { |
| 2232 | if (error.getUrl().equals(mCurrentState.mUrl)) { |
| 2233 | // The security state should currently be SECURITY_STATE_SECURE. |
| 2234 | setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE); |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 2235 | mCurrentState.mSslCertificateError = error; |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 2236 | } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) { |
Steve Block | 08a6f0c | 2011-10-06 12:12:53 +0100 | [diff] [blame] | 2237 | // The page's main resource is secure and this error is for a |
| 2238 | // sub-resource. |
Steve Block | 4895b01 | 2011-10-03 16:26:46 +0100 | [diff] [blame] | 2239 | setSecurityState(SecurityState.SECURITY_STATE_MIXED); |
| 2240 | } |
| 2241 | } |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 2242 | } |