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