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