blob: ab5985388f6559d4a2ff635e8b2e7ca5a5aad271 [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.R;
65import com.android.browser.TabControl.OnThumbnailUpdatedListener;
66import com.android.browser.homepages.HomeProvider;
67import com.android.browser.mynavigation.MyNavigationUtil;
68import com.android.browser.provider.MyNavigationProvider;
69import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080070
71import org.codeaurora.swe.BrowserDownloadListener;
72import org.codeaurora.swe.ClientCertRequestHandler;
73import org.codeaurora.swe.HttpAuthHandler;
74import org.codeaurora.swe.SslErrorHandler;
75import org.codeaurora.swe.WebBackForwardList;
76import org.codeaurora.swe.WebBackForwardListClient;
77import org.codeaurora.swe.WebChromeClient;
78import org.codeaurora.swe.WebHistoryItem;
79import org.codeaurora.swe.WebView;
80import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070081import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080082import org.codeaurora.swe.WebViewClient;
83
John Reck541f55a2011-06-07 16:34:43 -070084import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070085import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080086import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070087import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070088import java.util.LinkedList;
89import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070090import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070091import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010092import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080093import java.sql.Timestamp;
94import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070095
Grace Kloba22ac16e2009-10-07 18:00:23 -070096/**
97 * Class for maintaining Tabs with a main WebView and a subwindow.
98 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070099class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Grace Kloba22ac16e2009-10-07 18:00:23 -0700101 // Log Tag
102 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700103 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000104 // Special case the logtag for messages for the Console to make it easier to
105 // filter them and match the logtag used for these messages in older versions
106 // of the browser.
107 private static final String CONSOLE_LOGTAG = "browser";
108
Michael Kolb9ef259a2011-07-12 15:33:08 -0700109 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800110 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700111 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700112
John Reck1cf4b792011-07-26 10:22:22 -0700113 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800114 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700115
Michael Kolba3194d02011-09-07 11:23:51 -0700116 private static Paint sAlphaPaint = new Paint();
117 static {
118 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
119 sAlphaPaint.setColor(Color.TRANSPARENT);
120 }
121
Steve Block2466eff2011-10-03 15:33:09 +0100122 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100123 // The page's main resource does not use SSL. Note that we use this
124 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100125 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100126 // The page's main resource uses SSL and the certificate is good. The
127 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100128 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100129 // The page's main resource uses SSL and the certificate is good, but
130 // some sub-resources either do not use SSL or have problems with their
131 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100132 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100133 // The page's main resource uses SSL but there is a problem with its
134 // certificate.
135 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800136 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700137
Michael Kolb14612442011-06-24 13:06:29 -0700138 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700139 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700140
Michael Kolbc831b632011-05-11 09:30:34 -0700141 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700142 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700143
Grace Kloba22ac16e2009-10-07 18:00:23 -0700144 // The Geolocation permissions prompt
145 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
146 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800147 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700148 // Main WebView
149 private WebView mMainView;
150 // Subwindow container
151 private View mSubViewContainer;
152 // Subwindow WebView
153 private WebView mSubView;
154 // Saved bundle for when we are running low on memory. It contains the
155 // information needed to restore the WebView if the user goes back to the
156 // tab.
157 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700158 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
159 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700160 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700161 // Tab that constructed by this Tab. This is used when this Tab is
162 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700163 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700164 // If true, the tab is in the foreground of the current activity.
165 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700166 // If true, the tab is in page loading state (after onPageStarted,
167 // before onPageFinsihed)
168 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700169 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700170 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800171 // The last reported progress of the current page
172 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000173 // The time the load started, used to find load page time
174 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700175 // Application identifier used to find tabs that another application wants
176 // to reuse.
177 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700178 // flag to indicate if tab should be closed on back
179 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700180 // flag to indicate if the tab was opened from an intent
181 private boolean mDerivedFromIntent = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700182 // Keep the original url around to avoid killing the old WebView if the url
183 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700184 // Error console for the tab
185 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500186 // The listener that gets invoked when a download is started from the
187 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700188 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500189 // Listener used to know when we move forward or back in the history list.
190 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800191 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700192
193 // AsyncTask for downloading touch icons
194 DownloadTouchIcon mTouchIconLoader;
195
John Reck35e9dd62011-04-25 09:01:54 -0700196 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700197 private int mCaptureWidth;
198 private int mCaptureHeight;
199 private Bitmap mCapture;
200 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700201 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800202 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700203 private boolean mFullScreen = false;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700204
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100205 /**
Mathew Inwood9ad1eac2011-09-15 11:29:50 +0100206 * See {@link #clearBackStackWhenItemAdded(String)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100207 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100208 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100209
John Reck1cf4b792011-07-26 10:22:22 -0700210 private static synchronized Bitmap getDefaultFavicon(Context context) {
211 if (sDefaultFavicon == null) {
212 sDefaultFavicon = BitmapFactory.decodeResource(
213 context.getResources(), R.drawable.app_web_browser_sm);
214 }
215 return sDefaultFavicon;
216 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800217
John Reck30c714c2010-12-16 17:30:34 -0800218 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700219 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800220 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700221 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800222 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100223 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100224 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
225 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800226 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100227 boolean mIsBookmarkedSite;
228 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800229
230 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700231 mIncognito = incognito;
232 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700233 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800234 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800235 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700236 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800237 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800238 }
Steve Block2466eff2011-10-03 15:33:09 +0100239 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800240 }
241
242 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700243 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700244 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800245 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100246 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800247 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100248 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800249 }
John Reck1cf4b792011-07-26 10:22:22 -0700250 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800251 }
John Reck1cf4b792011-07-26 10:22:22 -0700252
Grace Kloba22ac16e2009-10-07 18:00:23 -0700253 }
254
John Reck30c714c2010-12-16 17:30:34 -0800255 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700256 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800257
Grace Kloba22ac16e2009-10-07 18:00:23 -0700258 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700259 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700260 static final String CURRURL = "currentUrl";
261 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 static final String PARENTTAB = "parentTab";
263 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700264 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700265 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700266 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700267
Grace Kloba22ac16e2009-10-07 18:00:23 -0700268 // Container class for the next error dialog that needs to be displayed
269 private class ErrorDialog {
270 public final int mTitle;
271 public final String mDescription;
272 public final int mError;
273 ErrorDialog(int title, String desc, int error) {
274 mTitle = title;
275 mDescription = desc;
276 mError = error;
277 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700279
280 private void processNextError() {
281 if (mQueuedErrors == null) {
282 return;
283 }
284 // The first one is currently displayed so just remove it.
285 mQueuedErrors.removeFirst();
286 if (mQueuedErrors.size() == 0) {
287 mQueuedErrors = null;
288 return;
289 }
290 showError(mQueuedErrors.getFirst());
291 }
292
293 private DialogInterface.OnDismissListener mDialogListener =
294 new DialogInterface.OnDismissListener() {
295 public void onDismiss(DialogInterface d) {
296 processNextError();
297 }
298 };
299 private LinkedList<ErrorDialog> mQueuedErrors;
300
301 private void queueError(int err, String desc) {
302 if (mQueuedErrors == null) {
303 mQueuedErrors = new LinkedList<ErrorDialog>();
304 }
305 for (ErrorDialog d : mQueuedErrors) {
306 if (d.mError == err) {
307 // Already saw a similar error, ignore the new one.
308 return;
309 }
310 }
311 ErrorDialog errDialog = new ErrorDialog(
312 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
313 R.string.browserFrameFileErrorLabel :
314 R.string.browserFrameNetworkErrorLabel,
315 desc, err);
316 mQueuedErrors.addLast(errDialog);
317
318 // Show the dialog now if the queue was empty and it is in foreground
319 if (mQueuedErrors.size() == 1 && mInForeground) {
320 showError(errDialog);
321 }
322 }
323
324 private void showError(ErrorDialog errDialog) {
325 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700326 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700327 .setTitle(errDialog.mTitle)
328 .setMessage(errDialog.mDescription)
329 .setPositiveButton(R.string.ok, null)
330 .create();
331 d.setOnDismissListener(mDialogListener);
332 d.show();
333 }
334 }
335
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800336 protected void replaceCrashView(View view, View container) {
337 if (hasCrashed && (view == mMainView)) {
338 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
339 wrapper.removeAllViewsInLayout();
340 wrapper.addView(view);
341 hasCrashed = false;
342 }
343 }
344
345 protected void showCrashView() {
346 if (hasCrashed) {
347 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
348 Context.LAYOUT_INFLATER_SERVICE);
349 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
350 final FrameLayout wrapper =
351 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
352 wrapper.removeAllViewsInLayout();
353 wrapper.addView(crashLayout);
354 mContainer.requestFocus();
355 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
356 reloadBtn.setOnClickListener(new OnClickListener() {
357 @Override
358 public void onClick(View arg0) {
359 replaceCrashView(mMainView, mContainer);
360 mMainView.reload();
361 }
362 });
363 }
364 }
365
Grace Kloba22ac16e2009-10-07 18:00:23 -0700366 // -------------------------------------------------------------------------
367 // WebViewClient implementation for the main WebView
368 // -------------------------------------------------------------------------
369
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800370 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500371 private Message mDontResend;
372 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700373
374 private boolean providersDiffer(String url, String otherUrl) {
375 Uri uri1 = Uri.parse(url);
376 Uri uri2 = Uri.parse(otherUrl);
377 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
378 }
379
Grace Kloba22ac16e2009-10-07 18:00:23 -0700380 @Override
381 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700383 mPageFinished = false;
Michael Kolb72864272012-05-03 15:42:15 -0700384 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700385 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700386 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800387 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000388 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700389
390 // If we start a touch icon load and then load a new page, we don't
391 // want to cancel the current touch icon loader. But, we do want to
392 // create a new one when the touch icon url is known.
393 if (mTouchIconLoader != null) {
394 mTouchIconLoader.mTab = null;
395 mTouchIconLoader = null;
396 }
397
398 // reset the error console
399 if (mErrorConsole != null) {
400 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700402 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
403 }
404 }
405
Grace Kloba22ac16e2009-10-07 18:00:23 -0700406 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800407 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500408
John Recke969cc52010-12-21 17:24:43 -0800409 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700410 }
411
412 @Override
413 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700414 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800415 if (!isPrivateBrowsingEnabled()) {
416 LogTag.logPageFinishedLoading(
417 url, SystemClock.uptimeMillis() - mLoadStartTime);
418 }
John Reck1cf4b792011-07-26 10:22:22 -0700419 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800420 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700421 }
422
423 // return true if want to hijack the url to let another app to handle it
424 @Override
425 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700426 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800427 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
428 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700429 } else {
430 return false;
431 }
432 }
433
434 /**
Steve Block2466eff2011-10-03 15:33:09 +0100435 * Updates the security state. This method is called when we discover
436 * another resource to be loaded for this page (for example,
437 * javascript). While we update the security state, we do not update
438 * the lock icon until we are done loading, as it is slightly more
439 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700440 */
441 @Override
442 public void onLoadResource(WebView view, String url) {
443 if (url != null && url.length() > 0) {
444 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100445 // to update the security state:
446 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
447 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700448 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
449 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100450 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700451 }
452 }
453 }
454 }
455
456 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700457 * Show a dialog informing the user of the network error reported by
458 * WebCore if it is in the foreground.
459 */
460 @Override
461 public void onReceivedError(WebView view, int errorCode,
462 String description, String failingUrl) {
463 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
464 errorCode != WebViewClient.ERROR_CONNECT &&
465 errorCode != WebViewClient.ERROR_BAD_URL &&
466 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
467 errorCode != WebViewClient.ERROR_FILE) {
468 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500469
Selim Gurun3da06b82011-10-10 13:58:12 -0700470 // Don't log URLs when in private browsing mode
471 if (!isPrivateBrowsingEnabled()) {
472 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500473 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700474 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500475 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700476 }
477
478 /**
479 * Check with the user if it is ok to resend POST data as the page they
480 * are trying to navigate to is the result of a POST.
481 */
482 @Override
483 public void onFormResubmission(WebView view, final Message dontResend,
484 final Message resend) {
485 if (!mInForeground) {
486 dontResend.sendToTarget();
487 return;
488 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500489 if (mDontResend != null) {
490 Log.w(LOGTAG, "onFormResubmission should not be called again "
491 + "while dialog is still up");
492 dontResend.sendToTarget();
493 return;
494 }
495 mDontResend = dontResend;
496 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700497 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700498 R.string.browserFrameFormResubmitLabel).setMessage(
499 R.string.browserFrameFormResubmitMessage)
500 .setPositiveButton(R.string.ok,
501 new DialogInterface.OnClickListener() {
502 public void onClick(DialogInterface dialog,
503 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500504 if (mResend != null) {
505 mResend.sendToTarget();
506 mResend = null;
507 mDontResend = null;
508 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700509 }
510 }).setNegativeButton(R.string.cancel,
511 new DialogInterface.OnClickListener() {
512 public void onClick(DialogInterface dialog,
513 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500514 if (mDontResend != null) {
515 mDontResend.sendToTarget();
516 mResend = null;
517 mDontResend = null;
518 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700519 }
520 }).setOnCancelListener(new OnCancelListener() {
521 public void onCancel(DialogInterface dialog) {
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 }).show();
529 }
530
531 /**
532 * Insert the url into the visited history database.
533 * @param url The url to be inserted.
534 * @param isReload True if this url is being reloaded.
535 * FIXME: Not sure what to do when reloading the page.
536 */
537 @Override
538 public void doUpdateVisitedHistory(WebView view, String url,
539 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800540 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700541 }
542
543 /**
544 * Displays SSL error(s) dialog to the user.
545 */
546 @Override
547 public void onReceivedSslError(final WebView view,
548 final SslErrorHandler handler, final SslError error) {
549 if (!mInForeground) {
550 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100551 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700552 return;
553 }
John Reck35e9dd62011-04-25 09:01:54 -0700554 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700555 new AlertDialog.Builder(mContext)
556 .setTitle(R.string.security_warning)
557 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200558 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700559 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700560 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700561 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700562 public void onClick(DialogInterface dialog,
563 int whichButton) {
564 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100565 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700566 }
John Reckcb28b2c2011-08-26 17:39:44 -0700567 })
568 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700569 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700570 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700571 public void onClick(DialogInterface dialog,
572 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700573 mWebViewController.showSslCertificateOnError(
574 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700575 }
John Reckcb28b2c2011-08-26 17:39:44 -0700576 })
577 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700578 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700579 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580 public void onClick(DialogInterface dialog,
581 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800582 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700583 }
John Reckcb28b2c2011-08-26 17:39:44 -0700584 })
585 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700586 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700587 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700588 public void onCancel(DialogInterface dialog) {
589 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100590 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800591 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700592 }
John Reckcb28b2c2011-08-26 17:39:44 -0700593 })
594 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700595 } else {
596 handler.proceed();
597 }
598 }
599
600 /**
Steve Block4895b012011-10-03 16:26:46 +0100601 * Called when an SSL error occurred while loading a resource, but the
602 * WebView but chose to proceed anyway based on a decision retained
603 * from a previous response to onReceivedSslError(). We update our
604 * security state to reflect this.
605 */
606 @Override
607 public void onProceededAfterSslError(WebView view, SslError error) {
608 handleProceededAfterSslError(error);
609 }
610
611 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700612 * Displays client certificate request to the user.
613 */
614 @Override
615 public void onReceivedClientCertRequest(final WebView view,
616 final ClientCertRequestHandler handler, final String host_and_port) {
617 if (!mInForeground) {
618 handler.ignore();
619 return;
620 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700621 int colon = host_and_port.lastIndexOf(':');
622 String host;
623 int port;
624 if (colon == -1) {
625 host = host_and_port;
626 port = -1;
627 } else {
628 String portString = host_and_port.substring(colon + 1);
629 try {
630 port = Integer.parseInt(portString);
631 host = host_and_port.substring(0, colon);
632 } catch (NumberFormatException e) {
633 host = host_and_port;
634 port = -1;
635 }
636 }
Michael Kolb14612442011-06-24 13:06:29 -0700637 KeyChain.choosePrivateKeyAlias(
638 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700639 @Override public void alias(String alias) {
640 if (alias == null) {
641 handler.cancel();
642 return;
643 }
Michael Kolb14612442011-06-24 13:06:29 -0700644 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700645 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700646 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700647 }
648
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800649 @Override
650 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
651 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700652 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
653 hasCrashed = true;
654 showCrashView();
655 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800656 }
657
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700658 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700659 * Handles an HTTP authentication request.
660 *
661 * @param handler The authentication handler
662 * @param host The host
663 * @param realm The realm
664 */
665 @Override
666 public void onReceivedHttpAuthRequest(WebView view,
667 final HttpAuthHandler handler, final String host,
668 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700670 }
671
672 @Override
John Reck438bf462011-01-12 18:11:46 -0800673 public WebResourceResponse shouldInterceptRequest(WebView view,
674 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800675 //intercept if opening a new incognito tab - show the incognito welcome page
676 if (url.startsWith("browser:incognito")) {
677 Resources resourceHandle = mContext.getResources();
678 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700679 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800680 return new WebResourceResponse("text/html", "utf8", inStream);
681 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800682 WebResourceResponse res;
683 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
684 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
685 } else {
686 res = HomeProvider.shouldInterceptRequest(mContext, url);
687 }
John Reck438bf462011-01-12 18:11:46 -0800688 return res;
689 }
690
691 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700692 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
693 if (!mInForeground) {
694 return false;
695 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700696 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700697 }
698
699 @Override
700 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700702 return;
703 }
John Reck997b1b72012-04-19 18:08:25 -0700704 if (!mWebViewController.onUnhandledKeyEvent(event)) {
705 super.onUnhandledKeyEvent(view, event);
706 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700707 }
708 };
709
John Reck1cf4b792011-07-26 10:22:22 -0700710 private void syncCurrentState(WebView view, String url) {
711 // Sync state (in case of stop/timeout)
712 mCurrentState.mUrl = view.getUrl();
713 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700714 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700715 }
716 mCurrentState.mOriginalUrl = view.getOriginalUrl();
717 mCurrentState.mTitle = view.getTitle();
718 mCurrentState.mFavicon = view.getFavicon();
719 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
720 // In case we stop when loading an HTTPS page from an HTTP page
721 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100722 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100723 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700724 }
John Reck502a3532011-08-16 14:21:46 -0700725 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700726 }
727
Tarun Nainani8eb00912014-07-17 12:28:32 -0700728
729 public boolean isTabFullScreen() {
730 return mFullScreen;
731 }
732
Vivek Sekharf96064b2014-07-28 16:32:34 -0700733 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700734 Controller controller = (Controller)mWebViewController;
735
736 if (!mSettings.useFullscreen())
737 controller.getUi().setFullscreen(fullScreen);
738
739 if (getWebView() != null) {
740 if (fullScreen)
741 getWebView().updateTopControls(true, false, true);
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700742 else
Tarun Nainani8eb00912014-07-17 12:28:32 -0700743 getWebView().updateTopControls(true, true, true);
Vivek Sekharf96064b2014-07-28 16:32:34 -0700744 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700745
746 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700747 }
748
Grace Kloba22ac16e2009-10-07 18:00:23 -0700749 // -------------------------------------------------------------------------
750 // WebChromeClient implementation for the main WebView
751 // -------------------------------------------------------------------------
752
753 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
754 // Helper method to create a new tab or sub window.
755 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700756 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700757 }
758
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700759 private void createWindow(final boolean dialog, final Message msg, final String url,
760 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700761 WebView.WebViewTransport transport =
762 (WebView.WebViewTransport) msg.obj;
763 if (dialog) {
764 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700765 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700766 transport.setWebView(mSubView);
767 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700768 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700769 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700770 // This is special case for rendering links on a webpage in
771 // a new tab. If opener is suppressed, the WebContents created
772 // by the content layer are not fully initialized. This check
773 // will prevent content layer from overriding WebContents
774 // created by new tab with the uninitialized instance.
775 if (!opener_suppressed) {
776 transport.setWebView(newTab.getWebView());
777 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700778 }
779 msg.sendToTarget();
780 }
781
782 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700783 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
784 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700785 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700786 }
787 }
788
789 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700790 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
791 float contentOffsetYPix,
792 float overdrawBottomHeightPix) {
793 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700794 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700795 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700796 }
797 }
798
799 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700800 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700801 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700802 }
803
804 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700805 public boolean onCreateWindow(WebView view, final boolean dialog,
806 final boolean userGesture, final Message resultMsg) {
807 // only allow new window or sub window for the foreground case
808 if (!mInForeground) {
809 return false;
810 }
811 // Short-circuit if we can't create any more tabs or sub windows.
812 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700813 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700814 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200815 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700816 .setMessage(R.string.too_many_subwindows_dialog_message)
817 .setPositiveButton(R.string.ok, null)
818 .show();
819 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700820 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700821 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700822 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200823 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700824 .setMessage(R.string.too_many_windows_dialog_message)
825 .setPositiveButton(R.string.ok, null)
826 .show();
827 return false;
828 }
829
830 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800831 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700832 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700833 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700834 createWindow(dialog, resultMsg, windowParams.mURL, true);
835 // This is special case for rendering links on a webpage in
836 // a new tab. If opener is suppressed, the WebContents created
837 // by the content layer are not fully initialized. Returning false
838 // will prevent content layer from overriding WebContents
839 // created by new tab with the uninitialized instance.
840 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700841 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700842
843 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700844 return true;
845 }
846
847 // Allow the popup and create the appropriate window.
848 final AlertDialog.OnClickListener allowListener =
849 new AlertDialog.OnClickListener() {
850 public void onClick(DialogInterface d,
851 int which) {
852 createWindow(dialog, resultMsg);
853 }
854 };
855
856 // Block the popup by returning a null WebView.
857 final AlertDialog.OnClickListener blockListener =
858 new AlertDialog.OnClickListener() {
859 public void onClick(DialogInterface d, int which) {
860 resultMsg.sendToTarget();
861 }
862 };
863
864 // Build a confirmation dialog to display to the user.
865 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700866 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200867 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700868 .setMessage(R.string.popup_window_attempt)
869 .setPositiveButton(R.string.allow, allowListener)
870 .setNegativeButton(R.string.block, blockListener)
871 .setCancelable(false)
872 .create();
873
874 // Show the confirmation dialog.
875 d.show();
876 return true;
877 }
878
879 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500880 public void onRequestFocus(WebView view) {
881 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700882 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500883 }
884 }
885
886 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700887 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700888 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700889 // JavaScript can only close popup window.
890 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700891 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700892 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700893 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700894 }
895 }
896
897 @Override
898 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800899 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800900 if (newProgress == 100) {
901 mInPageLoad = false;
902 }
John Reck30c714c2010-12-16 17:30:34 -0800903 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700904 if (mUpdateThumbnail && newProgress == 100) {
905 mUpdateThumbnail = false;
906 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700907 }
908
909 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500910 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800911 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700912 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700913 }
914
915 @Override
916 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800917 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700918 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700919 }
920
921 @Override
922 public void onReceivedTouchIconUrl(WebView view, String url,
923 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700924 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400925 // Let precomposed icons take precedence over non-composed
926 // icons.
927 if (precomposed && mTouchIconLoader != null) {
928 mTouchIconLoader.cancel(false);
929 mTouchIconLoader = null;
930 }
931 // Have only one async task at a time.
932 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700933 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700934 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400935 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700936 }
937 }
938
939 @Override
940 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800941 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700942 Activity activity = mWebViewController.getActivity();
943 if (activity != null) {
944 onShowCustomView(view, activity.getRequestedOrientation(), callback);
945 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400946 }
947
948 @Override
949 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800950 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700951 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400952 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700953 }
954
955 @Override
956 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700957 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700958 }
959
960 /**
961 * The origin has exceeded its database quota.
962 * @param url the URL that exceeded the quota
963 * @param databaseIdentifier the identifier of the database on which the
964 * transaction that caused the quota overflow was run
965 * @param currentQuota the current quota for the origin.
966 * @param estimatedSize the estimated size of the database.
967 * @param totalUsedQuota is the sum of all origins' quota.
968 * @param quotaUpdater The callback to run when a decision to allow or
969 * deny quota has been made. Don't forget to call this!
970 */
971 @Override
972 public void onExceededDatabaseQuota(String url,
973 String databaseIdentifier, long currentQuota, long estimatedSize,
974 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700975 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700976 .onExceededDatabaseQuota(url, databaseIdentifier,
977 currentQuota, estimatedSize, totalUsedQuota,
978 quotaUpdater);
979 }
980
981 /**
982 * The Application Cache has exceeded its max size.
983 * @param spaceNeeded is the amount of disk space that would be needed
984 * in order for the last appcache operation to succeed.
985 * @param totalUsedQuota is the sum of all origins' quota.
986 * @param quotaUpdater A callback to inform the WebCore thread that a
987 * new app cache size is available. This callback must always
988 * be executed at some point to ensure that the sleeping
989 * WebCore thread is woken up.
990 */
991 @Override
992 public void onReachedMaxAppCacheSize(long spaceNeeded,
993 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700994 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700995 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
996 quotaUpdater);
997 }
998
999 /**
1000 * Instructs the browser to show a prompt to ask the user to set the
1001 * Geolocation permission state for the specified origin.
1002 * @param origin The origin for which Geolocation permissions are
1003 * requested.
1004 * @param callback The callback to call once the user has set the
1005 * Geolocation permission state.
1006 */
1007 @Override
1008 public void onGeolocationPermissionsShowPrompt(String origin,
1009 GeolocationPermissions.Callback callback) {
1010 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001011 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001012 }
1013 }
1014
1015 /**
1016 * Instructs the browser to hide the Geolocation permissions prompt.
1017 */
1018 @Override
1019 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001020 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001021 mGeolocationPermissionsPrompt.hide();
1022 }
1023 }
1024
Ben Murdoch65acc352009-11-19 18:16:04 +00001025 /* Adds a JavaScript error message to the system log and if the JS
1026 * console is enabled in the about:debug options, to that console
1027 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001028 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001029 */
1030 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001031 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001032 if (mInForeground) {
1033 // call getErrorConsole(true) so it will create one if needed
1034 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001035 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001036 if (mWebViewController.shouldShowErrorConsole()
1037 && errorConsole.getShowState() !=
1038 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001039 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1040 }
1041 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001042
Jeff Hamilton47654f42010-09-07 09:57:51 -05001043 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001044 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001045
Ben Murdochc42addf2010-01-28 15:19:59 +00001046 String message = "Console: " + consoleMessage.message() + " "
1047 + consoleMessage.sourceId() + ":"
1048 + consoleMessage.lineNumber();
1049
1050 switch (consoleMessage.messageLevel()) {
1051 case TIP:
1052 Log.v(CONSOLE_LOGTAG, message);
1053 break;
1054 case LOG:
1055 Log.i(CONSOLE_LOGTAG, message);
1056 break;
1057 case WARNING:
1058 Log.w(CONSOLE_LOGTAG, message);
1059 break;
1060 case ERROR:
1061 Log.e(CONSOLE_LOGTAG, message);
1062 break;
1063 case DEBUG:
1064 Log.d(CONSOLE_LOGTAG, message);
1065 break;
1066 }
1067
1068 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001069 }
1070
1071 /**
1072 * Ask the browser for an icon to represent a <video> element.
1073 * This icon will be used if the Web page did not specify a poster attribute.
1074 * @return Bitmap The icon or null if no such icon is available.
1075 */
1076 @Override
1077 public Bitmap getDefaultVideoPoster() {
1078 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001079 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001080 }
1081 return null;
1082 }
1083
1084 /**
1085 * Ask the host application for a custom progress view to show while
1086 * a <video> is loading.
1087 * @return View The progress view.
1088 */
1089 @Override
1090 public View getVideoLoadingProgressView() {
1091 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001092 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001093 }
1094 return null;
1095 }
1096
1097 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001098 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001099 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001100 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001101 } else {
1102 uploadMsg.onReceiveValue(null);
1103 }
1104 }
1105
Vivek Sekharb54614f2014-05-01 19:03:37 -07001106 @Override
1107 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1108 boolean capture) {
1109 if (mInForeground) {
1110 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1111 } else {
1112 uploadFilePaths.onReceiveValue(null);
1113 }
1114 }
1115
Grace Kloba22ac16e2009-10-07 18:00:23 -07001116 /**
1117 * Deliver a list of already-visited URLs
1118 */
1119 @Override
1120 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001121 mWebViewController.getVisitedHistory(callback);
1122 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001123
1124 @Override
1125 public void setupAutoFill(Message message) {
1126 // Prompt the user to set up their profile.
1127 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001128 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1129 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001130 Context.LAYOUT_INFLATER_SERVICE);
1131 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1132
1133 builder.setView(layout)
1134 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1135 @Override
1136 public void onClick(DialogInterface dialog, int id) {
1137 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1138 R.id.setup_autofill_dialog_disable_autofill);
1139
1140 if (disableAutoFill.isChecked()) {
1141 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001142 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001143 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001144 R.string.autofill_setup_dialog_negative_toast,
1145 Toast.LENGTH_LONG).show();
1146 } else {
1147 // Take user to the AutoFill profile editor. When they return,
1148 // we will send the message that we pass here which will trigger
1149 // the form to get filled out with their new profile.
1150 mWebViewController.setupAutoFill(msg);
1151 }
1152 }
1153 })
1154 .setNegativeButton(R.string.cancel, null)
1155 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001156 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001157 };
1158
1159 // -------------------------------------------------------------------------
1160 // WebViewClient implementation for the sub window
1161 // -------------------------------------------------------------------------
1162
1163 // Subclass of WebViewClient used in subwindows to notify the main
1164 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001165 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001166 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001167 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001168 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001169
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001170 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001171 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001172 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001173 }
1174 @Override
1175 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1176 // Unlike the others, do not call mClient's version, which would
1177 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001178 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001179 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001180 }
1181 @Override
1182 public void doUpdateVisitedHistory(WebView view, String url,
1183 boolean isReload) {
1184 mClient.doUpdateVisitedHistory(view, url, isReload);
1185 }
1186 @Override
1187 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1188 return mClient.shouldOverrideUrlLoading(view, url);
1189 }
1190 @Override
1191 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1192 SslError error) {
1193 mClient.onReceivedSslError(view, handler, error);
1194 }
1195 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001196 public void onReceivedClientCertRequest(WebView view,
1197 ClientCertRequestHandler handler, String host_and_port) {
1198 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1199 }
1200 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001201 public void onReceivedHttpAuthRequest(WebView view,
1202 HttpAuthHandler handler, String host, String realm) {
1203 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1204 }
1205 @Override
1206 public void onFormResubmission(WebView view, Message dontResend,
1207 Message resend) {
1208 mClient.onFormResubmission(view, dontResend, resend);
1209 }
1210 @Override
1211 public void onReceivedError(WebView view, int errorCode,
1212 String description, String failingUrl) {
1213 mClient.onReceivedError(view, errorCode, description, failingUrl);
1214 }
1215 @Override
1216 public boolean shouldOverrideKeyEvent(WebView view,
1217 android.view.KeyEvent event) {
1218 return mClient.shouldOverrideKeyEvent(view, event);
1219 }
1220 @Override
1221 public void onUnhandledKeyEvent(WebView view,
1222 android.view.KeyEvent event) {
1223 mClient.onUnhandledKeyEvent(view, event);
1224 }
1225 }
1226
1227 // -------------------------------------------------------------------------
1228 // WebChromeClient implementation for the sub window
1229 // -------------------------------------------------------------------------
1230
1231 private class SubWindowChromeClient extends WebChromeClient {
1232 // The main WebChromeClient.
1233 private final WebChromeClient mClient;
1234
1235 SubWindowChromeClient(WebChromeClient client) {
1236 mClient = client;
1237 }
1238 @Override
1239 public void onProgressChanged(WebView view, int newProgress) {
1240 mClient.onProgressChanged(view, newProgress);
1241 }
1242 @Override
1243 public boolean onCreateWindow(WebView view, boolean dialog,
1244 boolean userGesture, android.os.Message resultMsg) {
1245 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1246 }
1247 @Override
1248 public void onCloseWindow(WebView window) {
1249 if (window != mSubView) {
1250 Log.e(LOGTAG, "Can't close the window");
1251 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001252 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001253 }
1254 }
1255
1256 // -------------------------------------------------------------------------
1257
1258 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001259 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001260 this(wvcontroller, w, null);
1261 }
1262
1263 Tab(WebViewController wvcontroller, Bundle state) {
1264 this(wvcontroller, null, state);
1265 }
1266
1267 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001268 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001269 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001270 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001271 mDataController = DataController.getInstance(mContext);
1272 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001273 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001274 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001275 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001276 mInForeground = false;
1277
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001278 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001279 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001280 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001281 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001282 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001283 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001284 }
1285 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001286 mWebBackForwardListClient = new WebBackForwardListClient() {
1287 @Override
1288 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001289 if (mClearHistoryUrlPattern != null) {
1290 boolean match =
1291 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001292 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001293 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1294 + item.getUrl() + "\n\t"
1295 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001296 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001297 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001298 if (mMainView != null) {
1299 mMainView.clearHistory();
1300 }
1301 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001302 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001303 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001304 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001305 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001306
John Reck1cf4b792011-07-26 10:22:22 -07001307 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1308 R.dimen.tab_thumbnail_width);
1309 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1310 R.dimen.tab_thumbnail_height);
1311 updateShouldCaptureThumbnails();
1312 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001313 if (getId() == -1) {
1314 mId = TabControl.getNextId();
1315 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001316 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001317 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001318 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001319 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001320 switch (m.what) {
1321 case MSG_CAPTURE:
1322 capture();
1323 break;
1324 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001325 }
1326 };
John Reck1cf4b792011-07-26 10:22:22 -07001327 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001328
Michael Kolb72864272012-05-03 15:42:15 -07001329 public boolean shouldUpdateThumbnail() {
1330 return mUpdateThumbnail;
1331 }
1332
Mathew Inwoode09305e2011-09-02 12:03:26 +01001333 /**
1334 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1335 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1336 * to overlapping IDs between the preloaded and restored tabs.
1337 */
1338 public void refreshIdAfterPreload() {
1339 mId = TabControl.getNextId();
1340 }
1341
John Reck1cf4b792011-07-26 10:22:22 -07001342 public void updateShouldCaptureThumbnails() {
1343 if (mWebViewController.shouldCaptureThumbnails()) {
1344 synchronized (Tab.this) {
1345 if (mCapture == null) {
1346 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1347 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001348 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001349 if (mInForeground) {
1350 postCapture();
1351 }
1352 }
1353 }
1354 } else {
1355 synchronized (Tab.this) {
1356 mCapture = null;
1357 deleteThumbnail();
1358 }
1359 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001360 }
1361
Michael Kolb14612442011-06-24 13:06:29 -07001362 public void setController(WebViewController ctl) {
1363 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001364 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001365 }
1366
Michael Kolbc831b632011-05-11 09:30:34 -07001367 public long getId() {
1368 return mId;
1369 }
1370
Michael Kolb91911a22012-01-17 11:21:25 -08001371 void setWebView(WebView w) {
1372 setWebView(w, true);
1373 }
1374
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001375 public boolean isNativeActive(){
1376 if (mMainView == null)
1377 return false;
1378 return true;
1379 }
1380
1381 public void setTimeStamp(){
1382 Date d = new Date();
1383 timestamp = (new Timestamp(d.getTime()));
1384 }
1385
1386 public Timestamp getTimestamp() {
1387 return timestamp;
1388 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001389 /**
1390 * Sets the WebView for this tab, correctly removing the old WebView from
1391 * the container view.
1392 */
Michael Kolb91911a22012-01-17 11:21:25 -08001393 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001394 if (mMainView == w) {
1395 return;
1396 }
Michael Kolba713ec82010-11-29 17:27:06 -08001397
Grace Kloba22ac16e2009-10-07 18:00:23 -07001398 // If the WebView is changing, the page will be reloaded, so any ongoing
1399 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001400 if (mGeolocationPermissionsPrompt != null) {
1401 mGeolocationPermissionsPrompt.hide();
1402 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001403
Michael Kolba713ec82010-11-29 17:27:06 -08001404 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001405
John Reck1cf4b792011-07-26 10:22:22 -07001406 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001407 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001408 if (w != null) {
1409 syncCurrentState(w, null);
1410 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001411 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001412 }
1413 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001414 // set the new one
1415 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001416 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001417 if (mMainView != null) {
1418 mMainView.setWebViewClient(mWebViewClient);
1419 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001420 // Attach DownloadManager so that downloads can start in an active
1421 // or a non-active window. This can happen when going to a site that
1422 // does a redirect after a period of time. The user could have
1423 // switched to another tab while waiting for the download to start.
1424 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001425 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001426 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001427 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001428 mMainView.setPictureListener(this);
1429 }
Michael Kolb91911a22012-01-17 11:21:25 -08001430 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001431 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001432 WebBackForwardList restoredState
1433 = mMainView.restoreState(mSavedState);
1434 if (restoredState == null || restoredState.getSize() == 0) {
1435 Log.w(LOGTAG, "Failed to restore WebView state!");
1436 loadUrl(mCurrentState.mOriginalUrl, null);
1437 }
John Reck1cf4b792011-07-26 10:22:22 -07001438 mSavedState = null;
1439 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001440 }
1441 }
1442
1443 /**
1444 * Destroy the tab's main WebView and subWindow if any
1445 */
1446 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001447
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001448 if (mPostponeDestroy) {
1449 mShouldDestroy = true;
1450 return;
1451 }
1452 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001453 if (mMainView != null) {
1454 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001455 // save the WebView to call destroy() after detach it from the tab
1456 WebView webView = mMainView;
1457 setWebView(null);
1458 webView.destroy();
1459 }
1460 }
1461
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001462 private boolean mPostponeDestroy = false;
1463 private boolean mShouldDestroy = false;
1464
1465 public void postponeDestroy() {
1466 mPostponeDestroy = true;
1467 }
1468
1469 public void performPostponedDestroy() {
1470 mPostponeDestroy = false;
1471 if (mShouldDestroy) {
1472 destroy();
1473 }
1474 }
1475
Grace Kloba22ac16e2009-10-07 18:00:23 -07001476 /**
1477 * Remove the tab from the parent
1478 */
1479 void removeFromTree() {
1480 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001481 if (mChildren != null) {
1482 for(Tab t : mChildren) {
1483 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001484 }
1485 }
1486 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001487 if (mParent != null) {
1488 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001489 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001490
1491 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001492 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001493 }
1494
1495 /**
1496 * Create a new subwindow unless a subwindow already exists.
1497 * @return True if a new subwindow was created. False if one already exists.
1498 */
1499 boolean createSubWindow() {
1500 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001501 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001502 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001503 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001504 mSubView.setWebChromeClient(new SubWindowChromeClient(
1505 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001506 // Set a different DownloadListener for the mSubView, since it will
1507 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001508 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001509 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001510 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001511 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001512 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001513 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001514 if (mSubView.copyBackForwardList().getSize() == 0) {
1515 // This subwindow was opened for the sole purpose of
1516 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001517 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001518 }
1519 }
1520 });
Michael Kolb14612442011-06-24 13:06:29 -07001521 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001522 return true;
1523 }
1524 return false;
1525 }
1526
1527 /**
1528 * Dismiss the subWindow for the tab.
1529 */
1530 void dismissSubWindow() {
1531 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001532 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001533 mSubView.destroy();
1534 mSubView = null;
1535 mSubViewContainer = null;
1536 }
1537 }
1538
Grace Kloba22ac16e2009-10-07 18:00:23 -07001539
1540 /**
1541 * Set the parent tab of this tab.
1542 */
Michael Kolbc831b632011-05-11 09:30:34 -07001543 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001544 if (parent == this) {
1545 throw new IllegalStateException("Cannot set parent to self!");
1546 }
Michael Kolbc831b632011-05-11 09:30:34 -07001547 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001548 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001549 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001550 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001551 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001552 if (mSavedState != null) {
1553 if (parent == null) {
1554 mSavedState.remove(PARENTTAB);
1555 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001556 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001557 }
1558 }
John Reckb0a86db2011-05-24 14:05:58 -07001559
1560 // Sync the WebView useragent with the parent
1561 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1562 != mSettings.hasDesktopUseragent(getWebView())) {
1563 mSettings.toggleDesktopUseragent(getWebView());
1564 }
John Reck52be4782011-08-26 15:37:29 -07001565
1566 if (parent != null && parent.getId() == getId()) {
1567 throw new IllegalStateException("Parent has same ID as child!");
1568 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001569 }
1570
1571 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001572 * If this Tab was created through another Tab, then this method returns
1573 * that Tab.
1574 * @return the Tab parent or null
1575 */
1576 public Tab getParent() {
1577 return mParent;
1578 }
1579
1580 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001581 * When a Tab is created through the content of another Tab, then we
1582 * associate the Tabs.
1583 * @param child the Tab that was created from this Tab
1584 */
1585 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001586 if (mChildren == null) {
1587 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001588 }
Michael Kolbc831b632011-05-11 09:30:34 -07001589 mChildren.add(child);
1590 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001591 }
1592
Michael Kolbc831b632011-05-11 09:30:34 -07001593 Vector<Tab> getChildren() {
1594 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001595 }
1596
1597 void resume() {
1598 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001599 if (mMainView.hasCrashed()) {
1600 // Reload if render process has crashed. This is done here so that
1601 // setFocus call sends wasShown message to correct render process.
1602 mMainView.reload();
1603 }
John Reck56c1fcf2011-08-17 10:15:16 -07001604 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001605 mMainView.onResume();
1606 if (mSubView != null) {
1607 mSubView.onResume();
1608 }
1609 }
1610 }
1611
John Reck56c1fcf2011-08-17 10:15:16 -07001612 private void setupHwAcceleration(View web) {
1613 if (web == null) return;
1614 BrowserSettings settings = BrowserSettings.getInstance();
1615 if (settings.isHardwareAccelerated()) {
1616 web.setLayerType(View.LAYER_TYPE_NONE, null);
1617 } else {
1618 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1619 }
1620 }
1621
Grace Kloba22ac16e2009-10-07 18:00:23 -07001622 void pause() {
1623 if (mMainView != null) {
1624 mMainView.onPause();
1625 if (mSubView != null) {
1626 mSubView.onPause();
1627 }
1628 }
1629 }
1630
1631 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001632 if (mInForeground) {
1633 return;
1634 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001635 mInForeground = true;
1636 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001637 Activity activity = mWebViewController.getActivity();
1638 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001639 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001640 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001641 }
1642 // Show the pending error dialog if the queue is not empty
1643 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1644 showError(mQueuedErrors.getFirst());
1645 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001646 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001647 }
1648
1649 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001650 if (!mInForeground) {
1651 return;
1652 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001653 mInForeground = false;
1654 pause();
1655 mMainView.setOnCreateContextMenuListener(null);
1656 if (mSubView != null) {
1657 mSubView.setOnCreateContextMenuListener(null);
1658 }
1659 }
1660
Michael Kolb8233fac2010-10-26 16:08:53 -07001661 boolean inForeground() {
1662 return mInForeground;
1663 }
1664
Grace Kloba22ac16e2009-10-07 18:00:23 -07001665 /**
1666 * Return the top window of this tab; either the subwindow if it is not
1667 * null or the main window.
1668 * @return The top window of this tab.
1669 */
1670 WebView getTopWindow() {
1671 if (mSubView != null) {
1672 return mSubView;
1673 }
1674 return mMainView;
1675 }
1676
1677 /**
1678 * Return the main window of this tab. Note: if a tab is freed in the
1679 * background, this can return null. It is only guaranteed to be
1680 * non-null for the current tab.
1681 * @return The main WebView of this tab.
1682 */
1683 WebView getWebView() {
1684 return mMainView;
1685 }
1686
Michael Kolba713ec82010-11-29 17:27:06 -08001687 void setViewContainer(View container) {
1688 mContainer = container;
1689 }
1690
Michael Kolb8233fac2010-10-26 16:08:53 -07001691 View getViewContainer() {
1692 return mContainer;
1693 }
1694
Grace Kloba22ac16e2009-10-07 18:00:23 -07001695 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001696 * Return whether private browsing is enabled for the main window of
1697 * this tab.
1698 * @return True if private browsing is enabled.
1699 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001700 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001701 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001702 }
1703
1704 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001705 * Return the subwindow of this tab or null if there is no subwindow.
1706 * @return The subwindow of this tab or null.
1707 */
1708 WebView getSubWebView() {
1709 return mSubView;
1710 }
1711
Michael Kolb1514bb72010-11-22 09:11:48 -08001712 void setSubWebView(WebView subView) {
1713 mSubView = subView;
1714 }
1715
Michael Kolb8233fac2010-10-26 16:08:53 -07001716 View getSubViewContainer() {
1717 return mSubViewContainer;
1718 }
1719
Michael Kolb1514bb72010-11-22 09:11:48 -08001720 void setSubViewContainer(View subViewContainer) {
1721 mSubViewContainer = subViewContainer;
1722 }
1723
Grace Kloba22ac16e2009-10-07 18:00:23 -07001724 /**
1725 * @return The geolocation permissions prompt for this tab.
1726 */
1727 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001728 if (mGeolocationPermissionsPrompt == null) {
1729 ViewStub stub = (ViewStub) mContainer
1730 .findViewById(R.id.geolocation_permissions_prompt);
1731 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1732 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001733 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001734 return mGeolocationPermissionsPrompt;
1735 }
1736
1737 /**
1738 * @return The application id string
1739 */
1740 String getAppId() {
1741 return mAppId;
1742 }
1743
1744 /**
1745 * Set the application id string
1746 * @param id
1747 */
1748 void setAppId(String id) {
1749 mAppId = id;
1750 }
1751
Michael Kolbe28b3472011-08-04 16:54:31 -07001752 boolean closeOnBack() {
1753 return mCloseOnBack;
1754 }
1755
1756 void setCloseOnBack(boolean close) {
1757 mCloseOnBack = close;
1758 }
1759
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001760 boolean getDerivedFromIntent() {
1761 return mDerivedFromIntent;
1762 }
1763
1764 void setDerivedFromIntent(boolean derived) {
1765 mDerivedFromIntent = derived;
1766 }
1767
Grace Kloba22ac16e2009-10-07 18:00:23 -07001768 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001769 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001770 }
1771
Tarun Nainani8eb00912014-07-17 12:28:32 -07001772
1773 protected void onPageFinished() {
1774 mPageFinished = true;
1775 }
1776
1777 public boolean getPageFinishedStatus() {
1778 return mPageFinished;
1779 }
1780
John Reck49a603c2011-03-03 09:33:05 -08001781 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001782 if (mCurrentState.mOriginalUrl == null) {
1783 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001784 }
John Reckdb22ec42011-06-29 11:31:24 -07001785 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001786 }
1787
Grace Kloba22ac16e2009-10-07 18:00:23 -07001788 /**
John Reck30c714c2010-12-16 17:30:34 -08001789 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001790 */
1791 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001792 if (mCurrentState.mTitle == null && mInPageLoad) {
Michael Kolb14612442011-06-24 13:06:29 -07001793 return mContext.getString(R.string.title_bar_loading);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001794 }
John Reck30c714c2010-12-16 17:30:34 -08001795 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001796 }
1797
1798 /**
John Reck30c714c2010-12-16 17:30:34 -08001799 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001800 */
1801 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001802 if (mCurrentState.mFavicon != null) {
1803 return mCurrentState.mFavicon;
1804 }
1805 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001806 }
1807
John Recke969cc52010-12-21 17:24:43 -08001808 public boolean isBookmarkedSite() {
1809 return mCurrentState.mIsBookmarkedSite;
1810 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001811
Grace Kloba22ac16e2009-10-07 18:00:23 -07001812 /**
1813 * Return the tab's error console. Creates the console if createIfNEcessary
1814 * is true and we haven't already created the console.
1815 * @param createIfNecessary Flag to indicate if the console should be
1816 * created if it has not been already.
1817 * @return The tab's error console, or null if one has not been created and
1818 * createIfNecessary is false.
1819 */
1820 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1821 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001822 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001823 mErrorConsole.setWebView(mMainView);
1824 }
1825 return mErrorConsole;
1826 }
1827
Steve Block08a6f0c2011-10-06 12:12:53 +01001828 /**
1829 * Sets the security state, clears the SSL certificate error and informs
1830 * the controller.
1831 */
Steve Block2466eff2011-10-03 15:33:09 +01001832 private void setSecurityState(SecurityState securityState) {
1833 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001834 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001835 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001836 }
1837
1838 /**
Steve Block2466eff2011-10-03 15:33:09 +01001839 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001840 */
Steve Block2466eff2011-10-03 15:33:09 +01001841 SecurityState getSecurityState() {
1842 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001843 }
1844
Steve Block08a6f0c2011-10-06 12:12:53 +01001845 /**
1846 * Gets the SSL certificate error, if any, for the page's main resource.
1847 * This is only non-null when the security state is
1848 * SECURITY_STATE_BAD_CERTIFICATE.
1849 */
1850 SslError getSslCertificateError() {
1851 return mCurrentState.mSslCertificateError;
1852 }
1853
John Reck30c714c2010-12-16 17:30:34 -08001854 int getLoadProgress() {
1855 if (mInPageLoad) {
1856 return mPageLoadProgress;
1857 }
1858 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001859 }
1860
1861 /**
1862 * @return TRUE if onPageStarted is called while onPageFinished is not
1863 * called yet.
1864 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001865 boolean inPageLoad() {
1866 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001867 }
1868
Grace Kloba22ac16e2009-10-07 18:00:23 -07001869 /**
John Reck1cf4b792011-07-26 10:22:22 -07001870 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001871 */
John Reck1cf4b792011-07-26 10:22:22 -07001872 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001873 // If the WebView is null it means we ran low on memory and we already
1874 // stored the saved state in mSavedState.
1875 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001876 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001877 }
John Reck6c2e2f32011-08-22 13:41:23 -07001878
1879 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001880 return null;
John Reck24f18262011-06-17 14:47:20 -07001881 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001882
1883 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001884 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1885 if (savedList == null || savedList.getSize() == 0) {
1886 Log.w(LOGTAG, "Failed to save back/forward list for "
1887 + mCurrentState.mUrl);
1888 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001889
Michael Kolbc831b632011-05-11 09:30:34 -07001890 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001891 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1892 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001893 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001894 if (mAppId != null) {
1895 mSavedState.putString(APPID, mAppId);
1896 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001897 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001898 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001899 if (mParent != null) {
1900 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001901 }
John Reckb0a86db2011-05-24 14:05:58 -07001902 mSavedState.putBoolean(USERAGENT,
1903 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001904 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001905 }
1906
1907 /*
1908 * Restore the state of the tab.
1909 */
John Reck1cf4b792011-07-26 10:22:22 -07001910 private void restoreState(Bundle b) {
1911 mSavedState = b;
1912 if (mSavedState == null) {
1913 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001914 }
1915 // Restore the internal state even if the WebView fails to restore.
1916 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001917 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001918 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001919 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001920 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001921 String url = b.getString(CURRURL);
1922 String title = b.getString(CURRTITLE);
1923 boolean incognito = b.getBoolean(INCOGNITO);
1924 mCurrentState = new PageState(mContext, incognito, url, null);
1925 mCurrentState.mTitle = title;
1926 synchronized (Tab.this) {
1927 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001928 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001929 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001930 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001931 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001932
John Reck8b9bb8b2012-03-08 13:19:40 -08001933 private void restoreUserAgent() {
1934 if (mMainView == null || mSavedState == null) {
1935 return;
1936 }
1937 if (mSavedState.getBoolean(USERAGENT)
1938 != mSettings.hasDesktopUseragent(mMainView)) {
1939 mSettings.toggleDesktopUseragent(mMainView);
1940 }
1941 }
1942
Leon Scroggins1961ed22010-12-07 15:22:21 -05001943 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001944 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001945 }
1946
John Recke969cc52010-12-21 17:24:43 -08001947 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1948 = new DataController.OnQueryUrlIsBookmark() {
1949 @Override
1950 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1951 if (mCurrentState.mUrl.equals(url)) {
1952 mCurrentState.mIsBookmarkedSite = isBookmark;
1953 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1954 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001955 }
John Recke969cc52010-12-21 17:24:43 -08001956 };
Michael Kolb1acef692011-03-08 14:12:06 -08001957
Michael Kolbeb95db42011-03-03 10:38:40 -08001958 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001959 synchronized (Tab.this) {
1960 return mCapture;
1961 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001962 }
1963
John Reck541f55a2011-06-07 16:34:43 -07001964 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001965 return false;
1966 }
1967
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001968 private static class SaveCallback implements ValueCallback<String> {
1969 boolean onReceiveValueCalled = false;
1970 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001971
1972 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001973 public void onReceiveValue(String path) {
1974 this.onReceiveValueCalled = true;
1975 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001976 synchronized (this) {
1977 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001978 }
John Reck541f55a2011-06-07 16:34:43 -07001979 }
John Reck68234a92012-04-19 15:27:12 -07001980
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001981 public String getPath() {
1982 return mPath;
1983 }
John Reck68234a92012-04-19 15:27:12 -07001984 }
1985
1986 /**
1987 * Must be called on the UI thread
1988 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001989 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001990 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001991 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001992 ContentValues values = new ContentValues();
1993 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1994 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001995 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001996 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1997 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001998 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07001999 return values;
John Reck541f55a2011-06-07 16:34:43 -07002000 }
2001
John Reck68234a92012-04-19 15:27:12 -07002002 /**
2003 * Probably want to call this on a background thread
2004 */
2005 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002006 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002007 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002008 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002009 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002010 try {
John Reck68234a92012-04-19 15:27:12 -07002011 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002012 web.saveViewState(filename, callback);
2013 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002014 }
John Reck68234a92012-04-19 15:27:12 -07002015 } catch (Exception e) {
2016 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002017 String path = callback.getPath();
2018 if (path != null) {
2019 File file = mContext.getFileStreamPath(path);
2020 if (file.exists() && !file.delete()) {
2021 file.deleteOnExit();
2022 }
John Reck68234a92012-04-19 15:27:12 -07002023 }
2024 return false;
2025 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002026
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002027 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002028 // could be that saving of file failed
2029 if (path == null) {
2030 return false;
2031 }
2032
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002033 File savedFile = new File(path);
2034 if (!savedFile.exists()) {
2035 return false;
John Reck68234a92012-04-19 15:27:12 -07002036 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002037 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2038 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002039 return true;
2040 }
2041
John Reck8cc92352011-07-06 17:41:52 -07002042 public byte[] compressBitmap(Bitmap bitmap) {
2043 if (bitmap == null) {
2044 return null;
2045 }
2046 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2047 bitmap.compress(CompressFormat.PNG, 100, stream);
2048 return stream.toByteArray();
2049 }
2050
John Reck26b18322011-06-21 13:08:58 -07002051 public void loadUrl(String url, Map<String, String> headers) {
2052 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002053 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002054 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002055 mMainView.loadUrl(url, headers);
2056 }
2057 }
2058
John Reck38b39652012-06-05 09:22:59 -07002059 public void disableUrlOverridingForLoad() {
2060 mDisableOverrideUrlLoading = true;
2061 }
2062
Michael Kolb9ef259a2011-07-12 15:33:08 -07002063 protected void capture() {
2064 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002065 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2066 return;
2067 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002068
2069 mMainView
2070 .getContentBitmapAsync(
2071 (float) mCaptureWidth / mMainView.getWidth(),
2072 new Rect(),
2073 new ValueCallback<Bitmap>() {
2074 @Override
2075 public void onReceiveValue(Bitmap bitmap) {
2076 onCaptureCallback(bitmap);
2077 }});
2078 }
2079
2080 private void onCaptureCallback(Bitmap bitmap) {
2081 if (mCapture == null || bitmap == null)
2082 return;
2083
Michael Kolb9ef259a2011-07-12 15:33:08 -07002084 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002085 mCapture.eraseColor(Color.WHITE);
2086 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002087
Michael Kolba3194d02011-09-07 11:23:51 -07002088 // manually anti-alias the edges for the tilt
2089 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2090 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2091 mCapture.getHeight(), sAlphaPaint);
2092 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2093 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2094 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002095 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002096 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002097 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002098 TabControl tc = mWebViewController.getTabControl();
2099 if (tc != null) {
2100 OnThumbnailUpdatedListener updateListener
2101 = tc.getOnThumbnailUpdatedListener();
2102 if (updateListener != null) {
2103 updateListener.onThumbnailUpdated(this);
2104 }
2105 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002106 }
2107
2108 @Override
2109 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002110 postCapture();
2111 }
2112
2113 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002114 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2115 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2116 }
2117 }
2118
John Reckef654f12011-07-12 16:42:08 -07002119 public boolean canGoBack() {
2120 return mMainView != null ? mMainView.canGoBack() : false;
2121 }
2122
2123 public boolean canGoForward() {
2124 return mMainView != null ? mMainView.canGoForward() : false;
2125 }
2126
2127 public void goBack() {
2128 if (mMainView != null) {
2129 mMainView.goBack();
2130 }
2131 }
2132
2133 public void goForward() {
2134 if (mMainView != null) {
2135 mMainView.goForward();
2136 }
2137 }
2138
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002139 /**
2140 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2141 * to be added to the stack.
2142 *
2143 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2144 * not appear in the back stack.
2145 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002146 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2147 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002148 }
2149
John Reck1cf4b792011-07-26 10:22:22 -07002150 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002151 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002152 }
2153
2154 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002155 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002156 }
2157
John Reck4eadc342011-10-31 14:04:10 -07002158 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002159 synchronized (Tab.this) {
2160 if (mCapture == null) {
2161 return;
2162 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002163 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002164 try {
2165 mCapture.copyPixelsFromBuffer(buffer);
2166 } catch (RuntimeException rex) {
2167 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2168 + buffer.capacity() + " blob: " + blob.length
2169 + "capture: " + mCapture.getByteCount());
2170 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002171 }
John Reck1cf4b792011-07-26 10:22:22 -07002172 }
2173 }
2174
John Reck52be4782011-08-26 15:37:29 -07002175 @Override
2176 public String toString() {
2177 StringBuilder builder = new StringBuilder(100);
2178 builder.append(mId);
2179 builder.append(") has parent: ");
2180 if (getParent() != null) {
2181 builder.append("true[");
2182 builder.append(getParent().getId());
2183 builder.append("]");
2184 } else {
2185 builder.append("false");
2186 }
2187 builder.append(", incog: ");
2188 builder.append(isPrivateBrowsingEnabled());
2189 if (!isPrivateBrowsingEnabled()) {
2190 builder.append(", title: ");
2191 builder.append(getTitle());
2192 builder.append(", url: ");
2193 builder.append(getUrl());
2194 }
2195 return builder.toString();
2196 }
2197
Steve Block4895b012011-10-03 16:26:46 +01002198 private void handleProceededAfterSslError(SslError error) {
2199 if (error.getUrl().equals(mCurrentState.mUrl)) {
2200 // The security state should currently be SECURITY_STATE_SECURE.
2201 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002202 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002203 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002204 // The page's main resource is secure and this error is for a
2205 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002206 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2207 }
2208 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002209}