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