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