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