blob: 4b361a1b3e53c83660cc218db6d1cda03f77daf0 [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;
110
Michael Kolba3194d02011-09-07 11:23:51 -0700111 private static Paint sAlphaPaint = new Paint();
112 static {
113 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
114 sAlphaPaint.setColor(Color.TRANSPARENT);
115 }
116
Steve Block2466eff2011-10-03 15:33:09 +0100117 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100118 // The page's main resource does not use SSL. Note that we use this
119 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100120 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100121 // The page's main resource uses SSL and the certificate is good. The
122 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100123 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100124 // The page's main resource uses SSL and the certificate is good, but
125 // some sub-resources either do not use SSL or have problems with their
126 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100127 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100128 // The page's main resource uses SSL but there is a problem with its
129 // certificate.
130 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800131 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700132
Michael Kolb14612442011-06-24 13:06:29 -0700133 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700134 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700135
Michael Kolbc831b632011-05-11 09:30:34 -0700136 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700137 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700138
Grace Kloba22ac16e2009-10-07 18:00:23 -0700139 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800140 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700141 // Main WebView
142 private WebView mMainView;
143 // Subwindow container
144 private View mSubViewContainer;
145 // Subwindow WebView
146 private WebView mSubView;
147 // Saved bundle for when we are running low on memory. It contains the
148 // information needed to restore the WebView if the user goes back to the
149 // tab.
150 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700151 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
152 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700153 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700154 // Tab that constructed by this Tab. This is used when this Tab is
155 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700156 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700157 // If true, the tab is in the foreground of the current activity.
158 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700159 // If true, the tab is in page loading state (after onPageStarted,
160 // before onPageFinsihed)
161 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700162 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700163 private boolean mDisableOverrideUrlLoading;
Pankaj Garg79878492015-04-01 14:48:21 -0700164 private boolean mFirstVisualPixelPainted = false;
John Reck30c714c2010-12-16 17:30:34 -0800165 // The last reported progress of the current page
166 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000167 // The time the load started, used to find load page time
168 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700169 // Application identifier used to find tabs that another application wants
170 // to reuse.
171 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700172 // flag to indicate if tab should be closed on back
173 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700174 // flag to indicate if the tab was opened from an intent
175 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500176 // The listener that gets invoked when a download is started from the
177 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700178 private final BrowserDownloadListener mDownloadListener;
John Recke969cc52010-12-21 17:24:43 -0800179 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700180
181 // AsyncTask for downloading touch icons
182 DownloadTouchIcon mTouchIconLoader;
183
John Reck35e9dd62011-04-25 09:01:54 -0700184 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700185 private int mCaptureWidth;
186 private int mCaptureHeight;
187 private Bitmap mCapture;
188 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700189 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800190 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700191 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800192 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700193
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700194 // determine if webview is destroyed to MemoryMonitor
195 private boolean mWebViewDestroyedByMemoryMonitor;
196
Pankaj Garg21dad562015-07-02 17:17:24 -0700197 private String mTouchIconUrl;
198
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700199 private Observable mFirstPixelObservable;
200 private Observable mTabHistoryUpdateObservable;
201
202 Observable getFirstPixelObservable() {
203 return mFirstPixelObservable;
204 }
205
206 Observable getTabHistoryUpdateObservable() {
207 return mTabHistoryUpdateObservable;
208 }
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700209
Ze G Riande2a675c22015-06-03 11:15:24 -0700210 // dertermines if the tab contains a disllable page
211 private boolean mIsDistillable = false;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100212
John Reck1cf4b792011-07-26 10:22:22 -0700213 private static synchronized Bitmap getDefaultFavicon(Context context) {
214 if (sDefaultFavicon == null) {
215 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800216 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700217 }
218 return sDefaultFavicon;
219 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800220
John Reck30c714c2010-12-16 17:30:34 -0800221 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700222 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800223 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700224 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800225 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100226 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100227 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
228 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800229 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100230 boolean mIsBookmarkedSite;
231 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800232
233 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700234 mIncognito = incognito;
235 if (mIncognito) {
Vivek Sekhared791da2015-02-22 12:39:05 -0800236 mOriginalUrl = mUrl = "chrome://incognito";
John Reck30c714c2010-12-16 17:30:34 -0800237 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800238 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700239 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800240 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800241 }
Steve Block2466eff2011-10-03 15:33:09 +0100242 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800243 }
244
245 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700246 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700247 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800248 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100249 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800250 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100251 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800252 }
John Reck1cf4b792011-07-26 10:22:22 -0700253 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800254 }
John Reck1cf4b792011-07-26 10:22:22 -0700255
Grace Kloba22ac16e2009-10-07 18:00:23 -0700256 }
257
John Reck30c714c2010-12-16 17:30:34 -0800258 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700259 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800260
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700262 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700263 static final String CURRURL = "currentUrl";
264 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700265 static final String PARENTTAB = "parentTab";
266 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700267 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700268 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700269 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700270
Pankaj Garg18186a92015-03-31 14:59:33 -0700271 public void setNetworkAvailable(boolean networkUp) {
272 if (networkUp && mReceivedError && (mMainView != null)) {
273 mMainView.reload();
274 }
275 }
276
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700277 public boolean isFirstVisualPixelPainted() {
278 return mFirstVisualPixelPainted;
279 }
280
281 public int getCaptureIndex(int navIndex) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700282 int orientation = mWebViewController.getActivity().
283 getResources().getConfiguration().orientation;
284
285 int orientationBit = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? 0 : 1;
286
Vivek Sekhard0f60402015-06-05 14:07:11 -0700287 int index = orientationBit << 31 | (((int)mId & 0x7f) << 24) | (navIndex & 0xffffff);
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700288 return index;
289 }
290
291 public int getTabIdxFromCaptureIdx(int index) {
292 return (index & 0x7f000000) >> 24;
293 }
294
295 public int getOrientationFromCaptureIdx(int index) {
296 return ((index & 0x80000000) == 0) ? Configuration.ORIENTATION_LANDSCAPE :
297 Configuration.ORIENTATION_PORTRAIT;
298
299 }
300
301 public int getNavIdxFromCaptureIdx(int index) {
302 return (index & 0xffffff);
303 }
304
Grace Kloba22ac16e2009-10-07 18:00:23 -0700305 // -------------------------------------------------------------------------
306 // WebViewClient implementation for the main WebView
307 // -------------------------------------------------------------------------
308
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800309 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500310 private Message mDontResend;
311 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700312
313 private boolean providersDiffer(String url, String otherUrl) {
314 Uri uri1 = Uri.parse(url);
315 Uri uri2 = Uri.parse(otherUrl);
316 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
317 }
318
Grace Kloba22ac16e2009-10-07 18:00:23 -0700319 @Override
320 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Ze G Riande2a675c22015-06-03 11:15:24 -0700321 setIsDistillable(false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700322 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700323 mPageFinished = false;
Pankaj Garg79878492015-04-01 14:48:21 -0700324 mFirstVisualPixelPainted = false;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700325 mFirstPixelObservable.set(false);
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800326 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700327 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700328 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700329 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800330 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000331 mLoadStartTime = SystemClock.uptimeMillis();
Pankaj Garg62bc7912015-04-14 16:08:59 -0700332 // Need re-enable FullScreenMode on Page navigation if needed
333 if (BrowserSettings.getInstance().useFullscreen()){
334 Controller controller = (Controller) mWebViewController;
335 BaseUi ui = (BaseUi) controller.getUi();
336 ui.forceDisableFullscreenMode(false);
337 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700338 // If we start a touch icon load and then load a new page, we don't
339 // want to cancel the current touch icon loader. But, we do want to
340 // create a new one when the touch icon url is known.
341 if (mTouchIconLoader != null) {
342 mTouchIconLoader.mTab = null;
343 mTouchIconLoader = null;
344 }
345
Grace Kloba22ac16e2009-10-07 18:00:23 -0700346 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800347 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500348
John Recke969cc52010-12-21 17:24:43 -0800349 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700350 }
351
352 @Override
353 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700354 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800355 if (!isPrivateBrowsingEnabled()) {
356 LogTag.logPageFinishedLoading(
357 url, SystemClock.uptimeMillis() - mLoadStartTime);
358 }
John Reck1cf4b792011-07-26 10:22:22 -0700359 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800360 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700361 }
362
Pankaj Garg79878492015-04-01 14:48:21 -0700363 @Override
364 public void onFirstVisualPixel(WebView view) {
365 mFirstVisualPixelPainted = true;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700366 mFirstPixelObservable.set(true);
Pankaj Garg79878492015-04-01 14:48:21 -0700367 }
368
Grace Kloba22ac16e2009-10-07 18:00:23 -0700369 // return true if want to hijack the url to let another app to handle it
370 @Override
371 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700372 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800373 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
374 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700375 } else {
376 return false;
377 }
378 }
379
Vivek Sekharb991edb2014-12-17 18:18:07 -0800380 @Override
381 public boolean shouldDownloadFavicon(WebView view, String url) {
382 return true;
383 }
384
Grace Kloba22ac16e2009-10-07 18:00:23 -0700385 /**
Steve Block2466eff2011-10-03 15:33:09 +0100386 * Updates the security state. This method is called when we discover
387 * another resource to be loaded for this page (for example,
388 * javascript). While we update the security state, we do not update
389 * the lock icon until we are done loading, as it is slightly more
390 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700391 */
392 @Override
393 public void onLoadResource(WebView view, String url) {
394 if (url != null && url.length() > 0) {
395 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100396 // to update the security state:
397 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
398 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700399 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
400 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100401 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700402 }
403 }
404 }
405 }
406
407 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700408 * Show a dialog informing the user of the network error reported by
409 * WebCore if it is in the foreground.
410 */
411 @Override
412 public void onReceivedError(WebView view, int errorCode,
413 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800414 // Used for the syncCurrentState to use
415 // the failing url instead of using webview url
416 mReceivedError = true;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700417 }
418
419 /**
420 * Check with the user if it is ok to resend POST data as the page they
421 * are trying to navigate to is the result of a POST.
422 */
423 @Override
424 public void onFormResubmission(WebView view, final Message dontResend,
425 final Message resend) {
426 if (!mInForeground) {
427 dontResend.sendToTarget();
428 return;
429 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500430 if (mDontResend != null) {
431 Log.w(LOGTAG, "onFormResubmission should not be called again "
432 + "while dialog is still up");
433 dontResend.sendToTarget();
434 return;
435 }
436 mDontResend = dontResend;
437 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700438 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700439 R.string.browserFrameFormResubmitLabel).setMessage(
440 R.string.browserFrameFormResubmitMessage)
441 .setPositiveButton(R.string.ok,
442 new DialogInterface.OnClickListener() {
443 public void onClick(DialogInterface dialog,
444 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500445 if (mResend != null) {
446 mResend.sendToTarget();
447 mResend = null;
448 mDontResend = null;
449 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700450 }
451 }).setNegativeButton(R.string.cancel,
452 new DialogInterface.OnClickListener() {
453 public void onClick(DialogInterface dialog,
454 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500455 if (mDontResend != null) {
456 mDontResend.sendToTarget();
457 mResend = null;
458 mDontResend = null;
459 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700460 }
461 }).setOnCancelListener(new OnCancelListener() {
462 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500463 if (mDontResend != null) {
464 mDontResend.sendToTarget();
465 mResend = null;
466 mDontResend = null;
467 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700468 }
469 }).show();
470 }
471
472 /**
473 * Insert the url into the visited history database.
474 * @param url The url to be inserted.
475 * @param isReload True if this url is being reloaded.
476 * FIXME: Not sure what to do when reloading the page.
477 */
478 @Override
479 public void doUpdateVisitedHistory(WebView view, String url,
480 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800481 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700482 }
483
484 /**
485 * Displays SSL error(s) dialog to the user.
486 */
487 @Override
488 public void onReceivedSslError(final WebView view,
489 final SslErrorHandler handler, final SslError error) {
490 if (!mInForeground) {
491 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100492 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700493 return;
494 }
John Reck35e9dd62011-04-25 09:01:54 -0700495 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700496 new AlertDialog.Builder(mContext)
497 .setTitle(R.string.security_warning)
498 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200499 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700500 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700501 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700502 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700503 public void onClick(DialogInterface dialog,
504 int whichButton) {
505 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100506 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700507 }
John Reckcb28b2c2011-08-26 17:39:44 -0700508 })
509 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700510 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700511 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700512 public void onClick(DialogInterface dialog,
513 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700514 mWebViewController.showSslCertificateOnError(
515 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700516 }
John Reckcb28b2c2011-08-26 17:39:44 -0700517 })
518 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700519 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700520 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700521 public void onClick(DialogInterface dialog,
522 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800523 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700524 }
John Reckcb28b2c2011-08-26 17:39:44 -0700525 })
526 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700527 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700528 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700529 public void onCancel(DialogInterface dialog) {
530 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100531 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800532 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700533 }
John Reckcb28b2c2011-08-26 17:39:44 -0700534 })
535 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700536 } else {
537 handler.proceed();
538 }
539 }
540
541 /**
Steve Block4895b012011-10-03 16:26:46 +0100542 * Called when an SSL error occurred while loading a resource, but the
543 * WebView but chose to proceed anyway based on a decision retained
544 * from a previous response to onReceivedSslError(). We update our
545 * security state to reflect this.
546 */
547 @Override
548 public void onProceededAfterSslError(WebView view, SslError error) {
549 handleProceededAfterSslError(error);
550 }
551
552 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700553 * Displays client certificate request to the user.
554 */
555 @Override
556 public void onReceivedClientCertRequest(final WebView view,
557 final ClientCertRequestHandler handler, final String host_and_port) {
558 if (!mInForeground) {
559 handler.ignore();
560 return;
561 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700562 int colon = host_and_port.lastIndexOf(':');
563 String host;
564 int port;
565 if (colon == -1) {
566 host = host_and_port;
567 port = -1;
568 } else {
569 String portString = host_and_port.substring(colon + 1);
570 try {
571 port = Integer.parseInt(portString);
572 host = host_and_port.substring(0, colon);
573 } catch (NumberFormatException e) {
574 host = host_and_port;
575 port = -1;
576 }
577 }
Michael Kolb14612442011-06-24 13:06:29 -0700578 KeyChain.choosePrivateKeyAlias(
579 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700580 @Override public void alias(String alias) {
581 if (alias == null) {
582 handler.cancel();
583 return;
584 }
Michael Kolb14612442011-06-24 13:06:29 -0700585 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700586 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700587 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700588 }
589
590 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700591 * Handles an HTTP authentication request.
592 *
593 * @param handler The authentication handler
594 * @param host The host
595 * @param realm The realm
596 */
597 @Override
598 public void onReceivedHttpAuthRequest(WebView view,
599 final HttpAuthHandler handler, final String host,
600 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700602 }
603
604 @Override
John Reck438bf462011-01-12 18:11:46 -0800605 public WebResourceResponse shouldInterceptRequest(WebView view,
606 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800607 //intercept if opening a new incognito tab - show the incognito welcome page
Vivek Sekhared791da2015-02-22 12:39:05 -0800608 if (url.startsWith("chrome://incognito")) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800609 Resources resourceHandle = mContext.getResources();
610 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700611 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800612 return new WebResourceResponse("text/html", "utf8", inStream);
613 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800614 WebResourceResponse res;
615 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
616 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
617 } else {
618 res = HomeProvider.shouldInterceptRequest(mContext, url);
619 }
John Reck438bf462011-01-12 18:11:46 -0800620 return res;
621 }
622
623 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700624 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
625 if (!mInForeground) {
626 return false;
627 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700628 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700629 }
630
631 @Override
632 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700633 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700634 return;
635 }
John Reck997b1b72012-04-19 18:08:25 -0700636 if (!mWebViewController.onUnhandledKeyEvent(event)) {
637 super.onUnhandledKeyEvent(view, event);
638 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700639 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700640
641 @Override
642 public void beforeNavigation(WebView view, String url) {
Pankaj Garg21dad562015-07-02 17:17:24 -0700643 mTouchIconUrl = null;
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700644 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
645 return;
646 }
647
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700648 if (isPrivateBrowsingEnabled()) {
649 return;
650 }
651
652 if (!mFirstVisualPixelPainted) {
653 return;
654 }
655
656 final int idx = view.copyBackForwardList().getCurrentIndex();
657 boolean bitmapExists = view.hasSnapshot(idx);
658
659 int progress = 100;
660 Controller controller = (Controller)mWebViewController;
661 UI ui = controller.getUi();
662 if (ui instanceof BaseUi) {
663 BaseUi baseUi = (BaseUi) ui;
664 TitleBar titleBar = baseUi.getTitleBar();
665 progress = titleBar.getProgressView().getProgressPercent();
666 }
667
668 if (bitmapExists && progress < 85) {
669 return;
670 }
671
672 int index = getCaptureIndex(view.getLastCommittedHistoryIndex());
673 view.captureSnapshot(index , null);
674 }
675
676 @Override
677 public void onHistoryItemCommit(WebView view, int index) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700678 if (BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
679 return;
680 }
681
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700682 mTabHistoryUpdateObservable.set(index);
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700683 final int maxIdx = view.copyBackForwardList().getSize();
684 final WebView wv = view;
685 view.getSnapshotIds(new ValueCallback <List<Integer>>() {
686 @Override
687 public void onReceiveValue(List<Integer> ids) {
688 int currentTabIdx = mWebViewController.getTabControl().getCurrentPosition();
689 for (Integer id : ids) {
690 if (getTabIdxFromCaptureIdx(id) == currentTabIdx &&
691 getNavIdxFromCaptureIdx(id) >= maxIdx) {
692 wv.deleteSnapshot(id);
693 }
694 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700695 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700696 });
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700697 }
Pankaj Garg62bc7912015-04-14 16:08:59 -0700698
699 @Override
700 public void onKeyboardStateChange(boolean popup) {
701 if (BrowserSettings.getInstance().useFullscreen()) {
702 Controller controller = (Controller) mWebViewController;
703 BaseUi ui = (BaseUi) controller.getUi();
704 ui.forceDisableFullscreenMode(popup);
705 }
706 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700707 };
708
John Reck1cf4b792011-07-26 10:22:22 -0700709 private void syncCurrentState(WebView view, String url) {
710 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800711
712 if (mReceivedError) {
713 mCurrentState.mUrl = url;
714 mCurrentState.mOriginalUrl = url;
715 } else {
716 mCurrentState.mUrl = view.getUrl();
717 mCurrentState.mOriginalUrl = view.getOriginalUrl();
718 mCurrentState.mFavicon = view.getFavicon();
719 }
720
John Reck1cf4b792011-07-26 10:22:22 -0700721 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700722 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700723 }
John Reck1cf4b792011-07-26 10:22:22 -0700724 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800725
726
John Reck1cf4b792011-07-26 10:22:22 -0700727 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
728 // In case we stop when loading an HTTPS page from an HTTP page
729 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100730 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100731 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700732 }
John Reck502a3532011-08-16 14:21:46 -0700733 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700734 }
735
Pankaj Garg21dad562015-07-02 17:17:24 -0700736 public String getTouchIconUrl() {
737 return mTouchIconUrl;
738 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700739
740 public boolean isTabFullScreen() {
741 return mFullScreen;
742 }
743
Vivek Sekharf96064b2014-07-28 16:32:34 -0700744 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700745 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700746 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700747 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700748 }
749
Sudheer Koganti24766882014-10-02 10:58:09 -0700750 public boolean exitFullscreen() {
751 if (mFullScreen) {
752 Controller controller = (Controller)mWebViewController;
753 controller.getUi().showFullscreen(false);
754 if (getWebView() != null)
755 getWebView().exitFullscreen();
756 mFullScreen = false;
757 return true;
758 }
759 return false;
760 }
761
762
763
764
Grace Kloba22ac16e2009-10-07 18:00:23 -0700765 // -------------------------------------------------------------------------
766 // WebChromeClient implementation for the main WebView
767 // -------------------------------------------------------------------------
768
769 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
770 // Helper method to create a new tab or sub window.
771 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700772 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700773 }
774
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700775 private void createWindow(final boolean dialog, final Message msg, final String url,
776 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700777 WebView.WebViewTransport transport =
778 (WebView.WebViewTransport) msg.obj;
779 if (dialog) {
780 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700781 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700782 transport.setWebView(mSubView);
783 } else {
Pankaj Garg21dad562015-07-02 17:17:24 -0700784 capture();
785
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700786 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700787 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700788 // This is special case for rendering links on a webpage in
789 // a new tab. If opener is suppressed, the WebContents created
790 // by the content layer are not fully initialized. This check
791 // will prevent content layer from overriding WebContents
792 // created by new tab with the uninitialized instance.
793 if (!opener_suppressed) {
794 transport.setWebView(newTab.getWebView());
795 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700796 }
797 msg.sendToTarget();
798 }
799
800 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700801 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
802 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700803 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700804 }
805 }
806
807 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700808 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
809 float contentOffsetYPix,
810 float overdrawBottomHeightPix) {
811 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700812 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700813 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar11b40062015-06-24 11:49:04 -0700814 // Resize the viewport if top controls is not visible
Vivek Sekhar2ee19a32015-07-02 17:03:57 -0700815 if (mMainView != null &&
816 (topControlsOffsetYPix == 0.0f || contentOffsetYPix == 0.0f))
Vivek Sekhar11b40062015-06-24 11:49:04 -0700817 ((BrowserWebView)mMainView).enableTopControls(
818 (topControlsOffsetYPix == 0.0f) ? true : false);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700819 }
820 }
821
822 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700823 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700824 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700825 }
826
827 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700828 public boolean onCreateWindow(WebView view, final boolean dialog,
829 final boolean userGesture, final Message resultMsg) {
830 // only allow new window or sub window for the foreground case
831 if (!mInForeground) {
832 return false;
833 }
834 // Short-circuit if we can't create any more tabs or sub windows.
835 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700836 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700837 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200838 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700839 .setMessage(R.string.too_many_subwindows_dialog_message)
840 .setPositiveButton(R.string.ok, null)
841 .show();
842 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700843 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
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_windows_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_windows_dialog_message)
848 .setPositiveButton(R.string.ok, null)
849 .show();
850 return false;
851 }
852
853 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800854 if (userGesture || !mSettings.blockPopupWindows()) {
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700855 WebView.WebViewTransport transport =
856 (WebView.WebViewTransport) resultMsg.obj;
857 CreateWindowParams windowParams = transport.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700858 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700859 createWindow(dialog, resultMsg, windowParams.mURL, true);
860 // This is special case for rendering links on a webpage in
861 // a new tab. If opener is suppressed, the WebContents created
862 // by the content layer are not fully initialized. Returning false
863 // will prevent content layer from overriding WebContents
864 // created by new tab with the uninitialized instance.
865 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700866 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700867
868 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700869 return true;
870 }
871
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700872 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700873 return true;
874 }
875
876 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500877 public void onRequestFocus(WebView view) {
878 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700879 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500880 }
881 }
882
883 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700884 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700885 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700886 // JavaScript can only close popup window.
887 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700888 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700889 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700890 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700891 }
892 }
893
894 @Override
895 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800896 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800897 if (newProgress == 100) {
898 mInPageLoad = false;
899 }
John Reck30c714c2010-12-16 17:30:34 -0800900 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700901 if (mUpdateThumbnail && newProgress == 100) {
902 mUpdateThumbnail = false;
903 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700904 }
905
906 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500907 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800908 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700909 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700910 }
911
912 @Override
913 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800914 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700915 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700916 }
917
918 @Override
919 public void onReceivedTouchIconUrl(WebView view, String url,
920 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700921 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400922 // Let precomposed icons take precedence over non-composed
923 // icons.
924 if (precomposed && mTouchIconLoader != null) {
925 mTouchIconLoader.cancel(false);
926 mTouchIconLoader = null;
927 }
928 // Have only one async task at a time.
929 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700930 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700931 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400932 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700933 }
Pankaj Garg21dad562015-07-02 17:17:24 -0700934 mTouchIconUrl = url;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700935 }
936
937 @Override
938 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800939 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700940 Activity activity = mWebViewController.getActivity();
941 if (activity != null) {
942 onShowCustomView(view, activity.getRequestedOrientation(), callback);
943 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400944 }
945
946 @Override
947 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800948 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700949 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400950 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700951 }
952
953 @Override
954 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700955 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700956 }
957
958 /**
959 * The origin has exceeded its database quota.
960 * @param url the URL that exceeded the quota
961 * @param databaseIdentifier the identifier of the database on which the
962 * transaction that caused the quota overflow was run
963 * @param currentQuota the current quota for the origin.
964 * @param estimatedSize the estimated size of the database.
965 * @param totalUsedQuota is the sum of all origins' quota.
966 * @param quotaUpdater The callback to run when a decision to allow or
967 * deny quota has been made. Don't forget to call this!
968 */
969 @Override
970 public void onExceededDatabaseQuota(String url,
971 String databaseIdentifier, long currentQuota, long estimatedSize,
972 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700973 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700974 .onExceededDatabaseQuota(url, databaseIdentifier,
975 currentQuota, estimatedSize, totalUsedQuota,
976 quotaUpdater);
977 }
978
979 /**
980 * The Application Cache has exceeded its max size.
981 * @param spaceNeeded is the amount of disk space that would be needed
982 * in order for the last appcache operation to succeed.
983 * @param totalUsedQuota is the sum of all origins' quota.
984 * @param quotaUpdater A callback to inform the WebCore thread that a
985 * new app cache size is available. This callback must always
986 * be executed at some point to ensure that the sleeping
987 * WebCore thread is woken up.
988 */
989 @Override
990 public void onReachedMaxAppCacheSize(long spaceNeeded,
991 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700992 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700993 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
994 quotaUpdater);
995 }
996
Ben Murdoch65acc352009-11-19 18:16:04 +0000997 /* Adds a JavaScript error message to the system log and if the JS
998 * console is enabled in the about:debug options, to that console
999 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001000 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001001 */
1002 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001003 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -05001004 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001005 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001006
Ben Murdochc42addf2010-01-28 15:19:59 +00001007 String message = "Console: " + consoleMessage.message() + " "
1008 + consoleMessage.sourceId() + ":"
1009 + consoleMessage.lineNumber();
1010
1011 switch (consoleMessage.messageLevel()) {
1012 case TIP:
1013 Log.v(CONSOLE_LOGTAG, message);
1014 break;
1015 case LOG:
1016 Log.i(CONSOLE_LOGTAG, message);
1017 break;
1018 case WARNING:
1019 Log.w(CONSOLE_LOGTAG, message);
1020 break;
1021 case ERROR:
1022 Log.e(CONSOLE_LOGTAG, message);
1023 break;
1024 case DEBUG:
1025 Log.d(CONSOLE_LOGTAG, message);
1026 break;
1027 }
1028
1029 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001030 }
1031
1032 /**
1033 * Ask the browser for an icon to represent a <video> element.
1034 * This icon will be used if the Web page did not specify a poster attribute.
1035 * @return Bitmap The icon or null if no such icon is available.
1036 */
1037 @Override
1038 public Bitmap getDefaultVideoPoster() {
1039 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001040 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001041 }
1042 return null;
1043 }
1044
1045 /**
1046 * Ask the host application for a custom progress view to show while
1047 * a <video> is loading.
1048 * @return View The progress view.
1049 */
1050 @Override
1051 public View getVideoLoadingProgressView() {
1052 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001053 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001054 }
1055 return null;
1056 }
1057
1058 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001059 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001060 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001061 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001062 } else {
1063 uploadMsg.onReceiveValue(null);
1064 }
1065 }
1066
Vivek Sekharb54614f2014-05-01 19:03:37 -07001067 @Override
1068 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1069 boolean capture) {
1070 if (mInForeground) {
1071 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1072 } else {
1073 uploadFilePaths.onReceiveValue(null);
1074 }
1075 }
1076
Grace Kloba22ac16e2009-10-07 18:00:23 -07001077 /**
1078 * Deliver a list of already-visited URLs
1079 */
1080 @Override
1081 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001082 mWebViewController.getVisitedHistory(callback);
1083 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001084
1085 @Override
1086 public void setupAutoFill(Message message) {
1087 // Prompt the user to set up their profile.
1088 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001089 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1090 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001091 Context.LAYOUT_INFLATER_SERVICE);
1092 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1093
1094 builder.setView(layout)
1095 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1096 @Override
1097 public void onClick(DialogInterface dialog, int id) {
1098 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1099 R.id.setup_autofill_dialog_disable_autofill);
1100
1101 if (disableAutoFill.isChecked()) {
1102 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001103 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001104 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001105 R.string.autofill_setup_dialog_negative_toast,
1106 Toast.LENGTH_LONG).show();
1107 } else {
1108 // Take user to the AutoFill profile editor. When they return,
1109 // we will send the message that we pass here which will trigger
1110 // the form to get filled out with their new profile.
1111 mWebViewController.setupAutoFill(msg);
1112 }
1113 }
1114 })
1115 .setNegativeButton(R.string.cancel, null)
1116 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001117 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001118 };
1119
1120 // -------------------------------------------------------------------------
1121 // WebViewClient implementation for the sub window
1122 // -------------------------------------------------------------------------
1123
1124 // Subclass of WebViewClient used in subwindows to notify the main
1125 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001126 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001127 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001128 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001129 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001130
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001131 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001132 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001133 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001134 }
1135 @Override
1136 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1137 // Unlike the others, do not call mClient's version, which would
1138 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001139 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001140 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001141 }
1142 @Override
1143 public void doUpdateVisitedHistory(WebView view, String url,
1144 boolean isReload) {
1145 mClient.doUpdateVisitedHistory(view, url, isReload);
1146 }
1147 @Override
1148 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1149 return mClient.shouldOverrideUrlLoading(view, url);
1150 }
1151 @Override
1152 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1153 SslError error) {
1154 mClient.onReceivedSslError(view, handler, error);
1155 }
1156 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001157 public void onReceivedClientCertRequest(WebView view,
1158 ClientCertRequestHandler handler, String host_and_port) {
1159 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1160 }
1161 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001162 public void onReceivedHttpAuthRequest(WebView view,
1163 HttpAuthHandler handler, String host, String realm) {
1164 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1165 }
1166 @Override
1167 public void onFormResubmission(WebView view, Message dontResend,
1168 Message resend) {
1169 mClient.onFormResubmission(view, dontResend, resend);
1170 }
1171 @Override
1172 public void onReceivedError(WebView view, int errorCode,
1173 String description, String failingUrl) {
1174 mClient.onReceivedError(view, errorCode, description, failingUrl);
1175 }
1176 @Override
1177 public boolean shouldOverrideKeyEvent(WebView view,
1178 android.view.KeyEvent event) {
1179 return mClient.shouldOverrideKeyEvent(view, event);
1180 }
1181 @Override
1182 public void onUnhandledKeyEvent(WebView view,
1183 android.view.KeyEvent event) {
1184 mClient.onUnhandledKeyEvent(view, event);
1185 }
1186 }
1187
1188 // -------------------------------------------------------------------------
1189 // WebChromeClient implementation for the sub window
1190 // -------------------------------------------------------------------------
1191
1192 private class SubWindowChromeClient extends WebChromeClient {
1193 // The main WebChromeClient.
1194 private final WebChromeClient mClient;
1195
1196 SubWindowChromeClient(WebChromeClient client) {
1197 mClient = client;
1198 }
1199 @Override
1200 public void onProgressChanged(WebView view, int newProgress) {
1201 mClient.onProgressChanged(view, newProgress);
1202 }
1203 @Override
1204 public boolean onCreateWindow(WebView view, boolean dialog,
1205 boolean userGesture, android.os.Message resultMsg) {
1206 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1207 }
1208 @Override
1209 public void onCloseWindow(WebView window) {
1210 if (window != mSubView) {
1211 Log.e(LOGTAG, "Can't close the window");
1212 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001213 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001214 }
1215 }
1216
1217 // -------------------------------------------------------------------------
1218
1219 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001220 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001221 this(wvcontroller, w, null);
1222 }
1223
1224 Tab(WebViewController wvcontroller, Bundle state) {
1225 this(wvcontroller, null, state);
1226 }
1227
1228 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001229 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001230 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001231 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001232 mDataController = DataController.getInstance(mContext);
1233 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001234 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001235 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001236 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001237 mInForeground = false;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001238 mWebViewDestroyedByMemoryMonitor = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001239
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001240 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001241 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001242 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001243 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001244 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001245 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001246 }
1247 };
1248
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001249 mCaptureWidth = mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_width);
1250 mCaptureHeight =mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_height);
1251
1252 initCaptureBitmap();
1253
John Reck1cf4b792011-07-26 10:22:22 -07001254 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001255 if (getId() == -1) {
1256 mId = TabControl.getNextId();
1257 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001258 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001259 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001260 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001261 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001262 switch (m.what) {
1263 case MSG_CAPTURE:
1264 capture();
1265 break;
1266 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001267 }
1268 };
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001269
1270 mFirstPixelObservable = new Observable();
1271 mFirstPixelObservable.set(false);
1272 mTabHistoryUpdateObservable = new Observable();
John Reck1cf4b792011-07-26 10:22:22 -07001273 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001274
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001275 private void initCaptureBitmap() {
1276 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight, Bitmap.Config.RGB_565);
1277 mCapture.eraseColor(Color.WHITE);
Michael Kolb72864272012-05-03 15:42:15 -07001278 }
1279
Mathew Inwoode09305e2011-09-02 12:03:26 +01001280 /**
1281 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1282 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1283 * to overlapping IDs between the preloaded and restored tabs.
1284 */
1285 public void refreshIdAfterPreload() {
1286 mId = TabControl.getNextId();
1287 }
1288
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001289 public void setController(WebViewController ctl) {
1290 mWebViewController = ctl;
1291
John Reck1cf4b792011-07-26 10:22:22 -07001292 if (mWebViewController.shouldCaptureThumbnails()) {
1293 synchronized (Tab.this) {
1294 if (mCapture == null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001295 initCaptureBitmap();
1296 if (mInForeground && !mHandler.hasMessages(MSG_CAPTURE)) {
1297 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
John Reck1cf4b792011-07-26 10:22:22 -07001298 }
1299 }
1300 }
1301 } else {
1302 synchronized (Tab.this) {
1303 mCapture = null;
1304 deleteThumbnail();
1305 }
1306 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001307 }
1308
Michael Kolbc831b632011-05-11 09:30:34 -07001309 public long getId() {
1310 return mId;
1311 }
1312
Michael Kolb91911a22012-01-17 11:21:25 -08001313 void setWebView(WebView w) {
1314 setWebView(w, true);
1315 }
1316
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001317 public boolean isNativeActive(){
1318 if (mMainView == null)
1319 return false;
1320 return true;
1321 }
1322
1323 public void setTimeStamp(){
1324 Date d = new Date();
1325 timestamp = (new Timestamp(d.getTime()));
1326 }
1327
1328 public Timestamp getTimestamp() {
1329 return timestamp;
1330 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001331 /**
1332 * Sets the WebView for this tab, correctly removing the old WebView from
1333 * the container view.
1334 */
Michael Kolb91911a22012-01-17 11:21:25 -08001335 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001336 if (mMainView == w) {
1337 return;
1338 }
Michael Kolba713ec82010-11-29 17:27:06 -08001339
Michael Kolba713ec82010-11-29 17:27:06 -08001340 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001341
John Reck1cf4b792011-07-26 10:22:22 -07001342 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001343 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001344 if (w != null) {
1345 syncCurrentState(w, null);
1346 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001347 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001348
1349 if (mWebViewDestroyedByMemoryMonitor) {
1350 /*
1351 * If tab was destroyed as a result of the MemoryMonitor
1352 * then we need to restore the state properties
1353 * from the old WebView (mMainView)
1354 */
1355 syncCurrentState(mMainView, null);
1356 mWebViewDestroyedByMemoryMonitor = false;
1357 }
John Reck1cf4b792011-07-26 10:22:22 -07001358 }
1359 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001360 // set the new one
1361 mMainView = w;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001362
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001363 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001364 if (mMainView != null) {
1365 mMainView.setWebViewClient(mWebViewClient);
1366 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001367 // Attach DownloadManager so that downloads can start in an active
1368 // or a non-active window. This can happen when going to a site that
1369 // does a redirect after a period of time. The user could have
1370 // switched to another tab while waiting for the download to start.
1371 mMainView.setDownloadListener(mDownloadListener);
John Reck8ee633f2011-08-09 16:00:35 -07001372 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001373 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001374 mMainView.setPictureListener(this);
1375 }
Michael Kolb91911a22012-01-17 11:21:25 -08001376 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001377 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001378 WebBackForwardList restoredState
1379 = mMainView.restoreState(mSavedState);
1380 if (restoredState == null || restoredState.getSize() == 0) {
1381 Log.w(LOGTAG, "Failed to restore WebView state!");
1382 loadUrl(mCurrentState.mOriginalUrl, null);
1383 }
John Reck1cf4b792011-07-26 10:22:22 -07001384 mSavedState = null;
1385 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001386 }
1387 }
1388
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001389 public void destroyThroughMemoryMonitor() {
1390 mWebViewDestroyedByMemoryMonitor = true;
1391 destroy();
1392 }
1393
Grace Kloba22ac16e2009-10-07 18:00:23 -07001394 /**
1395 * Destroy the tab's main WebView and subWindow if any
1396 */
1397 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001398
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001399 if (mPostponeDestroy) {
1400 mShouldDestroy = true;
1401 return;
1402 }
1403 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001404 if (mMainView != null) {
1405 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001406 // save the WebView to call destroy() after detach it from the tab
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001407 final WebView webView = mMainView;
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001408 setWebView(null);
Pankaj Garg18aa0a12015-06-22 11:06:12 -07001409 if (!mWebViewDestroyedByMemoryMonitor &&
1410 !BrowserCommandLine.hasSwitch("ui-low-power-mode")) {
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001411 // Tabs can be reused with new instance of WebView so delete the snapshots
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001412 webView.getSnapshotIds(new ValueCallback<List<Integer>>() {
1413 @Override
1414 public void onReceiveValue(List<Integer> ids) {
1415 int currentTabIdx = mWebViewController.getTabControl().getCurrentPosition();
1416 for (Integer id : ids) {
1417 if (getTabIdxFromCaptureIdx(id) == currentTabIdx) {
1418 webView.deleteSnapshot(id);
1419 }
1420 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001421 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001422 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001423 });
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001424 } else {
1425 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001426 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001427 }
1428 }
1429
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001430 private boolean mPostponeDestroy = false;
1431 private boolean mShouldDestroy = false;
1432
1433 public void postponeDestroy() {
1434 mPostponeDestroy = true;
1435 }
1436
1437 public void performPostponedDestroy() {
1438 mPostponeDestroy = false;
1439 if (mShouldDestroy) {
1440 destroy();
1441 }
1442 }
1443
Grace Kloba22ac16e2009-10-07 18:00:23 -07001444 /**
1445 * Remove the tab from the parent
1446 */
1447 void removeFromTree() {
1448 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001449 if (mChildren != null) {
1450 for(Tab t : mChildren) {
1451 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001452 }
1453 }
1454 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001455 if (mParent != null) {
1456 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001457 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001458
1459 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001460 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001461 }
1462
1463 /**
1464 * Create a new subwindow unless a subwindow already exists.
1465 * @return True if a new subwindow was created. False if one already exists.
1466 */
1467 boolean createSubWindow() {
1468 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001469 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001470 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001471 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001472 mSubView.setWebChromeClient(new SubWindowChromeClient(
1473 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001474 // Set a different DownloadListener for the mSubView, since it will
1475 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001476 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001477 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001478 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001479 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001480 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001481 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001482 if (mSubView.copyBackForwardList().getSize() == 0) {
1483 // This subwindow was opened for the sole purpose of
1484 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001485 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001486 }
1487 }
1488 });
Michael Kolb14612442011-06-24 13:06:29 -07001489 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001490 return true;
1491 }
1492 return false;
1493 }
1494
1495 /**
1496 * Dismiss the subWindow for the tab.
1497 */
1498 void dismissSubWindow() {
1499 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001500 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001501 mSubView.destroy();
1502 mSubView = null;
1503 mSubViewContainer = null;
1504 }
1505 }
1506
Grace Kloba22ac16e2009-10-07 18:00:23 -07001507
1508 /**
1509 * Set the parent tab of this tab.
1510 */
Michael Kolbc831b632011-05-11 09:30:34 -07001511 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001512 if (parent == this) {
1513 throw new IllegalStateException("Cannot set parent to self!");
1514 }
Michael Kolbc831b632011-05-11 09:30:34 -07001515 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001516 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001517 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001518 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001519 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001520 if (mSavedState != null) {
1521 if (parent == null) {
1522 mSavedState.remove(PARENTTAB);
1523 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001524 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001525 }
1526 }
John Reckb0a86db2011-05-24 14:05:58 -07001527
1528 // Sync the WebView useragent with the parent
1529 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1530 != mSettings.hasDesktopUseragent(getWebView())) {
1531 mSettings.toggleDesktopUseragent(getWebView());
1532 }
John Reck52be4782011-08-26 15:37:29 -07001533
1534 if (parent != null && parent.getId() == getId()) {
1535 throw new IllegalStateException("Parent has same ID as child!");
1536 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001537 }
1538
1539 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001540 * If this Tab was created through another Tab, then this method returns
1541 * that Tab.
1542 * @return the Tab parent or null
1543 */
1544 public Tab getParent() {
1545 return mParent;
1546 }
1547
1548 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001549 * When a Tab is created through the content of another Tab, then we
1550 * associate the Tabs.
1551 * @param child the Tab that was created from this Tab
1552 */
1553 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001554 if (mChildren == null) {
1555 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001556 }
Michael Kolbc831b632011-05-11 09:30:34 -07001557 mChildren.add(child);
1558 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001559 }
1560
Michael Kolbc831b632011-05-11 09:30:34 -07001561 Vector<Tab> getChildren() {
1562 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001563 }
1564
1565 void resume() {
1566 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001567 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001568 mMainView.onResume();
1569 if (mSubView != null) {
1570 mSubView.onResume();
1571 }
1572 }
1573 }
1574
John Reck56c1fcf2011-08-17 10:15:16 -07001575 private void setupHwAcceleration(View web) {
1576 if (web == null) return;
1577 BrowserSettings settings = BrowserSettings.getInstance();
1578 if (settings.isHardwareAccelerated()) {
1579 web.setLayerType(View.LAYER_TYPE_NONE, null);
1580 } else {
1581 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1582 }
1583 }
1584
Grace Kloba22ac16e2009-10-07 18:00:23 -07001585 void pause() {
1586 if (mMainView != null) {
1587 mMainView.onPause();
1588 if (mSubView != null) {
1589 mSubView.onPause();
1590 }
1591 }
1592 }
1593
1594 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001595 if (mInForeground) {
1596 return;
1597 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001598 mInForeground = true;
1599 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001600 Activity activity = mWebViewController.getActivity();
1601 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001602 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001603 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001604 }
Axesh R. Ajmerac6b5c322015-05-01 11:06:10 -07001605
Leon Scroggins1961ed22010-12-07 15:22:21 -05001606 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001607 }
1608
1609 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001610 if (!mInForeground) {
1611 return;
1612 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001613 mInForeground = false;
1614 pause();
1615 mMainView.setOnCreateContextMenuListener(null);
1616 if (mSubView != null) {
1617 mSubView.setOnCreateContextMenuListener(null);
1618 }
1619 }
1620
Michael Kolb8233fac2010-10-26 16:08:53 -07001621 boolean inForeground() {
1622 return mInForeground;
1623 }
1624
Grace Kloba22ac16e2009-10-07 18:00:23 -07001625 /**
1626 * Return the top window of this tab; either the subwindow if it is not
1627 * null or the main window.
1628 * @return The top window of this tab.
1629 */
1630 WebView getTopWindow() {
1631 if (mSubView != null) {
1632 return mSubView;
1633 }
1634 return mMainView;
1635 }
1636
1637 /**
1638 * Return the main window of this tab. Note: if a tab is freed in the
1639 * background, this can return null. It is only guaranteed to be
1640 * non-null for the current tab.
1641 * @return The main WebView of this tab.
1642 */
1643 WebView getWebView() {
1644 return mMainView;
1645 }
1646
Michael Kolba713ec82010-11-29 17:27:06 -08001647 void setViewContainer(View container) {
1648 mContainer = container;
1649 }
1650
Michael Kolb8233fac2010-10-26 16:08:53 -07001651 View getViewContainer() {
1652 return mContainer;
1653 }
1654
Grace Kloba22ac16e2009-10-07 18:00:23 -07001655 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001656 * Return whether private browsing is enabled for the main window of
1657 * this tab.
1658 * @return True if private browsing is enabled.
1659 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001660 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001661 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001662 }
1663
1664 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001665 * Return the subwindow of this tab or null if there is no subwindow.
1666 * @return The subwindow of this tab or null.
1667 */
1668 WebView getSubWebView() {
1669 return mSubView;
1670 }
1671
Michael Kolb1514bb72010-11-22 09:11:48 -08001672 void setSubWebView(WebView subView) {
1673 mSubView = subView;
1674 }
1675
Michael Kolb8233fac2010-10-26 16:08:53 -07001676 View getSubViewContainer() {
1677 return mSubViewContainer;
1678 }
1679
Michael Kolb1514bb72010-11-22 09:11:48 -08001680 void setSubViewContainer(View subViewContainer) {
1681 mSubViewContainer = subViewContainer;
1682 }
1683
Grace Kloba22ac16e2009-10-07 18:00:23 -07001684
1685 /**
1686 * @return The application id string
1687 */
1688 String getAppId() {
1689 return mAppId;
1690 }
1691
1692 /**
1693 * Set the application id string
1694 * @param id
1695 */
1696 void setAppId(String id) {
1697 mAppId = id;
1698 }
1699
Michael Kolbe28b3472011-08-04 16:54:31 -07001700 boolean closeOnBack() {
1701 return mCloseOnBack;
1702 }
1703
1704 void setCloseOnBack(boolean close) {
1705 mCloseOnBack = close;
1706 }
1707
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001708 boolean getDerivedFromIntent() {
1709 return mDerivedFromIntent;
1710 }
1711
1712 void setDerivedFromIntent(boolean derived) {
1713 mDerivedFromIntent = derived;
1714 }
1715
Grace Kloba22ac16e2009-10-07 18:00:23 -07001716 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001717 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001718 }
1719
Tarun Nainani8eb00912014-07-17 12:28:32 -07001720
1721 protected void onPageFinished() {
1722 mPageFinished = true;
Ze G Riande2a675c22015-06-03 11:15:24 -07001723 isDistillable();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001724 }
1725
1726 public boolean getPageFinishedStatus() {
1727 return mPageFinished;
1728 }
1729
John Reck49a603c2011-03-03 09:33:05 -08001730 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001731 if (mCurrentState.mOriginalUrl == null) {
1732 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001733 }
John Reckdb22ec42011-06-29 11:31:24 -07001734 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001735 }
1736
Grace Kloba22ac16e2009-10-07 18:00:23 -07001737 /**
John Reck30c714c2010-12-16 17:30:34 -08001738 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001739 */
1740 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001741 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001742 }
1743
1744 /**
John Reck30c714c2010-12-16 17:30:34 -08001745 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001746 */
1747 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001748 if (mCurrentState.mFavicon != null) {
1749 return mCurrentState.mFavicon;
1750 }
1751 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001752 }
1753
Pankaj Garg32e1b942015-06-03 18:13:24 -07001754 public boolean hasFavicon() {
1755 return mCurrentState.mFavicon != null;
1756 }
1757
John Recke969cc52010-12-21 17:24:43 -08001758 public boolean isBookmarkedSite() {
1759 return mCurrentState.mIsBookmarkedSite;
1760 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001761
Grace Kloba22ac16e2009-10-07 18:00:23 -07001762 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001763 * Sets the security state, clears the SSL certificate error and informs
1764 * the controller.
1765 */
Steve Block2466eff2011-10-03 15:33:09 +01001766 private void setSecurityState(SecurityState securityState) {
1767 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001768 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001769 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001770 }
1771
1772 /**
Steve Block2466eff2011-10-03 15:33:09 +01001773 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001774 */
Steve Block2466eff2011-10-03 15:33:09 +01001775 SecurityState getSecurityState() {
1776 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001777 }
1778
Steve Block08a6f0c2011-10-06 12:12:53 +01001779 /**
1780 * Gets the SSL certificate error, if any, for the page's main resource.
1781 * This is only non-null when the security state is
1782 * SECURITY_STATE_BAD_CERTIFICATE.
1783 */
1784 SslError getSslCertificateError() {
1785 return mCurrentState.mSslCertificateError;
1786 }
1787
John Reck30c714c2010-12-16 17:30:34 -08001788 int getLoadProgress() {
1789 if (mInPageLoad) {
1790 return mPageLoadProgress;
1791 }
1792 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001793 }
1794
1795 /**
1796 * @return TRUE if onPageStarted is called while onPageFinished is not
1797 * called yet.
1798 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001799 boolean inPageLoad() {
1800 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001801 }
1802
Grace Kloba22ac16e2009-10-07 18:00:23 -07001803 /**
John Reck1cf4b792011-07-26 10:22:22 -07001804 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001805 */
John Reck1cf4b792011-07-26 10:22:22 -07001806 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001807 // If the WebView is null it means we ran low on memory and we already
1808 // stored the saved state in mSavedState.
1809 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001810 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001811 }
John Reck6c2e2f32011-08-22 13:41:23 -07001812
1813 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001814 return null;
John Reck24f18262011-06-17 14:47:20 -07001815 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001816
1817 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001818 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1819 if (savedList == null || savedList.getSize() == 0) {
1820 Log.w(LOGTAG, "Failed to save back/forward list for "
1821 + mCurrentState.mUrl);
1822 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001823
Michael Kolbc831b632011-05-11 09:30:34 -07001824 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001825 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1826 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001827 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001828 if (mAppId != null) {
1829 mSavedState.putString(APPID, mAppId);
1830 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001831 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001832 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001833 if (mParent != null) {
1834 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001835 }
John Reckb0a86db2011-05-24 14:05:58 -07001836 mSavedState.putBoolean(USERAGENT,
1837 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001838 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001839 }
1840
1841 /*
1842 * Restore the state of the tab.
1843 */
John Reck1cf4b792011-07-26 10:22:22 -07001844 private void restoreState(Bundle b) {
1845 mSavedState = b;
1846 if (mSavedState == null) {
1847 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001848 }
1849 // Restore the internal state even if the WebView fails to restore.
1850 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001851 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001852 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001853 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001854 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001855 String url = b.getString(CURRURL);
1856 String title = b.getString(CURRTITLE);
1857 boolean incognito = b.getBoolean(INCOGNITO);
1858 mCurrentState = new PageState(mContext, incognito, url, null);
1859 mCurrentState.mTitle = title;
1860 synchronized (Tab.this) {
1861 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001862 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001863 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001864 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001865 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001866
John Reck8b9bb8b2012-03-08 13:19:40 -08001867 private void restoreUserAgent() {
1868 if (mMainView == null || mSavedState == null) {
1869 return;
1870 }
1871 if (mSavedState.getBoolean(USERAGENT)
1872 != mSettings.hasDesktopUseragent(mMainView)) {
1873 mSettings.toggleDesktopUseragent(mMainView);
1874 }
1875 }
1876
Leon Scroggins1961ed22010-12-07 15:22:21 -05001877 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001878 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001879 }
1880
John Recke969cc52010-12-21 17:24:43 -08001881 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1882 = new DataController.OnQueryUrlIsBookmark() {
1883 @Override
1884 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1885 if (mCurrentState.mUrl.equals(url)) {
1886 mCurrentState.mIsBookmarkedSite = isBookmark;
1887 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1888 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001889 }
John Recke969cc52010-12-21 17:24:43 -08001890 };
Michael Kolb1acef692011-03-08 14:12:06 -08001891
Michael Kolbeb95db42011-03-03 10:38:40 -08001892 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001893 synchronized (Tab.this) {
1894 return mCapture;
1895 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001896 }
1897
John Reck541f55a2011-06-07 16:34:43 -07001898 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001899 return false;
1900 }
1901
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001902 private static class SaveCallback implements ValueCallback<String> {
1903 boolean onReceiveValueCalled = false;
1904 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001905
1906 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001907 public void onReceiveValue(String path) {
1908 this.onReceiveValueCalled = true;
1909 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001910 synchronized (this) {
1911 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001912 }
John Reck541f55a2011-06-07 16:34:43 -07001913 }
John Reck68234a92012-04-19 15:27:12 -07001914
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001915 public String getPath() {
1916 return mPath;
1917 }
John Reck68234a92012-04-19 15:27:12 -07001918 }
1919
1920 /**
1921 * Must be called on the UI thread
1922 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001923 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001924 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001925 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001926 ContentValues values = new ContentValues();
1927 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1928 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001929 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001930 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1931 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001932 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07001933 return values;
John Reck541f55a2011-06-07 16:34:43 -07001934 }
1935
John Reck68234a92012-04-19 15:27:12 -07001936 /**
1937 * Probably want to call this on a background thread
1938 */
1939 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001940 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001941 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001942 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07001943 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07001944 try {
John Reck68234a92012-04-19 15:27:12 -07001945 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001946 web.saveViewState(filename, callback);
1947 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07001948 }
John Reck68234a92012-04-19 15:27:12 -07001949 } catch (Exception e) {
1950 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001951 String path = callback.getPath();
1952 if (path != null) {
1953 File file = mContext.getFileStreamPath(path);
1954 if (file.exists() && !file.delete()) {
1955 file.deleteOnExit();
1956 }
John Reck68234a92012-04-19 15:27:12 -07001957 }
1958 return false;
1959 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001960
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001961 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001962 // could be that saving of file failed
1963 if (path == null) {
1964 return false;
1965 }
1966
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001967 File savedFile = new File(path);
1968 if (!savedFile.exists()) {
1969 return false;
John Reck68234a92012-04-19 15:27:12 -07001970 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001971 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
1972 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07001973 return true;
1974 }
1975
John Reck8cc92352011-07-06 17:41:52 -07001976 public byte[] compressBitmap(Bitmap bitmap) {
1977 if (bitmap == null) {
1978 return null;
1979 }
1980 ByteArrayOutputStream stream = new ByteArrayOutputStream();
1981 bitmap.compress(CompressFormat.PNG, 100, stream);
1982 return stream.toByteArray();
1983 }
1984
John Reck26b18322011-06-21 13:08:58 -07001985 public void loadUrl(String url, Map<String, String> headers) {
1986 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07001987 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07001988 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07001989 mMainView.loadUrl(url, headers);
1990 }
1991 }
1992
John Reck38b39652012-06-05 09:22:59 -07001993 public void disableUrlOverridingForLoad() {
1994 mDisableOverrideUrlLoading = true;
1995 }
1996
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001997 private void thumbnailUpdated() {
John Reck8ee633f2011-08-09 16:00:35 -07001998 mHandler.removeMessages(MSG_CAPTURE);
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001999
John Reck8ee633f2011-08-09 16:00:35 -07002000 TabControl tc = mWebViewController.getTabControl();
2001 if (tc != null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002002 OnThumbnailUpdatedListener updateListener = tc.getOnThumbnailUpdatedListener();
John Reck8ee633f2011-08-09 16:00:35 -07002003 if (updateListener != null) {
2004 updateListener.onThumbnailUpdated(this);
2005 }
2006 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002007 }
2008
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002009 protected void capture() {
2010 if (mMainView == null || mCapture == null || !mMainView.isReady() ||
2011 mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0 ||
2012 !mFirstVisualPixelPainted || mMainView.isShowingCrashView()) {
2013
2014 initCaptureBitmap();
2015 thumbnailUpdated();
2016 return;
2017 }
2018
2019 mMainView.getContentBitmapAsync((float) mCaptureWidth / mMainView.getWidth(), new Rect(),
2020 new ValueCallback<Bitmap>() {
2021 @Override
2022 public void onReceiveValue(Bitmap bitmap) {
2023 if (mCapture == null) {
2024 initCaptureBitmap();
2025 }
2026
2027 if (bitmap == null) {
2028 thumbnailUpdated();
2029 return;
2030 }
2031
2032 Canvas c = new Canvas(mCapture);
2033 mCapture.eraseColor(Color.WHITE);
2034 c.drawBitmap(bitmap, 0, 0, null);
2035
2036 // manually anti-alias the edges for the tilt
2037 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2038 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2039 mCapture.getHeight(), sAlphaPaint);
2040 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2041 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2042 mCapture.getHeight(), sAlphaPaint);
2043 c.setBitmap(null);
2044
2045 persistThumbnail();
2046 thumbnailUpdated();
2047 }
2048 }
2049 );
John Reck1cf4b792011-07-26 10:22:22 -07002050 }
2051
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002052 @Override
2053 public void onNewPicture(WebView view, Picture picture) {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002054 }
2055
John Reckef654f12011-07-12 16:42:08 -07002056 public boolean canGoBack() {
2057 return mMainView != null ? mMainView.canGoBack() : false;
2058 }
2059
2060 public boolean canGoForward() {
2061 return mMainView != null ? mMainView.canGoForward() : false;
2062 }
2063
2064 public void goBack() {
2065 if (mMainView != null) {
2066 mMainView.goBack();
2067 }
2068 }
2069
2070 public void goForward() {
2071 if (mMainView != null) {
2072 mMainView.goForward();
2073 }
2074 }
2075
John Reck1cf4b792011-07-26 10:22:22 -07002076 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002077 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002078 }
2079
2080 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002081 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002082 }
2083
John Reck4eadc342011-10-31 14:04:10 -07002084 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002085 synchronized (Tab.this) {
2086 if (mCapture == null) {
2087 return;
2088 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002089 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002090 try {
2091 mCapture.copyPixelsFromBuffer(buffer);
2092 } catch (RuntimeException rex) {
2093 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2094 + buffer.capacity() + " blob: " + blob.length
2095 + "capture: " + mCapture.getByteCount());
2096 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002097 }
John Reck1cf4b792011-07-26 10:22:22 -07002098 }
2099 }
2100
John Reck52be4782011-08-26 15:37:29 -07002101 @Override
2102 public String toString() {
2103 StringBuilder builder = new StringBuilder(100);
2104 builder.append(mId);
2105 builder.append(") has parent: ");
2106 if (getParent() != null) {
2107 builder.append("true[");
2108 builder.append(getParent().getId());
2109 builder.append("]");
2110 } else {
2111 builder.append("false");
2112 }
2113 builder.append(", incog: ");
2114 builder.append(isPrivateBrowsingEnabled());
2115 if (!isPrivateBrowsingEnabled()) {
2116 builder.append(", title: ");
2117 builder.append(getTitle());
2118 builder.append(", url: ");
2119 builder.append(getUrl());
2120 }
2121 return builder.toString();
2122 }
2123
Steve Block4895b012011-10-03 16:26:46 +01002124 private void handleProceededAfterSslError(SslError error) {
2125 if (error.getUrl().equals(mCurrentState.mUrl)) {
2126 // The security state should currently be SECURITY_STATE_SECURE.
2127 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002128 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002129 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002130 // The page's main resource is secure and this error is for a
2131 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002132 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2133 }
2134 }
Ze G Riande2a675c22015-06-03 11:15:24 -07002135
2136 // dertermines if the tab contains a dislled page
2137 public boolean isDistilled() {
2138 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2139 return false;
2140 }
2141 try {
2142 return DomDistillerUtils.isUrlDistilled(getUrl());
2143 } catch (Exception e) {
2144 return false;
2145 }
2146 }
2147
2148 //determines if the tab contains a distillable page
2149 public boolean isDistillable() {
2150 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2151 mIsDistillable = false;
2152 return mIsDistillable;
2153 }
2154 final ValueCallback<String> onIsDistillable = new ValueCallback<String>() {
2155 @Override
2156 public void onReceiveValue(String str) {
2157 mIsDistillable = Boolean.parseBoolean(str);
2158 }
2159 };
2160
2161 if (isDistilled()) {
2162 mIsDistillable = true;
2163 return mIsDistillable;
2164 }
2165
2166 try {
2167 DomDistillerUtils.isWebViewDistillable(getWebView(), onIsDistillable);
2168 } catch (Exception e) {
2169 mIsDistillable = false;
2170 }
2171
2172 return mIsDistillable;
2173 }
2174
2175 // Function that sets the mIsDistillable variable
2176 public void setIsDistillable(boolean value) {
2177 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2178 mIsDistillable = false;
2179 }
2180 mIsDistillable = value;
2181 }
2182
2183 // Function that returns the distilled url of the current url
2184 public String getDistilledUrl() {
2185 if (getUrl() != null) {
2186 return DomDistillerUtils.getDistilledUrl(getUrl());
2187 }
2188 return new String();
2189 }
2190
2191 // function that returns the non-distilled version of the current url
2192 public String getNonDistilledUrl() {
2193 if (getUrl() != null) {
2194 return DomDistillerUtils.getOriginalUrlFromDistilledUrl(getUrl());
2195 }
2196 return new String();
2197 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002198}