blob: fab2ec02b186d7a746246f52a5d8e7b7d6d3b120 [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;
Grace Kloba22ac16e2009-10-07 18:00:23 -070036import android.net.Uri;
37import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070038import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070039import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070040import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000041import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070042import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070043import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070044import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070045import android.util.Log;
46import android.view.KeyEvent;
47import android.view.LayoutInflater;
48import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070049import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080050import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000051import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070052import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080054import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070055import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080056import android.webkit.WebChromeClient.CustomViewCallback;
57import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000058import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000059import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080060import android.widget.FrameLayout;
61import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070062
Bijan Amirzada41242f22014-03-21 12:12:18 -070063import com.android.browser.R;
64import 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;
80import org.codeaurora.swe.WebViewClient;
81
John Reck541f55a2011-06-07 16:34:43 -070082
83import 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;
John Reck38b39652012-06-05 09:22:59 -0700168 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800169 // The last reported progress of the current page
170 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000171 // The time the load started, used to find load page time
172 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700173 // Application identifier used to find tabs that another application wants
174 // to reuse.
175 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700176 // flag to indicate if tab should be closed on back
177 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700178 // flag to indicate if the tab was opened from an intent
179 private boolean mDerivedFromIntent = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700180 // Keep the original url around to avoid killing the old WebView if the url
181 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700182 // Error console for the tab
183 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500184 // The listener that gets invoked when a download is started from the
185 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700186 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500187 // Listener used to know when we move forward or back in the history list.
188 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800189 private DataController mDataController;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700190 //Indicates if a JS interface was created for a specific url
191 private boolean mJsInterfaceEnabled = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700192
193 // AsyncTask for downloading touch icons
194 DownloadTouchIcon mTouchIconLoader;
195
John Reck35e9dd62011-04-25 09:01:54 -0700196 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700197 private int mCaptureWidth;
198 private int mCaptureHeight;
199 private Bitmap mCapture;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700200 private Bitmap mScreenShot;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700201 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700202 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800203 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700204 private boolean mFullScreen = false;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700205
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100206 /**
Mathew Inwood9ad1eac2011-09-15 11:29:50 +0100207 * See {@link #clearBackStackWhenItemAdded(String)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100208 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100209 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100210
John Reck1cf4b792011-07-26 10:22:22 -0700211 private static synchronized Bitmap getDefaultFavicon(Context context) {
212 if (sDefaultFavicon == null) {
213 sDefaultFavicon = BitmapFactory.decodeResource(
214 context.getResources(), R.drawable.app_web_browser_sm);
215 }
216 return sDefaultFavicon;
217 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800218
John Reck30c714c2010-12-16 17:30:34 -0800219 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700220 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800221 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700222 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800223 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100224 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100225 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
226 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800227 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100228 boolean mIsBookmarkedSite;
229 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800230
231 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700232 mIncognito = incognito;
233 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700234 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800235 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800236 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700237 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800238 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800239 }
Steve Block2466eff2011-10-03 15:33:09 +0100240 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800241 }
242
243 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700244 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700245 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800246 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100247 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800248 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100249 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800250 }
John Reck1cf4b792011-07-26 10:22:22 -0700251 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800252 }
John Reck1cf4b792011-07-26 10:22:22 -0700253
Grace Kloba22ac16e2009-10-07 18:00:23 -0700254 }
255
John Reck30c714c2010-12-16 17:30:34 -0800256 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700257 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800258
Grace Kloba22ac16e2009-10-07 18:00:23 -0700259 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700260 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261 static final String CURRURL = "currentUrl";
262 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700263 static final String PARENTTAB = "parentTab";
264 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700265 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700266 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700267 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700268
Grace Kloba22ac16e2009-10-07 18:00:23 -0700269 // Container class for the next error dialog that needs to be displayed
270 private class ErrorDialog {
271 public final int mTitle;
272 public final String mDescription;
273 public final int mError;
274 ErrorDialog(int title, String desc, int error) {
275 mTitle = title;
276 mDescription = desc;
277 mError = error;
278 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700279 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700280
281 private void processNextError() {
282 if (mQueuedErrors == null) {
283 return;
284 }
285 // The first one is currently displayed so just remove it.
286 mQueuedErrors.removeFirst();
287 if (mQueuedErrors.size() == 0) {
288 mQueuedErrors = null;
289 return;
290 }
291 showError(mQueuedErrors.getFirst());
292 }
293
294 private DialogInterface.OnDismissListener mDialogListener =
295 new DialogInterface.OnDismissListener() {
296 public void onDismiss(DialogInterface d) {
297 processNextError();
298 }
299 };
300 private LinkedList<ErrorDialog> mQueuedErrors;
301
302 private void queueError(int err, String desc) {
303 if (mQueuedErrors == null) {
304 mQueuedErrors = new LinkedList<ErrorDialog>();
305 }
306 for (ErrorDialog d : mQueuedErrors) {
307 if (d.mError == err) {
308 // Already saw a similar error, ignore the new one.
309 return;
310 }
311 }
312 ErrorDialog errDialog = new ErrorDialog(
313 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
314 R.string.browserFrameFileErrorLabel :
315 R.string.browserFrameNetworkErrorLabel,
316 desc, err);
317 mQueuedErrors.addLast(errDialog);
318
319 // Show the dialog now if the queue was empty and it is in foreground
320 if (mQueuedErrors.size() == 1 && mInForeground) {
321 showError(errDialog);
322 }
323 }
324
325 private void showError(ErrorDialog errDialog) {
326 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700327 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700328 .setTitle(errDialog.mTitle)
329 .setMessage(errDialog.mDescription)
330 .setPositiveButton(R.string.ok, null)
331 .create();
332 d.setOnDismissListener(mDialogListener);
333 d.show();
334 }
335 }
336
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800337 protected void replaceCrashView(View view, View container) {
338 if (hasCrashed && (view == mMainView)) {
339 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
340 wrapper.removeAllViewsInLayout();
341 wrapper.addView(view);
342 hasCrashed = false;
343 }
344 }
345
346 protected void showCrashView() {
347 if (hasCrashed) {
348 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
349 Context.LAYOUT_INFLATER_SERVICE);
350 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
351 final FrameLayout wrapper =
352 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
353 wrapper.removeAllViewsInLayout();
354 wrapper.addView(crashLayout);
355 mContainer.requestFocus();
356 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
357 reloadBtn.setOnClickListener(new OnClickListener() {
358 @Override
359 public void onClick(View arg0) {
360 replaceCrashView(mMainView, mContainer);
361 mMainView.reload();
362 }
363 });
364 }
365 }
366
Grace Kloba22ac16e2009-10-07 18:00:23 -0700367 // -------------------------------------------------------------------------
368 // WebViewClient implementation for the main WebView
369 // -------------------------------------------------------------------------
370
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800371 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500372 private Message mDontResend;
373 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700374
375 private boolean providersDiffer(String url, String otherUrl) {
376 Uri uri1 = Uri.parse(url);
377 Uri uri2 = Uri.parse(otherUrl);
378 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
379 }
380
Grace Kloba22ac16e2009-10-07 18:00:23 -0700381 @Override
382 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700383 mInPageLoad = true;
Michael Kolb72864272012-05-03 15:42:15 -0700384 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700385 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700386 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800387 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000388 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700389
390 // If we start a touch icon load and then load a new page, we don't
391 // want to cancel the current touch icon loader. But, we do want to
392 // create a new one when the touch icon url is known.
393 if (mTouchIconLoader != null) {
394 mTouchIconLoader.mTab = null;
395 mTouchIconLoader = null;
396 }
397
398 // reset the error console
399 if (mErrorConsole != null) {
400 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700401 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700402 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
403 }
404 }
405
Grace Kloba22ac16e2009-10-07 18:00:23 -0700406 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800407 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500408
John Recke969cc52010-12-21 17:24:43 -0800409 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700410 }
411
412 @Override
413 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700414 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800415 if (!isPrivateBrowsingEnabled()) {
416 LogTag.logPageFinishedLoading(
417 url, SystemClock.uptimeMillis() - mLoadStartTime);
418 }
John Reck1cf4b792011-07-26 10:22:22 -0700419 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800420 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700421 }
422
423 // return true if want to hijack the url to let another app to handle it
424 @Override
425 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700426 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800427 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
428 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700429 } else {
430 return false;
431 }
432 }
433
434 /**
Steve Block2466eff2011-10-03 15:33:09 +0100435 * Updates the security state. This method is called when we discover
436 * another resource to be loaded for this page (for example,
437 * javascript). While we update the security state, we do not update
438 * the lock icon until we are done loading, as it is slightly more
439 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700440 */
441 @Override
442 public void onLoadResource(WebView view, String url) {
443 if (url != null && url.length() > 0) {
444 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100445 // to update the security state:
446 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
447 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700448 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
449 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100450 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700451 }
452 }
453 }
454 }
455
456 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700457 * Show a dialog informing the user of the network error reported by
458 * WebCore if it is in the foreground.
459 */
460 @Override
461 public void onReceivedError(WebView view, int errorCode,
462 String description, String failingUrl) {
463 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
464 errorCode != WebViewClient.ERROR_CONNECT &&
465 errorCode != WebViewClient.ERROR_BAD_URL &&
466 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
467 errorCode != WebViewClient.ERROR_FILE) {
468 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500469
Selim Gurun3da06b82011-10-10 13:58:12 -0700470 // Don't log URLs when in private browsing mode
471 if (!isPrivateBrowsingEnabled()) {
472 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500473 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700474 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500475 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700476 }
477
478 /**
479 * Check with the user if it is ok to resend POST data as the page they
480 * are trying to navigate to is the result of a POST.
481 */
482 @Override
483 public void onFormResubmission(WebView view, final Message dontResend,
484 final Message resend) {
485 if (!mInForeground) {
486 dontResend.sendToTarget();
487 return;
488 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500489 if (mDontResend != null) {
490 Log.w(LOGTAG, "onFormResubmission should not be called again "
491 + "while dialog is still up");
492 dontResend.sendToTarget();
493 return;
494 }
495 mDontResend = dontResend;
496 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700497 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700498 R.string.browserFrameFormResubmitLabel).setMessage(
499 R.string.browserFrameFormResubmitMessage)
500 .setPositiveButton(R.string.ok,
501 new DialogInterface.OnClickListener() {
502 public void onClick(DialogInterface dialog,
503 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500504 if (mResend != null) {
505 mResend.sendToTarget();
506 mResend = null;
507 mDontResend = null;
508 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700509 }
510 }).setNegativeButton(R.string.cancel,
511 new DialogInterface.OnClickListener() {
512 public void onClick(DialogInterface dialog,
513 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500514 if (mDontResend != null) {
515 mDontResend.sendToTarget();
516 mResend = null;
517 mDontResend = null;
518 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700519 }
520 }).setOnCancelListener(new OnCancelListener() {
521 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500522 if (mDontResend != null) {
523 mDontResend.sendToTarget();
524 mResend = null;
525 mDontResend = null;
526 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700527 }
528 }).show();
529 }
530
531 /**
532 * Insert the url into the visited history database.
533 * @param url The url to be inserted.
534 * @param isReload True if this url is being reloaded.
535 * FIXME: Not sure what to do when reloading the page.
536 */
537 @Override
538 public void doUpdateVisitedHistory(WebView view, String url,
539 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800540 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700541 }
542
543 /**
544 * Displays SSL error(s) dialog to the user.
545 */
546 @Override
547 public void onReceivedSslError(final WebView view,
548 final SslErrorHandler handler, final SslError error) {
549 if (!mInForeground) {
550 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100551 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700552 return;
553 }
John Reck35e9dd62011-04-25 09:01:54 -0700554 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700555 new AlertDialog.Builder(mContext)
556 .setTitle(R.string.security_warning)
557 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200558 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700559 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700560 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700561 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700562 public void onClick(DialogInterface dialog,
563 int whichButton) {
564 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100565 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700566 }
John Reckcb28b2c2011-08-26 17:39:44 -0700567 })
568 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700569 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700570 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700571 public void onClick(DialogInterface dialog,
572 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700573 mWebViewController.showSslCertificateOnError(
574 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700575 }
John Reckcb28b2c2011-08-26 17:39:44 -0700576 })
577 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700578 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700579 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580 public void onClick(DialogInterface dialog,
581 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800582 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700583 }
John Reckcb28b2c2011-08-26 17:39:44 -0700584 })
585 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700586 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700587 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700588 public void onCancel(DialogInterface dialog) {
589 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100590 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800591 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700592 }
John Reckcb28b2c2011-08-26 17:39:44 -0700593 })
594 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700595 } else {
596 handler.proceed();
597 }
598 }
599
600 /**
Steve Block4895b012011-10-03 16:26:46 +0100601 * Called when an SSL error occurred while loading a resource, but the
602 * WebView but chose to proceed anyway based on a decision retained
603 * from a previous response to onReceivedSslError(). We update our
604 * security state to reflect this.
605 */
606 @Override
607 public void onProceededAfterSslError(WebView view, SslError error) {
608 handleProceededAfterSslError(error);
609 }
610
611 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700612 * Displays client certificate request to the user.
613 */
614 @Override
615 public void onReceivedClientCertRequest(final WebView view,
616 final ClientCertRequestHandler handler, final String host_and_port) {
617 if (!mInForeground) {
618 handler.ignore();
619 return;
620 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700621 int colon = host_and_port.lastIndexOf(':');
622 String host;
623 int port;
624 if (colon == -1) {
625 host = host_and_port;
626 port = -1;
627 } else {
628 String portString = host_and_port.substring(colon + 1);
629 try {
630 port = Integer.parseInt(portString);
631 host = host_and_port.substring(0, colon);
632 } catch (NumberFormatException e) {
633 host = host_and_port;
634 port = -1;
635 }
636 }
Michael Kolb14612442011-06-24 13:06:29 -0700637 KeyChain.choosePrivateKeyAlias(
638 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700639 @Override public void alias(String alias) {
640 if (alias == null) {
641 handler.cancel();
642 return;
643 }
Michael Kolb14612442011-06-24 13:06:29 -0700644 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700645 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700646 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700647 }
648
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800649 @Override
650 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
651 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700652 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
653 hasCrashed = true;
654 showCrashView();
655 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800656 }
657
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700658 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700659 * Handles an HTTP authentication request.
660 *
661 * @param handler The authentication handler
662 * @param host The host
663 * @param realm The realm
664 */
665 @Override
666 public void onReceivedHttpAuthRequest(WebView view,
667 final HttpAuthHandler handler, final String host,
668 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700670 }
671
672 @Override
John Reck438bf462011-01-12 18:11:46 -0800673 public WebResourceResponse shouldInterceptRequest(WebView view,
674 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800675 //intercept if opening a new incognito tab - show the incognito welcome page
676 if (url.startsWith("browser:incognito")) {
677 Resources resourceHandle = mContext.getResources();
678 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700679 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800680 return new WebResourceResponse("text/html", "utf8", inStream);
681 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800682 WebResourceResponse res;
683 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
684 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
685 } else {
686 res = HomeProvider.shouldInterceptRequest(mContext, url);
687 }
John Reck438bf462011-01-12 18:11:46 -0800688 return res;
689 }
690
691 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700692 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
693 if (!mInForeground) {
694 return false;
695 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700696 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700697 }
698
699 @Override
700 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700702 return;
703 }
John Reck997b1b72012-04-19 18:08:25 -0700704 if (!mWebViewController.onUnhandledKeyEvent(event)) {
705 super.onUnhandledKeyEvent(view, event);
706 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700707 }
708 };
709
John Reck1cf4b792011-07-26 10:22:22 -0700710 private void syncCurrentState(WebView view, String url) {
711 // Sync state (in case of stop/timeout)
712 mCurrentState.mUrl = view.getUrl();
713 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700714 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700715 }
716 mCurrentState.mOriginalUrl = view.getOriginalUrl();
717 mCurrentState.mTitle = view.getTitle();
718 mCurrentState.mFavicon = view.getFavicon();
719 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
720 // In case we stop when loading an HTTPS page from an HTTP page
721 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100722 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100723 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700724 }
John Reck502a3532011-08-16 14:21:46 -0700725 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700726 }
727
Vivek Sekharf96064b2014-07-28 16:32:34 -0700728 protected void setTabFullscreen(boolean fullScreen) {
729 if (mMainView != null) {
730 mFullScreen = fullScreen;
731 mMainView.setFullScreen(fullScreen);
732 }
733 }
734
Grace Kloba22ac16e2009-10-07 18:00:23 -0700735 // -------------------------------------------------------------------------
736 // WebChromeClient implementation for the main WebView
737 // -------------------------------------------------------------------------
738
739 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
740 // Helper method to create a new tab or sub window.
741 private void createWindow(final boolean dialog, final Message msg) {
742 WebView.WebViewTransport transport =
743 (WebView.WebViewTransport) msg.obj;
744 if (dialog) {
745 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700746 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700747 transport.setWebView(mSubView);
748 } else {
Michael Kolb7bcafde2011-05-09 13:55:59 -0700749 final Tab newTab = mWebViewController.openTab(null,
John Reck5949c662011-05-27 09:52:29 -0700750 Tab.this, true, true);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700751 transport.setWebView(newTab.getWebView());
752 }
753 msg.sendToTarget();
754 }
755
756 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700757 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
758 if (mWebViewController instanceof Controller) {
759 Controller controller = (Controller)mWebViewController;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700760 controller.getUi().setFullscreen(enterFullscreen);
761 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700762 }
763 }
764
765 @Override
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700766 public void onOffsetsForFullscreenChanged(
767 float topControlsOffsetYPix, float contentOffsetYPix, float overdrawBottomHeightPix) {
768 boolean hide_title_on_scroll =
769 mContext.getResources().getBoolean(R.bool.hide_title_on_scroll);
770 if (mWebViewController instanceof Controller && hide_title_on_scroll) {
771 Controller controller = (Controller)mWebViewController;
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700772 controller.getUi().transalateTitleBar(topControlsOffsetYPix);
773 }
774 }
775
776 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700777 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700778 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700779 }
780
781 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700782 public boolean onCreateWindow(WebView view, final boolean dialog,
783 final boolean userGesture, final Message resultMsg) {
784 // only allow new window or sub window for the foreground case
785 if (!mInForeground) {
786 return false;
787 }
788 // Short-circuit if we can't create any more tabs or sub windows.
789 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700790 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700791 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200792 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700793 .setMessage(R.string.too_many_subwindows_dialog_message)
794 .setPositiveButton(R.string.ok, null)
795 .show();
796 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700797 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700798 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700799 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200800 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700801 .setMessage(R.string.too_many_windows_dialog_message)
802 .setPositiveButton(R.string.ok, null)
803 .show();
804 return false;
805 }
806
807 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800808 if (userGesture || !mSettings.blockPopupWindows()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700809 createWindow(dialog, resultMsg);
810 return true;
811 }
812
813 // Allow the popup and create the appropriate window.
814 final AlertDialog.OnClickListener allowListener =
815 new AlertDialog.OnClickListener() {
816 public void onClick(DialogInterface d,
817 int which) {
818 createWindow(dialog, resultMsg);
819 }
820 };
821
822 // Block the popup by returning a null WebView.
823 final AlertDialog.OnClickListener blockListener =
824 new AlertDialog.OnClickListener() {
825 public void onClick(DialogInterface d, int which) {
826 resultMsg.sendToTarget();
827 }
828 };
829
830 // Build a confirmation dialog to display to the user.
831 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700832 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200833 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700834 .setMessage(R.string.popup_window_attempt)
835 .setPositiveButton(R.string.allow, allowListener)
836 .setNegativeButton(R.string.block, blockListener)
837 .setCancelable(false)
838 .create();
839
840 // Show the confirmation dialog.
841 d.show();
842 return true;
843 }
844
845 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500846 public void onRequestFocus(WebView view) {
847 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700848 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500849 }
850 }
851
852 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700853 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700854 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700855 // JavaScript can only close popup window.
856 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700857 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700858 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700859 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700860 }
861 }
862
863 @Override
864 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800865 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800866 if (newProgress == 100) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800867 Log.i(CONSOLE_LOGTAG, "SWE Pageload Progress = 100");
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800868 mInPageLoad = false;
869 }
John Reck30c714c2010-12-16 17:30:34 -0800870 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700871 if (mUpdateThumbnail && newProgress == 100) {
872 mUpdateThumbnail = false;
873 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700874 }
875
876 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500877 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800878 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700879 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700880 }
881
882 @Override
883 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800884 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700885 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700886 }
887
888 @Override
889 public void onReceivedTouchIconUrl(WebView view, String url,
890 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700891 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400892 // Let precomposed icons take precedence over non-composed
893 // icons.
894 if (precomposed && mTouchIconLoader != null) {
895 mTouchIconLoader.cancel(false);
896 mTouchIconLoader = null;
897 }
898 // Have only one async task at a time.
899 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700900 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700901 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400902 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700903 }
904 }
905
906 @Override
907 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800908 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700909 Activity activity = mWebViewController.getActivity();
910 if (activity != null) {
911 onShowCustomView(view, activity.getRequestedOrientation(), callback);
912 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400913 }
914
915 @Override
916 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800917 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700918 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400919 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700920 }
921
922 @Override
923 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700924 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700925 }
926
927 /**
928 * The origin has exceeded its database quota.
929 * @param url the URL that exceeded the quota
930 * @param databaseIdentifier the identifier of the database on which the
931 * transaction that caused the quota overflow was run
932 * @param currentQuota the current quota for the origin.
933 * @param estimatedSize the estimated size of the database.
934 * @param totalUsedQuota is the sum of all origins' quota.
935 * @param quotaUpdater The callback to run when a decision to allow or
936 * deny quota has been made. Don't forget to call this!
937 */
938 @Override
939 public void onExceededDatabaseQuota(String url,
940 String databaseIdentifier, long currentQuota, long estimatedSize,
941 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700942 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700943 .onExceededDatabaseQuota(url, databaseIdentifier,
944 currentQuota, estimatedSize, totalUsedQuota,
945 quotaUpdater);
946 }
947
948 /**
949 * The Application Cache has exceeded its max size.
950 * @param spaceNeeded is the amount of disk space that would be needed
951 * in order for the last appcache operation to succeed.
952 * @param totalUsedQuota is the sum of all origins' quota.
953 * @param quotaUpdater A callback to inform the WebCore thread that a
954 * new app cache size is available. This callback must always
955 * be executed at some point to ensure that the sleeping
956 * WebCore thread is woken up.
957 */
958 @Override
959 public void onReachedMaxAppCacheSize(long spaceNeeded,
960 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700961 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700962 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
963 quotaUpdater);
964 }
965
966 /**
967 * Instructs the browser to show a prompt to ask the user to set the
968 * Geolocation permission state for the specified origin.
969 * @param origin The origin for which Geolocation permissions are
970 * requested.
971 * @param callback The callback to call once the user has set the
972 * Geolocation permission state.
973 */
974 @Override
975 public void onGeolocationPermissionsShowPrompt(String origin,
976 GeolocationPermissions.Callback callback) {
977 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -0700978 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700979 }
980 }
981
982 /**
983 * Instructs the browser to hide the Geolocation permissions prompt.
984 */
985 @Override
986 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -0700987 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700988 mGeolocationPermissionsPrompt.hide();
989 }
990 }
991
Ben Murdoch65acc352009-11-19 18:16:04 +0000992 /* Adds a JavaScript error message to the system log and if the JS
993 * console is enabled in the about:debug options, to that console
994 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +0000995 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700996 */
997 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +0000998 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700999 if (mInForeground) {
1000 // call getErrorConsole(true) so it will create one if needed
1001 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001002 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001003 if (mWebViewController.shouldShowErrorConsole()
1004 && errorConsole.getShowState() !=
1005 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001006 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1007 }
1008 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001009
Jeff Hamilton47654f42010-09-07 09:57:51 -05001010 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001011 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001012
Ben Murdochc42addf2010-01-28 15:19:59 +00001013 String message = "Console: " + consoleMessage.message() + " "
1014 + consoleMessage.sourceId() + ":"
1015 + consoleMessage.lineNumber();
1016
1017 switch (consoleMessage.messageLevel()) {
1018 case TIP:
1019 Log.v(CONSOLE_LOGTAG, message);
1020 break;
1021 case LOG:
1022 Log.i(CONSOLE_LOGTAG, message);
1023 break;
1024 case WARNING:
1025 Log.w(CONSOLE_LOGTAG, message);
1026 break;
1027 case ERROR:
1028 Log.e(CONSOLE_LOGTAG, message);
1029 break;
1030 case DEBUG:
1031 Log.d(CONSOLE_LOGTAG, message);
1032 break;
1033 }
1034
1035 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001036 }
1037
1038 /**
1039 * Ask the browser for an icon to represent a <video> element.
1040 * This icon will be used if the Web page did not specify a poster attribute.
1041 * @return Bitmap The icon or null if no such icon is available.
1042 */
1043 @Override
1044 public Bitmap getDefaultVideoPoster() {
1045 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001046 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001047 }
1048 return null;
1049 }
1050
1051 /**
1052 * Ask the host application for a custom progress view to show while
1053 * a <video> is loading.
1054 * @return View The progress view.
1055 */
1056 @Override
1057 public View getVideoLoadingProgressView() {
1058 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001059 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001060 }
1061 return null;
1062 }
1063
1064 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001065 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001066 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001067 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001068 } else {
1069 uploadMsg.onReceiveValue(null);
1070 }
1071 }
1072
Vivek Sekharb54614f2014-05-01 19:03:37 -07001073 @Override
1074 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1075 boolean capture) {
1076 if (mInForeground) {
1077 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1078 } else {
1079 uploadFilePaths.onReceiveValue(null);
1080 }
1081 }
1082
Grace Kloba22ac16e2009-10-07 18:00:23 -07001083 /**
1084 * Deliver a list of already-visited URLs
1085 */
1086 @Override
1087 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001088 mWebViewController.getVisitedHistory(callback);
1089 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001090
1091 @Override
1092 public void setupAutoFill(Message message) {
1093 // Prompt the user to set up their profile.
1094 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001095 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1096 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001097 Context.LAYOUT_INFLATER_SERVICE);
1098 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1099
1100 builder.setView(layout)
1101 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1102 @Override
1103 public void onClick(DialogInterface dialog, int id) {
1104 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1105 R.id.setup_autofill_dialog_disable_autofill);
1106
1107 if (disableAutoFill.isChecked()) {
1108 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001109 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001110 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001111 R.string.autofill_setup_dialog_negative_toast,
1112 Toast.LENGTH_LONG).show();
1113 } else {
1114 // Take user to the AutoFill profile editor. When they return,
1115 // we will send the message that we pass here which will trigger
1116 // the form to get filled out with their new profile.
1117 mWebViewController.setupAutoFill(msg);
1118 }
1119 }
1120 })
1121 .setNegativeButton(R.string.cancel, null)
1122 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001123 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001124 };
1125
1126 // -------------------------------------------------------------------------
1127 // WebViewClient implementation for the sub window
1128 // -------------------------------------------------------------------------
1129
1130 // Subclass of WebViewClient used in subwindows to notify the main
1131 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001132 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001133 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001134 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001135 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001136
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001137 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001138 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001139 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001140 }
1141 @Override
1142 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1143 // Unlike the others, do not call mClient's version, which would
1144 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001145 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001146 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001147 }
1148 @Override
1149 public void doUpdateVisitedHistory(WebView view, String url,
1150 boolean isReload) {
1151 mClient.doUpdateVisitedHistory(view, url, isReload);
1152 }
1153 @Override
1154 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1155 return mClient.shouldOverrideUrlLoading(view, url);
1156 }
1157 @Override
1158 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1159 SslError error) {
1160 mClient.onReceivedSslError(view, handler, error);
1161 }
1162 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001163 public void onReceivedClientCertRequest(WebView view,
1164 ClientCertRequestHandler handler, String host_and_port) {
1165 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1166 }
1167 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001168 public void onReceivedHttpAuthRequest(WebView view,
1169 HttpAuthHandler handler, String host, String realm) {
1170 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1171 }
1172 @Override
1173 public void onFormResubmission(WebView view, Message dontResend,
1174 Message resend) {
1175 mClient.onFormResubmission(view, dontResend, resend);
1176 }
1177 @Override
1178 public void onReceivedError(WebView view, int errorCode,
1179 String description, String failingUrl) {
1180 mClient.onReceivedError(view, errorCode, description, failingUrl);
1181 }
1182 @Override
1183 public boolean shouldOverrideKeyEvent(WebView view,
1184 android.view.KeyEvent event) {
1185 return mClient.shouldOverrideKeyEvent(view, event);
1186 }
1187 @Override
1188 public void onUnhandledKeyEvent(WebView view,
1189 android.view.KeyEvent event) {
1190 mClient.onUnhandledKeyEvent(view, event);
1191 }
1192 }
1193
1194 // -------------------------------------------------------------------------
1195 // WebChromeClient implementation for the sub window
1196 // -------------------------------------------------------------------------
1197
1198 private class SubWindowChromeClient extends WebChromeClient {
1199 // The main WebChromeClient.
1200 private final WebChromeClient mClient;
1201
1202 SubWindowChromeClient(WebChromeClient client) {
1203 mClient = client;
1204 }
1205 @Override
1206 public void onProgressChanged(WebView view, int newProgress) {
1207 mClient.onProgressChanged(view, newProgress);
1208 }
1209 @Override
1210 public boolean onCreateWindow(WebView view, boolean dialog,
1211 boolean userGesture, android.os.Message resultMsg) {
1212 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1213 }
1214 @Override
1215 public void onCloseWindow(WebView window) {
1216 if (window != mSubView) {
1217 Log.e(LOGTAG, "Can't close the window");
1218 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001219 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001220 }
1221 }
1222
1223 // -------------------------------------------------------------------------
1224
1225 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001226 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001227 this(wvcontroller, w, null);
1228 }
1229
1230 Tab(WebViewController wvcontroller, Bundle state) {
1231 this(wvcontroller, null, state);
1232 }
1233
1234 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001235 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001236 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001237 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001238 mDataController = DataController.getInstance(mContext);
1239 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001240 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001241 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001242 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001243 mInForeground = false;
1244
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001245 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001246 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001247 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001248 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001249 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001250 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001251 }
1252 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001253 mWebBackForwardListClient = new WebBackForwardListClient() {
1254 @Override
1255 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001256 if (mClearHistoryUrlPattern != null) {
1257 boolean match =
1258 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001259 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001260 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1261 + item.getUrl() + "\n\t"
1262 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001263 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001264 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001265 if (mMainView != null) {
1266 mMainView.clearHistory();
1267 }
1268 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001269 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001270 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001271 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001272 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001273
John Reck1cf4b792011-07-26 10:22:22 -07001274 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1275 R.dimen.tab_thumbnail_width);
1276 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1277 R.dimen.tab_thumbnail_height);
1278 updateShouldCaptureThumbnails();
1279 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001280 if (getId() == -1) {
1281 mId = TabControl.getNextId();
1282 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001283 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001284 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001285 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001286 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001287 switch (m.what) {
1288 case MSG_CAPTURE:
1289 capture();
1290 break;
1291 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001292 }
1293 };
John Reck1cf4b792011-07-26 10:22:22 -07001294 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001295
Michael Kolb72864272012-05-03 15:42:15 -07001296 public boolean shouldUpdateThumbnail() {
1297 return mUpdateThumbnail;
1298 }
1299
Mathew Inwoode09305e2011-09-02 12:03:26 +01001300 /**
1301 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1302 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1303 * to overlapping IDs between the preloaded and restored tabs.
1304 */
1305 public void refreshIdAfterPreload() {
1306 mId = TabControl.getNextId();
1307 }
1308
John Reck1cf4b792011-07-26 10:22:22 -07001309 public void updateShouldCaptureThumbnails() {
1310 if (mWebViewController.shouldCaptureThumbnails()) {
1311 synchronized (Tab.this) {
1312 if (mCapture == null) {
1313 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1314 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001315 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001316 if (mInForeground) {
1317 postCapture();
1318 }
1319 }
1320 }
1321 } else {
1322 synchronized (Tab.this) {
1323 mCapture = null;
1324 deleteThumbnail();
1325 }
1326 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001327 }
1328
Michael Kolb14612442011-06-24 13:06:29 -07001329 public void setController(WebViewController ctl) {
1330 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001331 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001332 }
1333
Michael Kolbc831b632011-05-11 09:30:34 -07001334 public long getId() {
1335 return mId;
1336 }
1337
Michael Kolb91911a22012-01-17 11:21:25 -08001338 void setWebView(WebView w) {
1339 setWebView(w, true);
1340 }
1341
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001342 public boolean isNativeActive(){
1343 if (mMainView == null)
1344 return false;
1345 return true;
1346 }
1347
1348 public void setTimeStamp(){
1349 Date d = new Date();
1350 timestamp = (new Timestamp(d.getTime()));
1351 }
1352
1353 public Timestamp getTimestamp() {
1354 return timestamp;
1355 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001356 /**
1357 * Sets the WebView for this tab, correctly removing the old WebView from
1358 * the container view.
1359 */
Michael Kolb91911a22012-01-17 11:21:25 -08001360 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001361 if (mMainView == w) {
1362 return;
1363 }
Michael Kolba713ec82010-11-29 17:27:06 -08001364
Grace Kloba22ac16e2009-10-07 18:00:23 -07001365 // If the WebView is changing, the page will be reloaded, so any ongoing
1366 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001367 if (mGeolocationPermissionsPrompt != null) {
1368 mGeolocationPermissionsPrompt.hide();
1369 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001370
Michael Kolba713ec82010-11-29 17:27:06 -08001371 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001372
John Reck1cf4b792011-07-26 10:22:22 -07001373 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001374 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001375 if (w != null) {
1376 syncCurrentState(w, null);
1377 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001378 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001379 }
1380 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001381 // set the new one
1382 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001383 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001384 if (mMainView != null) {
1385 mMainView.setWebViewClient(mWebViewClient);
1386 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001387 // Attach DownloadManager so that downloads can start in an active
1388 // or a non-active window. This can happen when going to a site that
1389 // does a redirect after a period of time. The user could have
1390 // switched to another tab while waiting for the download to start.
1391 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001392 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001393 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001394 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001395 mMainView.setPictureListener(this);
1396 }
Michael Kolb91911a22012-01-17 11:21:25 -08001397 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001398 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001399 WebBackForwardList restoredState
1400 = mMainView.restoreState(mSavedState);
1401 if (restoredState == null || restoredState.getSize() == 0) {
1402 Log.w(LOGTAG, "Failed to restore WebView state!");
1403 loadUrl(mCurrentState.mOriginalUrl, null);
1404 }
John Reck1cf4b792011-07-26 10:22:22 -07001405 mSavedState = null;
1406 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001407 }
1408 }
1409
Vivek Sekharf96064b2014-07-28 16:32:34 -07001410 public boolean isTabFullScreen() {
1411 return mFullScreen;
1412 }
1413
Grace Kloba22ac16e2009-10-07 18:00:23 -07001414 /**
1415 * Destroy the tab's main WebView and subWindow if any
1416 */
1417 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001418
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001419 if (mPostponeDestroy) {
1420 mShouldDestroy = true;
1421 return;
1422 }
1423 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001424 if (mMainView != null) {
1425 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001426 // save the WebView to call destroy() after detach it from the tab
1427 WebView webView = mMainView;
1428 setWebView(null);
1429 webView.destroy();
1430 }
1431 }
1432
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001433 private boolean mPostponeDestroy = false;
1434 private boolean mShouldDestroy = false;
1435
1436 public void postponeDestroy() {
1437 mPostponeDestroy = true;
1438 }
1439
1440 public void performPostponedDestroy() {
1441 mPostponeDestroy = false;
1442 if (mShouldDestroy) {
1443 destroy();
1444 }
1445 }
1446
Grace Kloba22ac16e2009-10-07 18:00:23 -07001447 /**
1448 * Remove the tab from the parent
1449 */
1450 void removeFromTree() {
1451 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001452 if (mChildren != null) {
1453 for(Tab t : mChildren) {
1454 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001455 }
1456 }
1457 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001458 if (mParent != null) {
1459 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001460 }
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001461 if (mScreenShot != null) {
1462 mScreenShot.recycle();
1463 mScreenShot = null;
1464 }
1465 if (mCapture != null ) {
1466 mCapture.recycle();
1467 mCapture = null;
1468 }
John Reck1cf4b792011-07-26 10:22:22 -07001469 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001470 }
1471
1472 /**
1473 * Create a new subwindow unless a subwindow already exists.
1474 * @return True if a new subwindow was created. False if one already exists.
1475 */
1476 boolean createSubWindow() {
1477 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001478 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001479 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001480 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001481 mSubView.setWebChromeClient(new SubWindowChromeClient(
1482 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001483 // Set a different DownloadListener for the mSubView, since it will
1484 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001485 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001486 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001487 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001488 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001489 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001490 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001491 if (mSubView.copyBackForwardList().getSize() == 0) {
1492 // This subwindow was opened for the sole purpose of
1493 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001494 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001495 }
1496 }
1497 });
Michael Kolb14612442011-06-24 13:06:29 -07001498 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001499 return true;
1500 }
1501 return false;
1502 }
1503
1504 /**
1505 * Dismiss the subWindow for the tab.
1506 */
1507 void dismissSubWindow() {
1508 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001509 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001510 mSubView.destroy();
1511 mSubView = null;
1512 mSubViewContainer = null;
1513 }
1514 }
1515
Grace Kloba22ac16e2009-10-07 18:00:23 -07001516
1517 /**
1518 * Set the parent tab of this tab.
1519 */
Michael Kolbc831b632011-05-11 09:30:34 -07001520 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001521 if (parent == this) {
1522 throw new IllegalStateException("Cannot set parent to self!");
1523 }
Michael Kolbc831b632011-05-11 09:30:34 -07001524 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001525 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001526 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001527 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001528 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001529 if (mSavedState != null) {
1530 if (parent == null) {
1531 mSavedState.remove(PARENTTAB);
1532 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001533 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001534 }
1535 }
John Reckb0a86db2011-05-24 14:05:58 -07001536
1537 // Sync the WebView useragent with the parent
1538 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1539 != mSettings.hasDesktopUseragent(getWebView())) {
1540 mSettings.toggleDesktopUseragent(getWebView());
1541 }
John Reck52be4782011-08-26 15:37:29 -07001542
1543 if (parent != null && parent.getId() == getId()) {
1544 throw new IllegalStateException("Parent has same ID as child!");
1545 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001546 }
1547
1548 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001549 * If this Tab was created through another Tab, then this method returns
1550 * that Tab.
1551 * @return the Tab parent or null
1552 */
1553 public Tab getParent() {
1554 return mParent;
1555 }
1556
1557 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001558 * When a Tab is created through the content of another Tab, then we
1559 * associate the Tabs.
1560 * @param child the Tab that was created from this Tab
1561 */
1562 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001563 if (mChildren == null) {
1564 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001565 }
Michael Kolbc831b632011-05-11 09:30:34 -07001566 mChildren.add(child);
1567 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001568 }
1569
Michael Kolbc831b632011-05-11 09:30:34 -07001570 Vector<Tab> getChildren() {
1571 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001572 }
1573
1574 void resume() {
1575 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001576 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001577 mMainView.onResume();
1578 if (mSubView != null) {
1579 mSubView.onResume();
1580 }
1581 }
1582 }
1583
John Reck56c1fcf2011-08-17 10:15:16 -07001584 private void setupHwAcceleration(View web) {
1585 if (web == null) return;
1586 BrowserSettings settings = BrowserSettings.getInstance();
1587 if (settings.isHardwareAccelerated()) {
1588 web.setLayerType(View.LAYER_TYPE_NONE, null);
1589 } else {
1590 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1591 }
1592 }
1593
Grace Kloba22ac16e2009-10-07 18:00:23 -07001594 void pause() {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001595 capture();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001596 if (mMainView != null) {
1597 mMainView.onPause();
1598 if (mSubView != null) {
1599 mSubView.onPause();
1600 }
1601 }
1602 }
1603
1604 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001605 if (mInForeground) {
1606 return;
1607 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001608 mInForeground = true;
1609 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001610 Activity activity = mWebViewController.getActivity();
1611 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001612 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001613 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001614 }
1615 // Show the pending error dialog if the queue is not empty
1616 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1617 showError(mQueuedErrors.getFirst());
1618 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001619 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001620 }
1621
1622 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001623 if (!mInForeground) {
1624 return;
1625 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001626 mInForeground = false;
1627 pause();
1628 mMainView.setOnCreateContextMenuListener(null);
1629 if (mSubView != null) {
1630 mSubView.setOnCreateContextMenuListener(null);
1631 }
1632 }
1633
Michael Kolb8233fac2010-10-26 16:08:53 -07001634 boolean inForeground() {
1635 return mInForeground;
1636 }
1637
Grace Kloba22ac16e2009-10-07 18:00:23 -07001638 /**
1639 * Return the top window of this tab; either the subwindow if it is not
1640 * null or the main window.
1641 * @return The top window of this tab.
1642 */
1643 WebView getTopWindow() {
1644 if (mSubView != null) {
1645 return mSubView;
1646 }
1647 return mMainView;
1648 }
1649
1650 /**
1651 * Return the main window of this tab. Note: if a tab is freed in the
1652 * background, this can return null. It is only guaranteed to be
1653 * non-null for the current tab.
1654 * @return The main WebView of this tab.
1655 */
1656 WebView getWebView() {
1657 return mMainView;
1658 }
1659
Michael Kolba713ec82010-11-29 17:27:06 -08001660 void setViewContainer(View container) {
1661 mContainer = container;
1662 }
1663
Michael Kolb8233fac2010-10-26 16:08:53 -07001664 View getViewContainer() {
1665 return mContainer;
1666 }
1667
Grace Kloba22ac16e2009-10-07 18:00:23 -07001668 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001669 * Return whether private browsing is enabled for the main window of
1670 * this tab.
1671 * @return True if private browsing is enabled.
1672 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001673 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001674 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001675 }
1676
1677 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001678 * Return the subwindow of this tab or null if there is no subwindow.
1679 * @return The subwindow of this tab or null.
1680 */
1681 WebView getSubWebView() {
1682 return mSubView;
1683 }
1684
Michael Kolb1514bb72010-11-22 09:11:48 -08001685 void setSubWebView(WebView subView) {
1686 mSubView = subView;
1687 }
1688
Michael Kolb8233fac2010-10-26 16:08:53 -07001689 View getSubViewContainer() {
1690 return mSubViewContainer;
1691 }
1692
Michael Kolb1514bb72010-11-22 09:11:48 -08001693 void setSubViewContainer(View subViewContainer) {
1694 mSubViewContainer = subViewContainer;
1695 }
1696
Grace Kloba22ac16e2009-10-07 18:00:23 -07001697 /**
1698 * @return The geolocation permissions prompt for this tab.
1699 */
1700 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001701 if (mGeolocationPermissionsPrompt == null) {
1702 ViewStub stub = (ViewStub) mContainer
1703 .findViewById(R.id.geolocation_permissions_prompt);
1704 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1705 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001706 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001707 return mGeolocationPermissionsPrompt;
1708 }
1709
1710 /**
1711 * @return The application id string
1712 */
1713 String getAppId() {
1714 return mAppId;
1715 }
1716
1717 /**
1718 * Set the application id string
1719 * @param id
1720 */
1721 void setAppId(String id) {
1722 mAppId = id;
1723 }
1724
Michael Kolbe28b3472011-08-04 16:54:31 -07001725 boolean closeOnBack() {
1726 return mCloseOnBack;
1727 }
1728
1729 void setCloseOnBack(boolean close) {
1730 mCloseOnBack = close;
1731 }
1732
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001733 boolean getDerivedFromIntent() {
1734 return mDerivedFromIntent;
1735 }
1736
1737 void setDerivedFromIntent(boolean derived) {
1738 mDerivedFromIntent = derived;
1739 }
1740
Grace Kloba22ac16e2009-10-07 18:00:23 -07001741 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001742 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001743 }
1744
John Reck49a603c2011-03-03 09:33:05 -08001745 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001746 if (mCurrentState.mOriginalUrl == null) {
1747 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001748 }
John Reckdb22ec42011-06-29 11:31:24 -07001749 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001750 }
1751
Grace Kloba22ac16e2009-10-07 18:00:23 -07001752 /**
John Reck30c714c2010-12-16 17:30:34 -08001753 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001754 */
1755 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001756 if (mCurrentState.mTitle == null && mInPageLoad) {
Michael Kolb14612442011-06-24 13:06:29 -07001757 return mContext.getString(R.string.title_bar_loading);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001758 }
John Reck30c714c2010-12-16 17:30:34 -08001759 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001760 }
1761
1762 /**
John Reck30c714c2010-12-16 17:30:34 -08001763 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001764 */
1765 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001766 if (mCurrentState.mFavicon != null) {
1767 return mCurrentState.mFavicon;
1768 }
1769 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001770 }
1771
John Recke969cc52010-12-21 17:24:43 -08001772 public boolean isBookmarkedSite() {
1773 return mCurrentState.mIsBookmarkedSite;
1774 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001775
Grace Kloba22ac16e2009-10-07 18:00:23 -07001776 /**
1777 * Return the tab's error console. Creates the console if createIfNEcessary
1778 * is true and we haven't already created the console.
1779 * @param createIfNecessary Flag to indicate if the console should be
1780 * created if it has not been already.
1781 * @return The tab's error console, or null if one has not been created and
1782 * createIfNecessary is false.
1783 */
1784 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1785 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001786 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001787 mErrorConsole.setWebView(mMainView);
1788 }
1789 return mErrorConsole;
1790 }
1791
Steve Block08a6f0c2011-10-06 12:12:53 +01001792 /**
1793 * Sets the security state, clears the SSL certificate error and informs
1794 * the controller.
1795 */
Steve Block2466eff2011-10-03 15:33:09 +01001796 private void setSecurityState(SecurityState securityState) {
1797 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001798 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001799 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001800 }
1801
1802 /**
Steve Block2466eff2011-10-03 15:33:09 +01001803 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001804 */
Steve Block2466eff2011-10-03 15:33:09 +01001805 SecurityState getSecurityState() {
1806 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001807 }
1808
Steve Block08a6f0c2011-10-06 12:12:53 +01001809 /**
1810 * Gets the SSL certificate error, if any, for the page's main resource.
1811 * This is only non-null when the security state is
1812 * SECURITY_STATE_BAD_CERTIFICATE.
1813 */
1814 SslError getSslCertificateError() {
1815 return mCurrentState.mSslCertificateError;
1816 }
1817
John Reck30c714c2010-12-16 17:30:34 -08001818 int getLoadProgress() {
1819 if (mInPageLoad) {
1820 return mPageLoadProgress;
1821 }
1822 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001823 }
1824
1825 /**
1826 * @return TRUE if onPageStarted is called while onPageFinished is not
1827 * called yet.
1828 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001829 boolean inPageLoad() {
1830 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001831 }
1832
Grace Kloba22ac16e2009-10-07 18:00:23 -07001833 /**
John Reck1cf4b792011-07-26 10:22:22 -07001834 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001835 */
John Reck1cf4b792011-07-26 10:22:22 -07001836 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001837 // If the WebView is null it means we ran low on memory and we already
1838 // stored the saved state in mSavedState.
1839 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001840 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001841 }
John Reck6c2e2f32011-08-22 13:41:23 -07001842
1843 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001844 return null;
John Reck24f18262011-06-17 14:47:20 -07001845 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001846
1847 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001848 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1849 if (savedList == null || savedList.getSize() == 0) {
1850 Log.w(LOGTAG, "Failed to save back/forward list for "
1851 + mCurrentState.mUrl);
1852 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001853
Michael Kolbc831b632011-05-11 09:30:34 -07001854 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001855 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1856 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001857 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001858 if (mAppId != null) {
1859 mSavedState.putString(APPID, mAppId);
1860 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001861 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001862 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001863 if (mParent != null) {
1864 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001865 }
John Reckb0a86db2011-05-24 14:05:58 -07001866 mSavedState.putBoolean(USERAGENT,
1867 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001868 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001869 }
1870
1871 /*
1872 * Restore the state of the tab.
1873 */
John Reck1cf4b792011-07-26 10:22:22 -07001874 private void restoreState(Bundle b) {
1875 mSavedState = b;
1876 if (mSavedState == null) {
1877 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001878 }
1879 // Restore the internal state even if the WebView fails to restore.
1880 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001881 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001882 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001883 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001884 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001885 String url = b.getString(CURRURL);
1886 String title = b.getString(CURRTITLE);
1887 boolean incognito = b.getBoolean(INCOGNITO);
1888 mCurrentState = new PageState(mContext, incognito, url, null);
1889 mCurrentState.mTitle = title;
1890 synchronized (Tab.this) {
1891 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001892 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001893 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001894 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001895 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001896
John Reck8b9bb8b2012-03-08 13:19:40 -08001897 private void restoreUserAgent() {
1898 if (mMainView == null || mSavedState == null) {
1899 return;
1900 }
1901 if (mSavedState.getBoolean(USERAGENT)
1902 != mSettings.hasDesktopUseragent(mMainView)) {
1903 mSettings.toggleDesktopUseragent(mMainView);
1904 }
1905 }
1906
Leon Scroggins1961ed22010-12-07 15:22:21 -05001907 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001908 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001909 }
1910
John Recke969cc52010-12-21 17:24:43 -08001911 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1912 = new DataController.OnQueryUrlIsBookmark() {
1913 @Override
1914 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1915 if (mCurrentState.mUrl.equals(url)) {
1916 mCurrentState.mIsBookmarkedSite = isBookmark;
1917 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1918 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001919 }
John Recke969cc52010-12-21 17:24:43 -08001920 };
Michael Kolb1acef692011-03-08 14:12:06 -08001921
Michael Kolbeb95db42011-03-03 10:38:40 -08001922 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001923 synchronized (Tab.this) {
1924 return mCapture;
1925 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001926 }
1927
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001928 public Bitmap getFullScreenshot() {
1929 synchronized (Tab.this) {
1930 return mScreenShot;
1931 }
1932 }
1933
John Reck541f55a2011-06-07 16:34:43 -07001934 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001935 return false;
1936 }
1937
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001938 private static class SaveCallback implements ValueCallback<String> {
1939 boolean onReceiveValueCalled = false;
1940 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001941
1942 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001943 public void onReceiveValue(String path) {
1944 this.onReceiveValueCalled = true;
1945 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001946 synchronized (this) {
1947 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001948 }
John Reck541f55a2011-06-07 16:34:43 -07001949 }
John Reck68234a92012-04-19 15:27:12 -07001950
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001951 public String getPath() {
1952 return mPath;
1953 }
John Reck68234a92012-04-19 15:27:12 -07001954 }
1955
1956 /**
1957 * Must be called on the UI thread
1958 */
1959 public ContentValues createSnapshotValues() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001960 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001961 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001962 ContentValues values = new ContentValues();
1963 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1964 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001965 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001966 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1967 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001968 Bitmap screenshot = web.getViewportBitmap();
John Reck8cc92352011-07-06 17:41:52 -07001969 values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
John Reckd8c74522011-06-14 08:45:00 -07001970 return values;
John Reck541f55a2011-06-07 16:34:43 -07001971 }
1972
John Reck68234a92012-04-19 15:27:12 -07001973 /**
1974 * Probably want to call this on a background thread
1975 */
1976 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001977 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001978 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001979 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07001980 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07001981 try {
John Reck68234a92012-04-19 15:27:12 -07001982 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001983 web.saveViewState(filename, callback);
1984 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07001985 }
John Reck68234a92012-04-19 15:27:12 -07001986 } catch (Exception e) {
1987 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001988 String path = callback.getPath();
1989 if (path != null) {
1990 File file = mContext.getFileStreamPath(path);
1991 if (file.exists() && !file.delete()) {
1992 file.deleteOnExit();
1993 }
John Reck68234a92012-04-19 15:27:12 -07001994 }
1995 return false;
1996 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001997 String path = callback.getPath();
1998 File savedFile = new File(path);
1999 if (!savedFile.exists()) {
2000 return false;
John Reck68234a92012-04-19 15:27:12 -07002001 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002002 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2003 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002004 return true;
2005 }
2006
John Reck8cc92352011-07-06 17:41:52 -07002007 public byte[] compressBitmap(Bitmap bitmap) {
2008 if (bitmap == null) {
2009 return null;
2010 }
2011 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2012 bitmap.compress(CompressFormat.PNG, 100, stream);
2013 return stream.toByteArray();
2014 }
2015
John Reck26b18322011-06-21 13:08:58 -07002016 public void loadUrl(String url, Map<String, String> headers) {
2017 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002018 mPageLoadProgress = INITIAL_PROGRESS;
2019 mInPageLoad = true;
Michael Kolb14612442011-06-24 13:06:29 -07002020 mCurrentState = new PageState(mContext, false, url, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002021 handleJsInterface(mMainView, url);
John Reck26b18322011-06-21 13:08:58 -07002022 mMainView.loadUrl(url, headers);
2023 }
2024 }
2025
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002026 public void handleJsInterface(WebView webview, String url){
2027 if (url != null &&
2028 url.equals(mContext.getResources().getString(R.string.homepage_base)) &&
2029 url.startsWith("file:///")) {
2030 mJsInterfaceEnabled = true;
2031 webview.getSettings().setJavaScriptEnabled(true);
2032 webview.addJavascriptInterface(mContext, "default_homepage");
2033 } else {
2034 if (mJsInterfaceEnabled) {
2035 webview.removeJavascriptInterface("default_homepage");
2036 mJsInterfaceEnabled = false;
2037 }
2038 }
2039 }
2040
John Reck38b39652012-06-05 09:22:59 -07002041 public void disableUrlOverridingForLoad() {
2042 mDisableOverrideUrlLoading = true;
2043 }
2044
Michael Kolb9ef259a2011-07-12 15:33:08 -07002045 protected void capture() {
2046 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002047 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2048 return;
2049 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002050 Canvas c = new Canvas(mCapture);
Michael Kolba3194d02011-09-07 11:23:51 -07002051 int state = c.save();
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002052 float scale = 0;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002053 Bitmap screenShot = mMainView.getViewportBitmap();
Vivek Sekhar0ab52512014-07-02 14:51:32 -07002054 if (mScreenShot != null) {
2055 mScreenShot.recycle();
2056 mScreenShot = null;
2057 }
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002058 mScreenShot = screenShot;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002059 if (screenShot != null) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002060 //scale based on device orientation
2061 if (screenShot.getHeight() > screenShot.getWidth()){
2062 scale = (float) mCaptureWidth / screenShot.getWidth();
2063 } else {
2064 scale = (float) mCaptureHeight / screenShot.getHeight();
2065 }
2066 mCapture.eraseColor(Color.WHITE);
2067 c.scale(scale, scale);
2068 c.drawBitmap(screenShot, 0, 0, null);
2069 } else {
2070 final int left = mMainView.getViewScrollX();
2071 final int top = mMainView.getViewScrollY() + mMainView.getVisibleTitleHeight();
2072
2073 if (mMainView.getHeight() > mMainView.getWidth()){
2074 scale = mCaptureWidth / (float) mMainView.getWidth();
2075 } else {
2076 scale = mCaptureHeight / (float) mMainView.getHeight();
2077 }
2078
2079 c.translate(-left, -top);
2080 c.scale(scale, scale, left, top);
2081 if (mMainView instanceof BrowserWebView) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002082 ((BrowserWebView)mMainView).drawContent(c);
2083 } else {
2084 mMainView.draw(c);
2085 }
John Reck8ee633f2011-08-09 16:00:35 -07002086 }
Michael Kolba3194d02011-09-07 11:23:51 -07002087 c.restoreToCount(state);
2088 // manually anti-alias the edges for the tilt
2089 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2090 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2091 mCapture.getHeight(), sAlphaPaint);
2092 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2093 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2094 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002095 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002096 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002097 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002098 TabControl tc = mWebViewController.getTabControl();
2099 if (tc != null) {
2100 OnThumbnailUpdatedListener updateListener
2101 = tc.getOnThumbnailUpdatedListener();
2102 if (updateListener != null) {
2103 updateListener.onThumbnailUpdated(this);
2104 }
2105 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002106 }
2107
2108 @Override
2109 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002110 postCapture();
2111 }
2112
2113 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002114 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2115 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2116 }
2117 }
2118
John Reckef654f12011-07-12 16:42:08 -07002119 public boolean canGoBack() {
2120 return mMainView != null ? mMainView.canGoBack() : false;
2121 }
2122
2123 public boolean canGoForward() {
2124 return mMainView != null ? mMainView.canGoForward() : false;
2125 }
2126
2127 public void goBack() {
2128 if (mMainView != null) {
2129 mMainView.goBack();
2130 }
2131 }
2132
2133 public void goForward() {
2134 if (mMainView != null) {
2135 mMainView.goForward();
2136 }
2137 }
2138
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002139 /**
2140 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2141 * to be added to the stack.
2142 *
2143 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2144 * not appear in the back stack.
2145 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002146 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2147 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002148 }
2149
John Reck1cf4b792011-07-26 10:22:22 -07002150 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002151 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002152 }
2153
2154 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002155 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002156 }
2157
John Reck4eadc342011-10-31 14:04:10 -07002158 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002159 synchronized (Tab.this) {
2160 if (mCapture == null) {
2161 return;
2162 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002163 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002164 try {
2165 mCapture.copyPixelsFromBuffer(buffer);
2166 } catch (RuntimeException rex) {
2167 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2168 + buffer.capacity() + " blob: " + blob.length
2169 + "capture: " + mCapture.getByteCount());
2170 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002171 }
John Reck1cf4b792011-07-26 10:22:22 -07002172 }
2173 }
2174
John Reck52be4782011-08-26 15:37:29 -07002175 @Override
2176 public String toString() {
2177 StringBuilder builder = new StringBuilder(100);
2178 builder.append(mId);
2179 builder.append(") has parent: ");
2180 if (getParent() != null) {
2181 builder.append("true[");
2182 builder.append(getParent().getId());
2183 builder.append("]");
2184 } else {
2185 builder.append("false");
2186 }
2187 builder.append(", incog: ");
2188 builder.append(isPrivateBrowsingEnabled());
2189 if (!isPrivateBrowsingEnabled()) {
2190 builder.append(", title: ");
2191 builder.append(getTitle());
2192 builder.append(", url: ");
2193 builder.append(getUrl());
2194 }
2195 return builder.toString();
2196 }
2197
Steve Block4895b012011-10-03 16:26:46 +01002198 private void handleProceededAfterSslError(SslError error) {
2199 if (error.getUrl().equals(mCurrentState.mUrl)) {
2200 // The security state should currently be SECURITY_STATE_SECURE.
2201 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002202 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002203 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002204 // The page's main resource is secure and this error is for a
2205 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002206 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2207 }
2208 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002209}