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