blob: 80ef16d988e0c298d1b19e0361674e339594c892 [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;
Grace Kloba22ac16e2009-10-07 18:00:23 -070039import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070040import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070041import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000042import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070043import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070044import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070045import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070046import android.util.Log;
47import android.view.KeyEvent;
48import android.view.LayoutInflater;
49import android.view.View;
Ben Murdochc42addf2010-01-28 15:19:59 +000050import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070051import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080052import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080054import android.webkit.WebChromeClient.CustomViewCallback;
55import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000056import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000057import android.widget.Toast;
Grace Kloba22ac16e2009-10-07 18:00:23 -070058
Bijan Amirzada41242f22014-03-21 12:12:18 -070059import com.android.browser.TabControl.OnThumbnailUpdatedListener;
60import com.android.browser.homepages.HomeProvider;
61import com.android.browser.mynavigation.MyNavigationUtil;
62import com.android.browser.provider.MyNavigationProvider;
63import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080064
Pankaj Garg18aa0a12015-06-22 11:06:12 -070065import org.codeaurora.swe.BrowserCommandLine;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080066import org.codeaurora.swe.BrowserDownloadListener;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080067import org.codeaurora.swe.HttpAuthHandler;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080068import org.codeaurora.swe.WebBackForwardList;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069import org.codeaurora.swe.WebChromeClient;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080070import org.codeaurora.swe.WebView;
71import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070072import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080073import org.codeaurora.swe.WebViewClient;
Pankaj Garg1c13cab2015-05-12 11:52:17 -070074import org.codeaurora.swe.util.Observable;
Ze G Riande2a675c22015-06-03 11:15:24 -070075import org.codeaurora.swe.DomDistillerUtils;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080076
John Reck541f55a2011-06-07 16:34:43 -070077import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070078import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080079import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070080import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070081import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070082import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070083import java.util.Vector;
Vivek Sekhar53ef8932015-06-18 16:51:43 -070084import java.util.List;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080085import java.sql.Timestamp;
86import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070087
Grace Kloba22ac16e2009-10-07 18:00:23 -070088/**
89 * Class for maintaining Tabs with a main WebView and a subwindow.
90 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070091class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Grace Kloba22ac16e2009-10-07 18:00:23 -070093 // Log Tag
94 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -070095 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +000096 // Special case the logtag for messages for the Console to make it easier to
97 // filter them and match the logtag used for these messages in older versions
98 // of the browser.
99 private static final String CONSOLE_LOGTAG = "browser";
100
Michael Kolb9ef259a2011-07-12 15:33:08 -0700101 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800102 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700103 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700104
John Reck1cf4b792011-07-26 10:22:22 -0700105 private static Bitmap sDefaultFavicon;
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700106 private boolean mIsKeyboardUp = false;
John Reck1cf4b792011-07-26 10:22:22 -0700107
Michael Kolba3194d02011-09-07 11:23:51 -0700108 private static Paint sAlphaPaint = new Paint();
109 static {
110 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
111 sAlphaPaint.setColor(Color.TRANSPARENT);
112 }
113
Steve Block2466eff2011-10-03 15:33:09 +0100114 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100115 // The page's main resource does not use SSL. Note that we use this
116 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100117 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100118 // The page's main resource uses SSL and the certificate is good. The
119 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100120 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100121 // The page's main resource uses SSL and the certificate is good, but
122 // some sub-resources either do not use SSL or have problems with their
123 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100124 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100125 // The page's main resource uses SSL but there is a problem with its
126 // certificate.
127 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800128 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700129
Michael Kolb14612442011-06-24 13:06:29 -0700130 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700131 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700132
Michael Kolbc831b632011-05-11 09:30:34 -0700133 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700134 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700135
Grace Kloba22ac16e2009-10-07 18:00:23 -0700136 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800137 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700138 // Main WebView
139 private WebView mMainView;
140 // Subwindow container
141 private View mSubViewContainer;
142 // Subwindow WebView
143 private WebView mSubView;
144 // Saved bundle for when we are running low on memory. It contains the
145 // information needed to restore the WebView if the user goes back to the
146 // tab.
147 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700148 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
149 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700150 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700151 // Tab that constructed by this Tab. This is used when this Tab is
152 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700153 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700154 // If true, the tab is in the foreground of the current activity.
155 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700156 // If true, the tab is in page loading state (after onPageStarted,
157 // before onPageFinsihed)
158 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700159 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700160 private boolean mDisableOverrideUrlLoading;
Pankaj Garg79878492015-04-01 14:48:21 -0700161 private boolean mFirstVisualPixelPainted = false;
John Reck30c714c2010-12-16 17:30:34 -0800162 // The last reported progress of the current page
163 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000164 // The time the load started, used to find load page time
165 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700166 // Application identifier used to find tabs that another application wants
167 // to reuse.
168 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700169 // flag to indicate if tab should be closed on back
170 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700171 // flag to indicate if the tab was opened from an intent
172 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500173 // The listener that gets invoked when a download is started from the
174 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700175 private final BrowserDownloadListener mDownloadListener;
John Recke969cc52010-12-21 17:24:43 -0800176 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700177
178 // AsyncTask for downloading touch icons
179 DownloadTouchIcon mTouchIconLoader;
180
John Reck35e9dd62011-04-25 09:01:54 -0700181 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700182 private int mCaptureWidth;
183 private int mCaptureHeight;
184 private Bitmap mCapture;
Pankaj Gargf49e0222015-09-01 12:19:13 -0700185 private Bitmap mViewportCapture;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700186 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700187 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800188 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700189 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800190 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700191
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700192 // determine if webview is destroyed to MemoryMonitor
193 private boolean mWebViewDestroyedByMemoryMonitor;
194
Vivek Sekhar0c609cd2015-12-10 16:00:05 -0800195 // Tab started initally in background
196 private boolean mBackgroundTab;
197
Pankaj Garg21dad562015-07-02 17:17:24 -0700198 private String mTouchIconUrl;
199
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700200 private Observable mFirstPixelObservable;
201 private Observable mTabHistoryUpdateObservable;
202
203 Observable getFirstPixelObservable() {
204 return mFirstPixelObservable;
205 }
206
207 Observable getTabHistoryUpdateObservable() {
208 return mTabHistoryUpdateObservable;
209 }
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700210
Ze G Riande2a675c22015-06-03 11:15:24 -0700211 // dertermines if the tab contains a disllable page
212 private boolean mIsDistillable = false;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100213
John Reck1cf4b792011-07-26 10:22:22 -0700214 private static synchronized Bitmap getDefaultFavicon(Context context) {
215 if (sDefaultFavicon == null) {
216 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800217 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700218 }
219 return sDefaultFavicon;
220 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800221
John Reck30c714c2010-12-16 17:30:34 -0800222 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700223 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800224 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700225 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800226 String mTitle;
Steve Block08a6f0c2011-10-06 12:12:53 +0100227 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700228 SecurityState mSecurityState;
229 // This is non-null only when onReceivedIcon is called or SnapshotTab restores it.
John Reck30c714c2010-12-16 17:30:34 -0800230 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100231 boolean mIsBookmarkedSite;
232 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800233
234 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700235 mIncognito = incognito;
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700236 mOriginalUrl = mUrl = "";
John Reck502a3532011-08-16 14:21:46 -0700237 if (mIncognito) {
John Reck30c714c2010-12-16 17:30:34 -0800238 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800239 } else {
John 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
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700245 PageState(Context c, boolean incognito, String url) {
John Reck502a3532011-08-16 14:21:46 -0700246 mIncognito = incognito;
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700247 if (mIncognito)
248 mOriginalUrl = mUrl = "";
249 else
250 mOriginalUrl = mUrl = url;
Pankaj Garg96d0ccd2015-07-30 16:49:47 -0700251 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800252 }
John Reck1cf4b792011-07-26 10:22:22 -0700253
Grace Kloba22ac16e2009-10-07 18:00:23 -0700254 }
255
John Reck30c714c2010-12-16 17:30:34 -0800256 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700257 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800258
Grace Kloba22ac16e2009-10-07 18:00:23 -0700259 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700260 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261 static final String CURRURL = "currentUrl";
262 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700263 static final String PARENTTAB = "parentTab";
264 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700265 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700266 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700267 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700268
Pankaj Garg18186a92015-03-31 14:59:33 -0700269 public void setNetworkAvailable(boolean networkUp) {
270 if (networkUp && mReceivedError && (mMainView != null)) {
271 mMainView.reload();
272 }
273 }
274
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700275 public boolean isFirstVisualPixelPainted() {
276 return mFirstVisualPixelPainted;
277 }
278
279 public int getCaptureIndex(int navIndex) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700280 int orientation = mWebViewController.getActivity().
281 getResources().getConfiguration().orientation;
282
283 int orientationBit = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? 0 : 1;
284
Vivek Sekhard0f60402015-06-05 14:07:11 -0700285 int index = orientationBit << 31 | (((int)mId & 0x7f) << 24) | (navIndex & 0xffffff);
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700286 return index;
287 }
288
289 public int getTabIdxFromCaptureIdx(int index) {
290 return (index & 0x7f000000) >> 24;
291 }
292
293 public int getOrientationFromCaptureIdx(int index) {
294 return ((index & 0x80000000) == 0) ? Configuration.ORIENTATION_LANDSCAPE :
295 Configuration.ORIENTATION_PORTRAIT;
296
297 }
298
299 public int getNavIdxFromCaptureIdx(int index) {
300 return (index & 0xffffff);
301 }
302
Pankaj Garg96d0ccd2015-07-30 16:49:47 -0700303 public static SecurityState getWebViewSecurityState(WebView view) {
304 switch (view.getSecurityLevel()) {
305 case WebView.SecurityLevel.EV_SECURE:
306 case WebView.SecurityLevel.SECURE:
307 return SecurityState.SECURITY_STATE_SECURE;
308 case WebView.SecurityLevel.SECURITY_ERROR:
309 return SecurityState.SECURITY_STATE_BAD_CERTIFICATE;
310 case WebView.SecurityLevel.SECURITY_POLICY_WARNING:
311 case WebView.SecurityLevel.SECURITY_WARNING:
312 return SecurityState.SECURITY_STATE_MIXED;
313 }
314 return SecurityState.SECURITY_STATE_NOT_SECURE;
315 }
316
Grace Kloba22ac16e2009-10-07 18:00:23 -0700317 // -------------------------------------------------------------------------
318 // WebViewClient implementation for the main WebView
319 // -------------------------------------------------------------------------
320
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800321 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500322 private Message mDontResend;
323 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700324
325 private boolean providersDiffer(String url, String otherUrl) {
326 Uri uri1 = Uri.parse(url);
327 Uri uri2 = Uri.parse(otherUrl);
328 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
329 }
330
Grace Kloba22ac16e2009-10-07 18:00:23 -0700331 @Override
332 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Ze G Riande2a675c22015-06-03 11:15:24 -0700333 setIsDistillable(false);
Vivek Sekhar0c609cd2015-12-10 16:00:05 -0800334 mBackgroundTab = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700335 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700336 mPageFinished = false;
Pankaj Garg79878492015-04-01 14:48:21 -0700337 mFirstVisualPixelPainted = false;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700338 mFirstPixelObservable.set(false);
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800339 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700340 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700341 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700342 mCurrentState = new PageState(mContext,
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700343 view.isPrivateBrowsingEnabled(), url);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000344 mLoadStartTime = SystemClock.uptimeMillis();
Pankaj Garg62bc7912015-04-14 16:08:59 -0700345 // Need re-enable FullScreenMode on Page navigation if needed
346 if (BrowserSettings.getInstance().useFullscreen()){
347 Controller controller = (Controller) mWebViewController;
348 BaseUi ui = (BaseUi) controller.getUi();
349 ui.forceDisableFullscreenMode(false);
350 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700351 // If we start a touch icon load and then load a new page, we don't
352 // want to cancel the current touch icon loader. But, we do want to
353 // create a new one when the touch icon url is known.
354 if (mTouchIconLoader != null) {
355 mTouchIconLoader.mTab = null;
356 mTouchIconLoader = null;
357 }
358
Grace Kloba22ac16e2009-10-07 18:00:23 -0700359 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800360 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500361
John Recke969cc52010-12-21 17:24:43 -0800362 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700363 }
364
365 @Override
366 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700367 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800368 if (!isPrivateBrowsingEnabled()) {
369 LogTag.logPageFinishedLoading(
370 url, SystemClock.uptimeMillis() - mLoadStartTime);
371 }
John Reck1cf4b792011-07-26 10:22:22 -0700372 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800373 mWebViewController.onPageFinished(Tab.this);
Pankaj Garg96d0ccd2015-07-30 16:49:47 -0700374 setSecurityState(getWebViewSecurityState(view));
Grace Kloba22ac16e2009-10-07 18:00:23 -0700375 }
376
Pankaj Garg79878492015-04-01 14:48:21 -0700377 @Override
378 public void onFirstVisualPixel(WebView view) {
379 mFirstVisualPixelPainted = true;
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700380 mFirstPixelObservable.set(true);
Pankaj Garg79878492015-04-01 14:48:21 -0700381 }
382
Grace Kloba22ac16e2009-10-07 18:00:23 -0700383 // return true if want to hijack the url to let another app to handle it
384 @Override
385 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700386 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800387 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
388 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700389 } else {
390 return false;
391 }
392 }
393
Vivek Sekharb991edb2014-12-17 18:18:07 -0800394 @Override
395 public boolean shouldDownloadFavicon(WebView view, String url) {
396 return true;
397 }
398
Grace Kloba22ac16e2009-10-07 18:00:23 -0700399 /**
Steve Block2466eff2011-10-03 15:33:09 +0100400 * Updates the security state. This method is called when we discover
401 * another resource to be loaded for this page (for example,
402 * javascript). While we update the security state, we do not update
403 * the lock icon until we are done loading, as it is slightly more
404 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700405 */
406 @Override
407 public void onLoadResource(WebView view, String url) {
408 if (url != null && url.length() > 0) {
409 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100410 // to update the security state:
411 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
412 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700413 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
414 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100415 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700416 }
417 }
418 }
419 }
420
421 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700422 * Show a dialog informing the user of the network error reported by
423 * WebCore if it is in the foreground.
424 */
425 @Override
426 public void onReceivedError(WebView view, int errorCode,
427 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800428 // Used for the syncCurrentState to use
429 // the failing url instead of using webview url
430 mReceivedError = true;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700431 }
432
433 /**
434 * Check with the user if it is ok to resend POST data as the page they
435 * are trying to navigate to is the result of a POST.
436 */
437 @Override
438 public void onFormResubmission(WebView view, final Message dontResend,
439 final Message resend) {
440 if (!mInForeground) {
441 dontResend.sendToTarget();
442 return;
443 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500444 if (mDontResend != null) {
445 Log.w(LOGTAG, "onFormResubmission should not be called again "
446 + "while dialog is still up");
447 dontResend.sendToTarget();
448 return;
449 }
450 mDontResend = dontResend;
451 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700452 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700453 R.string.browserFrameFormResubmitLabel).setMessage(
454 R.string.browserFrameFormResubmitMessage)
455 .setPositiveButton(R.string.ok,
456 new DialogInterface.OnClickListener() {
457 public void onClick(DialogInterface dialog,
458 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500459 if (mResend != null) {
460 mResend.sendToTarget();
461 mResend = null;
462 mDontResend = null;
463 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700464 }
465 }).setNegativeButton(R.string.cancel,
466 new DialogInterface.OnClickListener() {
467 public void onClick(DialogInterface dialog,
468 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500469 if (mDontResend != null) {
470 mDontResend.sendToTarget();
471 mResend = null;
472 mDontResend = null;
473 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700474 }
475 }).setOnCancelListener(new OnCancelListener() {
476 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500477 if (mDontResend != null) {
478 mDontResend.sendToTarget();
479 mResend = null;
480 mDontResend = null;
481 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700482 }
483 }).show();
484 }
485
486 /**
487 * Insert the url into the visited history database.
488 * @param url The url to be inserted.
489 * @param isReload True if this url is being reloaded.
490 * FIXME: Not sure what to do when reloading the page.
491 */
492 @Override
493 public void doUpdateVisitedHistory(WebView view, String url,
494 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800495 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700496 }
497
498 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700499 * Handles an HTTP authentication request.
500 *
501 * @param handler The authentication handler
502 * @param host The host
503 * @param realm The realm
504 */
505 @Override
506 public void onReceivedHttpAuthRequest(WebView view,
507 final HttpAuthHandler handler, final String host,
508 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700509 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700510 }
511
512 @Override
John Reck438bf462011-01-12 18:11:46 -0800513 public WebResourceResponse shouldInterceptRequest(WebView view,
514 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800515 //intercept if opening a new incognito tab - show the incognito welcome page
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700516
517 // show only incognito content and webview has private
518 // and cannot go back(only supported if explicit from UI )
519 if (view.isPrivateBrowsingEnabled() &&
520 !view.canGoBack() &&
521 url.startsWith(Controller.INCOGNITO_URI)) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800522 Resources resourceHandle = mContext.getResources();
523 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700524 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800525 return new WebResourceResponse("text/html", "utf8", inStream);
526 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800527 WebResourceResponse res;
528 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
529 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
530 } else {
531 res = HomeProvider.shouldInterceptRequest(mContext, url);
532 }
John Reck438bf462011-01-12 18:11:46 -0800533 return res;
534 }
535
536 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700537 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
538 if (!mInForeground) {
539 return false;
540 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700541 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700542 }
543
544 @Override
545 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700546 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700547 return;
548 }
John Reck997b1b72012-04-19 18:08:25 -0700549 if (!mWebViewController.onUnhandledKeyEvent(event)) {
550 super.onUnhandledKeyEvent(view, event);
551 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700552 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700553
554 @Override
555 public void beforeNavigation(WebView view, String url) {
Pankaj Garg21dad562015-07-02 17:17:24 -0700556 mTouchIconUrl = null;
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700557 TitleBar titleBar = null;
558 Controller controller = (Controller)mWebViewController;
559 UI ui = controller.getUi();
560
Sagar Dhawanfb79bf42015-08-21 12:37:29 -0700561 // Clear the page state
562 mCurrentState = new PageState(mContext,
563 view.isPrivateBrowsingEnabled(), url);
564
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700565 if (ui instanceof BaseUi) {
566 titleBar = ((BaseUi)ui).getTitleBar();
567 if (titleBar != null) {
568 NavigationBarBase navBar = titleBar.getNavigationBar();
569 navBar.showCurrentFavicon(Tab.this); // Show the default Favicon while loading a new page
570 }
571 }
572
Site Mao61b68212015-07-16 10:56:31 -0700573 if (BaseUi.isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700574 return;
575 }
576
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700577 if (isPrivateBrowsingEnabled()) {
578 return;
579 }
580
581 if (!mFirstVisualPixelPainted) {
582 return;
583 }
584
585 final int idx = view.copyBackForwardList().getCurrentIndex();
586 boolean bitmapExists = view.hasSnapshot(idx);
587
588 int progress = 100;
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700589 if (titleBar != null) {
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700590 progress = titleBar.getProgressView().getProgressPercent();
591 }
592
593 if (bitmapExists && progress < 85) {
594 return;
595 }
596
597 int index = getCaptureIndex(view.getLastCommittedHistoryIndex());
Sagar Dhawan49f85cf2015-07-10 16:54:20 -0700598 view.captureSnapshot(index, null);
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700599 }
600
601 @Override
602 public void onHistoryItemCommit(WebView view, int index) {
Site Mao61b68212015-07-16 10:56:31 -0700603 if (BaseUi.isUiLowPowerMode()) {
Pankaj Garg18aa0a12015-06-22 11:06:12 -0700604 return;
605 }
606
Axesh R. Ajmera4a6838a2015-07-23 15:08:14 -0700607 // prevent snapshot tab from commiting any history
608 if (isSnapshot()) {
609 return;
610 }
611
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700612 mTabHistoryUpdateObservable.set(index);
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700613 final int maxIdx = view.copyBackForwardList().getSize();
614 final WebView wv = view;
Pankaj Garg036365b2015-09-14 11:21:19 -0700615 final int currIdx = index;
Vivek Sekhar6213e2e2015-12-22 10:51:04 -0800616 final int currentTabIdx = (int) Tab.this.getId();
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700617 view.getSnapshotIds(new ValueCallback <List<Integer>>() {
618 @Override
619 public void onReceiveValue(List<Integer> ids) {
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700620 for (Integer id : ids) {
Pankaj Garg036365b2015-09-14 11:21:19 -0700621 int tabIdx = getTabIdxFromCaptureIdx(id);
622 int navIdx = getNavIdxFromCaptureIdx(id);
623 if (tabIdx == currentTabIdx && (navIdx >= maxIdx || navIdx == currIdx)) {
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700624 wv.deleteSnapshot(id);
625 }
626 }
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700627 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -0700628 });
Pankaj Garg1c13cab2015-05-12 11:52:17 -0700629 }
Pankaj Garg62bc7912015-04-14 16:08:59 -0700630
631 @Override
632 public void onKeyboardStateChange(boolean popup) {
Vivek Sekhard4de6162015-07-21 15:01:45 -0700633 boolean keyboardWasShowing = isKeyboardShowing();
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700634 mIsKeyboardUp = popup;
Vivek Sekhard4de6162015-07-21 15:01:45 -0700635 Controller controller = (Controller)mWebViewController;
636 BaseUi ui = (BaseUi) controller.getUi();
637 // lock the title bar
638 if (popup)
639 ui.getTitleBar().showTopControls(true);
640 if (keyboardWasShowing && popup)
641 ui.getTitleBar().enableTopControls(true);
Pankaj Garg62bc7912015-04-14 16:08:59 -0700642 if (BrowserSettings.getInstance().useFullscreen()) {
Pankaj Garg62bc7912015-04-14 16:08:59 -0700643 ui.forceDisableFullscreenMode(popup);
644 }
645 }
Vivek Sekharae3b1792015-08-03 12:26:41 -0700646
647 @Override
648 public void onAttachInterstitialPage(WebView mWebView) {
649 Controller controller = (Controller)mWebViewController;
650 BaseUi ui = (BaseUi) controller.getUi();
651 ui.getTitleBar().showTopControls(false);
652 }
653
654 @Override
655 public void onDetachInterstitialPage(WebView mWebView) {
656 Controller controller = (Controller)mWebViewController;
657 BaseUi ui = (BaseUi) controller.getUi();
658 ui.getTitleBar().enableTopControls(true);
659 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700660 };
661
John Reck1cf4b792011-07-26 10:22:22 -0700662 private void syncCurrentState(WebView view, String url) {
663 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800664
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700665
666
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800667 if (mReceivedError) {
668 mCurrentState.mUrl = url;
669 mCurrentState.mOriginalUrl = url;
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700670 } else if (view.isPrivateBrowsingEnabled() &&
671 !TextUtils.isEmpty(url) &&
672 url.contains(Controller.INCOGNITO_URI)) {
Vivek Sekharb826fba2015-12-09 11:27:20 -0800673 mCurrentState.mUrl = mCurrentState.mOriginalUrl = Controller.INCOGNITO_URI;
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700674 }
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -0700675
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -0700676 else {
677 mCurrentState.mUrl = view.getUrl();
678 mCurrentState.mOriginalUrl = view.getOriginalUrl();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800679 }
680
John Reck1cf4b792011-07-26 10:22:22 -0700681 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700682 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700683 }
John Reck1cf4b792011-07-26 10:22:22 -0700684 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800685
686
John Reck1cf4b792011-07-26 10:22:22 -0700687 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
688 // In case we stop when loading an HTTPS page from an HTTP page
689 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100690 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck1cf4b792011-07-26 10:22:22 -0700691 }
John Reck502a3532011-08-16 14:21:46 -0700692 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700693 }
694
Pankaj Garg21dad562015-07-02 17:17:24 -0700695 public String getTouchIconUrl() {
696 return mTouchIconUrl;
697 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700698
Sagar Dhawan33551ff2015-07-08 17:24:44 -0700699 public boolean isKeyboardShowing() {
700 Controller controller = (Controller)mWebViewController;
701 return (mIsKeyboardUp || controller.getUi().isEditingUrl());
702 }
703
Tarun Nainani8eb00912014-07-17 12:28:32 -0700704 public boolean isTabFullScreen() {
705 return mFullScreen;
706 }
707
Vivek Sekharf96064b2014-07-28 16:32:34 -0700708 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700709 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700710 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700711 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700712 }
713
Sudheer Koganti24766882014-10-02 10:58:09 -0700714 public boolean exitFullscreen() {
715 if (mFullScreen) {
716 Controller controller = (Controller)mWebViewController;
717 controller.getUi().showFullscreen(false);
718 if (getWebView() != null)
719 getWebView().exitFullscreen();
720 mFullScreen = false;
721 return true;
722 }
723 return false;
724 }
725
726
727
728
Grace Kloba22ac16e2009-10-07 18:00:23 -0700729 // -------------------------------------------------------------------------
730 // WebChromeClient implementation for the main WebView
731 // -------------------------------------------------------------------------
732
733 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
734 // Helper method to create a new tab or sub window.
735 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700736 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700737 }
738
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700739 private void createWindow(final boolean dialog, final Message msg, final String url,
740 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700741 WebView.WebViewTransport transport =
742 (WebView.WebViewTransport) msg.obj;
743 if (dialog) {
744 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700745 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700746 transport.setWebView(mSubView);
747 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700748 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700749 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700750 // This is special case for rendering links on a webpage in
751 // a new tab. If opener is suppressed, the WebContents created
752 // by the content layer are not fully initialized. This check
753 // will prevent content layer from overriding WebContents
754 // created by new tab with the uninitialized instance.
755 if (!opener_suppressed) {
756 transport.setWebView(newTab.getWebView());
757 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700758 }
759 msg.sendToTarget();
760 }
761
762 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700763 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
764 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700765 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700766 }
767 }
768
769 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700770 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
771 float contentOffsetYPix,
772 float overdrawBottomHeightPix) {
773 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700774 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700775 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar11b40062015-06-24 11:49:04 -0700776 // Resize the viewport if top controls is not visible
Vivek Sekhar2ee19a32015-07-02 17:03:57 -0700777 if (mMainView != null &&
778 (topControlsOffsetYPix == 0.0f || contentOffsetYPix == 0.0f))
Vivek Sekhar11b40062015-06-24 11:49:04 -0700779 ((BrowserWebView)mMainView).enableTopControls(
780 (topControlsOffsetYPix == 0.0f) ? true : false);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700781 }
782 }
783
784 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700785 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700786 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700787 }
788
789 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700790 public boolean onCreateWindow(WebView view, final boolean dialog,
791 final boolean userGesture, final Message resultMsg) {
792 // only allow new window or sub window for the foreground case
793 if (!mInForeground) {
794 return false;
795 }
796 // Short-circuit if we can't create any more tabs or sub windows.
797 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700798 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700799 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200800 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700801 .setMessage(R.string.too_many_subwindows_dialog_message)
802 .setPositiveButton(R.string.ok, null)
803 .show();
804 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700805 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700806 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700807 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200808 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700809 .setMessage(R.string.too_many_windows_dialog_message)
810 .setPositiveButton(R.string.ok, null)
811 .show();
812 return false;
813 }
814
815 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800816 if (userGesture || !mSettings.blockPopupWindows()) {
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700817 WebView.WebViewTransport transport =
818 (WebView.WebViewTransport) resultMsg.obj;
819 CreateWindowParams windowParams = transport.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700820 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700821 createWindow(dialog, resultMsg, windowParams.mURL, true);
822 // This is special case for rendering links on a webpage in
823 // a new tab. If opener is suppressed, the WebContents created
824 // by the content layer are not fully initialized. Returning false
825 // will prevent content layer from overriding WebContents
826 // created by new tab with the uninitialized instance.
827 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700828 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700829
830 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700831 return true;
832 }
833
Tarun Nainani4f5137d2015-04-16 17:26:18 -0700834 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700835 return true;
836 }
837
838 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500839 public void onRequestFocus(WebView view) {
840 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700841 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500842 }
843 }
844
845 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700846 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700847 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700848 // JavaScript can only close popup window.
849 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700850 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700851 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700852 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700853 }
854 }
855
856 @Override
857 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800858 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800859 if (newProgress == 100) {
860 mInPageLoad = false;
861 }
John Reck30c714c2010-12-16 17:30:34 -0800862 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700863 if (mUpdateThumbnail && newProgress == 100) {
864 mUpdateThumbnail = false;
865 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700866 }
867
868 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500869 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800870 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700871 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700872 }
873
874 @Override
875 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800876 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700877 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700878 }
879
880 @Override
881 public void onReceivedTouchIconUrl(WebView view, String url,
882 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700883 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400884 // Let precomposed icons take precedence over non-composed
885 // icons.
886 if (precomposed && mTouchIconLoader != null) {
887 mTouchIconLoader.cancel(false);
888 mTouchIconLoader = null;
889 }
890 // Have only one async task at a time.
891 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700892 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700893 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400894 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700895 }
Pankaj Garg21dad562015-07-02 17:17:24 -0700896 mTouchIconUrl = url;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700897 }
898
899 @Override
900 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800901 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700902 Activity activity = mWebViewController.getActivity();
903 if (activity != null) {
904 onShowCustomView(view, activity.getRequestedOrientation(), callback);
905 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400906 }
907
908 @Override
909 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800910 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700911 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400912 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700913 }
914
915 @Override
916 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700917 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700918 }
919
920 /**
921 * The origin has exceeded its database quota.
922 * @param url the URL that exceeded the quota
923 * @param databaseIdentifier the identifier of the database on which the
924 * transaction that caused the quota overflow was run
925 * @param currentQuota the current quota for the origin.
926 * @param estimatedSize the estimated size of the database.
927 * @param totalUsedQuota is the sum of all origins' quota.
928 * @param quotaUpdater The callback to run when a decision to allow or
929 * deny quota has been made. Don't forget to call this!
930 */
931 @Override
932 public void onExceededDatabaseQuota(String url,
933 String databaseIdentifier, long currentQuota, long estimatedSize,
934 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700935 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700936 .onExceededDatabaseQuota(url, databaseIdentifier,
937 currentQuota, estimatedSize, totalUsedQuota,
938 quotaUpdater);
939 }
940
941 /**
942 * The Application Cache has exceeded its max size.
943 * @param spaceNeeded is the amount of disk space that would be needed
944 * in order for the last appcache operation to succeed.
945 * @param totalUsedQuota is the sum of all origins' quota.
946 * @param quotaUpdater A callback to inform the WebCore thread that a
947 * new app cache size is available. This callback must always
948 * be executed at some point to ensure that the sleeping
949 * WebCore thread is woken up.
950 */
951 @Override
952 public void onReachedMaxAppCacheSize(long spaceNeeded,
953 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700954 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700955 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
956 quotaUpdater);
957 }
958
Ben Murdoch65acc352009-11-19 18:16:04 +0000959 /* Adds a JavaScript error message to the system log and if the JS
960 * console is enabled in the about:debug options, to that console
961 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +0000962 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700963 */
964 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +0000965 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -0500966 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -0700967 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -0500968
Ben Murdochc42addf2010-01-28 15:19:59 +0000969 String message = "Console: " + consoleMessage.message() + " "
970 + consoleMessage.sourceId() + ":"
971 + consoleMessage.lineNumber();
972
973 switch (consoleMessage.messageLevel()) {
974 case TIP:
975 Log.v(CONSOLE_LOGTAG, message);
976 break;
977 case LOG:
978 Log.i(CONSOLE_LOGTAG, message);
979 break;
980 case WARNING:
981 Log.w(CONSOLE_LOGTAG, message);
982 break;
983 case ERROR:
984 Log.e(CONSOLE_LOGTAG, message);
985 break;
986 case DEBUG:
987 Log.d(CONSOLE_LOGTAG, message);
988 break;
989 }
990
991 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700992 }
993
994 /**
995 * Ask the browser for an icon to represent a <video> element.
996 * This icon will be used if the Web page did not specify a poster attribute.
997 * @return Bitmap The icon or null if no such icon is available.
998 */
999 @Override
1000 public Bitmap getDefaultVideoPoster() {
1001 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001002 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001003 }
1004 return null;
1005 }
1006
1007 /**
1008 * Ask the host application for a custom progress view to show while
1009 * a <video> is loading.
1010 * @return View The progress view.
1011 */
1012 @Override
1013 public View getVideoLoadingProgressView() {
1014 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001015 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001016 }
1017 return null;
1018 }
1019
1020 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001021 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001022 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001023 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001024 } else {
1025 uploadMsg.onReceiveValue(null);
1026 }
1027 }
1028
Vivek Sekharb54614f2014-05-01 19:03:37 -07001029 @Override
1030 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1031 boolean capture) {
1032 if (mInForeground) {
1033 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1034 } else {
1035 uploadFilePaths.onReceiveValue(null);
1036 }
1037 }
1038
Grace Kloba22ac16e2009-10-07 18:00:23 -07001039 /**
1040 * Deliver a list of already-visited URLs
1041 */
1042 @Override
1043 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001044 mWebViewController.getVisitedHistory(callback);
1045 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001046
1047 @Override
1048 public void setupAutoFill(Message message) {
1049 // Prompt the user to set up their profile.
1050 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001051 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1052 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001053 Context.LAYOUT_INFLATER_SERVICE);
1054 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1055
1056 builder.setView(layout)
1057 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1058 @Override
1059 public void onClick(DialogInterface dialog, int id) {
1060 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1061 R.id.setup_autofill_dialog_disable_autofill);
1062
1063 if (disableAutoFill.isChecked()) {
1064 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001065 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001066 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001067 R.string.autofill_setup_dialog_negative_toast,
1068 Toast.LENGTH_LONG).show();
1069 } else {
1070 // Take user to the AutoFill profile editor. When they return,
1071 // we will send the message that we pass here which will trigger
1072 // the form to get filled out with their new profile.
1073 mWebViewController.setupAutoFill(msg);
1074 }
1075 }
1076 })
1077 .setNegativeButton(R.string.cancel, null)
1078 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001079 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001080 };
1081
1082 // -------------------------------------------------------------------------
1083 // WebViewClient implementation for the sub window
1084 // -------------------------------------------------------------------------
1085
1086 // Subclass of WebViewClient used in subwindows to notify the main
1087 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001088 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001089 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001090 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001091 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001092
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001093 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001094 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001095 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001096 }
1097 @Override
1098 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1099 // Unlike the others, do not call mClient's version, which would
1100 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001101 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001102 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001103 }
1104 @Override
1105 public void doUpdateVisitedHistory(WebView view, String url,
1106 boolean isReload) {
1107 mClient.doUpdateVisitedHistory(view, url, isReload);
1108 }
1109 @Override
1110 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1111 return mClient.shouldOverrideUrlLoading(view, url);
1112 }
1113 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001114 public void onReceivedHttpAuthRequest(WebView view,
1115 HttpAuthHandler handler, String host, String realm) {
1116 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1117 }
1118 @Override
1119 public void onFormResubmission(WebView view, Message dontResend,
1120 Message resend) {
1121 mClient.onFormResubmission(view, dontResend, resend);
1122 }
1123 @Override
1124 public void onReceivedError(WebView view, int errorCode,
1125 String description, String failingUrl) {
1126 mClient.onReceivedError(view, errorCode, description, failingUrl);
1127 }
1128 @Override
1129 public boolean shouldOverrideKeyEvent(WebView view,
1130 android.view.KeyEvent event) {
1131 return mClient.shouldOverrideKeyEvent(view, event);
1132 }
1133 @Override
1134 public void onUnhandledKeyEvent(WebView view,
1135 android.view.KeyEvent event) {
1136 mClient.onUnhandledKeyEvent(view, event);
1137 }
1138 }
1139
1140 // -------------------------------------------------------------------------
1141 // WebChromeClient implementation for the sub window
1142 // -------------------------------------------------------------------------
1143
1144 private class SubWindowChromeClient extends WebChromeClient {
1145 // The main WebChromeClient.
1146 private final WebChromeClient mClient;
1147
1148 SubWindowChromeClient(WebChromeClient client) {
1149 mClient = client;
1150 }
1151 @Override
1152 public void onProgressChanged(WebView view, int newProgress) {
1153 mClient.onProgressChanged(view, newProgress);
1154 }
1155 @Override
1156 public boolean onCreateWindow(WebView view, boolean dialog,
1157 boolean userGesture, android.os.Message resultMsg) {
1158 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1159 }
1160 @Override
1161 public void onCloseWindow(WebView window) {
1162 if (window != mSubView) {
1163 Log.e(LOGTAG, "Can't close the window");
1164 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001165 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001166 }
1167 }
1168
1169 // -------------------------------------------------------------------------
1170
1171 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001172 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001173 this(wvcontroller, w, null);
1174 }
1175
1176 Tab(WebViewController wvcontroller, Bundle state) {
1177 this(wvcontroller, null, state);
1178 }
1179
1180 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Vivek Sekhar0c609cd2015-12-10 16:00:05 -08001181 this(wvcontroller, null, state, false);
1182 }
1183
1184 Tab(WebViewController wvcontroller, WebView w, Bundle state, boolean backgroundTab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001185 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001186 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001187 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001188 mDataController = DataController.getInstance(mContext);
1189 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001190 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001191 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001192 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001193 mInForeground = false;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001194 mWebViewDestroyedByMemoryMonitor = false;
Vivek Sekhar0c609cd2015-12-10 16:00:05 -08001195 mBackgroundTab = backgroundTab;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001196
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001197 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001198 public void onDownloadStart(String url, String userAgent,
Pankaj Garg5762b362015-11-02 07:57:06 -08001199 String contentDisposition, String mimetype, String referer, String auth,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001200 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001201 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Pankaj Garg5762b362015-11-02 07:57:06 -08001202 mimetype, referer, auth, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001203 }
1204 };
1205
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001206 mCaptureWidth = mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_width);
1207 mCaptureHeight =mContext.getResources().getDimensionPixelSize(R.dimen.tab_thumbnail_height);
1208
1209 initCaptureBitmap();
1210
John Reck1cf4b792011-07-26 10:22:22 -07001211 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001212 if (getId() == -1) {
1213 mId = TabControl.getNextId();
1214 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001215 setWebView(w);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -07001216
1217 UI ui = ((Controller)mWebViewController).getUi();
1218 if (ui instanceof BaseUi) {
1219 TitleBar titleBar = ((BaseUi)ui).getTitleBar();
1220 if (titleBar != null) {
1221 NavigationBarBase navBar = titleBar.getNavigationBar();
1222 navBar.showCurrentFavicon(this); // Show the default Favicon while loading a new page
1223 }
1224 }
1225
Michael Kolb9ef259a2011-07-12 15:33:08 -07001226 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001227 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001228 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001229 switch (m.what) {
1230 case MSG_CAPTURE:
1231 capture();
1232 break;
1233 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001234 }
1235 };
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001236
1237 mFirstPixelObservable = new Observable();
1238 mFirstPixelObservable.set(false);
1239 mTabHistoryUpdateObservable = new Observable();
John Reck1cf4b792011-07-26 10:22:22 -07001240 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001241
Pankaj Gargb4b4f012015-08-04 16:19:14 -07001242 public void initCaptureBitmap() {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001243 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight, Bitmap.Config.RGB_565);
1244 mCapture.eraseColor(Color.WHITE);
Michael Kolb72864272012-05-03 15:42:15 -07001245 }
1246
Mathew Inwoode09305e2011-09-02 12:03:26 +01001247 /**
1248 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1249 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1250 * to overlapping IDs between the preloaded and restored tabs.
1251 */
1252 public void refreshIdAfterPreload() {
1253 mId = TabControl.getNextId();
1254 }
1255
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001256 public void setController(WebViewController ctl) {
1257 mWebViewController = ctl;
1258
John Reck1cf4b792011-07-26 10:22:22 -07001259 if (mWebViewController.shouldCaptureThumbnails()) {
1260 synchronized (Tab.this) {
1261 if (mCapture == null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001262 initCaptureBitmap();
1263 if (mInForeground && !mHandler.hasMessages(MSG_CAPTURE)) {
1264 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
John Reck1cf4b792011-07-26 10:22:22 -07001265 }
1266 }
1267 }
1268 } else {
1269 synchronized (Tab.this) {
1270 mCapture = null;
1271 deleteThumbnail();
1272 }
1273 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001274 }
1275
Michael Kolbc831b632011-05-11 09:30:34 -07001276 public long getId() {
1277 return mId;
1278 }
1279
Michael Kolb91911a22012-01-17 11:21:25 -08001280 void setWebView(WebView w) {
1281 setWebView(w, true);
1282 }
1283
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001284 public boolean isNativeActive(){
1285 if (mMainView == null)
1286 return false;
1287 return true;
1288 }
1289
1290 public void setTimeStamp(){
1291 Date d = new Date();
1292 timestamp = (new Timestamp(d.getTime()));
1293 }
1294
1295 public Timestamp getTimestamp() {
1296 return timestamp;
1297 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001298 /**
1299 * Sets the WebView for this tab, correctly removing the old WebView from
1300 * the container view.
1301 */
Michael Kolb91911a22012-01-17 11:21:25 -08001302 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001303 if (mMainView == w) {
1304 return;
1305 }
Michael Kolba713ec82010-11-29 17:27:06 -08001306
Michael Kolba713ec82010-11-29 17:27:06 -08001307 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001308
John Reck1cf4b792011-07-26 10:22:22 -07001309 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001310 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001311 if (w != null) {
1312 syncCurrentState(w, null);
Vivek Sekhar0c609cd2015-12-10 16:00:05 -08001313 } else if(!mWebViewDestroyedByMemoryMonitor) {
1314 mCurrentState = new PageState(mContext,
1315 mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001316 }
1317 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001318 // set the new one
1319 mMainView = w;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001320
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001321 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001322 if (mMainView != null) {
1323 mMainView.setWebViewClient(mWebViewClient);
1324 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001325 // Attach DownloadManager so that downloads can start in an active
1326 // or a non-active window. This can happen when going to a site that
1327 // does a redirect after a period of time. The user could have
1328 // switched to another tab while waiting for the download to start.
1329 mMainView.setDownloadListener(mDownloadListener);
John Reck8ee633f2011-08-09 16:00:35 -07001330 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001331 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001332 mMainView.setPictureListener(this);
1333 }
Michael Kolb91911a22012-01-17 11:21:25 -08001334 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001335 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001336 WebBackForwardList restoredState
1337 = mMainView.restoreState(mSavedState);
1338 if (restoredState == null || restoredState.getSize() == 0) {
1339 Log.w(LOGTAG, "Failed to restore WebView state!");
1340 loadUrl(mCurrentState.mOriginalUrl, null);
1341 }
Vivek Sekhar0c609cd2015-12-10 16:00:05 -08001342 mWebViewDestroyedByMemoryMonitor = false;
John Reck1cf4b792011-07-26 10:22:22 -07001343 mSavedState = null;
Vivek Sekhar0c609cd2015-12-10 16:00:05 -08001344 } else if(restore && mBackgroundTab && mWebViewDestroyedByMemoryMonitor) {
1345 loadUrl(mCurrentState.mOriginalUrl, null);
1346 mWebViewDestroyedByMemoryMonitor = false;
John Reck1cf4b792011-07-26 10:22:22 -07001347 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001348 }
1349 }
1350
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001351 public void destroyThroughMemoryMonitor() {
1352 mWebViewDestroyedByMemoryMonitor = true;
1353 destroy();
1354 }
1355
Grace Kloba22ac16e2009-10-07 18:00:23 -07001356 /**
1357 * Destroy the tab's main WebView and subWindow if any
1358 */
1359 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001360
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001361 if (mPostponeDestroy) {
1362 mShouldDestroy = true;
1363 return;
1364 }
1365 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001366 if (mMainView != null) {
1367 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001368 // save the WebView to call destroy() after detach it from the tab
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001369 final WebView webView = mMainView;
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001370 setWebView(null);
Site Mao61b68212015-07-16 10:56:31 -07001371 if (!mWebViewDestroyedByMemoryMonitor && !BaseUi.isUiLowPowerMode()) {
Pankaj Garg036365b2015-09-14 11:21:19 -07001372 final int destroyedTabIdx = (int) mId;
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001373 // Tabs can be reused with new instance of WebView so delete the snapshots
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001374 webView.getSnapshotIds(new ValueCallback<List<Integer>>() {
1375 @Override
1376 public void onReceiveValue(List<Integer> ids) {
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001377 for (Integer id : ids) {
Pankaj Garg036365b2015-09-14 11:21:19 -07001378 if (getTabIdxFromCaptureIdx(id) == destroyedTabIdx) {
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001379 webView.deleteSnapshot(id);
1380 }
1381 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001382 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001383 }
Vivek Sekhar53ef8932015-06-18 16:51:43 -07001384 });
Vivek Sekhar2ee19a32015-07-02 17:03:57 -07001385 } else {
1386 webView.destroy();
Pankaj Garg1c13cab2015-05-12 11:52:17 -07001387 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001388 }
1389 }
1390
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001391 private boolean mPostponeDestroy = false;
1392 private boolean mShouldDestroy = false;
1393
1394 public void postponeDestroy() {
1395 mPostponeDestroy = true;
1396 }
1397
1398 public void performPostponedDestroy() {
1399 mPostponeDestroy = false;
1400 if (mShouldDestroy) {
1401 destroy();
1402 }
1403 }
1404
Grace Kloba22ac16e2009-10-07 18:00:23 -07001405 /**
1406 * Remove the tab from the parent
1407 */
1408 void removeFromTree() {
1409 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001410 if (mChildren != null) {
1411 for(Tab t : mChildren) {
1412 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001413 }
1414 }
1415 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001416 if (mParent != null) {
1417 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001418 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001419
1420 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001421 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001422 }
1423
1424 /**
1425 * Create a new subwindow unless a subwindow already exists.
1426 * @return True if a new subwindow was created. False if one already exists.
1427 */
1428 boolean createSubWindow() {
1429 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001430 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001431 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001432 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001433 mSubView.setWebChromeClient(new SubWindowChromeClient(
1434 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001435 // Set a different DownloadListener for the mSubView, since it will
1436 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001437 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001438 public void onDownloadStart(String url, String userAgent,
Pankaj Garg5762b362015-11-02 07:57:06 -08001439 String contentDisposition, String mimetype, String referer, String auth,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001440 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001441 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Pankaj Garg5762b362015-11-02 07:57:06 -08001442 contentDisposition, mimetype, referer, auth, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001443 if (mSubView.copyBackForwardList().getSize() == 0) {
1444 // This subwindow was opened for the sole purpose of
1445 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001446 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001447 }
1448 }
1449 });
Michael Kolb14612442011-06-24 13:06:29 -07001450 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001451 return true;
1452 }
1453 return false;
1454 }
1455
1456 /**
1457 * Dismiss the subWindow for the tab.
1458 */
1459 void dismissSubWindow() {
1460 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001461 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001462 mSubView.destroy();
1463 mSubView = null;
1464 mSubViewContainer = null;
1465 }
1466 }
1467
Grace Kloba22ac16e2009-10-07 18:00:23 -07001468
1469 /**
1470 * Set the parent tab of this tab.
1471 */
Michael Kolbc831b632011-05-11 09:30:34 -07001472 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001473 if (parent == this) {
1474 throw new IllegalStateException("Cannot set parent to self!");
1475 }
Michael Kolbc831b632011-05-11 09:30:34 -07001476 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001477 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001478 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001479 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001480 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001481 if (mSavedState != null) {
1482 if (parent == null) {
1483 mSavedState.remove(PARENTTAB);
1484 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001485 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001486 }
1487 }
John Reckb0a86db2011-05-24 14:05:58 -07001488
1489 // Sync the WebView useragent with the parent
1490 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1491 != mSettings.hasDesktopUseragent(getWebView())) {
1492 mSettings.toggleDesktopUseragent(getWebView());
1493 }
John Reck52be4782011-08-26 15:37:29 -07001494
1495 if (parent != null && parent.getId() == getId()) {
1496 throw new IllegalStateException("Parent has same ID as child!");
1497 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001498 }
1499
1500 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001501 * If this Tab was created through another Tab, then this method returns
1502 * that Tab.
1503 * @return the Tab parent or null
1504 */
1505 public Tab getParent() {
1506 return mParent;
1507 }
1508
1509 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001510 * When a Tab is created through the content of another Tab, then we
1511 * associate the Tabs.
1512 * @param child the Tab that was created from this Tab
1513 */
1514 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001515 if (mChildren == null) {
1516 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001517 }
Michael Kolbc831b632011-05-11 09:30:34 -07001518 mChildren.add(child);
1519 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001520 }
1521
Michael Kolbc831b632011-05-11 09:30:34 -07001522 Vector<Tab> getChildren() {
1523 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001524 }
1525
1526 void resume() {
1527 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001528 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001529 mMainView.onResume();
1530 if (mSubView != null) {
1531 mSubView.onResume();
1532 }
1533 }
1534 }
1535
John Reck56c1fcf2011-08-17 10:15:16 -07001536 private void setupHwAcceleration(View web) {
1537 if (web == null) return;
1538 BrowserSettings settings = BrowserSettings.getInstance();
1539 if (settings.isHardwareAccelerated()) {
1540 web.setLayerType(View.LAYER_TYPE_NONE, null);
1541 } else {
1542 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1543 }
1544 }
1545
Grace Kloba22ac16e2009-10-07 18:00:23 -07001546 void pause() {
1547 if (mMainView != null) {
1548 mMainView.onPause();
1549 if (mSubView != null) {
1550 mSubView.onPause();
1551 }
1552 }
1553 }
1554
1555 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001556 if (mInForeground) {
1557 return;
1558 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001559 mInForeground = true;
1560 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001561 Activity activity = mWebViewController.getActivity();
1562 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001563 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001564 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001565 }
Axesh R. Ajmerac6b5c322015-05-01 11:06:10 -07001566
Leon Scroggins1961ed22010-12-07 15:22:21 -05001567 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001568 }
1569
1570 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001571 if (!mInForeground) {
1572 return;
1573 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001574 mInForeground = false;
1575 pause();
1576 mMainView.setOnCreateContextMenuListener(null);
1577 if (mSubView != null) {
1578 mSubView.setOnCreateContextMenuListener(null);
1579 }
1580 }
1581
Michael Kolb8233fac2010-10-26 16:08:53 -07001582 boolean inForeground() {
1583 return mInForeground;
1584 }
1585
Grace Kloba22ac16e2009-10-07 18:00:23 -07001586 /**
1587 * Return the top window of this tab; either the subwindow if it is not
1588 * null or the main window.
1589 * @return The top window of this tab.
1590 */
1591 WebView getTopWindow() {
1592 if (mSubView != null) {
1593 return mSubView;
1594 }
1595 return mMainView;
1596 }
1597
1598 /**
1599 * Return the main window of this tab. Note: if a tab is freed in the
1600 * background, this can return null. It is only guaranteed to be
1601 * non-null for the current tab.
1602 * @return The main WebView of this tab.
1603 */
1604 WebView getWebView() {
1605 return mMainView;
1606 }
1607
Michael Kolba713ec82010-11-29 17:27:06 -08001608 void setViewContainer(View container) {
1609 mContainer = container;
1610 }
1611
Michael Kolb8233fac2010-10-26 16:08:53 -07001612 View getViewContainer() {
1613 return mContainer;
1614 }
1615
Grace Kloba22ac16e2009-10-07 18:00:23 -07001616 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001617 * Return whether private browsing is enabled for the main window of
1618 * this tab.
1619 * @return True if private browsing is enabled.
1620 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001621 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001622 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001623 }
1624
1625 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001626 * Return the subwindow of this tab or null if there is no subwindow.
1627 * @return The subwindow of this tab or null.
1628 */
1629 WebView getSubWebView() {
1630 return mSubView;
1631 }
1632
Michael Kolb1514bb72010-11-22 09:11:48 -08001633 void setSubWebView(WebView subView) {
1634 mSubView = subView;
1635 }
1636
Michael Kolb8233fac2010-10-26 16:08:53 -07001637 View getSubViewContainer() {
1638 return mSubViewContainer;
1639 }
1640
Michael Kolb1514bb72010-11-22 09:11:48 -08001641 void setSubViewContainer(View subViewContainer) {
1642 mSubViewContainer = subViewContainer;
1643 }
1644
Grace Kloba22ac16e2009-10-07 18:00:23 -07001645
1646 /**
1647 * @return The application id string
1648 */
1649 String getAppId() {
1650 return mAppId;
1651 }
1652
1653 /**
1654 * Set the application id string
1655 * @param id
1656 */
1657 void setAppId(String id) {
1658 mAppId = id;
1659 }
1660
Michael Kolbe28b3472011-08-04 16:54:31 -07001661 boolean closeOnBack() {
1662 return mCloseOnBack;
1663 }
1664
1665 void setCloseOnBack(boolean close) {
1666 mCloseOnBack = close;
1667 }
1668
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001669 boolean getDerivedFromIntent() {
1670 return mDerivedFromIntent;
1671 }
1672
1673 void setDerivedFromIntent(boolean derived) {
1674 mDerivedFromIntent = derived;
1675 }
1676
Grace Kloba22ac16e2009-10-07 18:00:23 -07001677 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001678 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001679 }
1680
Tarun Nainani8eb00912014-07-17 12:28:32 -07001681
1682 protected void onPageFinished() {
1683 mPageFinished = true;
Ze G Riande2a675c22015-06-03 11:15:24 -07001684 isDistillable();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001685 }
1686
1687 public boolean getPageFinishedStatus() {
1688 return mPageFinished;
1689 }
1690
John Reck49a603c2011-03-03 09:33:05 -08001691 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001692 if (mCurrentState.mOriginalUrl == null) {
1693 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001694 }
John Reckdb22ec42011-06-29 11:31:24 -07001695 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001696 }
1697
Grace Kloba22ac16e2009-10-07 18:00:23 -07001698 /**
John Reck30c714c2010-12-16 17:30:34 -08001699 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001700 */
1701 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001702 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001703 }
1704
1705 /**
John Reck30c714c2010-12-16 17:30:34 -08001706 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001707 */
1708 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001709 if (mCurrentState.mFavicon != null) {
1710 return mCurrentState.mFavicon;
1711 }
1712 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001713 }
1714
Pankaj Garg32e1b942015-06-03 18:13:24 -07001715 public boolean hasFavicon() {
1716 return mCurrentState.mFavicon != null;
1717 }
1718
John Recke969cc52010-12-21 17:24:43 -08001719 public boolean isBookmarkedSite() {
1720 return mCurrentState.mIsBookmarkedSite;
1721 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001722
Grace Kloba22ac16e2009-10-07 18:00:23 -07001723 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001724 * Sets the security state, clears the SSL certificate error and informs
1725 * the controller.
1726 */
Steve Block2466eff2011-10-03 15:33:09 +01001727 private void setSecurityState(SecurityState securityState) {
1728 mCurrentState.mSecurityState = securityState;
1729 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001730 }
1731
1732 /**
Steve Block2466eff2011-10-03 15:33:09 +01001733 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001734 */
Steve Block2466eff2011-10-03 15:33:09 +01001735 SecurityState getSecurityState() {
1736 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001737 }
1738
1739 int getLoadProgress() {
1740 if (mInPageLoad) {
1741 return mPageLoadProgress;
1742 }
1743 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001744 }
1745
1746 /**
1747 * @return TRUE if onPageStarted is called while onPageFinished is not
1748 * called yet.
1749 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001750 boolean inPageLoad() {
1751 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001752 }
1753
Grace Kloba22ac16e2009-10-07 18:00:23 -07001754 /**
John Reck1cf4b792011-07-26 10:22:22 -07001755 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001756 */
John Reck1cf4b792011-07-26 10:22:22 -07001757 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001758 // If the WebView is null it means we ran low on memory and we already
1759 // stored the saved state in mSavedState.
1760 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001761 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001762 }
John Reck6c2e2f32011-08-22 13:41:23 -07001763
1764 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001765 return null;
John Reck24f18262011-06-17 14:47:20 -07001766 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001767
1768 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001769 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1770 if (savedList == null || savedList.getSize() == 0) {
1771 Log.w(LOGTAG, "Failed to save back/forward list for "
1772 + mCurrentState.mUrl);
1773 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001774
Michael Kolbc831b632011-05-11 09:30:34 -07001775 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001776 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1777 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001778 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001779 if (mAppId != null) {
1780 mSavedState.putString(APPID, mAppId);
1781 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001782 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001783 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001784 if (mParent != null) {
1785 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001786 }
John Reckb0a86db2011-05-24 14:05:58 -07001787 mSavedState.putBoolean(USERAGENT,
1788 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001789 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001790 }
1791
1792 /*
1793 * Restore the state of the tab.
1794 */
John Reck1cf4b792011-07-26 10:22:22 -07001795 private void restoreState(Bundle b) {
1796 mSavedState = b;
1797 if (mSavedState == null) {
1798 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001799 }
1800 // Restore the internal state even if the WebView fails to restore.
1801 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001802 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001803 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001804 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001805 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001806 String url = b.getString(CURRURL);
1807 String title = b.getString(CURRTITLE);
1808 boolean incognito = b.getBoolean(INCOGNITO);
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -07001809 mCurrentState = new PageState(mContext, incognito, url);
John Reck1cf4b792011-07-26 10:22:22 -07001810 mCurrentState.mTitle = title;
1811 synchronized (Tab.this) {
1812 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001813 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001814 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001815 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001816 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001817
John Reck8b9bb8b2012-03-08 13:19:40 -08001818 private void restoreUserAgent() {
1819 if (mMainView == null || mSavedState == null) {
1820 return;
1821 }
1822 if (mSavedState.getBoolean(USERAGENT)
1823 != mSettings.hasDesktopUseragent(mMainView)) {
1824 mSettings.toggleDesktopUseragent(mMainView);
1825 }
1826 }
1827
Leon Scroggins1961ed22010-12-07 15:22:21 -05001828 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001829 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001830 }
1831
John Recke969cc52010-12-21 17:24:43 -08001832 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1833 = new DataController.OnQueryUrlIsBookmark() {
1834 @Override
1835 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
Karthikeyan Periasamy66c06a12015-10-21 18:04:14 -07001836 if (TextUtils.isEmpty(mCurrentState.mUrl) || mCurrentState.mUrl.equals(url)) {
John Recke969cc52010-12-21 17:24:43 -08001837 mCurrentState.mIsBookmarkedSite = isBookmark;
1838 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1839 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001840 }
John Recke969cc52010-12-21 17:24:43 -08001841 };
Michael Kolb1acef692011-03-08 14:12:06 -08001842
Michael Kolbeb95db42011-03-03 10:38:40 -08001843 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001844 synchronized (Tab.this) {
1845 return mCapture;
1846 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001847 }
1848
John Reck541f55a2011-06-07 16:34:43 -07001849 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001850 return false;
1851 }
1852
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001853 private static class SaveCallback implements ValueCallback<String> {
1854 boolean onReceiveValueCalled = false;
1855 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001856
1857 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001858 public void onReceiveValue(String path) {
1859 this.onReceiveValueCalled = true;
1860 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001861 synchronized (this) {
1862 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001863 }
John Reck541f55a2011-06-07 16:34:43 -07001864 }
John Reck68234a92012-04-19 15:27:12 -07001865
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001866 public String getPath() {
1867 return mPath;
1868 }
John Reck68234a92012-04-19 15:27:12 -07001869 }
1870
1871 /**
1872 * Must be called on the UI thread
1873 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001874 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001875 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001876 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001877 ContentValues values = new ContentValues();
1878 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1879 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001880 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001881 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1882 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001883 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07001884 return values;
John Reck541f55a2011-06-07 16:34:43 -07001885 }
1886
John Reck68234a92012-04-19 15:27:12 -07001887 /**
1888 * Probably want to call this on a background thread
1889 */
1890 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001891 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001892 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001893 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07001894 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07001895 try {
John Reck68234a92012-04-19 15:27:12 -07001896 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001897 web.saveViewState(filename, callback);
1898 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07001899 }
John Reck68234a92012-04-19 15:27:12 -07001900 } catch (Exception e) {
1901 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001902 String path = callback.getPath();
1903 if (path != null) {
1904 File file = mContext.getFileStreamPath(path);
1905 if (file.exists() && !file.delete()) {
1906 file.deleteOnExit();
1907 }
John Reck68234a92012-04-19 15:27:12 -07001908 }
1909 return false;
1910 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001911
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001912 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07001913 // could be that saving of file failed
1914 if (path == null) {
1915 return false;
1916 }
1917
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001918 File savedFile = new File(path);
1919 if (!savedFile.exists()) {
1920 return false;
John Reck68234a92012-04-19 15:27:12 -07001921 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001922 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
1923 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07001924 return true;
1925 }
1926
John Reck8cc92352011-07-06 17:41:52 -07001927 public byte[] compressBitmap(Bitmap bitmap) {
1928 if (bitmap == null) {
1929 return null;
1930 }
1931 ByteArrayOutputStream stream = new ByteArrayOutputStream();
1932 bitmap.compress(CompressFormat.PNG, 100, stream);
1933 return stream.toByteArray();
1934 }
1935
John Reck26b18322011-06-21 13:08:58 -07001936 public void loadUrl(String url, Map<String, String> headers) {
1937 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07001938 mPageLoadProgress = INITIAL_PROGRESS;
Axesh R. Ajmerad04cad12015-08-12 12:02:44 -07001939 mCurrentState = new PageState(
Sagar Dhawanca9ecfb2015-08-10 17:27:58 -07001940 mContext, mMainView.isPrivateBrowsingEnabled(), url);
John Reck26b18322011-06-21 13:08:58 -07001941 mMainView.loadUrl(url, headers);
1942 }
1943 }
1944
John Reck38b39652012-06-05 09:22:59 -07001945 public void disableUrlOverridingForLoad() {
1946 mDisableOverrideUrlLoading = true;
1947 }
1948
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001949 private void thumbnailUpdated() {
John Reck8ee633f2011-08-09 16:00:35 -07001950 mHandler.removeMessages(MSG_CAPTURE);
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001951
John Reck8ee633f2011-08-09 16:00:35 -07001952 TabControl tc = mWebViewController.getTabControl();
1953 if (tc != null) {
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001954 OnThumbnailUpdatedListener updateListener = tc.getOnThumbnailUpdatedListener();
John Reck8ee633f2011-08-09 16:00:35 -07001955 if (updateListener != null) {
1956 updateListener.onThumbnailUpdated(this);
1957 }
1958 }
Pankaj Gargf49e0222015-09-01 12:19:13 -07001959
1960 if (mViewportCapture != null) {
1961 mWebViewController.onThumbnailCapture(mViewportCapture);
1962 mViewportCapture.recycle();
1963 mViewportCapture = null;
1964 } else {
1965 mWebViewController.onThumbnailCapture(mCapture);
1966 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001967 }
1968
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001969 protected void capture() {
1970 if (mMainView == null || mCapture == null || !mMainView.isReady() ||
1971 mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0 ||
1972 !mFirstVisualPixelPainted || mMainView.isShowingCrashView()) {
Pankaj Gargf49e0222015-09-01 12:19:13 -07001973 mViewportCapture = null;
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001974 initCaptureBitmap();
1975 thumbnailUpdated();
1976 return;
1977 }
Vivek Sekhar4ab271d2016-01-04 17:13:35 -08001978 int orientation = mWebViewController.getActivity().
1979 getResources().getConfiguration().orientation;
1980 int width = (orientation == Configuration.ORIENTATION_PORTRAIT) ? mMainView.getWidth() :
1981 mMainView.getHeight();
1982 mMainView.getContentBitmapAsync((float) mCaptureWidth / width, new Rect(),
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001983 new ValueCallback<Bitmap>() {
1984 @Override
1985 public void onReceiveValue(Bitmap bitmap) {
Pankaj Gargf49e0222015-09-01 12:19:13 -07001986 mViewportCapture = bitmap;
1987
Pankaj Garg6bedeba2015-06-23 15:47:37 -07001988 if (mCapture == null) {
1989 initCaptureBitmap();
1990 }
1991
1992 if (bitmap == null) {
1993 thumbnailUpdated();
1994 return;
1995 }
1996
1997 Canvas c = new Canvas(mCapture);
1998 mCapture.eraseColor(Color.WHITE);
1999 c.drawBitmap(bitmap, 0, 0, null);
2000
2001 // manually anti-alias the edges for the tilt
2002 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2003 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2004 mCapture.getHeight(), sAlphaPaint);
2005 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2006 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2007 mCapture.getHeight(), sAlphaPaint);
2008 c.setBitmap(null);
2009
2010 persistThumbnail();
2011 thumbnailUpdated();
2012 }
2013 }
2014 );
John Reck1cf4b792011-07-26 10:22:22 -07002015 }
2016
Pankaj Garg6bedeba2015-06-23 15:47:37 -07002017 @Override
2018 public void onNewPicture(WebView view, Picture picture) {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002019 }
2020
John Reckef654f12011-07-12 16:42:08 -07002021 public boolean canGoBack() {
2022 return mMainView != null ? mMainView.canGoBack() : false;
2023 }
2024
2025 public boolean canGoForward() {
2026 return mMainView != null ? mMainView.canGoForward() : false;
2027 }
2028
2029 public void goBack() {
2030 if (mMainView != null) {
2031 mMainView.goBack();
2032 }
2033 }
2034
2035 public void goForward() {
2036 if (mMainView != null) {
2037 mMainView.goForward();
2038 }
2039 }
2040
John Reck1cf4b792011-07-26 10:22:22 -07002041 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002042 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002043 }
2044
2045 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002046 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002047 }
2048
John Reck4eadc342011-10-31 14:04:10 -07002049 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002050 synchronized (Tab.this) {
2051 if (mCapture == null) {
2052 return;
2053 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002054 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002055 try {
2056 mCapture.copyPixelsFromBuffer(buffer);
2057 } catch (RuntimeException rex) {
2058 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2059 + buffer.capacity() + " blob: " + blob.length
2060 + "capture: " + mCapture.getByteCount());
2061 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002062 }
John Reck1cf4b792011-07-26 10:22:22 -07002063 }
2064 }
2065
John Reck52be4782011-08-26 15:37:29 -07002066 @Override
2067 public String toString() {
2068 StringBuilder builder = new StringBuilder(100);
2069 builder.append(mId);
2070 builder.append(") has parent: ");
2071 if (getParent() != null) {
2072 builder.append("true[");
2073 builder.append(getParent().getId());
2074 builder.append("]");
2075 } else {
2076 builder.append("false");
2077 }
2078 builder.append(", incog: ");
2079 builder.append(isPrivateBrowsingEnabled());
2080 if (!isPrivateBrowsingEnabled()) {
2081 builder.append(", title: ");
2082 builder.append(getTitle());
2083 builder.append(", url: ");
2084 builder.append(getUrl());
2085 }
2086 return builder.toString();
2087 }
2088
Ze G Riande2a675c22015-06-03 11:15:24 -07002089 // dertermines if the tab contains a dislled page
2090 public boolean isDistilled() {
2091 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2092 return false;
2093 }
2094 try {
2095 return DomDistillerUtils.isUrlDistilled(getUrl());
2096 } catch (Exception e) {
2097 return false;
2098 }
2099 }
2100
2101 //determines if the tab contains a distillable page
2102 public boolean isDistillable() {
2103 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2104 mIsDistillable = false;
2105 return mIsDistillable;
2106 }
2107 final ValueCallback<String> onIsDistillable = new ValueCallback<String>() {
2108 @Override
2109 public void onReceiveValue(String str) {
2110 mIsDistillable = Boolean.parseBoolean(str);
2111 }
2112 };
2113
2114 if (isDistilled()) {
2115 mIsDistillable = true;
2116 return mIsDistillable;
2117 }
2118
2119 try {
2120 DomDistillerUtils.isWebViewDistillable(getWebView(), onIsDistillable);
2121 } catch (Exception e) {
2122 mIsDistillable = false;
2123 }
2124
2125 return mIsDistillable;
2126 }
2127
2128 // Function that sets the mIsDistillable variable
2129 public void setIsDistillable(boolean value) {
2130 if (!BrowserCommandLine.hasSwitch("reader-mode")) {
2131 mIsDistillable = false;
2132 }
2133 mIsDistillable = value;
2134 }
2135
2136 // Function that returns the distilled url of the current url
2137 public String getDistilledUrl() {
2138 if (getUrl() != null) {
2139 return DomDistillerUtils.getDistilledUrl(getUrl());
2140 }
2141 return new String();
2142 }
2143
2144 // function that returns the non-distilled version of the current url
2145 public String getNonDistilledUrl() {
2146 if (getUrl() != null) {
2147 return DomDistillerUtils.getOriginalUrlFromDistilledUrl(getUrl());
2148 }
2149 return new String();
2150 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002151}