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