blob: 107ab07bebceff115027f4c652e4d28e90bbf0df [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;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070027import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070028import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070029import android.graphics.BitmapFactory;
30import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070032import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070033import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070034import android.graphics.PorterDuff;
35import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070036import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070037import android.net.Uri;
38import android.net.http.SslError;
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;
Grace Kloba50c241e2010-04-20 11:07:50 -070050import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080051import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070054import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080055import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070056import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057import android.webkit.WebChromeClient.CustomViewCallback;
58import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000059import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000060import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import android.widget.FrameLayout;
62import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070063
Bijan Amirzada41242f22014-03-21 12:12:18 -070064import com.android.browser.TabControl.OnThumbnailUpdatedListener;
65import com.android.browser.homepages.HomeProvider;
66import com.android.browser.mynavigation.MyNavigationUtil;
67import com.android.browser.provider.MyNavigationProvider;
68import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069
70import org.codeaurora.swe.BrowserDownloadListener;
71import org.codeaurora.swe.ClientCertRequestHandler;
72import org.codeaurora.swe.HttpAuthHandler;
73import org.codeaurora.swe.SslErrorHandler;
74import org.codeaurora.swe.WebBackForwardList;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080075import org.codeaurora.swe.WebChromeClient;
76import org.codeaurora.swe.WebHistoryItem;
77import org.codeaurora.swe.WebView;
78import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070079import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080080import org.codeaurora.swe.WebViewClient;
81
John Reck541f55a2011-06-07 16:34:43 -070082import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070083import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080084import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070085import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070086import java.util.LinkedList;
87import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070088import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070089import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010090import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080091import java.sql.Timestamp;
92import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070093
Grace Kloba22ac16e2009-10-07 18:00:23 -070094/**
95 * Class for maintaining Tabs with a main WebView and a subwindow.
96 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070097class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070098
Grace Kloba22ac16e2009-10-07 18:00:23 -070099 // Log Tag
100 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700101 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000102 // Special case the logtag for messages for the Console to make it easier to
103 // filter them and match the logtag used for these messages in older versions
104 // of the browser.
105 private static final String CONSOLE_LOGTAG = "browser";
106
Michael Kolb9ef259a2011-07-12 15:33:08 -0700107 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800108 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700109 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700110
John Reck1cf4b792011-07-26 10:22:22 -0700111 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800112 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700113
Michael Kolba3194d02011-09-07 11:23:51 -0700114 private static Paint sAlphaPaint = new Paint();
115 static {
116 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
117 sAlphaPaint.setColor(Color.TRANSPARENT);
118 }
119
Steve Block2466eff2011-10-03 15:33:09 +0100120 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100121 // The page's main resource does not use SSL. Note that we use this
122 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100123 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100124 // The page's main resource uses SSL and the certificate is good. The
125 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100126 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100127 // The page's main resource uses SSL and the certificate is good, but
128 // some sub-resources either do not use SSL or have problems with their
129 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100130 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100131 // The page's main resource uses SSL but there is a problem with its
132 // certificate.
133 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800134 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700135
Michael Kolb14612442011-06-24 13:06:29 -0700136 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700137 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700138
Michael Kolbc831b632011-05-11 09:30:34 -0700139 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700140 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700141
Grace Kloba22ac16e2009-10-07 18:00:23 -0700142 // The Geolocation permissions prompt
143 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
144 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800145 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700146 // Main WebView
147 private WebView mMainView;
148 // Subwindow container
149 private View mSubViewContainer;
150 // Subwindow WebView
151 private WebView mSubView;
152 // Saved bundle for when we are running low on memory. It contains the
153 // information needed to restore the WebView if the user goes back to the
154 // tab.
155 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700156 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
157 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700158 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700159 // Tab that constructed by this Tab. This is used when this Tab is
160 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700161 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700162 // If true, the tab is in the foreground of the current activity.
163 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700164 // If true, the tab is in page loading state (after onPageStarted,
165 // before onPageFinsihed)
166 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700167 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700168 private boolean mDisableOverrideUrlLoading;
Pankaj Garg79878492015-04-01 14:48:21 -0700169 private boolean mFirstVisualPixelPainted = false;
John Reck30c714c2010-12-16 17:30:34 -0800170 // The last reported progress of the current page
171 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000172 // The time the load started, used to find load page time
173 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700174 // Application identifier used to find tabs that another application wants
175 // to reuse.
176 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700177 // flag to indicate if tab should be closed on back
178 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700179 // flag to indicate if the tab was opened from an intent
180 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500181 // The listener that gets invoked when a download is started from the
182 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700183 private final BrowserDownloadListener mDownloadListener;
John Recke969cc52010-12-21 17:24:43 -0800184 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700185
186 // AsyncTask for downloading touch icons
187 DownloadTouchIcon mTouchIconLoader;
188
John Reck35e9dd62011-04-25 09:01:54 -0700189 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700190 private int mCaptureWidth;
191 private int mCaptureHeight;
192 private Bitmap mCapture;
193 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700194 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800195 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700196 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800197 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700198
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700199 // determine if webview is destroyed to MemoryMonitor
200 private boolean mWebViewDestroyedByMemoryMonitor;
201
202
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100203
John Reck1cf4b792011-07-26 10:22:22 -0700204 private static synchronized Bitmap getDefaultFavicon(Context context) {
205 if (sDefaultFavicon == null) {
206 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800207 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700208 }
209 return sDefaultFavicon;
210 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800211
John Reck30c714c2010-12-16 17:30:34 -0800212 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700213 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800214 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700215 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800216 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100217 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100218 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
219 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800220 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100221 boolean mIsBookmarkedSite;
222 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800223
224 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700225 mIncognito = incognito;
226 if (mIncognito) {
Vivek Sekhared791da2015-02-22 12:39:05 -0800227 mOriginalUrl = mUrl = "chrome://incognito";
John Reck30c714c2010-12-16 17:30:34 -0800228 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800229 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700230 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800231 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800232 }
Steve Block2466eff2011-10-03 15:33:09 +0100233 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800234 }
235
236 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700237 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700238 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800239 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100240 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800241 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100242 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800243 }
John Reck1cf4b792011-07-26 10:22:22 -0700244 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800245 }
John Reck1cf4b792011-07-26 10:22:22 -0700246
Grace Kloba22ac16e2009-10-07 18:00:23 -0700247 }
248
John Reck30c714c2010-12-16 17:30:34 -0800249 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700250 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800251
Grace Kloba22ac16e2009-10-07 18:00:23 -0700252 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700253 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700254 static final String CURRURL = "currentUrl";
255 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700256 static final String PARENTTAB = "parentTab";
257 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700258 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700259 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700260 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 // Container class for the next error dialog that needs to be displayed
263 private class ErrorDialog {
264 public final int mTitle;
265 public final String mDescription;
266 public final int mError;
267 ErrorDialog(int title, String desc, int error) {
268 mTitle = title;
269 mDescription = desc;
270 mError = error;
271 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700273
274 private void processNextError() {
275 if (mQueuedErrors == null) {
276 return;
277 }
278 // The first one is currently displayed so just remove it.
279 mQueuedErrors.removeFirst();
280 if (mQueuedErrors.size() == 0) {
281 mQueuedErrors = null;
282 return;
283 }
284 showError(mQueuedErrors.getFirst());
285 }
286
287 private DialogInterface.OnDismissListener mDialogListener =
288 new DialogInterface.OnDismissListener() {
289 public void onDismiss(DialogInterface d) {
290 processNextError();
291 }
292 };
293 private LinkedList<ErrorDialog> mQueuedErrors;
294
295 private void queueError(int err, String desc) {
296 if (mQueuedErrors == null) {
297 mQueuedErrors = new LinkedList<ErrorDialog>();
298 }
299 for (ErrorDialog d : mQueuedErrors) {
300 if (d.mError == err) {
301 // Already saw a similar error, ignore the new one.
302 return;
303 }
304 }
305 ErrorDialog errDialog = new ErrorDialog(
306 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
307 R.string.browserFrameFileErrorLabel :
308 R.string.browserFrameNetworkErrorLabel,
309 desc, err);
310 mQueuedErrors.addLast(errDialog);
311
312 // Show the dialog now if the queue was empty and it is in foreground
313 if (mQueuedErrors.size() == 1 && mInForeground) {
314 showError(errDialog);
315 }
316 }
317
318 private void showError(ErrorDialog errDialog) {
319 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700320 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700321 .setTitle(errDialog.mTitle)
322 .setMessage(errDialog.mDescription)
323 .setPositiveButton(R.string.ok, null)
324 .create();
325 d.setOnDismissListener(mDialogListener);
326 d.show();
327 }
328 }
329
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800330 protected void replaceCrashView(View view, View container) {
331 if (hasCrashed && (view == mMainView)) {
332 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
333 wrapper.removeAllViewsInLayout();
334 wrapper.addView(view);
335 hasCrashed = false;
336 }
Vivek Sekhar2868b8d2014-12-03 17:22:50 -0800337 mMainView.reload();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800338 }
339
340 protected void showCrashView() {
341 if (hasCrashed) {
342 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
343 Context.LAYOUT_INFLATER_SERVICE);
344 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
345 final FrameLayout wrapper =
346 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
347 wrapper.removeAllViewsInLayout();
348 wrapper.addView(crashLayout);
349 mContainer.requestFocus();
350 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
351 reloadBtn.setOnClickListener(new OnClickListener() {
352 @Override
353 public void onClick(View arg0) {
354 replaceCrashView(mMainView, mContainer);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800355 }
356 });
357 }
358 }
359
Grace Kloba22ac16e2009-10-07 18:00:23 -0700360 // -------------------------------------------------------------------------
361 // WebViewClient implementation for the main WebView
362 // -------------------------------------------------------------------------
363
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800364 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500365 private Message mDontResend;
366 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700367
368 private boolean providersDiffer(String url, String otherUrl) {
369 Uri uri1 = Uri.parse(url);
370 Uri uri2 = Uri.parse(otherUrl);
371 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
372 }
373
Grace Kloba22ac16e2009-10-07 18:00:23 -0700374 @Override
375 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700376 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700377 mPageFinished = false;
Pankaj Garg79878492015-04-01 14:48:21 -0700378 mFirstVisualPixelPainted = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800379 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700380 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700381 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700382 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800383 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000384 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700385
386 // If we start a touch icon load and then load a new page, we don't
387 // want to cancel the current touch icon loader. But, we do want to
388 // create a new one when the touch icon url is known.
389 if (mTouchIconLoader != null) {
390 mTouchIconLoader.mTab = null;
391 mTouchIconLoader = null;
392 }
393
Panos Thomasb298aad2014-10-22 12:24:21 -0700394 // Loading a new page voids any ongoing Geolocation permission
395 // requests.
396 if (mGeolocationPermissionsPrompt != null) {
397 mGeolocationPermissionsPrompt.dismiss();
398 }
399
Grace Kloba22ac16e2009-10-07 18:00:23 -0700400 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800401 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500402
John Recke969cc52010-12-21 17:24:43 -0800403 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700404 }
405
406 @Override
407 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700408 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800409 if (!isPrivateBrowsingEnabled()) {
410 LogTag.logPageFinishedLoading(
411 url, SystemClock.uptimeMillis() - mLoadStartTime);
412 }
John Reck1cf4b792011-07-26 10:22:22 -0700413 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800414 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700415 }
416
Pankaj Garg79878492015-04-01 14:48:21 -0700417 @Override
418 public void onFirstVisualPixel(WebView view) {
419 mFirstVisualPixelPainted = true;
420 }
421
Grace Kloba22ac16e2009-10-07 18:00:23 -0700422 // return true if want to hijack the url to let another app to handle it
423 @Override
424 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700425 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800426 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
427 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700428 } else {
429 return false;
430 }
431 }
432
Vivek Sekharb991edb2014-12-17 18:18:07 -0800433 @Override
434 public boolean shouldDownloadFavicon(WebView view, String url) {
435 return true;
436 }
437
Grace Kloba22ac16e2009-10-07 18:00:23 -0700438 /**
Steve Block2466eff2011-10-03 15:33:09 +0100439 * Updates the security state. This method is called when we discover
440 * another resource to be loaded for this page (for example,
441 * javascript). While we update the security state, we do not update
442 * the lock icon until we are done loading, as it is slightly more
443 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700444 */
445 @Override
446 public void onLoadResource(WebView view, String url) {
447 if (url != null && url.length() > 0) {
448 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100449 // to update the security state:
450 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
451 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700452 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
453 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100454 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700455 }
456 }
457 }
458 }
459
460 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700461 * Show a dialog informing the user of the network error reported by
462 * WebCore if it is in the foreground.
463 */
464 @Override
465 public void onReceivedError(WebView view, int errorCode,
466 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800467 // Used for the syncCurrentState to use
468 // the failing url instead of using webview url
469 mReceivedError = true;
470
Grace Kloba22ac16e2009-10-07 18:00:23 -0700471 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
472 errorCode != WebViewClient.ERROR_CONNECT &&
473 errorCode != WebViewClient.ERROR_BAD_URL &&
474 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
475 errorCode != WebViewClient.ERROR_FILE) {
476 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500477
Selim Gurun3da06b82011-10-10 13:58:12 -0700478 // Don't log URLs when in private browsing mode
479 if (!isPrivateBrowsingEnabled()) {
480 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500481 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700482 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500483 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700484 }
485
486 /**
487 * Check with the user if it is ok to resend POST data as the page they
488 * are trying to navigate to is the result of a POST.
489 */
490 @Override
491 public void onFormResubmission(WebView view, final Message dontResend,
492 final Message resend) {
493 if (!mInForeground) {
494 dontResend.sendToTarget();
495 return;
496 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500497 if (mDontResend != null) {
498 Log.w(LOGTAG, "onFormResubmission should not be called again "
499 + "while dialog is still up");
500 dontResend.sendToTarget();
501 return;
502 }
503 mDontResend = dontResend;
504 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700505 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700506 R.string.browserFrameFormResubmitLabel).setMessage(
507 R.string.browserFrameFormResubmitMessage)
508 .setPositiveButton(R.string.ok,
509 new DialogInterface.OnClickListener() {
510 public void onClick(DialogInterface dialog,
511 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500512 if (mResend != null) {
513 mResend.sendToTarget();
514 mResend = null;
515 mDontResend = null;
516 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700517 }
518 }).setNegativeButton(R.string.cancel,
519 new DialogInterface.OnClickListener() {
520 public void onClick(DialogInterface dialog,
521 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500522 if (mDontResend != null) {
523 mDontResend.sendToTarget();
524 mResend = null;
525 mDontResend = null;
526 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700527 }
528 }).setOnCancelListener(new OnCancelListener() {
529 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500530 if (mDontResend != null) {
531 mDontResend.sendToTarget();
532 mResend = null;
533 mDontResend = null;
534 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700535 }
536 }).show();
537 }
538
539 /**
540 * Insert the url into the visited history database.
541 * @param url The url to be inserted.
542 * @param isReload True if this url is being reloaded.
543 * FIXME: Not sure what to do when reloading the page.
544 */
545 @Override
546 public void doUpdateVisitedHistory(WebView view, String url,
547 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800548 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700549 }
550
551 /**
552 * Displays SSL error(s) dialog to the user.
553 */
554 @Override
555 public void onReceivedSslError(final WebView view,
556 final SslErrorHandler handler, final SslError error) {
557 if (!mInForeground) {
558 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100559 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700560 return;
561 }
John Reck35e9dd62011-04-25 09:01:54 -0700562 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700563 new AlertDialog.Builder(mContext)
564 .setTitle(R.string.security_warning)
565 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200566 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700567 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700568 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700569 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700570 public void onClick(DialogInterface dialog,
571 int whichButton) {
572 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100573 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700574 }
John Reckcb28b2c2011-08-26 17:39:44 -0700575 })
576 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700577 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700578 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700579 public void onClick(DialogInterface dialog,
580 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700581 mWebViewController.showSslCertificateOnError(
582 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700583 }
John Reckcb28b2c2011-08-26 17:39:44 -0700584 })
585 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700586 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700587 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700588 public void onClick(DialogInterface dialog,
589 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800590 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700591 }
John Reckcb28b2c2011-08-26 17:39:44 -0700592 })
593 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700594 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700595 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700596 public void onCancel(DialogInterface dialog) {
597 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100598 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800599 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700600 }
John Reckcb28b2c2011-08-26 17:39:44 -0700601 })
602 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700603 } else {
604 handler.proceed();
605 }
606 }
607
608 /**
Steve Block4895b012011-10-03 16:26:46 +0100609 * Called when an SSL error occurred while loading a resource, but the
610 * WebView but chose to proceed anyway based on a decision retained
611 * from a previous response to onReceivedSslError(). We update our
612 * security state to reflect this.
613 */
614 @Override
615 public void onProceededAfterSslError(WebView view, SslError error) {
616 handleProceededAfterSslError(error);
617 }
618
619 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700620 * Displays client certificate request to the user.
621 */
622 @Override
623 public void onReceivedClientCertRequest(final WebView view,
624 final ClientCertRequestHandler handler, final String host_and_port) {
625 if (!mInForeground) {
626 handler.ignore();
627 return;
628 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700629 int colon = host_and_port.lastIndexOf(':');
630 String host;
631 int port;
632 if (colon == -1) {
633 host = host_and_port;
634 port = -1;
635 } else {
636 String portString = host_and_port.substring(colon + 1);
637 try {
638 port = Integer.parseInt(portString);
639 host = host_and_port.substring(0, colon);
640 } catch (NumberFormatException e) {
641 host = host_and_port;
642 port = -1;
643 }
644 }
Michael Kolb14612442011-06-24 13:06:29 -0700645 KeyChain.choosePrivateKeyAlias(
646 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700647 @Override public void alias(String alias) {
648 if (alias == null) {
649 handler.cancel();
650 return;
651 }
Michael Kolb14612442011-06-24 13:06:29 -0700652 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700653 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700654 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700655 }
656
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800657 @Override
658 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
659 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700660 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
661 hasCrashed = true;
662 showCrashView();
663 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800664 }
665
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700666 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700667 * Handles an HTTP authentication request.
668 *
669 * @param handler The authentication handler
670 * @param host The host
671 * @param realm The realm
672 */
673 @Override
674 public void onReceivedHttpAuthRequest(WebView view,
675 final HttpAuthHandler handler, final String host,
676 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700678 }
679
680 @Override
John Reck438bf462011-01-12 18:11:46 -0800681 public WebResourceResponse shouldInterceptRequest(WebView view,
682 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800683 //intercept if opening a new incognito tab - show the incognito welcome page
Vivek Sekhared791da2015-02-22 12:39:05 -0800684 if (url.startsWith("chrome://incognito")) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800685 Resources resourceHandle = mContext.getResources();
686 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700687 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800688 return new WebResourceResponse("text/html", "utf8", inStream);
689 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800690 WebResourceResponse res;
691 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
692 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
693 } else {
694 res = HomeProvider.shouldInterceptRequest(mContext, url);
695 }
John Reck438bf462011-01-12 18:11:46 -0800696 return res;
697 }
698
699 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700700 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
701 if (!mInForeground) {
702 return false;
703 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700705 }
706
707 @Override
708 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700710 return;
711 }
John Reck997b1b72012-04-19 18:08:25 -0700712 if (!mWebViewController.onUnhandledKeyEvent(event)) {
713 super.onUnhandledKeyEvent(view, event);
714 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700715 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800716 //SWE-download-file
717 @Override
718 public void onDownloadStart(String url,
719 String userAgent,
720 String contentDisposition,
721 String mimeType,
722 long contentLength) {
723 if (mDownloadListener != null) {
724 if (mDownloadListener instanceof BrowserDownloadListener) {
725 ((BrowserDownloadListener) mDownloadListener).onDownloadStart(url,
726 userAgent, contentDisposition, mimeType, contentLength);
727 } else {
728 mDownloadListener.onDownloadStart(url, userAgent,
729 contentDisposition, mimeType, contentLength);
730 }
731 }
732 }
733 //SWE-download-file
Grace Kloba22ac16e2009-10-07 18:00:23 -0700734 };
735
John Reck1cf4b792011-07-26 10:22:22 -0700736 private void syncCurrentState(WebView view, String url) {
737 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800738
739 if (mReceivedError) {
740 mCurrentState.mUrl = url;
741 mCurrentState.mOriginalUrl = url;
742 } else {
743 mCurrentState.mUrl = view.getUrl();
744 mCurrentState.mOriginalUrl = view.getOriginalUrl();
745 mCurrentState.mFavicon = view.getFavicon();
746 }
747
John Reck1cf4b792011-07-26 10:22:22 -0700748 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700749 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700750 }
John Reck1cf4b792011-07-26 10:22:22 -0700751 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800752
753
John Reck1cf4b792011-07-26 10:22:22 -0700754 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
755 // In case we stop when loading an HTTPS page from an HTTP page
756 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100757 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100758 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700759 }
John Reck502a3532011-08-16 14:21:46 -0700760 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700761 }
762
Tarun Nainani8eb00912014-07-17 12:28:32 -0700763
764 public boolean isTabFullScreen() {
765 return mFullScreen;
766 }
767
Vivek Sekharf96064b2014-07-28 16:32:34 -0700768 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700769 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700770 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700771 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700772 }
773
Sudheer Koganti24766882014-10-02 10:58:09 -0700774 public boolean exitFullscreen() {
775 if (mFullScreen) {
776 Controller controller = (Controller)mWebViewController;
777 controller.getUi().showFullscreen(false);
778 if (getWebView() != null)
779 getWebView().exitFullscreen();
780 mFullScreen = false;
781 return true;
782 }
783 return false;
784 }
785
786
787
788
Grace Kloba22ac16e2009-10-07 18:00:23 -0700789 // -------------------------------------------------------------------------
790 // WebChromeClient implementation for the main WebView
791 // -------------------------------------------------------------------------
792
793 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
794 // Helper method to create a new tab or sub window.
795 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700796 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700797 }
798
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700799 private void createWindow(final boolean dialog, final Message msg, final String url,
800 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700801 WebView.WebViewTransport transport =
802 (WebView.WebViewTransport) msg.obj;
803 if (dialog) {
804 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700805 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700806 transport.setWebView(mSubView);
807 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700808 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700809 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700810 // This is special case for rendering links on a webpage in
811 // a new tab. If opener is suppressed, the WebContents created
812 // by the content layer are not fully initialized. This check
813 // will prevent content layer from overriding WebContents
814 // created by new tab with the uninitialized instance.
815 if (!opener_suppressed) {
816 transport.setWebView(newTab.getWebView());
817 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700818 }
819 msg.sendToTarget();
820 }
821
822 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700823 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
824 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700825 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700826 }
827 }
828
829 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700830 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
831 float contentOffsetYPix,
832 float overdrawBottomHeightPix) {
833 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700834 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700835 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700836 }
837 }
838
839 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700840 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700841 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700842 }
843
844 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700845 public boolean onCreateWindow(WebView view, final boolean dialog,
846 final boolean userGesture, final Message resultMsg) {
847 // only allow new window or sub window for the foreground case
848 if (!mInForeground) {
849 return false;
850 }
851 // Short-circuit if we can't create any more tabs or sub windows.
852 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700853 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700854 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200855 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700856 .setMessage(R.string.too_many_subwindows_dialog_message)
857 .setPositiveButton(R.string.ok, null)
858 .show();
859 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700860 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700861 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700862 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200863 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700864 .setMessage(R.string.too_many_windows_dialog_message)
865 .setPositiveButton(R.string.ok, null)
866 .show();
867 return false;
868 }
869
870 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800871 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700872 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700873 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700874 createWindow(dialog, resultMsg, windowParams.mURL, true);
875 // This is special case for rendering links on a webpage in
876 // a new tab. If opener is suppressed, the WebContents created
877 // by the content layer are not fully initialized. Returning false
878 // will prevent content layer from overriding WebContents
879 // created by new tab with the uninitialized instance.
880 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700881 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700882
883 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700884 return true;
885 }
886
887 // Allow the popup and create the appropriate window.
888 final AlertDialog.OnClickListener allowListener =
889 new AlertDialog.OnClickListener() {
890 public void onClick(DialogInterface d,
891 int which) {
892 createWindow(dialog, resultMsg);
893 }
894 };
895
896 // Block the popup by returning a null WebView.
897 final AlertDialog.OnClickListener blockListener =
898 new AlertDialog.OnClickListener() {
899 public void onClick(DialogInterface d, int which) {
900 resultMsg.sendToTarget();
901 }
902 };
903
904 // Build a confirmation dialog to display to the user.
905 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700906 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200907 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700908 .setMessage(R.string.popup_window_attempt)
909 .setPositiveButton(R.string.allow, allowListener)
910 .setNegativeButton(R.string.block, blockListener)
911 .setCancelable(false)
912 .create();
913
914 // Show the confirmation dialog.
915 d.show();
916 return true;
917 }
918
919 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500920 public void onRequestFocus(WebView view) {
921 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700922 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500923 }
924 }
925
926 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700927 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700928 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700929 // JavaScript can only close popup window.
930 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700931 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700932 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700933 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700934 }
935 }
936
937 @Override
938 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800939 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800940 if (newProgress == 100) {
941 mInPageLoad = false;
942 }
John Reck30c714c2010-12-16 17:30:34 -0800943 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700944 if (mUpdateThumbnail && newProgress == 100) {
945 mUpdateThumbnail = false;
946 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700947 }
948
949 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500950 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800951 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700952 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700953 }
954
955 @Override
956 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800957 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700958 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700959 }
960
961 @Override
962 public void onReceivedTouchIconUrl(WebView view, String url,
963 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700964 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400965 // Let precomposed icons take precedence over non-composed
966 // icons.
967 if (precomposed && mTouchIconLoader != null) {
968 mTouchIconLoader.cancel(false);
969 mTouchIconLoader = null;
970 }
971 // Have only one async task at a time.
972 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700973 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700974 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400975 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700976 }
977 }
978
979 @Override
980 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800981 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700982 Activity activity = mWebViewController.getActivity();
983 if (activity != null) {
984 onShowCustomView(view, activity.getRequestedOrientation(), callback);
985 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400986 }
987
988 @Override
989 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800990 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700991 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400992 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700993 }
994
995 @Override
996 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700997 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700998 }
999
1000 /**
1001 * The origin has exceeded its database quota.
1002 * @param url the URL that exceeded the quota
1003 * @param databaseIdentifier the identifier of the database on which the
1004 * transaction that caused the quota overflow was run
1005 * @param currentQuota the current quota for the origin.
1006 * @param estimatedSize the estimated size of the database.
1007 * @param totalUsedQuota is the sum of all origins' quota.
1008 * @param quotaUpdater The callback to run when a decision to allow or
1009 * deny quota has been made. Don't forget to call this!
1010 */
1011 @Override
1012 public void onExceededDatabaseQuota(String url,
1013 String databaseIdentifier, long currentQuota, long estimatedSize,
1014 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001015 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001016 .onExceededDatabaseQuota(url, databaseIdentifier,
1017 currentQuota, estimatedSize, totalUsedQuota,
1018 quotaUpdater);
1019 }
1020
1021 /**
1022 * The Application Cache has exceeded its max size.
1023 * @param spaceNeeded is the amount of disk space that would be needed
1024 * in order for the last appcache operation to succeed.
1025 * @param totalUsedQuota is the sum of all origins' quota.
1026 * @param quotaUpdater A callback to inform the WebCore thread that a
1027 * new app cache size is available. This callback must always
1028 * be executed at some point to ensure that the sleeping
1029 * WebCore thread is woken up.
1030 */
1031 @Override
1032 public void onReachedMaxAppCacheSize(long spaceNeeded,
1033 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001034 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001035 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1036 quotaUpdater);
1037 }
1038
1039 /**
1040 * Instructs the browser to show a prompt to ask the user to set the
1041 * Geolocation permission state for the specified origin.
1042 * @param origin The origin for which Geolocation permissions are
1043 * requested.
1044 * @param callback The callback to call once the user has set the
1045 * Geolocation permission state.
1046 */
1047 @Override
1048 public void onGeolocationPermissionsShowPrompt(String origin,
1049 GeolocationPermissions.Callback callback) {
1050 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001051 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001052 }
1053 }
1054
1055 /**
1056 * Instructs the browser to hide the Geolocation permissions prompt.
1057 */
1058 @Override
1059 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001060 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001061 mGeolocationPermissionsPrompt.hide();
1062 }
1063 }
1064
Ben Murdoch65acc352009-11-19 18:16:04 +00001065 /* Adds a JavaScript error message to the system log and if the JS
1066 * console is enabled in the about:debug options, to that console
1067 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001068 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001069 */
1070 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001071 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -05001072 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001073 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001074
Ben Murdochc42addf2010-01-28 15:19:59 +00001075 String message = "Console: " + consoleMessage.message() + " "
1076 + consoleMessage.sourceId() + ":"
1077 + consoleMessage.lineNumber();
1078
1079 switch (consoleMessage.messageLevel()) {
1080 case TIP:
1081 Log.v(CONSOLE_LOGTAG, message);
1082 break;
1083 case LOG:
1084 Log.i(CONSOLE_LOGTAG, message);
1085 break;
1086 case WARNING:
1087 Log.w(CONSOLE_LOGTAG, message);
1088 break;
1089 case ERROR:
1090 Log.e(CONSOLE_LOGTAG, message);
1091 break;
1092 case DEBUG:
1093 Log.d(CONSOLE_LOGTAG, message);
1094 break;
1095 }
1096
1097 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001098 }
1099
1100 /**
1101 * Ask the browser for an icon to represent a <video> element.
1102 * This icon will be used if the Web page did not specify a poster attribute.
1103 * @return Bitmap The icon or null if no such icon is available.
1104 */
1105 @Override
1106 public Bitmap getDefaultVideoPoster() {
1107 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001108 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001109 }
1110 return null;
1111 }
1112
1113 /**
1114 * Ask the host application for a custom progress view to show while
1115 * a <video> is loading.
1116 * @return View The progress view.
1117 */
1118 @Override
1119 public View getVideoLoadingProgressView() {
1120 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001121 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001122 }
1123 return null;
1124 }
1125
1126 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001127 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001128 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001129 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001130 } else {
1131 uploadMsg.onReceiveValue(null);
1132 }
1133 }
1134
Vivek Sekharb54614f2014-05-01 19:03:37 -07001135 @Override
1136 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1137 boolean capture) {
1138 if (mInForeground) {
1139 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1140 } else {
1141 uploadFilePaths.onReceiveValue(null);
1142 }
1143 }
1144
Grace Kloba22ac16e2009-10-07 18:00:23 -07001145 /**
1146 * Deliver a list of already-visited URLs
1147 */
1148 @Override
1149 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001150 mWebViewController.getVisitedHistory(callback);
1151 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001152
1153 @Override
1154 public void setupAutoFill(Message message) {
1155 // Prompt the user to set up their profile.
1156 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001157 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1158 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001159 Context.LAYOUT_INFLATER_SERVICE);
1160 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1161
1162 builder.setView(layout)
1163 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1164 @Override
1165 public void onClick(DialogInterface dialog, int id) {
1166 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1167 R.id.setup_autofill_dialog_disable_autofill);
1168
1169 if (disableAutoFill.isChecked()) {
1170 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001171 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001172 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001173 R.string.autofill_setup_dialog_negative_toast,
1174 Toast.LENGTH_LONG).show();
1175 } else {
1176 // Take user to the AutoFill profile editor. When they return,
1177 // we will send the message that we pass here which will trigger
1178 // the form to get filled out with their new profile.
1179 mWebViewController.setupAutoFill(msg);
1180 }
1181 }
1182 })
1183 .setNegativeButton(R.string.cancel, null)
1184 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001185 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001186 };
1187
1188 // -------------------------------------------------------------------------
1189 // WebViewClient implementation for the sub window
1190 // -------------------------------------------------------------------------
1191
1192 // Subclass of WebViewClient used in subwindows to notify the main
1193 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001194 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001195 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001196 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001197 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001198
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001199 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001200 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001201 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001202 }
1203 @Override
1204 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1205 // Unlike the others, do not call mClient's version, which would
1206 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001207 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001208 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001209 }
1210 @Override
1211 public void doUpdateVisitedHistory(WebView view, String url,
1212 boolean isReload) {
1213 mClient.doUpdateVisitedHistory(view, url, isReload);
1214 }
1215 @Override
1216 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1217 return mClient.shouldOverrideUrlLoading(view, url);
1218 }
1219 @Override
1220 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1221 SslError error) {
1222 mClient.onReceivedSslError(view, handler, error);
1223 }
1224 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001225 public void onReceivedClientCertRequest(WebView view,
1226 ClientCertRequestHandler handler, String host_and_port) {
1227 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1228 }
1229 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001230 public void onReceivedHttpAuthRequest(WebView view,
1231 HttpAuthHandler handler, String host, String realm) {
1232 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1233 }
1234 @Override
1235 public void onFormResubmission(WebView view, Message dontResend,
1236 Message resend) {
1237 mClient.onFormResubmission(view, dontResend, resend);
1238 }
1239 @Override
1240 public void onReceivedError(WebView view, int errorCode,
1241 String description, String failingUrl) {
1242 mClient.onReceivedError(view, errorCode, description, failingUrl);
1243 }
1244 @Override
1245 public boolean shouldOverrideKeyEvent(WebView view,
1246 android.view.KeyEvent event) {
1247 return mClient.shouldOverrideKeyEvent(view, event);
1248 }
1249 @Override
1250 public void onUnhandledKeyEvent(WebView view,
1251 android.view.KeyEvent event) {
1252 mClient.onUnhandledKeyEvent(view, event);
1253 }
1254 }
1255
1256 // -------------------------------------------------------------------------
1257 // WebChromeClient implementation for the sub window
1258 // -------------------------------------------------------------------------
1259
1260 private class SubWindowChromeClient extends WebChromeClient {
1261 // The main WebChromeClient.
1262 private final WebChromeClient mClient;
1263
1264 SubWindowChromeClient(WebChromeClient client) {
1265 mClient = client;
1266 }
1267 @Override
1268 public void onProgressChanged(WebView view, int newProgress) {
1269 mClient.onProgressChanged(view, newProgress);
1270 }
1271 @Override
1272 public boolean onCreateWindow(WebView view, boolean dialog,
1273 boolean userGesture, android.os.Message resultMsg) {
1274 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1275 }
1276 @Override
1277 public void onCloseWindow(WebView window) {
1278 if (window != mSubView) {
1279 Log.e(LOGTAG, "Can't close the window");
1280 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001281 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001282 }
1283 }
1284
1285 // -------------------------------------------------------------------------
1286
1287 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001288 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001289 this(wvcontroller, w, null);
1290 }
1291
1292 Tab(WebViewController wvcontroller, Bundle state) {
1293 this(wvcontroller, null, state);
1294 }
1295
1296 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001297 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001298 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001299 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001300 mDataController = DataController.getInstance(mContext);
1301 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001302 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001303 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001304 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001305 mInForeground = false;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001306 mWebViewDestroyedByMemoryMonitor = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001307
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001308 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001309 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001310 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001311 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001312 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001313 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001314 }
1315 };
1316
John Reck1cf4b792011-07-26 10:22:22 -07001317 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1318 R.dimen.tab_thumbnail_width);
1319 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1320 R.dimen.tab_thumbnail_height);
1321 updateShouldCaptureThumbnails();
1322 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001323 if (getId() == -1) {
1324 mId = TabControl.getNextId();
1325 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001326 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001327 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001328 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001329 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001330 switch (m.what) {
1331 case MSG_CAPTURE:
1332 capture();
1333 break;
1334 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001335 }
1336 };
John Reck1cf4b792011-07-26 10:22:22 -07001337 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001338
Michael Kolb72864272012-05-03 15:42:15 -07001339 public boolean shouldUpdateThumbnail() {
1340 return mUpdateThumbnail;
1341 }
1342
Mathew Inwoode09305e2011-09-02 12:03:26 +01001343 /**
1344 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1345 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1346 * to overlapping IDs between the preloaded and restored tabs.
1347 */
1348 public void refreshIdAfterPreload() {
1349 mId = TabControl.getNextId();
1350 }
1351
John Reck1cf4b792011-07-26 10:22:22 -07001352 public void updateShouldCaptureThumbnails() {
1353 if (mWebViewController.shouldCaptureThumbnails()) {
1354 synchronized (Tab.this) {
1355 if (mCapture == null) {
1356 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1357 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001358 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001359 if (mInForeground) {
1360 postCapture();
1361 }
1362 }
1363 }
1364 } else {
1365 synchronized (Tab.this) {
1366 mCapture = null;
1367 deleteThumbnail();
1368 }
1369 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001370 }
1371
Michael Kolb14612442011-06-24 13:06:29 -07001372 public void setController(WebViewController ctl) {
1373 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001374 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001375 }
1376
Michael Kolbc831b632011-05-11 09:30:34 -07001377 public long getId() {
1378 return mId;
1379 }
1380
Michael Kolb91911a22012-01-17 11:21:25 -08001381 void setWebView(WebView w) {
1382 setWebView(w, true);
1383 }
1384
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001385 public boolean isNativeActive(){
1386 if (mMainView == null)
1387 return false;
1388 return true;
1389 }
1390
1391 public void setTimeStamp(){
1392 Date d = new Date();
1393 timestamp = (new Timestamp(d.getTime()));
1394 }
1395
1396 public Timestamp getTimestamp() {
1397 return timestamp;
1398 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001399 /**
1400 * Sets the WebView for this tab, correctly removing the old WebView from
1401 * the container view.
1402 */
Michael Kolb91911a22012-01-17 11:21:25 -08001403 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001404 if (mMainView == w) {
1405 return;
1406 }
Michael Kolba713ec82010-11-29 17:27:06 -08001407
Grace Kloba22ac16e2009-10-07 18:00:23 -07001408 // If the WebView is changing, the page will be reloaded, so any ongoing
1409 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001410 if (mGeolocationPermissionsPrompt != null) {
1411 mGeolocationPermissionsPrompt.hide();
1412 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001413
Michael Kolba713ec82010-11-29 17:27:06 -08001414 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001415
John Reck1cf4b792011-07-26 10:22:22 -07001416 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001417 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001418 if (w != null) {
1419 syncCurrentState(w, null);
1420 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001421 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001422
1423 if (mWebViewDestroyedByMemoryMonitor) {
1424 /*
1425 * If tab was destroyed as a result of the MemoryMonitor
1426 * then we need to restore the state properties
1427 * from the old WebView (mMainView)
1428 */
1429 syncCurrentState(mMainView, null);
1430 mWebViewDestroyedByMemoryMonitor = false;
1431 }
John Reck1cf4b792011-07-26 10:22:22 -07001432 }
1433 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001434 // set the new one
1435 mMainView = w;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001436
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001437 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001438 if (mMainView != null) {
1439 mMainView.setWebViewClient(mWebViewClient);
1440 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001441 // Attach DownloadManager so that downloads can start in an active
1442 // or a non-active window. This can happen when going to a site that
1443 // does a redirect after a period of time. The user could have
1444 // switched to another tab while waiting for the download to start.
1445 mMainView.setDownloadListener(mDownloadListener);
John Reck8ee633f2011-08-09 16:00:35 -07001446 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001447 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001448 mMainView.setPictureListener(this);
1449 }
Michael Kolb91911a22012-01-17 11:21:25 -08001450 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001451 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001452 WebBackForwardList restoredState
1453 = mMainView.restoreState(mSavedState);
1454 if (restoredState == null || restoredState.getSize() == 0) {
1455 Log.w(LOGTAG, "Failed to restore WebView state!");
1456 loadUrl(mCurrentState.mOriginalUrl, null);
1457 }
John Reck1cf4b792011-07-26 10:22:22 -07001458 mSavedState = null;
1459 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001460 }
1461 }
1462
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001463 public void destroyThroughMemoryMonitor() {
1464 mWebViewDestroyedByMemoryMonitor = true;
1465 destroy();
1466 }
1467
Grace Kloba22ac16e2009-10-07 18:00:23 -07001468 /**
1469 * Destroy the tab's main WebView and subWindow if any
1470 */
1471 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001472
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001473 if (mPostponeDestroy) {
1474 mShouldDestroy = true;
1475 return;
1476 }
1477 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001478 if (mMainView != null) {
1479 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001480 // save the WebView to call destroy() after detach it from the tab
1481 WebView webView = mMainView;
1482 setWebView(null);
1483 webView.destroy();
1484 }
1485 }
1486
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001487 private boolean mPostponeDestroy = false;
1488 private boolean mShouldDestroy = false;
1489
1490 public void postponeDestroy() {
1491 mPostponeDestroy = true;
1492 }
1493
1494 public void performPostponedDestroy() {
1495 mPostponeDestroy = false;
1496 if (mShouldDestroy) {
1497 destroy();
1498 }
1499 }
1500
Grace Kloba22ac16e2009-10-07 18:00:23 -07001501 /**
1502 * Remove the tab from the parent
1503 */
1504 void removeFromTree() {
1505 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001506 if (mChildren != null) {
1507 for(Tab t : mChildren) {
1508 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001509 }
1510 }
1511 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001512 if (mParent != null) {
1513 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001514 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001515
1516 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001517 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001518 }
1519
1520 /**
1521 * Create a new subwindow unless a subwindow already exists.
1522 * @return True if a new subwindow was created. False if one already exists.
1523 */
1524 boolean createSubWindow() {
1525 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001526 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001527 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001528 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001529 mSubView.setWebChromeClient(new SubWindowChromeClient(
1530 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001531 // Set a different DownloadListener for the mSubView, since it will
1532 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001533 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001534 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001535 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001536 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001537 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001538 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001539 if (mSubView.copyBackForwardList().getSize() == 0) {
1540 // This subwindow was opened for the sole purpose of
1541 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001542 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001543 }
1544 }
1545 });
Michael Kolb14612442011-06-24 13:06:29 -07001546 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001547 return true;
1548 }
1549 return false;
1550 }
1551
1552 /**
1553 * Dismiss the subWindow for the tab.
1554 */
1555 void dismissSubWindow() {
1556 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001557 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001558 mSubView.destroy();
1559 mSubView = null;
1560 mSubViewContainer = null;
1561 }
1562 }
1563
Grace Kloba22ac16e2009-10-07 18:00:23 -07001564
1565 /**
1566 * Set the parent tab of this tab.
1567 */
Michael Kolbc831b632011-05-11 09:30:34 -07001568 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001569 if (parent == this) {
1570 throw new IllegalStateException("Cannot set parent to self!");
1571 }
Michael Kolbc831b632011-05-11 09:30:34 -07001572 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001573 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001574 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001575 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001576 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001577 if (mSavedState != null) {
1578 if (parent == null) {
1579 mSavedState.remove(PARENTTAB);
1580 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001581 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001582 }
1583 }
John Reckb0a86db2011-05-24 14:05:58 -07001584
1585 // Sync the WebView useragent with the parent
1586 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1587 != mSettings.hasDesktopUseragent(getWebView())) {
1588 mSettings.toggleDesktopUseragent(getWebView());
1589 }
John Reck52be4782011-08-26 15:37:29 -07001590
1591 if (parent != null && parent.getId() == getId()) {
1592 throw new IllegalStateException("Parent has same ID as child!");
1593 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001594 }
1595
1596 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001597 * If this Tab was created through another Tab, then this method returns
1598 * that Tab.
1599 * @return the Tab parent or null
1600 */
1601 public Tab getParent() {
1602 return mParent;
1603 }
1604
1605 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001606 * When a Tab is created through the content of another Tab, then we
1607 * associate the Tabs.
1608 * @param child the Tab that was created from this Tab
1609 */
1610 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001611 if (mChildren == null) {
1612 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001613 }
Michael Kolbc831b632011-05-11 09:30:34 -07001614 mChildren.add(child);
1615 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001616 }
1617
Michael Kolbc831b632011-05-11 09:30:34 -07001618 Vector<Tab> getChildren() {
1619 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001620 }
1621
1622 void resume() {
1623 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001624 if (mMainView.hasCrashed()) {
1625 // Reload if render process has crashed. This is done here so that
1626 // setFocus call sends wasShown message to correct render process.
Vivek Sekhared791da2015-02-22 12:39:05 -08001627 mMainView.setNeedsReload(true);
Pankaj Garg60221af2014-09-23 17:57:50 -07001628 }
John Reck56c1fcf2011-08-17 10:15:16 -07001629 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001630 mMainView.onResume();
1631 if (mSubView != null) {
1632 mSubView.onResume();
1633 }
1634 }
1635 }
1636
John Reck56c1fcf2011-08-17 10:15:16 -07001637 private void setupHwAcceleration(View web) {
1638 if (web == null) return;
1639 BrowserSettings settings = BrowserSettings.getInstance();
1640 if (settings.isHardwareAccelerated()) {
1641 web.setLayerType(View.LAYER_TYPE_NONE, null);
1642 } else {
1643 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1644 }
1645 }
1646
Grace Kloba22ac16e2009-10-07 18:00:23 -07001647 void pause() {
1648 if (mMainView != null) {
1649 mMainView.onPause();
1650 if (mSubView != null) {
1651 mSubView.onPause();
1652 }
1653 }
1654 }
1655
1656 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001657 if (mInForeground) {
1658 return;
1659 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001660 mInForeground = true;
1661 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001662 Activity activity = mWebViewController.getActivity();
1663 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001664 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001665 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001666 }
1667 // Show the pending error dialog if the queue is not empty
1668 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1669 showError(mQueuedErrors.getFirst());
1670 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001671 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001672 }
1673
1674 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001675 if (!mInForeground) {
1676 return;
1677 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001678 mInForeground = false;
1679 pause();
1680 mMainView.setOnCreateContextMenuListener(null);
1681 if (mSubView != null) {
1682 mSubView.setOnCreateContextMenuListener(null);
1683 }
1684 }
1685
Michael Kolb8233fac2010-10-26 16:08:53 -07001686 boolean inForeground() {
1687 return mInForeground;
1688 }
1689
Grace Kloba22ac16e2009-10-07 18:00:23 -07001690 /**
1691 * Return the top window of this tab; either the subwindow if it is not
1692 * null or the main window.
1693 * @return The top window of this tab.
1694 */
1695 WebView getTopWindow() {
1696 if (mSubView != null) {
1697 return mSubView;
1698 }
1699 return mMainView;
1700 }
1701
1702 /**
1703 * Return the main window of this tab. Note: if a tab is freed in the
1704 * background, this can return null. It is only guaranteed to be
1705 * non-null for the current tab.
1706 * @return The main WebView of this tab.
1707 */
1708 WebView getWebView() {
1709 return mMainView;
1710 }
1711
Michael Kolba713ec82010-11-29 17:27:06 -08001712 void setViewContainer(View container) {
1713 mContainer = container;
1714 }
1715
Michael Kolb8233fac2010-10-26 16:08:53 -07001716 View getViewContainer() {
1717 return mContainer;
1718 }
1719
Grace Kloba22ac16e2009-10-07 18:00:23 -07001720 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001721 * Return whether private browsing is enabled for the main window of
1722 * this tab.
1723 * @return True if private browsing is enabled.
1724 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001725 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001726 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001727 }
1728
1729 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001730 * Return the subwindow of this tab or null if there is no subwindow.
1731 * @return The subwindow of this tab or null.
1732 */
1733 WebView getSubWebView() {
1734 return mSubView;
1735 }
1736
Michael Kolb1514bb72010-11-22 09:11:48 -08001737 void setSubWebView(WebView subView) {
1738 mSubView = subView;
1739 }
1740
Michael Kolb8233fac2010-10-26 16:08:53 -07001741 View getSubViewContainer() {
1742 return mSubViewContainer;
1743 }
1744
Michael Kolb1514bb72010-11-22 09:11:48 -08001745 void setSubViewContainer(View subViewContainer) {
1746 mSubViewContainer = subViewContainer;
1747 }
1748
Grace Kloba22ac16e2009-10-07 18:00:23 -07001749 /**
1750 * @return The geolocation permissions prompt for this tab.
1751 */
1752 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001753 if (mGeolocationPermissionsPrompt == null) {
1754 ViewStub stub = (ViewStub) mContainer
1755 .findViewById(R.id.geolocation_permissions_prompt);
1756 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1757 .inflate();
Panos Thomasb298aad2014-10-22 12:24:21 -07001758 mGeolocationPermissionsPrompt.init(mCurrentState.mIncognito);
Grace Kloba50c241e2010-04-20 11:07:50 -07001759 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001760 return mGeolocationPermissionsPrompt;
1761 }
1762
1763 /**
1764 * @return The application id string
1765 */
1766 String getAppId() {
1767 return mAppId;
1768 }
1769
1770 /**
1771 * Set the application id string
1772 * @param id
1773 */
1774 void setAppId(String id) {
1775 mAppId = id;
1776 }
1777
Michael Kolbe28b3472011-08-04 16:54:31 -07001778 boolean closeOnBack() {
1779 return mCloseOnBack;
1780 }
1781
1782 void setCloseOnBack(boolean close) {
1783 mCloseOnBack = close;
1784 }
1785
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001786 boolean getDerivedFromIntent() {
1787 return mDerivedFromIntent;
1788 }
1789
1790 void setDerivedFromIntent(boolean derived) {
1791 mDerivedFromIntent = derived;
1792 }
1793
Grace Kloba22ac16e2009-10-07 18:00:23 -07001794 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001795 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001796 }
1797
Tarun Nainani8eb00912014-07-17 12:28:32 -07001798
1799 protected void onPageFinished() {
1800 mPageFinished = true;
1801 }
1802
1803 public boolean getPageFinishedStatus() {
1804 return mPageFinished;
1805 }
1806
John Reck49a603c2011-03-03 09:33:05 -08001807 String getOriginalUrl() {
Vivek Sekhar361065a2014-11-25 15:34:35 -08001808 if (mMainView != null)
1809 return mMainView.getOriginalUrl();
John Reckdb22ec42011-06-29 11:31:24 -07001810 if (mCurrentState.mOriginalUrl == null) {
1811 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001812 }
John Reckdb22ec42011-06-29 11:31:24 -07001813 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001814 }
1815
Grace Kloba22ac16e2009-10-07 18:00:23 -07001816 /**
John Reck30c714c2010-12-16 17:30:34 -08001817 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001818 */
1819 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001820 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001821 }
1822
1823 /**
John Reck30c714c2010-12-16 17:30:34 -08001824 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001825 */
1826 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001827 if (mCurrentState.mFavicon != null) {
1828 return mCurrentState.mFavicon;
1829 }
1830 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001831 }
1832
John Recke969cc52010-12-21 17:24:43 -08001833 public boolean isBookmarkedSite() {
1834 return mCurrentState.mIsBookmarkedSite;
1835 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001836
Grace Kloba22ac16e2009-10-07 18:00:23 -07001837 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001838 * Sets the security state, clears the SSL certificate error and informs
1839 * the controller.
1840 */
Steve Block2466eff2011-10-03 15:33:09 +01001841 private void setSecurityState(SecurityState securityState) {
1842 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001843 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001844 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001845 }
1846
1847 /**
Steve Block2466eff2011-10-03 15:33:09 +01001848 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001849 */
Steve Block2466eff2011-10-03 15:33:09 +01001850 SecurityState getSecurityState() {
1851 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001852 }
1853
Steve Block08a6f0c2011-10-06 12:12:53 +01001854 /**
1855 * Gets the SSL certificate error, if any, for the page's main resource.
1856 * This is only non-null when the security state is
1857 * SECURITY_STATE_BAD_CERTIFICATE.
1858 */
1859 SslError getSslCertificateError() {
1860 return mCurrentState.mSslCertificateError;
1861 }
1862
John Reck30c714c2010-12-16 17:30:34 -08001863 int getLoadProgress() {
1864 if (mInPageLoad) {
1865 return mPageLoadProgress;
1866 }
1867 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001868 }
1869
1870 /**
1871 * @return TRUE if onPageStarted is called while onPageFinished is not
1872 * called yet.
1873 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001874 boolean inPageLoad() {
1875 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001876 }
1877
Grace Kloba22ac16e2009-10-07 18:00:23 -07001878 /**
John Reck1cf4b792011-07-26 10:22:22 -07001879 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001880 */
John Reck1cf4b792011-07-26 10:22:22 -07001881 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001882 // If the WebView is null it means we ran low on memory and we already
1883 // stored the saved state in mSavedState.
1884 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001885 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001886 }
John Reck6c2e2f32011-08-22 13:41:23 -07001887
1888 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001889 return null;
John Reck24f18262011-06-17 14:47:20 -07001890 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001891
1892 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001893 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1894 if (savedList == null || savedList.getSize() == 0) {
1895 Log.w(LOGTAG, "Failed to save back/forward list for "
1896 + mCurrentState.mUrl);
1897 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001898
Michael Kolbc831b632011-05-11 09:30:34 -07001899 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001900 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1901 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001902 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001903 if (mAppId != null) {
1904 mSavedState.putString(APPID, mAppId);
1905 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001906 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001907 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001908 if (mParent != null) {
1909 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001910 }
John Reckb0a86db2011-05-24 14:05:58 -07001911 mSavedState.putBoolean(USERAGENT,
1912 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001913 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001914 }
1915
1916 /*
1917 * Restore the state of the tab.
1918 */
John Reck1cf4b792011-07-26 10:22:22 -07001919 private void restoreState(Bundle b) {
1920 mSavedState = b;
1921 if (mSavedState == null) {
1922 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001923 }
1924 // Restore the internal state even if the WebView fails to restore.
1925 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001926 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001927 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001928 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001929 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001930 String url = b.getString(CURRURL);
1931 String title = b.getString(CURRTITLE);
1932 boolean incognito = b.getBoolean(INCOGNITO);
1933 mCurrentState = new PageState(mContext, incognito, url, null);
1934 mCurrentState.mTitle = title;
1935 synchronized (Tab.this) {
1936 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001937 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001938 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001939 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001940 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001941
John Reck8b9bb8b2012-03-08 13:19:40 -08001942 private void restoreUserAgent() {
1943 if (mMainView == null || mSavedState == null) {
1944 return;
1945 }
1946 if (mSavedState.getBoolean(USERAGENT)
1947 != mSettings.hasDesktopUseragent(mMainView)) {
1948 mSettings.toggleDesktopUseragent(mMainView);
1949 }
1950 }
1951
Leon Scroggins1961ed22010-12-07 15:22:21 -05001952 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001953 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001954 }
1955
John Recke969cc52010-12-21 17:24:43 -08001956 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1957 = new DataController.OnQueryUrlIsBookmark() {
1958 @Override
1959 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1960 if (mCurrentState.mUrl.equals(url)) {
1961 mCurrentState.mIsBookmarkedSite = isBookmark;
1962 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1963 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001964 }
John Recke969cc52010-12-21 17:24:43 -08001965 };
Michael Kolb1acef692011-03-08 14:12:06 -08001966
Michael Kolbeb95db42011-03-03 10:38:40 -08001967 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001968 synchronized (Tab.this) {
1969 return mCapture;
1970 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001971 }
1972
John Reck541f55a2011-06-07 16:34:43 -07001973 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001974 return false;
1975 }
1976
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001977 private static class SaveCallback implements ValueCallback<String> {
1978 boolean onReceiveValueCalled = false;
1979 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001980
1981 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001982 public void onReceiveValue(String path) {
1983 this.onReceiveValueCalled = true;
1984 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001985 synchronized (this) {
1986 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001987 }
John Reck541f55a2011-06-07 16:34:43 -07001988 }
John Reck68234a92012-04-19 15:27:12 -07001989
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001990 public String getPath() {
1991 return mPath;
1992 }
John Reck68234a92012-04-19 15:27:12 -07001993 }
1994
1995 /**
1996 * Must be called on the UI thread
1997 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001998 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001999 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002000 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07002001 ContentValues values = new ContentValues();
2002 values.put(Snapshots.TITLE, mCurrentState.mTitle);
2003 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07002004 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07002005 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2006 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07002007 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07002008 return values;
John Reck541f55a2011-06-07 16:34:43 -07002009 }
2010
John Reck68234a92012-04-19 15:27:12 -07002011 /**
2012 * Probably want to call this on a background thread
2013 */
2014 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002015 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002016 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002017 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002018 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002019 try {
John Reck68234a92012-04-19 15:27:12 -07002020 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002021 web.saveViewState(filename, callback);
2022 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002023 }
John Reck68234a92012-04-19 15:27:12 -07002024 } catch (Exception e) {
2025 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002026 String path = callback.getPath();
2027 if (path != null) {
2028 File file = mContext.getFileStreamPath(path);
2029 if (file.exists() && !file.delete()) {
2030 file.deleteOnExit();
2031 }
John Reck68234a92012-04-19 15:27:12 -07002032 }
2033 return false;
2034 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002035
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002036 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002037 // could be that saving of file failed
2038 if (path == null) {
2039 return false;
2040 }
2041
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002042 File savedFile = new File(path);
2043 if (!savedFile.exists()) {
2044 return false;
John Reck68234a92012-04-19 15:27:12 -07002045 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002046 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2047 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002048 return true;
2049 }
2050
John Reck8cc92352011-07-06 17:41:52 -07002051 public byte[] compressBitmap(Bitmap bitmap) {
2052 if (bitmap == null) {
2053 return null;
2054 }
2055 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2056 bitmap.compress(CompressFormat.PNG, 100, stream);
2057 return stream.toByteArray();
2058 }
2059
John Reck26b18322011-06-21 13:08:58 -07002060 public void loadUrl(String url, Map<String, String> headers) {
2061 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002062 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002063 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002064 mMainView.loadUrl(url, headers);
2065 }
2066 }
2067
John Reck38b39652012-06-05 09:22:59 -07002068 public void disableUrlOverridingForLoad() {
2069 mDisableOverrideUrlLoading = true;
2070 }
2071
Michael Kolb9ef259a2011-07-12 15:33:08 -07002072 protected void capture() {
2073 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002074 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2075 return;
2076 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002077
Pankaj Garg79878492015-04-01 14:48:21 -07002078 if (!mFirstVisualPixelPainted) {
2079 mCapture = Bitmap.createBitmap(
2080 mCaptureWidth,
2081 mCaptureHeight,
2082 Bitmap.Config.RGB_565);
2083 mCapture.eraseColor(Color.WHITE);
2084
2085 mHandler.removeMessages(MSG_CAPTURE);
2086
2087 TabControl tc = mWebViewController.getTabControl();
2088 if (tc != null) {
2089 OnThumbnailUpdatedListener updateListener
2090 = tc.getOnThumbnailUpdatedListener();
2091 if (updateListener != null) {
2092 updateListener.onThumbnailUpdated(this);
2093 }
2094 }
2095 return;
2096 }
2097
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002098 mMainView
2099 .getContentBitmapAsync(
2100 (float) mCaptureWidth / mMainView.getWidth(),
2101 new Rect(),
2102 new ValueCallback<Bitmap>() {
2103 @Override
2104 public void onReceiveValue(Bitmap bitmap) {
2105 onCaptureCallback(bitmap);
2106 }});
2107 }
2108
2109 private void onCaptureCallback(Bitmap bitmap) {
2110 if (mCapture == null || bitmap == null)
2111 return;
2112
Michael Kolb9ef259a2011-07-12 15:33:08 -07002113 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002114 mCapture.eraseColor(Color.WHITE);
2115 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002116
Michael Kolba3194d02011-09-07 11:23:51 -07002117 // manually anti-alias the edges for the tilt
2118 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2119 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2120 mCapture.getHeight(), sAlphaPaint);
2121 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2122 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2123 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002124 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002125 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002126 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002127 TabControl tc = mWebViewController.getTabControl();
2128 if (tc != null) {
2129 OnThumbnailUpdatedListener updateListener
2130 = tc.getOnThumbnailUpdatedListener();
2131 if (updateListener != null) {
2132 updateListener.onThumbnailUpdated(this);
2133 }
2134 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002135 }
2136
2137 @Override
2138 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002139 postCapture();
2140 }
2141
2142 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002143 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2144 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2145 }
2146 }
2147
John Reckef654f12011-07-12 16:42:08 -07002148 public boolean canGoBack() {
2149 return mMainView != null ? mMainView.canGoBack() : false;
2150 }
2151
2152 public boolean canGoForward() {
2153 return mMainView != null ? mMainView.canGoForward() : false;
2154 }
2155
2156 public void goBack() {
2157 if (mMainView != null) {
2158 mMainView.goBack();
2159 }
2160 }
2161
2162 public void goForward() {
2163 if (mMainView != null) {
2164 mMainView.goForward();
2165 }
2166 }
2167
John Reck1cf4b792011-07-26 10:22:22 -07002168 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002169 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002170 }
2171
2172 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002173 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002174 }
2175
John Reck4eadc342011-10-31 14:04:10 -07002176 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002177 synchronized (Tab.this) {
2178 if (mCapture == null) {
2179 return;
2180 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002181 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002182 try {
2183 mCapture.copyPixelsFromBuffer(buffer);
2184 } catch (RuntimeException rex) {
2185 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2186 + buffer.capacity() + " blob: " + blob.length
2187 + "capture: " + mCapture.getByteCount());
2188 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002189 }
John Reck1cf4b792011-07-26 10:22:22 -07002190 }
2191 }
2192
John Reck52be4782011-08-26 15:37:29 -07002193 @Override
2194 public String toString() {
2195 StringBuilder builder = new StringBuilder(100);
2196 builder.append(mId);
2197 builder.append(") has parent: ");
2198 if (getParent() != null) {
2199 builder.append("true[");
2200 builder.append(getParent().getId());
2201 builder.append("]");
2202 } else {
2203 builder.append("false");
2204 }
2205 builder.append(", incog: ");
2206 builder.append(isPrivateBrowsingEnabled());
2207 if (!isPrivateBrowsingEnabled()) {
2208 builder.append(", title: ");
2209 builder.append(getTitle());
2210 builder.append(", url: ");
2211 builder.append(getUrl());
2212 }
2213 return builder.toString();
2214 }
2215
Steve Block4895b012011-10-03 16:26:46 +01002216 private void handleProceededAfterSslError(SslError error) {
2217 if (error.getUrl().equals(mCurrentState.mUrl)) {
2218 // The security state should currently be SECURITY_STATE_SECURE.
2219 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002220 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002221 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002222 // The page's main resource is secure and this error is for a
2223 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002224 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2225 }
2226 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002227}