blob: 320e4c8f37fb6324724d921f6368a98e7e58c073 [file] [log] [blame]
Grace Kloba22ac16e2009-10-07 18:00:23 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Grace Kloba22ac16e2009-10-07 18:00:23 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
21import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070022import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080023import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.DialogInterface.OnCancelListener;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070027import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070028import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070029import android.graphics.BitmapFactory;
30import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070032import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070033import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070034import android.graphics.PorterDuff;
35import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070036import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070037import android.net.Uri;
38import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070039import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070040import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070041import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000042import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070043import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070044import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070045import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070046import android.util.Log;
47import android.view.KeyEvent;
48import android.view.LayoutInflater;
49import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070050import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080051import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070054import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080055import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070056import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057import android.webkit.WebChromeClient.CustomViewCallback;
58import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000059import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000060import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import android.widget.FrameLayout;
62import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070063
Bijan Amirzada41242f22014-03-21 12:12:18 -070064import com.android.browser.TabControl.OnThumbnailUpdatedListener;
65import com.android.browser.homepages.HomeProvider;
66import com.android.browser.mynavigation.MyNavigationUtil;
67import com.android.browser.provider.MyNavigationProvider;
68import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069
70import org.codeaurora.swe.BrowserDownloadListener;
71import org.codeaurora.swe.ClientCertRequestHandler;
72import org.codeaurora.swe.HttpAuthHandler;
73import org.codeaurora.swe.SslErrorHandler;
74import org.codeaurora.swe.WebBackForwardList;
75import org.codeaurora.swe.WebBackForwardListClient;
76import org.codeaurora.swe.WebChromeClient;
77import org.codeaurora.swe.WebHistoryItem;
78import org.codeaurora.swe.WebView;
79import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070080import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080081import org.codeaurora.swe.WebViewClient;
82
John Reck541f55a2011-06-07 16:34:43 -070083import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070084import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080085import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070086import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070087import java.util.LinkedList;
88import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070089import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070090import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010091import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080092import java.sql.Timestamp;
93import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070094
Grace Kloba22ac16e2009-10-07 18:00:23 -070095/**
96 * Class for maintaining Tabs with a main WebView and a subwindow.
97 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070098class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070099
Grace Kloba22ac16e2009-10-07 18:00:23 -0700100 // Log Tag
101 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700102 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000103 // Special case the logtag for messages for the Console to make it easier to
104 // filter them and match the logtag used for these messages in older versions
105 // of the browser.
106 private static final String CONSOLE_LOGTAG = "browser";
107
Michael Kolb9ef259a2011-07-12 15:33:08 -0700108 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800109 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700110 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700111
John Reck1cf4b792011-07-26 10:22:22 -0700112 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800113 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700114
Michael Kolba3194d02011-09-07 11:23:51 -0700115 private static Paint sAlphaPaint = new Paint();
116 static {
117 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
118 sAlphaPaint.setColor(Color.TRANSPARENT);
119 }
120
Steve Block2466eff2011-10-03 15:33:09 +0100121 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100122 // The page's main resource does not use SSL. Note that we use this
123 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100124 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100125 // The page's main resource uses SSL and the certificate is good. The
126 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100127 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100128 // The page's main resource uses SSL and the certificate is good, but
129 // some sub-resources either do not use SSL or have problems with their
130 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100131 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100132 // The page's main resource uses SSL but there is a problem with its
133 // certificate.
134 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800135 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700136
Michael Kolb14612442011-06-24 13:06:29 -0700137 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700138 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700139
Michael Kolbc831b632011-05-11 09:30:34 -0700140 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700141 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700142
Grace Kloba22ac16e2009-10-07 18:00:23 -0700143 // The Geolocation permissions prompt
144 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
145 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800146 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700147 // Main WebView
148 private WebView mMainView;
149 // Subwindow container
150 private View mSubViewContainer;
151 // Subwindow WebView
152 private WebView mSubView;
153 // Saved bundle for when we are running low on memory. It contains the
154 // information needed to restore the WebView if the user goes back to the
155 // tab.
156 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700157 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
158 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700159 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700160 // Tab that constructed by this Tab. This is used when this Tab is
161 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700162 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700163 // If true, the tab is in the foreground of the current activity.
164 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 // If true, the tab is in page loading state (after onPageStarted,
166 // before onPageFinsihed)
167 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700168 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700169 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800170 // The last reported progress of the current page
171 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000172 // The time the load started, used to find load page time
173 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700174 // Application identifier used to find tabs that another application wants
175 // to reuse.
176 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700177 // flag to indicate if tab should be closed on back
178 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700179 // flag to indicate if the tab was opened from an intent
180 private boolean mDerivedFromIntent = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700181 // Keep the original url around to avoid killing the old WebView if the url
182 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700183 // Error console for the tab
184 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500185 // The listener that gets invoked when a download is started from the
186 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700187 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500188 // Listener used to know when we move forward or back in the history list.
189 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800190 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700191
192 // AsyncTask for downloading touch icons
193 DownloadTouchIcon mTouchIconLoader;
194
John Reck35e9dd62011-04-25 09:01:54 -0700195 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700196 private int mCaptureWidth;
197 private int mCaptureHeight;
198 private Bitmap mCapture;
199 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700200 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800201 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700202 private boolean mFullScreen = false;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700203
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100204 /**
Tarun Nainaniac724562014-11-03 17:40:38 -0800205 * See {@link #clearBackStackWhenItemAdded(java.util.regex.Pattern)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100206 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100207 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100208
John Reck1cf4b792011-07-26 10:22:22 -0700209 private static synchronized Bitmap getDefaultFavicon(Context context) {
210 if (sDefaultFavicon == null) {
211 sDefaultFavicon = BitmapFactory.decodeResource(
212 context.getResources(), R.drawable.app_web_browser_sm);
213 }
214 return sDefaultFavicon;
215 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800216
John Reck30c714c2010-12-16 17:30:34 -0800217 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700218 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800219 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700220 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800221 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100222 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100223 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
224 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800225 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100226 boolean mIsBookmarkedSite;
227 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800228
229 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700230 mIncognito = incognito;
231 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700232 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800233 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800234 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700235 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800236 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800237 }
Steve Block2466eff2011-10-03 15:33:09 +0100238 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800239 }
240
241 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700242 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700243 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800244 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100245 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800246 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100247 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800248 }
John Reck1cf4b792011-07-26 10:22:22 -0700249 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800250 }
John Reck1cf4b792011-07-26 10:22:22 -0700251
Grace Kloba22ac16e2009-10-07 18:00:23 -0700252 }
253
John Reck30c714c2010-12-16 17:30:34 -0800254 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700255 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800256
Grace Kloba22ac16e2009-10-07 18:00:23 -0700257 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700258 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700259 static final String CURRURL = "currentUrl";
260 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261 static final String PARENTTAB = "parentTab";
262 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700263 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700264 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700265 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700266
Grace Kloba22ac16e2009-10-07 18:00:23 -0700267 // Container class for the next error dialog that needs to be displayed
268 private class ErrorDialog {
269 public final int mTitle;
270 public final String mDescription;
271 public final int mError;
272 ErrorDialog(int title, String desc, int error) {
273 mTitle = title;
274 mDescription = desc;
275 mError = error;
276 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700277 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700278
279 private void processNextError() {
280 if (mQueuedErrors == null) {
281 return;
282 }
283 // The first one is currently displayed so just remove it.
284 mQueuedErrors.removeFirst();
285 if (mQueuedErrors.size() == 0) {
286 mQueuedErrors = null;
287 return;
288 }
289 showError(mQueuedErrors.getFirst());
290 }
291
292 private DialogInterface.OnDismissListener mDialogListener =
293 new DialogInterface.OnDismissListener() {
294 public void onDismiss(DialogInterface d) {
295 processNextError();
296 }
297 };
298 private LinkedList<ErrorDialog> mQueuedErrors;
299
300 private void queueError(int err, String desc) {
301 if (mQueuedErrors == null) {
302 mQueuedErrors = new LinkedList<ErrorDialog>();
303 }
304 for (ErrorDialog d : mQueuedErrors) {
305 if (d.mError == err) {
306 // Already saw a similar error, ignore the new one.
307 return;
308 }
309 }
310 ErrorDialog errDialog = new ErrorDialog(
311 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
312 R.string.browserFrameFileErrorLabel :
313 R.string.browserFrameNetworkErrorLabel,
314 desc, err);
315 mQueuedErrors.addLast(errDialog);
316
317 // Show the dialog now if the queue was empty and it is in foreground
318 if (mQueuedErrors.size() == 1 && mInForeground) {
319 showError(errDialog);
320 }
321 }
322
323 private void showError(ErrorDialog errDialog) {
324 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700325 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700326 .setTitle(errDialog.mTitle)
327 .setMessage(errDialog.mDescription)
328 .setPositiveButton(R.string.ok, null)
329 .create();
330 d.setOnDismissListener(mDialogListener);
331 d.show();
332 }
333 }
334
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800335 protected void replaceCrashView(View view, View container) {
336 if (hasCrashed && (view == mMainView)) {
337 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
338 wrapper.removeAllViewsInLayout();
339 wrapper.addView(view);
340 hasCrashed = false;
341 }
342 }
343
344 protected void showCrashView() {
345 if (hasCrashed) {
346 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
347 Context.LAYOUT_INFLATER_SERVICE);
348 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
349 final FrameLayout wrapper =
350 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
351 wrapper.removeAllViewsInLayout();
352 wrapper.addView(crashLayout);
353 mContainer.requestFocus();
354 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
355 reloadBtn.setOnClickListener(new OnClickListener() {
356 @Override
357 public void onClick(View arg0) {
358 replaceCrashView(mMainView, mContainer);
359 mMainView.reload();
360 }
361 });
362 }
363 }
364
Grace Kloba22ac16e2009-10-07 18:00:23 -0700365 // -------------------------------------------------------------------------
366 // WebViewClient implementation for the main WebView
367 // -------------------------------------------------------------------------
368
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800369 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500370 private Message mDontResend;
371 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700372
373 private boolean providersDiffer(String url, String otherUrl) {
374 Uri uri1 = Uri.parse(url);
375 Uri uri2 = Uri.parse(otherUrl);
376 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
377 }
378
Grace Kloba22ac16e2009-10-07 18:00:23 -0700379 @Override
380 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700382 mPageFinished = false;
Michael Kolb72864272012-05-03 15:42:15 -0700383 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700384 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700385 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800386 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000387 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700388
389 // If we start a touch icon load and then load a new page, we don't
390 // want to cancel the current touch icon loader. But, we do want to
391 // create a new one when the touch icon url is known.
392 if (mTouchIconLoader != null) {
393 mTouchIconLoader.mTab = null;
394 mTouchIconLoader = null;
395 }
396
397 // reset the error console
398 if (mErrorConsole != null) {
399 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700400 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700401 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
402 }
403 }
404
Grace Kloba22ac16e2009-10-07 18:00:23 -0700405 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800406 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500407
John Recke969cc52010-12-21 17:24:43 -0800408 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700409 }
410
411 @Override
412 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700413 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800414 if (!isPrivateBrowsingEnabled()) {
415 LogTag.logPageFinishedLoading(
416 url, SystemClock.uptimeMillis() - mLoadStartTime);
417 }
John Reck1cf4b792011-07-26 10:22:22 -0700418 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800419 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700420 }
421
422 // return true if want to hijack the url to let another app to handle it
423 @Override
424 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700425 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800426 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
427 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700428 } else {
429 return false;
430 }
431 }
432
433 /**
Steve Block2466eff2011-10-03 15:33:09 +0100434 * Updates the security state. This method is called when we discover
435 * another resource to be loaded for this page (for example,
436 * javascript). While we update the security state, we do not update
437 * the lock icon until we are done loading, as it is slightly more
438 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700439 */
440 @Override
441 public void onLoadResource(WebView view, String url) {
442 if (url != null && url.length() > 0) {
443 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100444 // to update the security state:
445 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
446 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700447 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
448 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100449 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700450 }
451 }
452 }
453 }
454
455 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700456 * Show a dialog informing the user of the network error reported by
457 * WebCore if it is in the foreground.
458 */
459 @Override
460 public void onReceivedError(WebView view, int errorCode,
461 String description, String failingUrl) {
462 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
463 errorCode != WebViewClient.ERROR_CONNECT &&
464 errorCode != WebViewClient.ERROR_BAD_URL &&
465 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
466 errorCode != WebViewClient.ERROR_FILE) {
467 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500468
Selim Gurun3da06b82011-10-10 13:58:12 -0700469 // Don't log URLs when in private browsing mode
470 if (!isPrivateBrowsingEnabled()) {
471 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500472 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700473 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500474 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700475 }
476
477 /**
478 * Check with the user if it is ok to resend POST data as the page they
479 * are trying to navigate to is the result of a POST.
480 */
481 @Override
482 public void onFormResubmission(WebView view, final Message dontResend,
483 final Message resend) {
484 if (!mInForeground) {
485 dontResend.sendToTarget();
486 return;
487 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500488 if (mDontResend != null) {
489 Log.w(LOGTAG, "onFormResubmission should not be called again "
490 + "while dialog is still up");
491 dontResend.sendToTarget();
492 return;
493 }
494 mDontResend = dontResend;
495 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700496 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700497 R.string.browserFrameFormResubmitLabel).setMessage(
498 R.string.browserFrameFormResubmitMessage)
499 .setPositiveButton(R.string.ok,
500 new DialogInterface.OnClickListener() {
501 public void onClick(DialogInterface dialog,
502 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500503 if (mResend != null) {
504 mResend.sendToTarget();
505 mResend = null;
506 mDontResend = null;
507 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700508 }
509 }).setNegativeButton(R.string.cancel,
510 new DialogInterface.OnClickListener() {
511 public void onClick(DialogInterface dialog,
512 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500513 if (mDontResend != null) {
514 mDontResend.sendToTarget();
515 mResend = null;
516 mDontResend = null;
517 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700518 }
519 }).setOnCancelListener(new OnCancelListener() {
520 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500521 if (mDontResend != null) {
522 mDontResend.sendToTarget();
523 mResend = null;
524 mDontResend = null;
525 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700526 }
527 }).show();
528 }
529
530 /**
531 * Insert the url into the visited history database.
532 * @param url The url to be inserted.
533 * @param isReload True if this url is being reloaded.
534 * FIXME: Not sure what to do when reloading the page.
535 */
536 @Override
537 public void doUpdateVisitedHistory(WebView view, String url,
538 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800539 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700540 }
541
542 /**
543 * Displays SSL error(s) dialog to the user.
544 */
545 @Override
546 public void onReceivedSslError(final WebView view,
547 final SslErrorHandler handler, final SslError error) {
548 if (!mInForeground) {
549 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100550 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700551 return;
552 }
John Reck35e9dd62011-04-25 09:01:54 -0700553 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700554 new AlertDialog.Builder(mContext)
555 .setTitle(R.string.security_warning)
556 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200557 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700558 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700559 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700560 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700561 public void onClick(DialogInterface dialog,
562 int whichButton) {
563 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100564 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700565 }
John Reckcb28b2c2011-08-26 17:39:44 -0700566 })
567 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700568 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700569 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700570 public void onClick(DialogInterface dialog,
571 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700572 mWebViewController.showSslCertificateOnError(
573 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700574 }
John Reckcb28b2c2011-08-26 17:39:44 -0700575 })
576 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700577 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700578 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700579 public void onClick(DialogInterface dialog,
580 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800581 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700582 }
John Reckcb28b2c2011-08-26 17:39:44 -0700583 })
584 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700585 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700586 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700587 public void onCancel(DialogInterface dialog) {
588 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100589 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800590 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700591 }
John Reckcb28b2c2011-08-26 17:39:44 -0700592 })
593 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700594 } else {
595 handler.proceed();
596 }
597 }
598
599 /**
Steve Block4895b012011-10-03 16:26:46 +0100600 * Called when an SSL error occurred while loading a resource, but the
601 * WebView but chose to proceed anyway based on a decision retained
602 * from a previous response to onReceivedSslError(). We update our
603 * security state to reflect this.
604 */
605 @Override
606 public void onProceededAfterSslError(WebView view, SslError error) {
607 handleProceededAfterSslError(error);
608 }
609
610 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700611 * Displays client certificate request to the user.
612 */
613 @Override
614 public void onReceivedClientCertRequest(final WebView view,
615 final ClientCertRequestHandler handler, final String host_and_port) {
616 if (!mInForeground) {
617 handler.ignore();
618 return;
619 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700620 int colon = host_and_port.lastIndexOf(':');
621 String host;
622 int port;
623 if (colon == -1) {
624 host = host_and_port;
625 port = -1;
626 } else {
627 String portString = host_and_port.substring(colon + 1);
628 try {
629 port = Integer.parseInt(portString);
630 host = host_and_port.substring(0, colon);
631 } catch (NumberFormatException e) {
632 host = host_and_port;
633 port = -1;
634 }
635 }
Michael Kolb14612442011-06-24 13:06:29 -0700636 KeyChain.choosePrivateKeyAlias(
637 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700638 @Override public void alias(String alias) {
639 if (alias == null) {
640 handler.cancel();
641 return;
642 }
Michael Kolb14612442011-06-24 13:06:29 -0700643 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700644 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700645 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700646 }
647
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800648 @Override
649 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
650 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700651 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
652 hasCrashed = true;
653 showCrashView();
654 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800655 }
656
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700657 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700658 * Handles an HTTP authentication request.
659 *
660 * @param handler The authentication handler
661 * @param host The host
662 * @param realm The realm
663 */
664 @Override
665 public void onReceivedHttpAuthRequest(WebView view,
666 final HttpAuthHandler handler, final String host,
667 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700668 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700669 }
670
671 @Override
John Reck438bf462011-01-12 18:11:46 -0800672 public WebResourceResponse shouldInterceptRequest(WebView view,
673 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800674 //intercept if opening a new incognito tab - show the incognito welcome page
675 if (url.startsWith("browser:incognito")) {
676 Resources resourceHandle = mContext.getResources();
677 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700678 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800679 return new WebResourceResponse("text/html", "utf8", inStream);
680 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800681 WebResourceResponse res;
682 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
683 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
684 } else {
685 res = HomeProvider.shouldInterceptRequest(mContext, url);
686 }
John Reck438bf462011-01-12 18:11:46 -0800687 return res;
688 }
689
690 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700691 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
692 if (!mInForeground) {
693 return false;
694 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700696 }
697
698 @Override
699 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700701 return;
702 }
John Reck997b1b72012-04-19 18:08:25 -0700703 if (!mWebViewController.onUnhandledKeyEvent(event)) {
704 super.onUnhandledKeyEvent(view, event);
705 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700706 }
707 };
708
John Reck1cf4b792011-07-26 10:22:22 -0700709 private void syncCurrentState(WebView view, String url) {
710 // Sync state (in case of stop/timeout)
711 mCurrentState.mUrl = view.getUrl();
712 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700713 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700714 }
715 mCurrentState.mOriginalUrl = view.getOriginalUrl();
716 mCurrentState.mTitle = view.getTitle();
717 mCurrentState.mFavicon = view.getFavicon();
718 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
719 // In case we stop when loading an HTTPS page from an HTTP page
720 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100721 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100722 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700723 }
John Reck502a3532011-08-16 14:21:46 -0700724 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700725 }
726
Tarun Nainani8eb00912014-07-17 12:28:32 -0700727
728 public boolean isTabFullScreen() {
729 return mFullScreen;
730 }
731
Vivek Sekharf96064b2014-07-28 16:32:34 -0700732 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700733 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700734 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700735 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700736 }
737
Sudheer Koganti24766882014-10-02 10:58:09 -0700738 public boolean exitFullscreen() {
739 if (mFullScreen) {
740 Controller controller = (Controller)mWebViewController;
741 controller.getUi().showFullscreen(false);
742 if (getWebView() != null)
743 getWebView().exitFullscreen();
744 mFullScreen = false;
745 return true;
746 }
747 return false;
748 }
749
750
751
752
Grace Kloba22ac16e2009-10-07 18:00:23 -0700753 // -------------------------------------------------------------------------
754 // WebChromeClient implementation for the main WebView
755 // -------------------------------------------------------------------------
756
757 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
758 // Helper method to create a new tab or sub window.
759 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700760 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700761 }
762
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700763 private void createWindow(final boolean dialog, final Message msg, final String url,
764 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700765 WebView.WebViewTransport transport =
766 (WebView.WebViewTransport) msg.obj;
767 if (dialog) {
768 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700769 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700770 transport.setWebView(mSubView);
771 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700772 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700773 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700774 // This is special case for rendering links on a webpage in
775 // a new tab. If opener is suppressed, the WebContents created
776 // by the content layer are not fully initialized. This check
777 // will prevent content layer from overriding WebContents
778 // created by new tab with the uninitialized instance.
779 if (!opener_suppressed) {
780 transport.setWebView(newTab.getWebView());
781 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700782 }
783 msg.sendToTarget();
784 }
785
786 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700787 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
788 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700789 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700790 }
791 }
792
793 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700794 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
795 float contentOffsetYPix,
796 float overdrawBottomHeightPix) {
797 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700798 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700799 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700800 }
801 }
802
803 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700804 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700805 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700806 }
807
808 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700809 public boolean onCreateWindow(WebView view, final boolean dialog,
810 final boolean userGesture, final Message resultMsg) {
811 // only allow new window or sub window for the foreground case
812 if (!mInForeground) {
813 return false;
814 }
815 // Short-circuit if we can't create any more tabs or sub windows.
816 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700817 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700818 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200819 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700820 .setMessage(R.string.too_many_subwindows_dialog_message)
821 .setPositiveButton(R.string.ok, null)
822 .show();
823 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700824 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700825 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700826 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200827 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700828 .setMessage(R.string.too_many_windows_dialog_message)
829 .setPositiveButton(R.string.ok, null)
830 .show();
831 return false;
832 }
833
834 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800835 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700836 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700837 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700838 createWindow(dialog, resultMsg, windowParams.mURL, true);
839 // This is special case for rendering links on a webpage in
840 // a new tab. If opener is suppressed, the WebContents created
841 // by the content layer are not fully initialized. Returning false
842 // will prevent content layer from overriding WebContents
843 // created by new tab with the uninitialized instance.
844 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700845 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700846
847 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700848 return true;
849 }
850
851 // Allow the popup and create the appropriate window.
852 final AlertDialog.OnClickListener allowListener =
853 new AlertDialog.OnClickListener() {
854 public void onClick(DialogInterface d,
855 int which) {
856 createWindow(dialog, resultMsg);
857 }
858 };
859
860 // Block the popup by returning a null WebView.
861 final AlertDialog.OnClickListener blockListener =
862 new AlertDialog.OnClickListener() {
863 public void onClick(DialogInterface d, int which) {
864 resultMsg.sendToTarget();
865 }
866 };
867
868 // Build a confirmation dialog to display to the user.
869 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700870 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200871 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700872 .setMessage(R.string.popup_window_attempt)
873 .setPositiveButton(R.string.allow, allowListener)
874 .setNegativeButton(R.string.block, blockListener)
875 .setCancelable(false)
876 .create();
877
878 // Show the confirmation dialog.
879 d.show();
880 return true;
881 }
882
883 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500884 public void onRequestFocus(WebView view) {
885 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700886 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500887 }
888 }
889
890 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700891 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700892 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700893 // JavaScript can only close popup window.
894 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700895 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700896 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700897 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700898 }
899 }
900
901 @Override
902 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800903 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800904 if (newProgress == 100) {
905 mInPageLoad = false;
906 }
John Reck30c714c2010-12-16 17:30:34 -0800907 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700908 if (mUpdateThumbnail && newProgress == 100) {
909 mUpdateThumbnail = false;
910 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700911 }
912
913 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500914 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800915 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700916 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700917 }
918
919 @Override
920 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800921 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700922 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700923 }
924
925 @Override
926 public void onReceivedTouchIconUrl(WebView view, String url,
927 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700928 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400929 // Let precomposed icons take precedence over non-composed
930 // icons.
931 if (precomposed && mTouchIconLoader != null) {
932 mTouchIconLoader.cancel(false);
933 mTouchIconLoader = null;
934 }
935 // Have only one async task at a time.
936 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700937 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700938 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400939 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700940 }
941 }
942
943 @Override
944 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800945 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700946 Activity activity = mWebViewController.getActivity();
947 if (activity != null) {
948 onShowCustomView(view, activity.getRequestedOrientation(), callback);
949 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400950 }
951
952 @Override
953 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800954 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700955 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400956 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700957 }
958
959 @Override
960 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700961 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700962 }
963
964 /**
965 * The origin has exceeded its database quota.
966 * @param url the URL that exceeded the quota
967 * @param databaseIdentifier the identifier of the database on which the
968 * transaction that caused the quota overflow was run
969 * @param currentQuota the current quota for the origin.
970 * @param estimatedSize the estimated size of the database.
971 * @param totalUsedQuota is the sum of all origins' quota.
972 * @param quotaUpdater The callback to run when a decision to allow or
973 * deny quota has been made. Don't forget to call this!
974 */
975 @Override
976 public void onExceededDatabaseQuota(String url,
977 String databaseIdentifier, long currentQuota, long estimatedSize,
978 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700979 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700980 .onExceededDatabaseQuota(url, databaseIdentifier,
981 currentQuota, estimatedSize, totalUsedQuota,
982 quotaUpdater);
983 }
984
985 /**
986 * The Application Cache has exceeded its max size.
987 * @param spaceNeeded is the amount of disk space that would be needed
988 * in order for the last appcache operation to succeed.
989 * @param totalUsedQuota is the sum of all origins' quota.
990 * @param quotaUpdater A callback to inform the WebCore thread that a
991 * new app cache size is available. This callback must always
992 * be executed at some point to ensure that the sleeping
993 * WebCore thread is woken up.
994 */
995 @Override
996 public void onReachedMaxAppCacheSize(long spaceNeeded,
997 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700998 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700999 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1000 quotaUpdater);
1001 }
1002
1003 /**
1004 * Instructs the browser to show a prompt to ask the user to set the
1005 * Geolocation permission state for the specified origin.
1006 * @param origin The origin for which Geolocation permissions are
1007 * requested.
1008 * @param callback The callback to call once the user has set the
1009 * Geolocation permission state.
1010 */
1011 @Override
1012 public void onGeolocationPermissionsShowPrompt(String origin,
1013 GeolocationPermissions.Callback callback) {
1014 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001015 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001016 }
1017 }
1018
1019 /**
1020 * Instructs the browser to hide the Geolocation permissions prompt.
1021 */
1022 @Override
1023 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001024 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001025 mGeolocationPermissionsPrompt.hide();
1026 }
1027 }
1028
Ben Murdoch65acc352009-11-19 18:16:04 +00001029 /* Adds a JavaScript error message to the system log and if the JS
1030 * console is enabled in the about:debug options, to that console
1031 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001032 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001033 */
1034 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001035 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001036 if (mInForeground) {
1037 // call getErrorConsole(true) so it will create one if needed
1038 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001039 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001040 if (mWebViewController.shouldShowErrorConsole()
1041 && errorConsole.getShowState() !=
1042 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001043 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1044 }
1045 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001046
Jeff Hamilton47654f42010-09-07 09:57:51 -05001047 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001048 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001049
Ben Murdochc42addf2010-01-28 15:19:59 +00001050 String message = "Console: " + consoleMessage.message() + " "
1051 + consoleMessage.sourceId() + ":"
1052 + consoleMessage.lineNumber();
1053
1054 switch (consoleMessage.messageLevel()) {
1055 case TIP:
1056 Log.v(CONSOLE_LOGTAG, message);
1057 break;
1058 case LOG:
1059 Log.i(CONSOLE_LOGTAG, message);
1060 break;
1061 case WARNING:
1062 Log.w(CONSOLE_LOGTAG, message);
1063 break;
1064 case ERROR:
1065 Log.e(CONSOLE_LOGTAG, message);
1066 break;
1067 case DEBUG:
1068 Log.d(CONSOLE_LOGTAG, message);
1069 break;
1070 }
1071
1072 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001073 }
1074
1075 /**
1076 * Ask the browser for an icon to represent a <video> element.
1077 * This icon will be used if the Web page did not specify a poster attribute.
1078 * @return Bitmap The icon or null if no such icon is available.
1079 */
1080 @Override
1081 public Bitmap getDefaultVideoPoster() {
1082 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001083 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001084 }
1085 return null;
1086 }
1087
1088 /**
1089 * Ask the host application for a custom progress view to show while
1090 * a <video> is loading.
1091 * @return View The progress view.
1092 */
1093 @Override
1094 public View getVideoLoadingProgressView() {
1095 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001096 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001097 }
1098 return null;
1099 }
1100
1101 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001102 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001103 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001104 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001105 } else {
1106 uploadMsg.onReceiveValue(null);
1107 }
1108 }
1109
Vivek Sekharb54614f2014-05-01 19:03:37 -07001110 @Override
1111 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1112 boolean capture) {
1113 if (mInForeground) {
1114 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1115 } else {
1116 uploadFilePaths.onReceiveValue(null);
1117 }
1118 }
1119
Grace Kloba22ac16e2009-10-07 18:00:23 -07001120 /**
1121 * Deliver a list of already-visited URLs
1122 */
1123 @Override
1124 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001125 mWebViewController.getVisitedHistory(callback);
1126 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001127
1128 @Override
1129 public void setupAutoFill(Message message) {
1130 // Prompt the user to set up their profile.
1131 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001132 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1133 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001134 Context.LAYOUT_INFLATER_SERVICE);
1135 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1136
1137 builder.setView(layout)
1138 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1139 @Override
1140 public void onClick(DialogInterface dialog, int id) {
1141 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1142 R.id.setup_autofill_dialog_disable_autofill);
1143
1144 if (disableAutoFill.isChecked()) {
1145 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001146 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001147 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001148 R.string.autofill_setup_dialog_negative_toast,
1149 Toast.LENGTH_LONG).show();
1150 } else {
1151 // Take user to the AutoFill profile editor. When they return,
1152 // we will send the message that we pass here which will trigger
1153 // the form to get filled out with their new profile.
1154 mWebViewController.setupAutoFill(msg);
1155 }
1156 }
1157 })
1158 .setNegativeButton(R.string.cancel, null)
1159 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001160 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001161 };
1162
1163 // -------------------------------------------------------------------------
1164 // WebViewClient implementation for the sub window
1165 // -------------------------------------------------------------------------
1166
1167 // Subclass of WebViewClient used in subwindows to notify the main
1168 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001169 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001170 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001171 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001172 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001173
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001174 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001175 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001176 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001177 }
1178 @Override
1179 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1180 // Unlike the others, do not call mClient's version, which would
1181 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001182 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001183 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001184 }
1185 @Override
1186 public void doUpdateVisitedHistory(WebView view, String url,
1187 boolean isReload) {
1188 mClient.doUpdateVisitedHistory(view, url, isReload);
1189 }
1190 @Override
1191 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1192 return mClient.shouldOverrideUrlLoading(view, url);
1193 }
1194 @Override
1195 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1196 SslError error) {
1197 mClient.onReceivedSslError(view, handler, error);
1198 }
1199 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001200 public void onReceivedClientCertRequest(WebView view,
1201 ClientCertRequestHandler handler, String host_and_port) {
1202 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1203 }
1204 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001205 public void onReceivedHttpAuthRequest(WebView view,
1206 HttpAuthHandler handler, String host, String realm) {
1207 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1208 }
1209 @Override
1210 public void onFormResubmission(WebView view, Message dontResend,
1211 Message resend) {
1212 mClient.onFormResubmission(view, dontResend, resend);
1213 }
1214 @Override
1215 public void onReceivedError(WebView view, int errorCode,
1216 String description, String failingUrl) {
1217 mClient.onReceivedError(view, errorCode, description, failingUrl);
1218 }
1219 @Override
1220 public boolean shouldOverrideKeyEvent(WebView view,
1221 android.view.KeyEvent event) {
1222 return mClient.shouldOverrideKeyEvent(view, event);
1223 }
1224 @Override
1225 public void onUnhandledKeyEvent(WebView view,
1226 android.view.KeyEvent event) {
1227 mClient.onUnhandledKeyEvent(view, event);
1228 }
1229 }
1230
1231 // -------------------------------------------------------------------------
1232 // WebChromeClient implementation for the sub window
1233 // -------------------------------------------------------------------------
1234
1235 private class SubWindowChromeClient extends WebChromeClient {
1236 // The main WebChromeClient.
1237 private final WebChromeClient mClient;
1238
1239 SubWindowChromeClient(WebChromeClient client) {
1240 mClient = client;
1241 }
1242 @Override
1243 public void onProgressChanged(WebView view, int newProgress) {
1244 mClient.onProgressChanged(view, newProgress);
1245 }
1246 @Override
1247 public boolean onCreateWindow(WebView view, boolean dialog,
1248 boolean userGesture, android.os.Message resultMsg) {
1249 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1250 }
1251 @Override
1252 public void onCloseWindow(WebView window) {
1253 if (window != mSubView) {
1254 Log.e(LOGTAG, "Can't close the window");
1255 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001256 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001257 }
1258 }
1259
1260 // -------------------------------------------------------------------------
1261
1262 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001263 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001264 this(wvcontroller, w, null);
1265 }
1266
1267 Tab(WebViewController wvcontroller, Bundle state) {
1268 this(wvcontroller, null, state);
1269 }
1270
1271 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001272 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001273 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001274 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001275 mDataController = DataController.getInstance(mContext);
1276 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001277 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001278 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001279 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001280 mInForeground = false;
1281
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001282 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001283 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001284 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001285 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001286 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001287 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001288 }
1289 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001290 mWebBackForwardListClient = new WebBackForwardListClient() {
1291 @Override
1292 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001293 if (mClearHistoryUrlPattern != null) {
1294 boolean match =
1295 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001296 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001297 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1298 + item.getUrl() + "\n\t"
1299 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001300 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001301 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001302 if (mMainView != null) {
1303 mMainView.clearHistory();
1304 }
1305 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001306 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001307 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001308 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001309 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001310
John Reck1cf4b792011-07-26 10:22:22 -07001311 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1312 R.dimen.tab_thumbnail_width);
1313 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1314 R.dimen.tab_thumbnail_height);
1315 updateShouldCaptureThumbnails();
1316 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001317 if (getId() == -1) {
1318 mId = TabControl.getNextId();
1319 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001320 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001321 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001322 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001323 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001324 switch (m.what) {
1325 case MSG_CAPTURE:
1326 capture();
1327 break;
1328 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001329 }
1330 };
John Reck1cf4b792011-07-26 10:22:22 -07001331 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001332
Michael Kolb72864272012-05-03 15:42:15 -07001333 public boolean shouldUpdateThumbnail() {
1334 return mUpdateThumbnail;
1335 }
1336
Mathew Inwoode09305e2011-09-02 12:03:26 +01001337 /**
1338 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1339 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1340 * to overlapping IDs between the preloaded and restored tabs.
1341 */
1342 public void refreshIdAfterPreload() {
1343 mId = TabControl.getNextId();
1344 }
1345
John Reck1cf4b792011-07-26 10:22:22 -07001346 public void updateShouldCaptureThumbnails() {
1347 if (mWebViewController.shouldCaptureThumbnails()) {
1348 synchronized (Tab.this) {
1349 if (mCapture == null) {
1350 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1351 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001352 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001353 if (mInForeground) {
1354 postCapture();
1355 }
1356 }
1357 }
1358 } else {
1359 synchronized (Tab.this) {
1360 mCapture = null;
1361 deleteThumbnail();
1362 }
1363 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001364 }
1365
Michael Kolb14612442011-06-24 13:06:29 -07001366 public void setController(WebViewController ctl) {
1367 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001368 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001369 }
1370
Michael Kolbc831b632011-05-11 09:30:34 -07001371 public long getId() {
1372 return mId;
1373 }
1374
Michael Kolb91911a22012-01-17 11:21:25 -08001375 void setWebView(WebView w) {
1376 setWebView(w, true);
1377 }
1378
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001379 public boolean isNativeActive(){
1380 if (mMainView == null)
1381 return false;
1382 return true;
1383 }
1384
1385 public void setTimeStamp(){
1386 Date d = new Date();
1387 timestamp = (new Timestamp(d.getTime()));
1388 }
1389
1390 public Timestamp getTimestamp() {
1391 return timestamp;
1392 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001393 /**
1394 * Sets the WebView for this tab, correctly removing the old WebView from
1395 * the container view.
1396 */
Michael Kolb91911a22012-01-17 11:21:25 -08001397 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001398 if (mMainView == w) {
1399 return;
1400 }
Michael Kolba713ec82010-11-29 17:27:06 -08001401
Grace Kloba22ac16e2009-10-07 18:00:23 -07001402 // If the WebView is changing, the page will be reloaded, so any ongoing
1403 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001404 if (mGeolocationPermissionsPrompt != null) {
1405 mGeolocationPermissionsPrompt.hide();
1406 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001407
Michael Kolba713ec82010-11-29 17:27:06 -08001408 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001409
John Reck1cf4b792011-07-26 10:22:22 -07001410 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001411 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001412 if (w != null) {
1413 syncCurrentState(w, null);
1414 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001415 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001416 }
1417 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001418 // set the new one
1419 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001420 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001421 if (mMainView != null) {
1422 mMainView.setWebViewClient(mWebViewClient);
1423 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001424 // Attach DownloadManager so that downloads can start in an active
1425 // or a non-active window. This can happen when going to a site that
1426 // does a redirect after a period of time. The user could have
1427 // switched to another tab while waiting for the download to start.
1428 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001429 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001430 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001431 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001432 mMainView.setPictureListener(this);
1433 }
Michael Kolb91911a22012-01-17 11:21:25 -08001434 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001435 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001436 WebBackForwardList restoredState
1437 = mMainView.restoreState(mSavedState);
1438 if (restoredState == null || restoredState.getSize() == 0) {
1439 Log.w(LOGTAG, "Failed to restore WebView state!");
1440 loadUrl(mCurrentState.mOriginalUrl, null);
1441 }
John Reck1cf4b792011-07-26 10:22:22 -07001442 mSavedState = null;
1443 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001444 }
1445 }
1446
1447 /**
1448 * Destroy the tab's main WebView and subWindow if any
1449 */
1450 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001451
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001452 if (mPostponeDestroy) {
1453 mShouldDestroy = true;
1454 return;
1455 }
1456 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001457 if (mMainView != null) {
1458 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001459 // save the WebView to call destroy() after detach it from the tab
1460 WebView webView = mMainView;
1461 setWebView(null);
1462 webView.destroy();
1463 }
1464 }
1465
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001466 private boolean mPostponeDestroy = false;
1467 private boolean mShouldDestroy = false;
1468
1469 public void postponeDestroy() {
1470 mPostponeDestroy = true;
1471 }
1472
1473 public void performPostponedDestroy() {
1474 mPostponeDestroy = false;
1475 if (mShouldDestroy) {
1476 destroy();
1477 }
1478 }
1479
Grace Kloba22ac16e2009-10-07 18:00:23 -07001480 /**
1481 * Remove the tab from the parent
1482 */
1483 void removeFromTree() {
1484 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001485 if (mChildren != null) {
1486 for(Tab t : mChildren) {
1487 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001488 }
1489 }
1490 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001491 if (mParent != null) {
1492 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001493 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001494
1495 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001496 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001497 }
1498
1499 /**
1500 * Create a new subwindow unless a subwindow already exists.
1501 * @return True if a new subwindow was created. False if one already exists.
1502 */
1503 boolean createSubWindow() {
1504 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001505 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001506 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001507 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001508 mSubView.setWebChromeClient(new SubWindowChromeClient(
1509 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001510 // Set a different DownloadListener for the mSubView, since it will
1511 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001512 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001513 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001514 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001515 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001516 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001517 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001518 if (mSubView.copyBackForwardList().getSize() == 0) {
1519 // This subwindow was opened for the sole purpose of
1520 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001521 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001522 }
1523 }
1524 });
Michael Kolb14612442011-06-24 13:06:29 -07001525 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001526 return true;
1527 }
1528 return false;
1529 }
1530
1531 /**
1532 * Dismiss the subWindow for the tab.
1533 */
1534 void dismissSubWindow() {
1535 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001536 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001537 mSubView.destroy();
1538 mSubView = null;
1539 mSubViewContainer = null;
1540 }
1541 }
1542
Grace Kloba22ac16e2009-10-07 18:00:23 -07001543
1544 /**
1545 * Set the parent tab of this tab.
1546 */
Michael Kolbc831b632011-05-11 09:30:34 -07001547 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001548 if (parent == this) {
1549 throw new IllegalStateException("Cannot set parent to self!");
1550 }
Michael Kolbc831b632011-05-11 09:30:34 -07001551 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001552 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001553 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001554 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001555 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001556 if (mSavedState != null) {
1557 if (parent == null) {
1558 mSavedState.remove(PARENTTAB);
1559 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001560 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001561 }
1562 }
John Reckb0a86db2011-05-24 14:05:58 -07001563
1564 // Sync the WebView useragent with the parent
1565 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1566 != mSettings.hasDesktopUseragent(getWebView())) {
1567 mSettings.toggleDesktopUseragent(getWebView());
1568 }
John Reck52be4782011-08-26 15:37:29 -07001569
1570 if (parent != null && parent.getId() == getId()) {
1571 throw new IllegalStateException("Parent has same ID as child!");
1572 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001573 }
1574
1575 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001576 * If this Tab was created through another Tab, then this method returns
1577 * that Tab.
1578 * @return the Tab parent or null
1579 */
1580 public Tab getParent() {
1581 return mParent;
1582 }
1583
1584 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001585 * When a Tab is created through the content of another Tab, then we
1586 * associate the Tabs.
1587 * @param child the Tab that was created from this Tab
1588 */
1589 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001590 if (mChildren == null) {
1591 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001592 }
Michael Kolbc831b632011-05-11 09:30:34 -07001593 mChildren.add(child);
1594 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001595 }
1596
Michael Kolbc831b632011-05-11 09:30:34 -07001597 Vector<Tab> getChildren() {
1598 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001599 }
1600
1601 void resume() {
1602 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001603 if (mMainView.hasCrashed()) {
1604 // Reload if render process has crashed. This is done here so that
1605 // setFocus call sends wasShown message to correct render process.
1606 mMainView.reload();
1607 }
John Reck56c1fcf2011-08-17 10:15:16 -07001608 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001609 mMainView.onResume();
1610 if (mSubView != null) {
1611 mSubView.onResume();
1612 }
1613 }
1614 }
1615
John Reck56c1fcf2011-08-17 10:15:16 -07001616 private void setupHwAcceleration(View web) {
1617 if (web == null) return;
1618 BrowserSettings settings = BrowserSettings.getInstance();
1619 if (settings.isHardwareAccelerated()) {
1620 web.setLayerType(View.LAYER_TYPE_NONE, null);
1621 } else {
1622 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1623 }
1624 }
1625
Grace Kloba22ac16e2009-10-07 18:00:23 -07001626 void pause() {
1627 if (mMainView != null) {
1628 mMainView.onPause();
1629 if (mSubView != null) {
1630 mSubView.onPause();
1631 }
1632 }
1633 }
1634
1635 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001636 if (mInForeground) {
1637 return;
1638 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001639 mInForeground = true;
1640 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001641 Activity activity = mWebViewController.getActivity();
1642 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001643 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001644 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001645 }
1646 // Show the pending error dialog if the queue is not empty
1647 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1648 showError(mQueuedErrors.getFirst());
1649 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001650 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001651 }
1652
1653 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001654 if (!mInForeground) {
1655 return;
1656 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001657 mInForeground = false;
1658 pause();
1659 mMainView.setOnCreateContextMenuListener(null);
1660 if (mSubView != null) {
1661 mSubView.setOnCreateContextMenuListener(null);
1662 }
1663 }
1664
Michael Kolb8233fac2010-10-26 16:08:53 -07001665 boolean inForeground() {
1666 return mInForeground;
1667 }
1668
Grace Kloba22ac16e2009-10-07 18:00:23 -07001669 /**
1670 * Return the top window of this tab; either the subwindow if it is not
1671 * null or the main window.
1672 * @return The top window of this tab.
1673 */
1674 WebView getTopWindow() {
1675 if (mSubView != null) {
1676 return mSubView;
1677 }
1678 return mMainView;
1679 }
1680
1681 /**
1682 * Return the main window of this tab. Note: if a tab is freed in the
1683 * background, this can return null. It is only guaranteed to be
1684 * non-null for the current tab.
1685 * @return The main WebView of this tab.
1686 */
1687 WebView getWebView() {
1688 return mMainView;
1689 }
1690
Michael Kolba713ec82010-11-29 17:27:06 -08001691 void setViewContainer(View container) {
1692 mContainer = container;
1693 }
1694
Michael Kolb8233fac2010-10-26 16:08:53 -07001695 View getViewContainer() {
1696 return mContainer;
1697 }
1698
Grace Kloba22ac16e2009-10-07 18:00:23 -07001699 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001700 * Return whether private browsing is enabled for the main window of
1701 * this tab.
1702 * @return True if private browsing is enabled.
1703 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001704 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001705 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001706 }
1707
1708 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001709 * Return the subwindow of this tab or null if there is no subwindow.
1710 * @return The subwindow of this tab or null.
1711 */
1712 WebView getSubWebView() {
1713 return mSubView;
1714 }
1715
Michael Kolb1514bb72010-11-22 09:11:48 -08001716 void setSubWebView(WebView subView) {
1717 mSubView = subView;
1718 }
1719
Michael Kolb8233fac2010-10-26 16:08:53 -07001720 View getSubViewContainer() {
1721 return mSubViewContainer;
1722 }
1723
Michael Kolb1514bb72010-11-22 09:11:48 -08001724 void setSubViewContainer(View subViewContainer) {
1725 mSubViewContainer = subViewContainer;
1726 }
1727
Grace Kloba22ac16e2009-10-07 18:00:23 -07001728 /**
1729 * @return The geolocation permissions prompt for this tab.
1730 */
1731 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001732 if (mGeolocationPermissionsPrompt == null) {
1733 ViewStub stub = (ViewStub) mContainer
1734 .findViewById(R.id.geolocation_permissions_prompt);
1735 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1736 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001737 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001738 return mGeolocationPermissionsPrompt;
1739 }
1740
1741 /**
1742 * @return The application id string
1743 */
1744 String getAppId() {
1745 return mAppId;
1746 }
1747
1748 /**
1749 * Set the application id string
1750 * @param id
1751 */
1752 void setAppId(String id) {
1753 mAppId = id;
1754 }
1755
Michael Kolbe28b3472011-08-04 16:54:31 -07001756 boolean closeOnBack() {
1757 return mCloseOnBack;
1758 }
1759
1760 void setCloseOnBack(boolean close) {
1761 mCloseOnBack = close;
1762 }
1763
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001764 boolean getDerivedFromIntent() {
1765 return mDerivedFromIntent;
1766 }
1767
1768 void setDerivedFromIntent(boolean derived) {
1769 mDerivedFromIntent = derived;
1770 }
1771
Grace Kloba22ac16e2009-10-07 18:00:23 -07001772 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001773 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001774 }
1775
Tarun Nainani8eb00912014-07-17 12:28:32 -07001776
1777 protected void onPageFinished() {
1778 mPageFinished = true;
1779 }
1780
1781 public boolean getPageFinishedStatus() {
1782 return mPageFinished;
1783 }
1784
John Reck49a603c2011-03-03 09:33:05 -08001785 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001786 if (mCurrentState.mOriginalUrl == null) {
1787 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001788 }
John Reckdb22ec42011-06-29 11:31:24 -07001789 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001790 }
1791
Grace Kloba22ac16e2009-10-07 18:00:23 -07001792 /**
John Reck30c714c2010-12-16 17:30:34 -08001793 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001794 */
1795 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001796 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001797 }
1798
1799 /**
John Reck30c714c2010-12-16 17:30:34 -08001800 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001801 */
1802 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001803 if (mCurrentState.mFavicon != null) {
1804 return mCurrentState.mFavicon;
1805 }
1806 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001807 }
1808
John Recke969cc52010-12-21 17:24:43 -08001809 public boolean isBookmarkedSite() {
1810 return mCurrentState.mIsBookmarkedSite;
1811 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001812
Grace Kloba22ac16e2009-10-07 18:00:23 -07001813 /**
1814 * Return the tab's error console. Creates the console if createIfNEcessary
1815 * is true and we haven't already created the console.
1816 * @param createIfNecessary Flag to indicate if the console should be
1817 * created if it has not been already.
1818 * @return The tab's error console, or null if one has not been created and
1819 * createIfNecessary is false.
1820 */
1821 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1822 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001823 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001824 mErrorConsole.setWebView(mMainView);
1825 }
1826 return mErrorConsole;
1827 }
1828
Steve Block08a6f0c2011-10-06 12:12:53 +01001829 /**
1830 * Sets the security state, clears the SSL certificate error and informs
1831 * the controller.
1832 */
Steve Block2466eff2011-10-03 15:33:09 +01001833 private void setSecurityState(SecurityState securityState) {
1834 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001835 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001836 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001837 }
1838
1839 /**
Steve Block2466eff2011-10-03 15:33:09 +01001840 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001841 */
Steve Block2466eff2011-10-03 15:33:09 +01001842 SecurityState getSecurityState() {
1843 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001844 }
1845
Steve Block08a6f0c2011-10-06 12:12:53 +01001846 /**
1847 * Gets the SSL certificate error, if any, for the page's main resource.
1848 * This is only non-null when the security state is
1849 * SECURITY_STATE_BAD_CERTIFICATE.
1850 */
1851 SslError getSslCertificateError() {
1852 return mCurrentState.mSslCertificateError;
1853 }
1854
John Reck30c714c2010-12-16 17:30:34 -08001855 int getLoadProgress() {
1856 if (mInPageLoad) {
1857 return mPageLoadProgress;
1858 }
1859 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001860 }
1861
1862 /**
1863 * @return TRUE if onPageStarted is called while onPageFinished is not
1864 * called yet.
1865 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001866 boolean inPageLoad() {
1867 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001868 }
1869
Grace Kloba22ac16e2009-10-07 18:00:23 -07001870 /**
John Reck1cf4b792011-07-26 10:22:22 -07001871 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001872 */
John Reck1cf4b792011-07-26 10:22:22 -07001873 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001874 // If the WebView is null it means we ran low on memory and we already
1875 // stored the saved state in mSavedState.
1876 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001877 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001878 }
John Reck6c2e2f32011-08-22 13:41:23 -07001879
1880 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001881 return null;
John Reck24f18262011-06-17 14:47:20 -07001882 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001883
1884 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001885 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1886 if (savedList == null || savedList.getSize() == 0) {
1887 Log.w(LOGTAG, "Failed to save back/forward list for "
1888 + mCurrentState.mUrl);
1889 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001890
Michael Kolbc831b632011-05-11 09:30:34 -07001891 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001892 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1893 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001894 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001895 if (mAppId != null) {
1896 mSavedState.putString(APPID, mAppId);
1897 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001898 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001899 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001900 if (mParent != null) {
1901 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001902 }
John Reckb0a86db2011-05-24 14:05:58 -07001903 mSavedState.putBoolean(USERAGENT,
1904 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001905 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001906 }
1907
1908 /*
1909 * Restore the state of the tab.
1910 */
John Reck1cf4b792011-07-26 10:22:22 -07001911 private void restoreState(Bundle b) {
1912 mSavedState = b;
1913 if (mSavedState == null) {
1914 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001915 }
1916 // Restore the internal state even if the WebView fails to restore.
1917 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001918 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001919 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001920 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001921 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001922 String url = b.getString(CURRURL);
1923 String title = b.getString(CURRTITLE);
1924 boolean incognito = b.getBoolean(INCOGNITO);
1925 mCurrentState = new PageState(mContext, incognito, url, null);
1926 mCurrentState.mTitle = title;
1927 synchronized (Tab.this) {
1928 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001929 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001930 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001931 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001932 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001933
John Reck8b9bb8b2012-03-08 13:19:40 -08001934 private void restoreUserAgent() {
1935 if (mMainView == null || mSavedState == null) {
1936 return;
1937 }
1938 if (mSavedState.getBoolean(USERAGENT)
1939 != mSettings.hasDesktopUseragent(mMainView)) {
1940 mSettings.toggleDesktopUseragent(mMainView);
1941 }
1942 }
1943
Leon Scroggins1961ed22010-12-07 15:22:21 -05001944 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001945 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001946 }
1947
John Recke969cc52010-12-21 17:24:43 -08001948 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1949 = new DataController.OnQueryUrlIsBookmark() {
1950 @Override
1951 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1952 if (mCurrentState.mUrl.equals(url)) {
1953 mCurrentState.mIsBookmarkedSite = isBookmark;
1954 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1955 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001956 }
John Recke969cc52010-12-21 17:24:43 -08001957 };
Michael Kolb1acef692011-03-08 14:12:06 -08001958
Michael Kolbeb95db42011-03-03 10:38:40 -08001959 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001960 synchronized (Tab.this) {
1961 return mCapture;
1962 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001963 }
1964
John Reck541f55a2011-06-07 16:34:43 -07001965 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001966 return false;
1967 }
1968
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001969 private static class SaveCallback implements ValueCallback<String> {
1970 boolean onReceiveValueCalled = false;
1971 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001972
1973 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001974 public void onReceiveValue(String path) {
1975 this.onReceiveValueCalled = true;
1976 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001977 synchronized (this) {
1978 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001979 }
John Reck541f55a2011-06-07 16:34:43 -07001980 }
John Reck68234a92012-04-19 15:27:12 -07001981
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001982 public String getPath() {
1983 return mPath;
1984 }
John Reck68234a92012-04-19 15:27:12 -07001985 }
1986
1987 /**
1988 * Must be called on the UI thread
1989 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001990 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001991 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001992 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001993 ContentValues values = new ContentValues();
1994 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1995 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001996 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001997 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1998 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001999 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07002000 return values;
John Reck541f55a2011-06-07 16:34:43 -07002001 }
2002
John Reck68234a92012-04-19 15:27:12 -07002003 /**
2004 * Probably want to call this on a background thread
2005 */
2006 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002007 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002008 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002009 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002010 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002011 try {
John Reck68234a92012-04-19 15:27:12 -07002012 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002013 web.saveViewState(filename, callback);
2014 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002015 }
John Reck68234a92012-04-19 15:27:12 -07002016 } catch (Exception e) {
2017 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002018 String path = callback.getPath();
2019 if (path != null) {
2020 File file = mContext.getFileStreamPath(path);
2021 if (file.exists() && !file.delete()) {
2022 file.deleteOnExit();
2023 }
John Reck68234a92012-04-19 15:27:12 -07002024 }
2025 return false;
2026 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002027
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002028 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002029 // could be that saving of file failed
2030 if (path == null) {
2031 return false;
2032 }
2033
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002034 File savedFile = new File(path);
2035 if (!savedFile.exists()) {
2036 return false;
John Reck68234a92012-04-19 15:27:12 -07002037 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002038 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2039 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002040 return true;
2041 }
2042
John Reck8cc92352011-07-06 17:41:52 -07002043 public byte[] compressBitmap(Bitmap bitmap) {
2044 if (bitmap == null) {
2045 return null;
2046 }
2047 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2048 bitmap.compress(CompressFormat.PNG, 100, stream);
2049 return stream.toByteArray();
2050 }
2051
John Reck26b18322011-06-21 13:08:58 -07002052 public void loadUrl(String url, Map<String, String> headers) {
2053 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002054 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002055 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002056 mMainView.loadUrl(url, headers);
2057 }
2058 }
2059
John Reck38b39652012-06-05 09:22:59 -07002060 public void disableUrlOverridingForLoad() {
2061 mDisableOverrideUrlLoading = true;
2062 }
2063
Michael Kolb9ef259a2011-07-12 15:33:08 -07002064 protected void capture() {
2065 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002066 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2067 return;
2068 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002069
2070 mMainView
2071 .getContentBitmapAsync(
2072 (float) mCaptureWidth / mMainView.getWidth(),
2073 new Rect(),
2074 new ValueCallback<Bitmap>() {
2075 @Override
2076 public void onReceiveValue(Bitmap bitmap) {
2077 onCaptureCallback(bitmap);
2078 }});
2079 }
2080
2081 private void onCaptureCallback(Bitmap bitmap) {
2082 if (mCapture == null || bitmap == null)
2083 return;
2084
Michael Kolb9ef259a2011-07-12 15:33:08 -07002085 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002086 mCapture.eraseColor(Color.WHITE);
2087 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002088
Michael Kolba3194d02011-09-07 11:23:51 -07002089 // manually anti-alias the edges for the tilt
2090 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2091 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2092 mCapture.getHeight(), sAlphaPaint);
2093 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2094 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2095 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002096 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002097 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002098 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002099 TabControl tc = mWebViewController.getTabControl();
2100 if (tc != null) {
2101 OnThumbnailUpdatedListener updateListener
2102 = tc.getOnThumbnailUpdatedListener();
2103 if (updateListener != null) {
2104 updateListener.onThumbnailUpdated(this);
2105 }
2106 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002107 }
2108
2109 @Override
2110 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002111 postCapture();
2112 }
2113
2114 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002115 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2116 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2117 }
2118 }
2119
John Reckef654f12011-07-12 16:42:08 -07002120 public boolean canGoBack() {
2121 return mMainView != null ? mMainView.canGoBack() : false;
2122 }
2123
2124 public boolean canGoForward() {
2125 return mMainView != null ? mMainView.canGoForward() : false;
2126 }
2127
2128 public void goBack() {
2129 if (mMainView != null) {
2130 mMainView.goBack();
2131 }
2132 }
2133
2134 public void goForward() {
2135 if (mMainView != null) {
2136 mMainView.goForward();
2137 }
2138 }
2139
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002140 /**
2141 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2142 * to be added to the stack.
2143 *
2144 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2145 * not appear in the back stack.
2146 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002147 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2148 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002149 }
2150
John Reck1cf4b792011-07-26 10:22:22 -07002151 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002152 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002153 }
2154
2155 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002156 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002157 }
2158
John Reck4eadc342011-10-31 14:04:10 -07002159 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002160 synchronized (Tab.this) {
2161 if (mCapture == null) {
2162 return;
2163 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002164 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002165 try {
2166 mCapture.copyPixelsFromBuffer(buffer);
2167 } catch (RuntimeException rex) {
2168 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2169 + buffer.capacity() + " blob: " + blob.length
2170 + "capture: " + mCapture.getByteCount());
2171 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002172 }
John Reck1cf4b792011-07-26 10:22:22 -07002173 }
2174 }
2175
John Reck52be4782011-08-26 15:37:29 -07002176 @Override
2177 public String toString() {
2178 StringBuilder builder = new StringBuilder(100);
2179 builder.append(mId);
2180 builder.append(") has parent: ");
2181 if (getParent() != null) {
2182 builder.append("true[");
2183 builder.append(getParent().getId());
2184 builder.append("]");
2185 } else {
2186 builder.append("false");
2187 }
2188 builder.append(", incog: ");
2189 builder.append(isPrivateBrowsingEnabled());
2190 if (!isPrivateBrowsingEnabled()) {
2191 builder.append(", title: ");
2192 builder.append(getTitle());
2193 builder.append(", url: ");
2194 builder.append(getUrl());
2195 }
2196 return builder.toString();
2197 }
2198
Steve Block4895b012011-10-03 16:26:46 +01002199 private void handleProceededAfterSslError(SslError error) {
2200 if (error.getUrl().equals(mCurrentState.mUrl)) {
2201 // The security state should currently be SECURITY_STATE_SECURE.
2202 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002203 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002204 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002205 // The page's main resource is secure and this error is for a
2206 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002207 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2208 }
2209 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002210}