blob: 0a4bc3465e945fd22a63234a47173ab305bea129 [file] [log] [blame]
Grace Kloba22ac16e2009-10-07 18:00:23 -07001/*
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 Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Grace Kloba22ac16e2009-10-07 18:00:23 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
21import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070022import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080023import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.DialogInterface.OnCancelListener;
Pankaj Garg1c13cab2015-05-12 11:52:17 -070026import android.content.res.Configuration;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080027import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070028import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070029import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070030import android.graphics.BitmapFactory;
31import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070032import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070033import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070034import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070035import android.graphics.PorterDuff;
36import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070037import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070038import android.net.Uri;
39import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070040import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070041import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070042import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000043import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070044import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070045import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070046import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070047import android.util.Log;
48import android.view.KeyEvent;
49import android.view.LayoutInflater;
50import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070051import android.view.ViewStub;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080054import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070055import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080056import android.webkit.WebChromeClient.CustomViewCallback;
57import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000058import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000059import android.widget.Toast;
Grace Kloba22ac16e2009-10-07 18:00:23 -070060
Bijan Amirzada41242f22014-03-21 12:12:18 -070061import com.android.browser.TabControl.OnThumbnailUpdatedListener;
62import com.android.browser.homepages.HomeProvider;
63import com.android.browser.mynavigation.MyNavigationUtil;
64import com.android.browser.provider.MyNavigationProvider;
65import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080066
Pankaj Garg18aa0a12015-06-22 11:06:12 -070067import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080068import org.codeaurora.swe.BrowserDownloadListener;
69import org.codeaurora.swe.ClientCertRequestHandler;
70import org.codeaurora.swe.HttpAuthHandler;
71import org.codeaurora.swe.SslErrorHandler;
72import org.codeaurora.swe.WebBackForwardList;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080073import org.codeaurora.swe.WebChromeClient;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080074import org.codeaurora.swe.WebView;
75import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070076import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080077import org.codeaurora.swe.WebViewClient;
Pankaj Garg1c13cab2015-05-12 11:52:17 -070078import org.codeaurora.swe.util.Observable;
Ze G Riande2a675c22015-06-03 11:15:24 -070079import org.codeaurora.swe.DomDistillerUtils;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080080
John Reck541f55a2011-06-07 16:34:43 -070081import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070082import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080083import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070084import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070085import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070086import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070087import java.util.Vector;
Vivek Sekhar53ef8932015-06-18 16:51:43 -070088import java.util.List;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080089import java.sql.Timestamp;
90import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070091
Grace Kloba22ac16e2009-10-07 18:00:23 -070092/**
93 * Class for maintaining Tabs with a main WebView and a subwindow.
94 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070095class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Grace Kloba22ac16e2009-10-07 18:00:23 -070097 // Log Tag
98 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -070099 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000100 // Special case the logtag for messages for the Console to make it easier to
101 // filter them and match the logtag used for these messages in older versions
102 // of the browser.
103 private static final String CONSOLE_LOGTAG = "browser";
104
Michael Kolb9ef259a2011-07-12 15:33:08 -0700105 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800106 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700107 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700108
John Reck1cf4b792011-07-26 10:22:22 -0700109 private static Bitmap sDefaultFavicon;
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700110 private boolean mIsKeyboardUp = false;
John Reck1cf4b792011-07-26 10:22:22 -0700111
Michael Kolba3194d02011-09-07 11:23:51 -0700112 private static Paint sAlphaPaint = new Paint();
113 static {
114 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
115 sAlphaPaint.setColor(Color.TRANSPARENT);
116 }
117
Steve Block2466eff2011-10-03 15:33:09 +0100118 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100119 // The page's main resource does not use SSL. Note that we use this
120 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100121 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100122 // The page's main resource uses SSL and the certificate is good. The
123 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100124 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100125 // The page's main resource uses SSL and the certificate is good, but
126 // some sub-resources either do not use SSL or have problems with their
127 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100128 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100129 // The page's main resource uses SSL but there is a problem with its
130 // certificate.
131 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800132 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700133
Michael Kolb14612442011-06-24 13:06:29 -0700134 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700135 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700136
Michael Kolbc831b632011-05-11 09:30:34 -0700137 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700138 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700139
Grace Kloba22ac16e2009-10-07 18:00:23 -0700140 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800141 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700142 // Main WebView
143 private WebView mMainView;
144 // Subwindow container
145 private View mSubViewContainer;
146 // Subwindow WebView
147 private WebView mSubView;
148 // Saved bundle for when we are running low on memory. It contains the
149 // information needed to restore the WebView if the user goes back to the
150 // tab.
151 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700152 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
153 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700154 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700155 // Tab that constructed by this Tab. This is used when this Tab is
156 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700157 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700158 // If true, the tab is in the foreground of the current activity.
159 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700160 // If true, the tab is in page loading state (after onPageStarted,
161 // before onPageFinsihed)
162 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700163 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700164 private boolean mDisableOverrideUrlLoading;
Pankaj Garg79878492015-04-01 14:48:21 -0700165 private boolean mFirstVisualPixelPainted = false;
John Reck30c714c2010-12-16 17:30:34 -0800166 // The last reported progress of the current page
167 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000168 // The time the load started, used to find load page time
169 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700170 // Application identifier used to find tabs that another application wants
171 // to reuse.
172 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700173 // flag to indicate if tab should be closed on back
174 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700175 // flag to indicate if the tab was opened from an intent
176 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500177 // The listener that gets invoked when a download is started from the
178 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700179 private final BrowserDownloadListener mDownloadListener;
John Recke969cc52010-12-21 17:24:43 -0800180 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700181
182 // AsyncTask for downloading touch icons
183 DownloadTouchIcon mTouchIconLoader;
184
John Reck35e9dd62011-04-25 09:01:54 -0700185 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700186 private int mCaptureWidth;
187 private int mCaptureHeight;
188 private Bitmap mCapture;
189 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700190 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800191 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700192 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800193 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700194
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700195 // determine if webview is destroyed to MemoryMonitor
196 private boolean mWebViewDestroyedByMemoryMonitor;
197
Pankaj Garg21dad562015-07-02 17:17:24 -0700198 private String mTouchIconUrl;
199
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700200 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. Ajmera2fa0ba12015-03-17 18:18:36 -0700210
Ze G Riande2a675c22015-06-03 11:15:24 -0700211 // dertermines if the tab contains a disllable page
212 private boolean mIsDistillable = false;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100213
John Reck1cf4b792011-07-26 10:22:22 -0700214 private static synchronized Bitmap getDefaultFavicon(Context context) {
215 if (sDefaultFavicon == null) {
216 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800217 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700218 }
219 return sDefaultFavicon;
220 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800221
John Reck30c714c2010-12-16 17:30:34 -0800222 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700223 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800224 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700225 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800226 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100227 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100228 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
229 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800230 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100231 boolean mIsBookmarkedSite;
232 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800233
234 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700235 mIncognito = incognito;
236 if (mIncognito) {
Vivek Sekhared791da2015-02-22 12:39:05 -0800237 mOriginalUrl = mUrl = "chrome://incognito";
John Reck30c714c2010-12-16 17:30:34 -0800238 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800239 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700240 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800241 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800242 }
Steve Block2466eff2011-10-03 15:33:09 +0100243 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800244 }
245
246 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700247 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700248 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800249 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100250 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800251 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100252 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800253 }
John Reck1cf4b792011-07-26 10:22:22 -0700254 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800255 }
John Reck1cf4b792011-07-26 10:22:22 -0700256
Grace Kloba22ac16e2009-10-07 18:00:23 -0700257 }
258
John Reck30c714c2010-12-16 17:30:34 -0800259 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700260 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800261
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700263 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700264 static final String CURRURL = "currentUrl";
265 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700266 static final String PARENTTAB = "parentTab";
267 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700268 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700269 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700270 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700271
Pankaj Garg18186a92015-03-31 14:59:33 -0700272 public void setNetworkAvailable(boolean networkUp) {
273 if (networkUp && mReceivedError && (mMainView != null)) {
274 mMainView.reload();
275 }
276 }
277
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700278 public boolean isFirstVisualPixelPainted() {
279 return mFirstVisualPixelPainted;
280 }
281
282 public int getCaptureIndex(int navIndex) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700283 int orientation = mWebViewController.getActivity().
284 getResources().getConfiguration().orientation;
285
286 int orientationBit = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? 0 : 1;
287
Vivek Sekhard0f60402015-06-05 14:07:11 -0700288 int index = orientationBit << 31 | (((int)mId & 0x7f) << 24) | (navIndex & 0xffffff);
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700289 return index;
290 }
291
292 public int getTabIdxFromCaptureIdx(int index) {
293 return (index & 0x7f000000) >> 24;
294 }
295
296 public int getOrientationFromCaptureIdx(int index) {
297 return ((index & 0x80000000) == 0) ? Configuration.ORIENTATION_LANDSCAPE :
298 Configuration.ORIENTATION_PORTRAIT;
299
300 }
301
302 public int getNavIdxFromCaptureIdx(int index) {
303 return (index & 0xffffff);
304 }
305
Grace Kloba22ac16e2009-10-07 18:00:23 -0700306 // -------------------------------------------------------------------------
307 // WebViewClient implementation for the main WebView
308 // -------------------------------------------------------------------------
309
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800310 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500311 private Message mDontResend;
312 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700313
314 private boolean providersDiffer(String url, String otherUrl) {
315 Uri uri1 = Uri.parse(url);
316 Uri uri2 = Uri.parse(otherUrl);
317 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
318 }
319
Grace Kloba22ac16e2009-10-07 18:00:23 -0700320 @Override
321 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Ze G Riande2a675c22015-06-03 11:15:24 -0700322 setIsDistillable(false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700323 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700324 mPageFinished = false;
Pankaj Garg79878492015-04-01 14:48:21 -0700325 mFirstVisualPixelPainted = false;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700326 mFirstPixelObservable.set(false);
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800327 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700328 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700329 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700330 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800331 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000332 mLoadStartTime = SystemClock.uptimeMillis();
Pankaj Garg62bc7912015-04-14 16:08:59 -0700333 // Need re-enable FullScreenMode on Page navigation if needed
334 if (BrowserSettings.getInstance().useFullscreen()){
335 Controller controller = (Controller) mWebViewController;
336 BaseUi ui = (BaseUi) controller.getUi();
337 ui.forceDisableFullscreenMode(false);
338 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700339 // If we start a touch icon load and then load a new page, we don't
340 // want to cancel the current touch icon loader. But, we do want to
341 // create a new one when the touch icon url is known.
342 if (mTouchIconLoader != null) {
343 mTouchIconLoader.mTab = null;
344 mTouchIconLoader = null;
345 }
346
Grace Kloba22ac16e2009-10-07 18:00:23 -0700347 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800348 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500349
John Recke969cc52010-12-21 17:24:43 -0800350 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700351 }
352
353 @Override
354 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700355 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800356 if (!isPrivateBrowsingEnabled()) {
357 LogTag.logPageFinishedLoading(
358 url, SystemClock.uptimeMillis() - mLoadStartTime);
359 }
John Reck1cf4b792011-07-26 10:22:22 -0700360 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800361 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700362 }
363
Pankaj Garg79878492015-04-01 14:48:21 -0700364 @Override
365 public void onFirstVisualPixel(WebView view) {
366 mFirstVisualPixelPainted = true;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700367 mFirstPixelObservable.set(true);
Pankaj Garg79878492015-04-01 14:48:21 -0700368 }
369
Grace Kloba22ac16e2009-10-07 18:00:23 -0700370 // return true if want to hijack the url to let another app to handle it
371 @Override
372 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700373 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800374 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
375 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700376 } else {
377 return false;
378 }
379 }
380
Vivek Sekharb991edb2014-12-17 18:18:07 -0800381 @Override
382 public boolean shouldDownloadFavicon(WebView view, String url) {
383 return true;
384 }
385
Grace Kloba22ac16e2009-10-07 18:00:23 -0700386 /**
Steve Block2466eff2011-10-03 15:33:09 +0100387 * Updates the security state. This method is called when we discover
388 * another resource to be loaded for this page (for example,
389 * javascript). While we update the security state, we do not update
390 * the lock icon until we are done loading, as it is slightly more
391 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700392 */
393 @Override
394 public void onLoadResource(WebView view, String url) {
395 if (url != null && url.length() > 0) {
396 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100397 // to update the security state:
398 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
399 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700400 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
401 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100402 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700403 }
404 }
405 }
406 }
407
408 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700409 * Show a dialog informing the user of the network error reported by
410 * WebCore if it is in the foreground.
411 */
412 @Override
413 public void onReceivedError(WebView view, int errorCode,
414 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800415 // Used for the syncCurrentState to use
416 // the failing url instead of using webview url
417 mReceivedError = true;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700418 }
419
420 /**
421 * Check with the user if it is ok to resend POST data as the page they
422 * are trying to navigate to is the result of a POST.
423 */
424 @Override
425 public void onFormResubmission(WebView view, final Message dontResend,
426 final Message resend) {
427 if (!mInForeground) {
428 dontResend.sendToTarget();
429 return;
430 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500431 if (mDontResend != null) {
432 Log.w(LOGTAG, "onFormResubmission should not be called again "
433 + "while dialog is still up");
434 dontResend.sendToTarget();
435 return;
436 }
437 mDontResend = dontResend;
438 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700439 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700440 R.string.browserFrameFormResubmitLabel).setMessage(
441 R.string.browserFrameFormResubmitMessage)
442 .setPositiveButton(R.string.ok,
443 new DialogInterface.OnClickListener() {
444 public void onClick(DialogInterface dialog,
445 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500446 if (mResend != null) {
447 mResend.sendToTarget();
448 mResend = null;
449 mDontResend = null;
450 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700451 }
452 }).setNegativeButton(R.string.cancel,
453 new DialogInterface.OnClickListener() {
454 public void onClick(DialogInterface dialog,
455 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500456 if (mDontResend != null) {
457 mDontResend.sendToTarget();
458 mResend = null;
459 mDontResend = null;
460 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700461 }
462 }).setOnCancelListener(new OnCancelListener() {
463 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500464 if (mDontResend != null) {
465 mDontResend.sendToTarget();
466 mResend = null;
467 mDontResend = null;
468 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700469 }
470 }).show();
471 }
472
473 /**
474 * Insert the url into the visited history database.
475 * @param url The url to be inserted.
476 * @param isReload True if this url is being reloaded.
477 * FIXME: Not sure what to do when reloading the page.
478 */
479 @Override
480 public void doUpdateVisitedHistory(WebView view, String url,
481 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800482 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700483 }
484
485 /**
486 * Displays SSL error(s) dialog to the user.
487 */
488 @Override
489 public void onReceivedSslError(final WebView view,
490 final SslErrorHandler handler, final SslError error) {
491 if (!mInForeground) {
492 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100493 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700494 return;
495 }
John Reck35e9dd62011-04-25 09:01:54 -0700496 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700497 new AlertDialog.Builder(mContext)
498 .setTitle(R.string.security_warning)
499 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200500 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700501 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700502 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700503 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700504 public void onClick(DialogInterface dialog,
505 int whichButton) {
506 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100507 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700508 }
John Reckcb28b2c2011-08-26 17:39:44 -0700509 })
510 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700511 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700512 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700513 public void onClick(DialogInterface dialog,
514 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700515 mWebViewController.showSslCertificateOnError(
516 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700517 }
John Reckcb28b2c2011-08-26 17:39:44 -0700518 })
519 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700520 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700521 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700522 public void onClick(DialogInterface dialog,
523 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800524 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700525 }
John Reckcb28b2c2011-08-26 17:39:44 -0700526 })
527 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700528 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700529 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700530 public void onCancel(DialogInterface dialog) {
531 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100532 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800533 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700534 }
John Reckcb28b2c2011-08-26 17:39:44 -0700535 })
536 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700537 } else {
538 handler.proceed();
539 }
540 }
541
542 /**
Steve Block4895b012011-10-03 16:26:46 +0100543 * Called when an SSL error occurred while loading a resource, but the
544 * WebView but chose to proceed anyway based on a decision retained
545 * from a previous response to onReceivedSslError(). We update our
546 * security state to reflect this.
547 */
548 @Override
549 public void onProceededAfterSslError(WebView view, SslError error) {
550 handleProceededAfterSslError(error);
551 }
552
553 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700554 * Displays client certificate request to the user.
555 */
556 @Override
557 public void onReceivedClientCertRequest(final WebView view,
558 final ClientCertRequestHandler handler, final String host_and_port) {
559 if (!mInForeground) {
560 handler.ignore();
561 return;
562 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700563 int colon = host_and_port.lastIndexOf(':');
564 String host;
565 int port;
566 if (colon == -1) {
567 host = host_and_port;
568 port = -1;
569 } else {
570 String portString = host_and_port.substring(colon + 1);
571 try {
572 port = Integer.parseInt(portString);
573 host = host_and_port.substring(0, colon);
574 } catch (NumberFormatException e) {
575 host = host_and_port;
576 port = -1;
577 }
578 }
Michael Kolb14612442011-06-24 13:06:29 -0700579 KeyChain.choosePrivateKeyAlias(
580 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Sagar Dhawan49f85cf2015-07-10 16:54:20 -0700581 @Override
582 public void alias(String alias) {
583 if (alias == null) {
584 handler.cancel();
585 return;
586 }
587 new KeyChainLookup(mContext, handler, alias).execute();
588 }
589 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700590 }
591
592 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700593 * Handles an HTTP authentication request.
594 *
595 * @param handler The authentication handler
596 * @param host The host
597 * @param realm The realm
598 */
599 @Override
600 public void onReceivedHttpAuthRequest(WebView view,
601 final HttpAuthHandler handler, final String host,
602 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700604 }
605
606 @Override
John Reck438bf462011-01-12 18:11:46 -0800607 public WebResourceResponse shouldInterceptRequest(WebView view,
608 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800609 //intercept if opening a new incognito tab - show the incognito welcome page
Vivek Sekhared791da2015-02-22 12:39:05 -0800610 if (url.startsWith("chrome://incognito")) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800611 Resources resourceHandle = mContext.getResources();
612 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700613 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800614 return new WebResourceResponse("text/html", "utf8", inStream);
615 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800616 WebResourceResponse res;
617 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
618 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
619 } else {
620 res = HomeProvider.shouldInterceptRequest(mContext, url);
621 }
John Reck438bf462011-01-12 18:11:46 -0800622 return res;
623 }
624
625 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700626 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
627 if (!mInForeground) {
628 return false;
629 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700631 }
632
633 @Override
634 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700636 return;
637 }
John Reck997b1b72012-04-19 18:08:25 -0700638 if (!mWebViewController.onUnhandledKeyEvent(event)) {
639 super.onUnhandledKeyEvent(view, event);
640 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700641 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700642
643 @Override
644 public void beforeNavigation(WebView view, String url) {
Pankaj Garg21dad562015-07-02 17:17:24 -0700645 mTouchIconUrl = null;
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700646 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
647 return;
648 }
649
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700650 if (isPrivateBrowsingEnabled()) {
651 return;
652 }
653
654 if (!mFirstVisualPixelPainted) {
655 return;
656 }
657
658 final int idx = view.copyBackForwardList().getCurrentIndex();
659 boolean bitmapExists = view.hasSnapshot(idx);
660
661 int progress = 100;
662 Controller controller = (Controller)mWebViewController;
663 UI ui = controller.getUi();
664 if (ui instanceof BaseUi) {
665 BaseUi baseUi = (BaseUi) ui;
666 TitleBar titleBar = baseUi.getTitleBar();
667 progress = titleBar.getProgressView().getProgressPercent();
668 }
669
670 if (bitmapExists && progress < 85) {
671 return;
672 }
673
674 int index = getCaptureIndex(view.getLastCommittedHistoryIndex());
Sagar Dhawan49f85cf2015-07-10 16:54:20 -0700675 view.captureSnapshot(index, null);
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700676 }
677
678 @Override
679 public void onHistoryItemCommit(WebView view, int index) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700680 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
681 return;
682 }
683
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700684 mTabHistoryUpdateObservable.set(index);
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700685 final int maxIdx = view.copyBackForwardList().getSize();
686 final WebView wv = view;
687 view.getSnapshotIds(new ValueCallback <List<Integer>>() {
688 @Override
689 public void onReceiveValue(List<Integer> ids) {
690 int currentTabIdx = mWebViewController.getTabControl().getCurrentPosition();
691 for (Integer id : ids) {
692 if (getTabIdxFromCaptureIdx(id) == currentTabIdx &&
693 getNavIdxFromCaptureIdx(id) >= maxIdx) {
694 wv.deleteSnapshot(id);
695 }
696 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700697 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700698 });
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700699 }
Pankaj Garg62bc7912015-04-14 16:08:59 -0700700
701 @Override
702 public void onKeyboardStateChange(boolean popup) {
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700703 mIsKeyboardUp = popup;
Pankaj Garg62bc7912015-04-14 16:08:59 -0700704 if (BrowserSettings.getInstance().useFullscreen()) {
705 Controller controller = (Controller) mWebViewController;
706 BaseUi ui = (BaseUi) controller.getUi();
707 ui.forceDisableFullscreenMode(popup);
708 }
709 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700710 };
711
John Reck1cf4b792011-07-26 10:22:22 -0700712 private void syncCurrentState(WebView view, String url) {
713 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800714
715 if (mReceivedError) {
716 mCurrentState.mUrl = url;
717 mCurrentState.mOriginalUrl = url;
718 } else {
719 mCurrentState.mUrl = view.getUrl();
720 mCurrentState.mOriginalUrl = view.getOriginalUrl();
721 mCurrentState.mFavicon = view.getFavicon();
722 }
723
John Reck1cf4b792011-07-26 10:22:22 -0700724 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700725 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700726 }
John Reck1cf4b792011-07-26 10:22:22 -0700727 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800728
729
John Reck1cf4b792011-07-26 10:22:22 -0700730 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
731 // In case we stop when loading an HTTPS page from an HTTP page
732 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100733 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100734 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700735 }
John Reck502a3532011-08-16 14:21:46 -0700736 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700737 }
738
Pankaj Garg21dad562015-07-02 17:17:24 -0700739 public String getTouchIconUrl() {
740 return mTouchIconUrl;
741 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700742
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700743 public boolean isKeyboardShowing() {
744 Controller controller = (Controller)mWebViewController;
745 return (mIsKeyboardUp || controller.getUi().isEditingUrl());
746 }
747
Tarun Nainani8eb00912014-07-17 12:28:32 -0700748 public boolean isTabFullScreen() {
749 return mFullScreen;
750 }
751
Vivek Sekharf96064b2014-07-28 16:32:34 -0700752 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700753 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700754 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700755 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700756 }
757
Sudheer Koganti24766882014-10-02 10:58:09 -0700758 public boolean exitFullscreen() {
759 if (mFullScreen) {
760 Controller controller = (Controller)mWebViewController;
761 controller.getUi().showFullscreen(false);
762 if (getWebView() != null)
763 getWebView().exitFullscreen();
764 mFullScreen = false;
765 return true;
766 }
767 return false;
768 }
769
770
771
772
Grace Kloba22ac16e2009-10-07 18:00:23 -0700773 // -------------------------------------------------------------------------
774 // WebChromeClient implementation for the main WebView
775 // -------------------------------------------------------------------------
776
777 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
778 // Helper method to create a new tab or sub window.
779 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700780 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700781 }
782
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700783 private void createWindow(final boolean dialog, final Message msg, final String url,
784 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700785 WebView.WebViewTransport transport =
786 (WebView.WebViewTransport) msg.obj;
787 if (dialog) {
788 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700789 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700790 transport.setWebView(mSubView);
791 } else {
Pankaj Garg21dad562015-07-02 17:17:24 -0700792 capture();
793
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700794 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700795 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700796 // This is special case for rendering links on a webpage in
797 // a new tab. If opener is suppressed, the WebContents created
798 // by the content layer are not fully initialized. This check
799 // will prevent content layer from overriding WebContents
800 // created by new tab with the uninitialized instance.
801 if (!opener_suppressed) {
802 transport.setWebView(newTab.getWebView());
803 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700804 }
805 msg.sendToTarget();
806 }
807
808 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700809 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
810 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700811 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700812 }
813 }
814
815 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700816 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
817 float contentOffsetYPix,
818 float overdrawBottomHeightPix) {
819 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700820 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700821 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar11b40062015-06-24 11:49:04 -0700822 // Resize the viewport if top controls is not visible
Vivek Sekhar2ee19a32015-07-02 17:03:57 -0700823 if (mMainView != null &&
824 (topControlsOffsetYPix == 0.0f || contentOffsetYPix == 0.0f))
Vivek Sekhar11b40062015-06-24 11:49:04 -0700825 ((BrowserWebView)mMainView).enableTopControls(
826 (topControlsOffsetYPix == 0.0f) ? true : false);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700827 }
828 }
829
830 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700831 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700832 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700833 }
834
835 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700836 public boolean onCreateWindow(WebView view, final boolean dialog,
837 final boolean userGesture, final Message resultMsg) {
838 // only allow new window or sub window for the foreground case
839 if (!mInForeground) {
840 return false;
841 }
842 // Short-circuit if we can't create any more tabs or sub windows.
843 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700844 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700845 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200846 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700847 .setMessage(R.string.too_many_subwindows_dialog_message)
848 .setPositiveButton(R.string.ok, null)
849 .show();
850 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700851 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700852 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700853 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200854 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700855 .setMessage(R.string.too_many_windows_dialog_message)
856 .setPositiveButton(R.string.ok, null)
857 .show();
858 return false;
859 }
860
861 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800862 if (userGesture || !mSettings.blockPopupWindows()) {
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700863 WebView.WebViewTransport transport =
864 (WebView.WebViewTransport) resultMsg.obj;
865 CreateWindowParams windowParams = transport.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700866 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700867 createWindow(dialog, resultMsg, windowParams.mURL, true);
868 // This is special case for rendering links on a webpage in
869 // a new tab. If opener is suppressed, the WebContents created
870 // by the content layer are not fully initialized. Returning false
871 // will prevent content layer from overriding WebContents
872 // created by new tab with the uninitialized instance.
873 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700874 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700875
876 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700877 return true;
878 }
879
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700880 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700881 return true;
882 }
883
884 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500885 public void onRequestFocus(WebView view) {
886 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700887 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500888 }
889 }
890
891 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700892 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700893 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700894 // JavaScript can only close popup window.
895 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700896 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700897 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700898 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700899 }
900 }
901
902 @Override
903 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800904 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800905 if (newProgress == 100) {
906 mInPageLoad = false;
907 }
John Reck30c714c2010-12-16 17:30:34 -0800908 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700909 if (mUpdateThumbnail && newProgress == 100) {
910 mUpdateThumbnail = false;
911 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700912 }
913
914 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500915 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800916 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700917 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700918 }
919
920 @Override
921 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800922 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700923 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700924 }
925
926 @Override
927 public void onReceivedTouchIconUrl(WebView view, String url,
928 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700929 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400930 // Let precomposed icons take precedence over non-composed
931 // icons.
932 if (precomposed && mTouchIconLoader != null) {
933 mTouchIconLoader.cancel(false);
934 mTouchIconLoader = null;
935 }
936 // Have only one async task at a time.
937 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700938 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700939 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400940 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700941 }
Pankaj Garg21dad562015-07-02 17:17:24 -0700942 mTouchIconUrl = url;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700943 }
944
945 @Override
946 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800947 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700948 Activity activity = mWebViewController.getActivity();
949 if (activity != null) {
950 onShowCustomView(view, activity.getRequestedOrientation(), callback);
951 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400952 }
953
954 @Override
955 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800956 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700957 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400958 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700959 }
960
961 @Override
962 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700963 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700964 }
965
966 /**
967 * The origin has exceeded its database quota.
968 * @param url the URL that exceeded the quota
969 * @param databaseIdentifier the identifier of the database on which the
970 * transaction that caused the quota overflow was run
971 * @param currentQuota the current quota for the origin.
972 * @param estimatedSize the estimated size of the database.
973 * @param totalUsedQuota is the sum of all origins' quota.
974 * @param quotaUpdater The callback to run when a decision to allow or
975 * deny quota has been made. Don't forget to call this!
976 */
977 @Override
978 public void onExceededDatabaseQuota(String url,
979 String databaseIdentifier, long currentQuota, long estimatedSize,
980 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700981 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700982 .onExceededDatabaseQuota(url, databaseIdentifier,
983 currentQuota, estimatedSize, totalUsedQuota,
984 quotaUpdater);
985 }
986
987 /**
988 * The Application Cache has exceeded its max size.
989 * @param spaceNeeded is the amount of disk space that would be needed
990 * in order for the last appcache operation to succeed.
991 * @param totalUsedQuota is the sum of all origins' quota.
992 * @param quotaUpdater A callback to inform the WebCore thread that a
993 * new app cache size is available. This callback must always
994 * be executed at some point to ensure that the sleeping
995 * WebCore thread is woken up.
996 */
997 @Override
998 public void onReachedMaxAppCacheSize(long spaceNeeded,
999 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001000 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001001 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1002 quotaUpdater);
1003 }
1004
Ben Murdoch65acc352009-11-19 18:16:04 +00001005 /* Adds a JavaScript error message to the system log and if the JS
1006 * console is enabled in the about:debug options, to that console
1007 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001008 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001009 */
1010 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001011 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -05001012 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001013 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001014
Ben Murdochc42addf2010-01-28 15:19:59 +00001015 String message = "Console: " + consoleMessage.message() + " "
1016 + consoleMessage.sourceId() + ":"
1017 + consoleMessage.lineNumber();
1018
1019 switch (consoleMessage.messageLevel()) {
1020 case TIP:
1021 Log.v(CONSOLE_LOGTAG, message);
1022 break;
1023 case LOG:
1024 Log.i(CONSOLE_LOGTAG, message);
1025 break;
1026 case WARNING:
1027 Log.w(CONSOLE_LOGTAG, message);
1028 break;
1029 case ERROR:
1030 Log.e(CONSOLE_LOGTAG, message);
1031 break;
1032 case DEBUG:
1033 Log.d(CONSOLE_LOGTAG, message);
1034 break;
1035 }
1036
1037 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001038 }
1039
1040 /**
1041 * Ask the browser for an icon to represent a <video> element.
1042 * This icon will be used if the Web page did not specify a poster attribute.
1043 * @return Bitmap The icon or null if no such icon is available.
1044 */
1045 @Override
1046 public Bitmap getDefaultVideoPoster() {
1047 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001048 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001049 }
1050 return null;
1051 }
1052
1053 /**
1054 * Ask the host application for a custom progress view to show while
1055 * a <video> is loading.
1056 * @return View The progress view.
1057 */
1058 @Override
1059 public View getVideoLoadingProgressView() {
1060 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001061 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001062 }
1063 return null;
1064 }
1065
1066 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001067 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001068 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001069 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001070 } else {
1071 uploadMsg.onReceiveValue(null);
1072 }
1073 }
1074
Vivek Sekharb54614f2014-05-01 19:03:37 -07001075 @Override
1076 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1077 boolean capture) {
1078 if (mInForeground) {
1079 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1080 } else {
1081 uploadFilePaths.onReceiveValue(null);
1082 }
1083 }
1084
Grace Kloba22ac16e2009-10-07 18:00:23 -07001085 /**
1086 * Deliver a list of already-visited URLs
1087 */
1088 @Override
1089 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001090 mWebViewController.getVisitedHistory(callback);
1091 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001092
1093 @Override
1094 public void setupAutoFill(Message message) {
1095 // Prompt the user to set up their profile.
1096 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001097 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1098 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001099 Context.LAYOUT_INFLATER_SERVICE);
1100 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1101
1102 builder.setView(layout)
1103 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1104 @Override
1105 public void onClick(DialogInterface dialog, int id) {
1106 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1107 R.id.setup_autofill_dialog_disable_autofill);
1108
1109 if (disableAutoFill.isChecked()) {
1110 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001111 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001112 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001113 R.string.autofill_setup_dialog_negative_toast,
1114 Toast.LENGTH_LONG).show();
1115 } else {
1116 // Take user to the AutoFill profile editor. When they return,
1117 // we will send the message that we pass here which will trigger
1118 // the form to get filled out with their new profile.
1119 mWebViewController.setupAutoFill(msg);
1120 }
1121 }
1122 })
1123 .setNegativeButton(R.string.cancel, null)
1124 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001125 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001126 };
1127
1128 // -------------------------------------------------------------------------
1129 // WebViewClient implementation for the sub window
1130 // -------------------------------------------------------------------------
1131
1132 // Subclass of WebViewClient used in subwindows to notify the main
1133 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001134 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001135 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001136 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001137 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001138
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001139 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001140 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001141 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001142 }
1143 @Override
1144 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1145 // Unlike the others, do not call mClient's version, which would
1146 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001147 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001148 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001149 }
1150 @Override
1151 public void doUpdateVisitedHistory(WebView view, String url,
1152 boolean isReload) {
1153 mClient.doUpdateVisitedHistory(view, url, isReload);
1154 }
1155 @Override
1156 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1157 return mClient.shouldOverrideUrlLoading(view, url);
1158 }
1159 @Override
1160 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1161 SslError error) {
1162 mClient.onReceivedSslError(view, handler, error);
1163 }
1164 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001165 public void onReceivedClientCertRequest(WebView view,
1166 ClientCertRequestHandler handler, String host_and_port) {
1167 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1168 }
1169 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001170 public void onReceivedHttpAuthRequest(WebView view,
1171 HttpAuthHandler handler, String host, String realm) {
1172 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1173 }
1174 @Override
1175 public void onFormResubmission(WebView view, Message dontResend,
1176 Message resend) {
1177 mClient.onFormResubmission(view, dontResend, resend);
1178 }
1179 @Override
1180 public void onReceivedError(WebView view, int errorCode,
1181 String description, String failingUrl) {
1182 mClient.onReceivedError(view, errorCode, description, failingUrl);
1183 }
1184 @Override
1185 public boolean shouldOverrideKeyEvent(WebView view,
1186 android.view.KeyEvent event) {
1187 return mClient.shouldOverrideKeyEvent(view, event);
1188 }
1189 @Override
1190 public void onUnhandledKeyEvent(WebView view,
1191 android.view.KeyEvent event) {
1192 mClient.onUnhandledKeyEvent(view, event);
1193 }
1194 }
1195
1196 // -------------------------------------------------------------------------
1197 // WebChromeClient implementation for the sub window
1198 // -------------------------------------------------------------------------
1199
1200 private class SubWindowChromeClient extends WebChromeClient {
1201 // The main WebChromeClient.
1202 private final WebChromeClient mClient;
1203
1204 SubWindowChromeClient(WebChromeClient client) {
1205 mClient = client;
1206 }
1207 @Override
1208 public void onProgressChanged(WebView view, int newProgress) {
1209 mClient.onProgressChanged(view, newProgress);
1210 }
1211 @Override
1212 public boolean onCreateWindow(WebView view, boolean dialog,
1213 boolean userGesture, android.os.Message resultMsg) {
1214 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1215 }
1216 @Override
1217 public void onCloseWindow(WebView window) {
1218 if (window != mSubView) {
1219 Log.e(LOGTAG, "Can't close the window");
1220 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001221 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001222 }
1223 }
1224
1225 // -------------------------------------------------------------------------
1226
1227 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001228 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001229 this(wvcontroller, w, null);
1230 }
1231
1232 Tab(WebViewController wvcontroller, Bundle state) {
1233 this(wvcontroller, null, state);
1234 }
1235
1236 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001237 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001238 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001239 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001240 mDataController = DataController.getInstance(mContext);
1241 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001242 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001243 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001244 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001245 mInForeground = false;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001246 mWebViewDestroyedByMemoryMonitor = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001247
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001248 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001249 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001250 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001251 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001252 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001253 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001254 }
1255 };
1256
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001257 mCaptureWidth = mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_width);
1258 mCaptureHeight =mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_height);
1259
1260 initCaptureBitmap();
1261
John Reck1cf4b792011-07-26 10:22:22 -07001262 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001263 if (getId() == -1) {
1264 mId = TabControl.getNextId();
1265 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001266 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001267 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001268 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001269 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001270 switch (m.what) {
1271 case MSG_CAPTURE:
1272 capture();
1273 break;
1274 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001275 }
1276 };
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001277
1278 mFirstPixelObservable = new Observable();
1279 mFirstPixelObservable.set(false);
1280 mTabHistoryUpdateObservable = new Observable();
John Reck1cf4b792011-07-26 10:22:22 -07001281 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001282
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001283 private void initCaptureBitmap() {
1284 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight, Bitmap.Config.RGB_565);
1285 mCapture.eraseColor(Color.WHITE);
Michael Kolb72864272012-05-03 15:42:15 -07001286 }
1287
Mathew Inwoode09305e2011-09-02 12:03:26 +01001288 /**
1289 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1290 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1291 * to overlapping IDs between the preloaded and restored tabs.
1292 */
1293 public void refreshIdAfterPreload() {
1294 mId = TabControl.getNextId();
1295 }
1296
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001297 public void setController(WebViewController ctl) {
1298 mWebViewController = ctl;
1299
John Reck1cf4b792011-07-26 10:22:22 -07001300 if (mWebViewController.shouldCaptureThumbnails()) {
1301 synchronized (Tab.this) {
1302 if (mCapture == null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001303 initCaptureBitmap();
1304 if (mInForeground && !mHandler.hasMessages(MSG_CAPTURE)) {
1305 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
John Reck1cf4b792011-07-26 10:22:22 -07001306 }
1307 }
1308 }
1309 } else {
1310 synchronized (Tab.this) {
1311 mCapture = null;
1312 deleteThumbnail();
1313 }
1314 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001315 }
1316
Michael Kolbc831b632011-05-11 09:30:34 -07001317 public long getId() {
1318 return mId;
1319 }
1320
Michael Kolb91911a22012-01-17 11:21:25 -08001321 void setWebView(WebView w) {
1322 setWebView(w, true);
1323 }
1324
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001325 public boolean isNativeActive(){
1326 if (mMainView == null)
1327 return false;
1328 return true;
1329 }
1330
1331 public void setTimeStamp(){
1332 Date d = new Date();
1333 timestamp = (new Timestamp(d.getTime()));
1334 }
1335
1336 public Timestamp getTimestamp() {
1337 return timestamp;
1338 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001339 /**
1340 * Sets the WebView for this tab, correctly removing the old WebView from
1341 * the container view.
1342 */
Michael Kolb91911a22012-01-17 11:21:25 -08001343 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001344 if (mMainView == w) {
1345 return;
1346 }
Michael Kolba713ec82010-11-29 17:27:06 -08001347
Michael Kolba713ec82010-11-29 17:27:06 -08001348 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001349
John Reck1cf4b792011-07-26 10:22:22 -07001350 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001351 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001352 if (w != null) {
1353 syncCurrentState(w, null);
1354 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001355 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001356
1357 if (mWebViewDestroyedByMemoryMonitor) {
1358 /*
1359 * If tab was destroyed as a result of the MemoryMonitor
1360 * then we need to restore the state properties
1361 * from the old WebView (mMainView)
1362 */
1363 syncCurrentState(mMainView, null);
1364 mWebViewDestroyedByMemoryMonitor = false;
1365 }
John Reck1cf4b792011-07-26 10:22:22 -07001366 }
1367 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001368 // set the new one
1369 mMainView = w;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001370
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001371 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001372 if (mMainView != null) {
1373 mMainView.setWebViewClient(mWebViewClient);
1374 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001375 // Attach DownloadManager so that downloads can start in an active
1376 // or a non-active window. This can happen when going to a site that
1377 // does a redirect after a period of time. The user could have
1378 // switched to another tab while waiting for the download to start.
1379 mMainView.setDownloadListener(mDownloadListener);
John Reck8ee633f2011-08-09 16:00:35 -07001380 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001381 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001382 mMainView.setPictureListener(this);
1383 }
Michael Kolb91911a22012-01-17 11:21:25 -08001384 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001385 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001386 WebBackForwardList restoredState
1387 = mMainView.restoreState(mSavedState);
1388 if (restoredState == null || restoredState.getSize() == 0) {
1389 Log.w(LOGTAG, "Failed to restore WebView state!");
1390 loadUrl(mCurrentState.mOriginalUrl, null);
1391 }
John Reck1cf4b792011-07-26 10:22:22 -07001392 mSavedState = null;
1393 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001394 }
1395 }
1396
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001397 public void destroyThroughMemoryMonitor() {
1398 mWebViewDestroyedByMemoryMonitor = true;
1399 destroy();
1400 }
1401
Grace Kloba22ac16e2009-10-07 18:00:23 -07001402 /**
1403 * Destroy the tab's main WebView and subWindow if any
1404 */
1405 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001406
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001407 if (mPostponeDestroy) {
1408 mShouldDestroy = true;
1409 return;
1410 }
1411 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001412 if (mMainView != null) {
1413 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001414 // save the WebView to call destroy() after detach it from the tab
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001415 final WebView webView = mMainView;
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001416 setWebView(null);
Pankaj Garg18aa0a12015-06-22 11:06:12 -07001417 if (!mWebViewDestroyedByMemoryMonitor &&
1418 !BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001419 // Tabs can be reused with new instance of WebView so delete the snapshots
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001420 webView.getSnapshotIds(new ValueCallback<List<Integer>>() {
1421 @Override
1422 public void onReceiveValue(List<Integer> ids) {
1423 int currentTabIdx = mWebViewController.getTabControl().getCurrentPosition();
1424 for (Integer id : ids) {
1425 if (getTabIdxFromCaptureIdx(id) == currentTabIdx) {
1426 webView.deleteSnapshot(id);
1427 }
1428 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001429 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001430 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001431 });
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001432 } else {
1433 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001434 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001435 }
1436 }
1437
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001438 private boolean mPostponeDestroy = false;
1439 private boolean mShouldDestroy = false;
1440
1441 public void postponeDestroy() {
1442 mPostponeDestroy = true;
1443 }
1444
1445 public void performPostponedDestroy() {
1446 mPostponeDestroy = false;
1447 if (mShouldDestroy) {
1448 destroy();
1449 }
1450 }
1451
Grace Kloba22ac16e2009-10-07 18:00:23 -07001452 /**
1453 * Remove the tab from the parent
1454 */
1455 void removeFromTree() {
1456 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001457 if (mChildren != null) {
1458 for(Tab t : mChildren) {
1459 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001460 }
1461 }
1462 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001463 if (mParent != null) {
1464 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001465 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001466
1467 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001468 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001469 }
1470
1471 /**
1472 * Create a new subwindow unless a subwindow already exists.
1473 * @return True if a new subwindow was created. False if one already exists.
1474 */
1475 boolean createSubWindow() {
1476 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001477 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001478 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001479 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001480 mSubView.setWebChromeClient(new SubWindowChromeClient(
1481 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001482 // Set a different DownloadListener for the mSubView, since it will
1483 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001484 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001485 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001486 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001487 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001488 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001489 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001490 if (mSubView.copyBackForwardList().getSize() == 0) {
1491 // This subwindow was opened for the sole purpose of
1492 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001493 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001494 }
1495 }
1496 });
Michael Kolb14612442011-06-24 13:06:29 -07001497 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001498 return true;
1499 }
1500 return false;
1501 }
1502
1503 /**
1504 * Dismiss the subWindow for the tab.
1505 */
1506 void dismissSubWindow() {
1507 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001508 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001509 mSubView.destroy();
1510 mSubView = null;
1511 mSubViewContainer = null;
1512 }
1513 }
1514
Grace Kloba22ac16e2009-10-07 18:00:23 -07001515
1516 /**
1517 * Set the parent tab of this tab.
1518 */
Michael Kolbc831b632011-05-11 09:30:34 -07001519 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001520 if (parent == this) {
1521 throw new IllegalStateException("Cannot set parent to self!");
1522 }
Michael Kolbc831b632011-05-11 09:30:34 -07001523 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001524 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001525 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001526 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001527 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001528 if (mSavedState != null) {
1529 if (parent == null) {
1530 mSavedState.remove(PARENTTAB);
1531 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001532 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001533 }
1534 }
John Reckb0a86db2011-05-24 14:05:58 -07001535
1536 // Sync the WebView useragent with the parent
1537 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1538 != mSettings.hasDesktopUseragent(getWebView())) {
1539 mSettings.toggleDesktopUseragent(getWebView());
1540 }
John Reck52be4782011-08-26 15:37:29 -07001541
1542 if (parent != null && parent.getId() == getId()) {
1543 throw new IllegalStateException("Parent has same ID as child!");
1544 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001545 }
1546
1547 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001548 * If this Tab was created through another Tab, then this method returns
1549 * that Tab.
1550 * @return the Tab parent or null
1551 */
1552 public Tab getParent() {
1553 return mParent;
1554 }
1555
1556 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001557 * When a Tab is created through the content of another Tab, then we
1558 * associate the Tabs.
1559 * @param child the Tab that was created from this Tab
1560 */
1561 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001562 if (mChildren == null) {
1563 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001564 }
Michael Kolbc831b632011-05-11 09:30:34 -07001565 mChildren.add(child);
1566 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001567 }
1568
Michael Kolbc831b632011-05-11 09:30:34 -07001569 Vector<Tab> getChildren() {
1570 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001571 }
1572
1573 void resume() {
1574 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001575 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001576 mMainView.onResume();
1577 if (mSubView != null) {
1578 mSubView.onResume();
1579 }
1580 }
1581 }
1582
John Reck56c1fcf2011-08-17 10:15:16 -07001583 private void setupHwAcceleration(View web) {
1584 if (web == null) return;
1585 BrowserSettings settings = BrowserSettings.getInstance();
1586 if (settings.isHardwareAccelerated()) {
1587 web.setLayerType(View.LAYER_TYPE_NONE, null);
1588 } else {
1589 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1590 }
1591 }
1592
Grace Kloba22ac16e2009-10-07 18:00:23 -07001593 void pause() {
1594 if (mMainView != null) {
1595 mMainView.onPause();
1596 if (mSubView != null) {
1597 mSubView.onPause();
1598 }
1599 }
1600 }
1601
1602 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001603 if (mInForeground) {
1604 return;
1605 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001606 mInForeground = true;
1607 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001608 Activity activity = mWebViewController.getActivity();
1609 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001610 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001611 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001612 }
Axesh R. Ajmerac6b5c322015-05-01 11:06:10 -07001613
Leon Scroggins1961ed22010-12-07 15:22:21 -05001614 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001615 }
1616
1617 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001618 if (!mInForeground) {
1619 return;
1620 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001621 mInForeground = false;
1622 pause();
1623 mMainView.setOnCreateContextMenuListener(null);
1624 if (mSubView != null) {
1625 mSubView.setOnCreateContextMenuListener(null);
1626 }
1627 }
1628
Michael Kolb8233fac2010-10-26 16:08:53 -07001629 boolean inForeground() {
1630 return mInForeground;
1631 }
1632
Grace Kloba22ac16e2009-10-07 18:00:23 -07001633 /**
1634 * Return the top window of this tab; either the subwindow if it is not
1635 * null or the main window.
1636 * @return The top window of this tab.
1637 */
1638 WebView getTopWindow() {
1639 if (mSubView != null) {
1640 return mSubView;
1641 }
1642 return mMainView;
1643 }
1644
1645 /**
1646 * Return the main window of this tab. Note: if a tab is freed in the
1647 * background, this can return null. It is only guaranteed to be
1648 * non-null for the current tab.
1649 * @return The main WebView of this tab.
1650 */
1651 WebView getWebView() {
1652 return mMainView;
1653 }
1654
Michael Kolba713ec82010-11-29 17:27:06 -08001655 void setViewContainer(View container) {
1656 mContainer = container;
1657 }
1658
Michael Kolb8233fac2010-10-26 16:08:53 -07001659 View getViewContainer() {
1660 return mContainer;
1661 }
1662
Grace Kloba22ac16e2009-10-07 18:00:23 -07001663 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001664 * Return whether private browsing is enabled for the main window of
1665 * this tab.
1666 * @return True if private browsing is enabled.
1667 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001668 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001669 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001670 }
1671
1672 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001673 * Return the subwindow of this tab or null if there is no subwindow.
1674 * @return The subwindow of this tab or null.
1675 */
1676 WebView getSubWebView() {
1677 return mSubView;
1678 }
1679
Michael Kolb1514bb72010-11-22 09:11:48 -08001680 void setSubWebView(WebView subView) {
1681 mSubView = subView;
1682 }
1683
Michael Kolb8233fac2010-10-26 16:08:53 -07001684 View getSubViewContainer() {
1685 return mSubViewContainer;
1686 }
1687
Michael Kolb1514bb72010-11-22 09:11:48 -08001688 void setSubViewContainer(View subViewContainer) {
1689 mSubViewContainer = subViewContainer;
1690 }
1691
Grace Kloba22ac16e2009-10-07 18:00:23 -07001692
1693 /**
1694 * @return The application id string
1695 */
1696 String getAppId() {
1697 return mAppId;
1698 }
1699
1700 /**
1701 * Set the application id string
1702 * @param id
1703 */
1704 void setAppId(String id) {
1705 mAppId = id;
1706 }
1707
Michael Kolbe28b3472011-08-04 16:54:31 -07001708 boolean closeOnBack() {
1709 return mCloseOnBack;
1710 }
1711
1712 void setCloseOnBack(boolean close) {
1713 mCloseOnBack = close;
1714 }
1715
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001716 boolean getDerivedFromIntent() {
1717 return mDerivedFromIntent;
1718 }
1719
1720 void setDerivedFromIntent(boolean derived) {
1721 mDerivedFromIntent = derived;
1722 }
1723
Grace Kloba22ac16e2009-10-07 18:00:23 -07001724 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001725 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001726 }
1727
Tarun Nainani8eb00912014-07-17 12:28:32 -07001728
1729 protected void onPageFinished() {
1730 mPageFinished = true;
Ze G Riande2a675c22015-06-03 11:15:24 -07001731 isDistillable();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001732 }
1733
1734 public boolean getPageFinishedStatus() {
1735 return mPageFinished;
1736 }
1737
John Reck49a603c2011-03-03 09:33:05 -08001738 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001739 if (mCurrentState.mOriginalUrl == null) {
1740 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001741 }
John Reckdb22ec42011-06-29 11:31:24 -07001742 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001743 }
1744
Grace Kloba22ac16e2009-10-07 18:00:23 -07001745 /**
John Reck30c714c2010-12-16 17:30:34 -08001746 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001747 */
1748 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001749 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001750 }
1751
1752 /**
John Reck30c714c2010-12-16 17:30:34 -08001753 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001754 */
1755 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001756 if (mCurrentState.mFavicon != null) {
1757 return mCurrentState.mFavicon;
1758 }
1759 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001760 }
1761
Pankaj Garg32e1b942015-06-03 18:13:24 -07001762 public boolean hasFavicon() {
1763 return mCurrentState.mFavicon != null;
1764 }
1765
John Recke969cc52010-12-21 17:24:43 -08001766 public boolean isBookmarkedSite() {
1767 return mCurrentState.mIsBookmarkedSite;
1768 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001769
Grace Kloba22ac16e2009-10-07 18:00:23 -07001770 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001771 * Sets the security state, clears the SSL certificate error and informs
1772 * the controller.
1773 */
Steve Block2466eff2011-10-03 15:33:09 +01001774 private void setSecurityState(SecurityState securityState) {
1775 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001776 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001777 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001778 }
1779
1780 /**
Steve Block2466eff2011-10-03 15:33:09 +01001781 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001782 */
Steve Block2466eff2011-10-03 15:33:09 +01001783 SecurityState getSecurityState() {
1784 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001785 }
1786
Steve Block08a6f0c2011-10-06 12:12:53 +01001787 /**
1788 * Gets the SSL certificate error, if any, for the page's main resource.
1789 * This is only non-null when the security state is
1790 * SECURITY_STATE_BAD_CERTIFICATE.
1791 */
1792 SslError getSslCertificateError() {
1793 return mCurrentState.mSslCertificateError;
1794 }
1795
John Reck30c714c2010-12-16 17:30:34 -08001796 int getLoadProgress() {
1797 if (mInPageLoad) {
1798 return mPageLoadProgress;
1799 }
1800 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001801 }
1802
1803 /**
1804 * @return TRUE if onPageStarted is called while onPageFinished is not
1805 * called yet.
1806 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001807 boolean inPageLoad() {
1808 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001809 }
1810
Grace Kloba22ac16e2009-10-07 18:00:23 -07001811 /**
John Reck1cf4b792011-07-26 10:22:22 -07001812 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001813 */
John Reck1cf4b792011-07-26 10:22:22 -07001814 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001815 // If the WebView is null it means we ran low on memory and we already
1816 // stored the saved state in mSavedState.
1817 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001818 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001819 }
John Reck6c2e2f32011-08-22 13:41:23 -07001820
1821 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001822 return null;
John Reck24f18262011-06-17 14:47:20 -07001823 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001824
1825 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001826 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1827 if (savedList == null || savedList.getSize() == 0) {
1828 Log.w(LOGTAG, "Failed to save back/forward list for "
1829 + mCurrentState.mUrl);
1830 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001831
Michael Kolbc831b632011-05-11 09:30:34 -07001832 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001833 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1834 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001835 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001836 if (mAppId != null) {
1837 mSavedState.putString(APPID, mAppId);
1838 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001839 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001840 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001841 if (mParent != null) {
1842 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001843 }
John Reckb0a86db2011-05-24 14:05:58 -07001844 mSavedState.putBoolean(USERAGENT,
1845 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001846 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001847 }
1848
1849 /*
1850 * Restore the state of the tab.
1851 */
John Reck1cf4b792011-07-26 10:22:22 -07001852 private void restoreState(Bundle b) {
1853 mSavedState = b;
1854 if (mSavedState == null) {
1855 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001856 }
1857 // Restore the internal state even if the WebView fails to restore.
1858 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001859 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001860 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001861 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001862 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001863 String url = b.getString(CURRURL);
1864 String title = b.getString(CURRTITLE);
1865 boolean incognito = b.getBoolean(INCOGNITO);
1866 mCurrentState = new PageState(mContext, incognito, url, null);
1867 mCurrentState.mTitle = title;
1868 synchronized (Tab.this) {
1869 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001870 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001871 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001872 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001873 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001874
John Reck8b9bb8b2012-03-08 13:19:40 -08001875 private void restoreUserAgent() {
1876 if (mMainView == null || mSavedState == null) {
1877 return;
1878 }
1879 if (mSavedState.getBoolean(USERAGENT)
1880 != mSettings.hasDesktopUseragent(mMainView)) {
1881 mSettings.toggleDesktopUseragent(mMainView);
1882 }
1883 }
1884
Leon Scroggins1961ed22010-12-07 15:22:21 -05001885 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001886 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001887 }
1888
John Recke969cc52010-12-21 17:24:43 -08001889 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1890 = new DataController.OnQueryUrlIsBookmark() {
1891 @Override
1892 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1893 if (mCurrentState.mUrl.equals(url)) {
1894 mCurrentState.mIsBookmarkedSite = isBookmark;
1895 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1896 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001897 }
John Recke969cc52010-12-21 17:24:43 -08001898 };
Michael Kolb1acef692011-03-08 14:12:06 -08001899
Michael Kolbeb95db42011-03-03 10:38:40 -08001900 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001901 synchronized (Tab.this) {
1902 return mCapture;
1903 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001904 }
1905
John Reck541f55a2011-06-07 16:34:43 -07001906 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001907 return false;
1908 }
1909
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001910 private static class SaveCallback implements ValueCallback<String> {
1911 boolean onReceiveValueCalled = false;
1912 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001913
1914 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001915 public void onReceiveValue(String path) {
1916 this.onReceiveValueCalled = true;
1917 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001918 synchronized (this) {
1919 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001920 }
John Reck541f55a2011-06-07 16:34:43 -07001921 }
John Reck68234a92012-04-19 15:27:12 -07001922
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001923 public String getPath() {
1924 return mPath;
1925 }
John Reck68234a92012-04-19 15:27:12 -07001926 }
1927
1928 /**
1929 * Must be called on the UI thread
1930 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001931 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001932 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001933 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001934 ContentValues values = new ContentValues();
1935 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1936 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001937 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001938 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1939 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001940 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07001941 return values;
John Reck541f55a2011-06-07 16:34:43 -07001942 }
1943
John Reck68234a92012-04-19 15:27:12 -07001944 /**
1945 * Probably want to call this on a background thread
1946 */
1947 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001948 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001949 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001950 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07001951 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07001952 try {
John Reck68234a92012-04-19 15:27:12 -07001953 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001954 web.saveViewState(filename, callback);
1955 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07001956 }
John Reck68234a92012-04-19 15:27:12 -07001957 } catch (Exception e) {
1958 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001959 String path = callback.getPath();
1960 if (path != null) {
1961 File file = mContext.getFileStreamPath(path);
1962 if (file.exists() && !file.delete()) {
1963 file.deleteOnExit();
1964 }
John Reck68234a92012-04-19 15:27:12 -07001965 }
1966 return false;
1967 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001968
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001969 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001970 // could be that saving of file failed
1971 if (path == null) {
1972 return false;
1973 }
1974
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001975 File savedFile = new File(path);
1976 if (!savedFile.exists()) {
1977 return false;
John Reck68234a92012-04-19 15:27:12 -07001978 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001979 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
1980 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07001981 return true;
1982 }
1983
John Reck8cc92352011-07-06 17:41:52 -07001984 public byte[] compressBitmap(Bitmap bitmap) {
1985 if (bitmap == null) {
1986 return null;
1987 }
1988 ByteArrayOutputStream stream = new ByteArrayOutputStream();
1989 bitmap.compress(CompressFormat.PNG, 100, stream);
1990 return stream.toByteArray();
1991 }
1992
John Reck26b18322011-06-21 13:08:58 -07001993 public void loadUrl(String url, Map<String, String> headers) {
1994 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07001995 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07001996 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07001997 mMainView.loadUrl(url, headers);
1998 }
1999 }
2000
John Reck38b39652012-06-05 09:22:59 -07002001 public void disableUrlOverridingForLoad() {
2002 mDisableOverrideUrlLoading = true;
2003 }
2004
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002005 private void thumbnailUpdated() {
John Reck8ee633f2011-08-09 16:00:35 -07002006 mHandler.removeMessages(MSG_CAPTURE);
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002007
John Reck8ee633f2011-08-09 16:00:35 -07002008 TabControl tc = mWebViewController.getTabControl();
2009 if (tc != null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002010 OnThumbnailUpdatedListener updateListener = tc.getOnThumbnailUpdatedListener();
John Reck8ee633f2011-08-09 16:00:35 -07002011 if (updateListener != null) {
2012 updateListener.onThumbnailUpdated(this);
2013 }
2014 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002015 }
2016
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002017 protected void capture() {
2018 if (mMainView == null || mCapture == null || !mMainView.isReady() ||
2019 mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0 ||
2020 !mFirstVisualPixelPainted || mMainView.isShowingCrashView()) {
2021
2022 initCaptureBitmap();
2023 thumbnailUpdated();
2024 return;
2025 }
2026
2027 mMainView.getContentBitmapAsync((float) mCaptureWidth / mMainView.getWidth(), new Rect(),
2028 new ValueCallback<Bitmap>() {
2029 @Override
2030 public void onReceiveValue(Bitmap bitmap) {
2031 if (mCapture == null) {
2032 initCaptureBitmap();
2033 }
2034
2035 if (bitmap == null) {
2036 thumbnailUpdated();
2037 return;
2038 }
2039
2040 Canvas c = new Canvas(mCapture);
2041 mCapture.eraseColor(Color.WHITE);
2042 c.drawBitmap(bitmap, 0, 0, null);
2043
2044 // manually anti-alias the edges for the tilt
2045 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2046 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2047 mCapture.getHeight(), sAlphaPaint);
2048 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2049 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2050 mCapture.getHeight(), sAlphaPaint);
2051 c.setBitmap(null);
2052
2053 persistThumbnail();
2054 thumbnailUpdated();
2055 }
2056 }
2057 );
John Reck1cf4b792011-07-26 10:22:22 -07002058 }
2059
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002060 @Override
2061 public void onNewPicture(WebView view, Picture picture) {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002062 }
2063
John Reckef654f12011-07-12 16:42:08 -07002064 public boolean canGoBack() {
2065 return mMainView != null ? mMainView.canGoBack() : false;
2066 }
2067
2068 public boolean canGoForward() {
2069 return mMainView != null ? mMainView.canGoForward() : false;
2070 }
2071
2072 public void goBack() {
2073 if (mMainView != null) {
2074 mMainView.goBack();
2075 }
2076 }
2077
2078 public void goForward() {
2079 if (mMainView != null) {
2080 mMainView.goForward();
2081 }
2082 }
2083
John Reck1cf4b792011-07-26 10:22:22 -07002084 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002085 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002086 }
2087
2088 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002089 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002090 }
2091
John Reck4eadc342011-10-31 14:04:10 -07002092 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002093 synchronized (Tab.this) {
2094 if (mCapture == null) {
2095 return;
2096 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002097 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002098 try {
2099 mCapture.copyPixelsFromBuffer(buffer);
2100 } catch (RuntimeException rex) {
2101 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2102 + buffer.capacity() + " blob: " + blob.length
2103 + "capture: " + mCapture.getByteCount());
2104 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002105 }
John Reck1cf4b792011-07-26 10:22:22 -07002106 }
2107 }
2108
John Reck52be4782011-08-26 15:37:29 -07002109 @Override
2110 public String toString() {
2111 StringBuilder builder = new StringBuilder(100);
2112 builder.append(mId);
2113 builder.append(") has parent: ");
2114 if (getParent() != null) {
2115 builder.append("true[");
2116 builder.append(getParent().getId());
2117 builder.append("]");
2118 } else {
2119 builder.append("false");
2120 }
2121 builder.append(", incog: ");
2122 builder.append(isPrivateBrowsingEnabled());
2123 if (!isPrivateBrowsingEnabled()) {
2124 builder.append(", title: ");
2125 builder.append(getTitle());
2126 builder.append(", url: ");
2127 builder.append(getUrl());
2128 }
2129 return builder.toString();
2130 }
2131
Steve Block4895b012011-10-03 16:26:46 +01002132 private void handleProceededAfterSslError(SslError error) {
2133 if (error.getUrl().equals(mCurrentState.mUrl)) {
2134 // The security state should currently be SECURITY_STATE_SECURE.
2135 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002136 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002137 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002138 // The page's main resource is secure and this error is for a
2139 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002140 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2141 }
2142 }
Ze G Riande2a675c22015-06-03 11:15:24 -07002143
2144 // dertermines if the tab contains a dislled page
2145 public boolean isDistilled() {
2146 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2147 return false;
2148 }
2149 try {
2150 return DomDistillerUtils.isUrlDistilled(getUrl());
2151 } catch (Exception e) {
2152 return false;
2153 }
2154 }
2155
2156 //determines if the tab contains a distillable page
2157 public boolean isDistillable() {
2158 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2159 mIsDistillable = false;
2160 return mIsDistillable;
2161 }
2162 final ValueCallback<String> onIsDistillable = new ValueCallback<String>() {
2163 @Override
2164 public void onReceiveValue(String str) {
2165 mIsDistillable = Boolean.parseBoolean(str);
2166 }
2167 };
2168
2169 if (isDistilled()) {
2170 mIsDistillable = true;
2171 return mIsDistillable;
2172 }
2173
2174 try {
2175 DomDistillerUtils.isWebViewDistillable(getWebView(), onIsDistillable);
2176 } catch (Exception e) {
2177 mIsDistillable = false;
2178 }
2179
2180 return mIsDistillable;
2181 }
2182
2183 // Function that sets the mIsDistillable variable
2184 public void setIsDistillable(boolean value) {
2185 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2186 mIsDistillable = false;
2187 }
2188 mIsDistillable = value;
2189 }
2190
2191 // Function that returns the distilled url of the current url
2192 public String getDistilledUrl() {
2193 if (getUrl() != null) {
2194 return DomDistillerUtils.getDistilledUrl(getUrl());
2195 }
2196 return new String();
2197 }
2198
2199 // function that returns the non-distilled version of the current url
2200 public String getNonDistilledUrl() {
2201 if (getUrl() != null) {
2202 return DomDistillerUtils.getOriginalUrlFromDistilledUrl(getUrl());
2203 }
2204 return new String();
2205 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002206}