blob: 756032243ebb0cbbea8d1c0c72ddac396223135e [file] [log] [blame]
Grace Kloba22ac16e2009-10-07 18:00:23 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Grace Kloba22ac16e2009-10-07 18:00:23 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
21import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070022import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080023import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.DialogInterface.OnCancelListener;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070027import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070028import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070029import android.graphics.BitmapFactory;
30import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070032import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070033import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070034import android.graphics.PorterDuff;
35import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070036import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070037import android.net.Uri;
38import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070039import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070040import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070041import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000042import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070043import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070044import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070045import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070046import android.util.Log;
47import android.view.KeyEvent;
48import android.view.LayoutInflater;
49import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070050import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080051import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070054import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080055import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070056import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057import android.webkit.WebChromeClient.CustomViewCallback;
58import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000059import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000060import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import android.widget.FrameLayout;
62import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070063
Bijan Amirzada41242f22014-03-21 12:12:18 -070064import com.android.browser.TabControl.OnThumbnailUpdatedListener;
65import com.android.browser.homepages.HomeProvider;
66import com.android.browser.mynavigation.MyNavigationUtil;
67import com.android.browser.provider.MyNavigationProvider;
68import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069
70import org.codeaurora.swe.BrowserDownloadListener;
71import org.codeaurora.swe.ClientCertRequestHandler;
72import org.codeaurora.swe.HttpAuthHandler;
73import org.codeaurora.swe.SslErrorHandler;
74import org.codeaurora.swe.WebBackForwardList;
75import org.codeaurora.swe.WebBackForwardListClient;
76import org.codeaurora.swe.WebChromeClient;
77import org.codeaurora.swe.WebHistoryItem;
78import org.codeaurora.swe.WebView;
79import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070080import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080081import org.codeaurora.swe.WebViewClient;
82
John Reck541f55a2011-06-07 16:34:43 -070083import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070084import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080085import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070086import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070087import java.util.LinkedList;
88import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070089import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070090import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010091import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080092import java.sql.Timestamp;
93import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070094
Grace Kloba22ac16e2009-10-07 18:00:23 -070095/**
96 * Class for maintaining Tabs with a main WebView and a subwindow.
97 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070098class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070099
Grace Kloba22ac16e2009-10-07 18:00:23 -0700100 // Log Tag
101 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700102 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000103 // Special case the logtag for messages for the Console to make it easier to
104 // filter them and match the logtag used for these messages in older versions
105 // of the browser.
106 private static final String CONSOLE_LOGTAG = "browser";
107
Michael Kolb9ef259a2011-07-12 15:33:08 -0700108 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800109 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700110 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700111
John Reck1cf4b792011-07-26 10:22:22 -0700112 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800113 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700114
Michael Kolba3194d02011-09-07 11:23:51 -0700115 private static Paint sAlphaPaint = new Paint();
116 static {
117 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
118 sAlphaPaint.setColor(Color.TRANSPARENT);
119 }
120
Steve Block2466eff2011-10-03 15:33:09 +0100121 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100122 // The page's main resource does not use SSL. Note that we use this
123 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100124 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100125 // The page's main resource uses SSL and the certificate is good. The
126 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100127 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100128 // The page's main resource uses SSL and the certificate is good, but
129 // some sub-resources either do not use SSL or have problems with their
130 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100131 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100132 // The page's main resource uses SSL but there is a problem with its
133 // certificate.
134 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800135 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700136
Michael Kolb14612442011-06-24 13:06:29 -0700137 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700138 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700139
Michael Kolbc831b632011-05-11 09:30:34 -0700140 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700141 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700142
Grace Kloba22ac16e2009-10-07 18:00:23 -0700143 // The Geolocation permissions prompt
144 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
145 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800146 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700147 // Main WebView
148 private WebView mMainView;
149 // Subwindow container
150 private View mSubViewContainer;
151 // Subwindow WebView
152 private WebView mSubView;
153 // Saved bundle for when we are running low on memory. It contains the
154 // information needed to restore the WebView if the user goes back to the
155 // tab.
156 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700157 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
158 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700159 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700160 // Tab that constructed by this Tab. This is used when this Tab is
161 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700162 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700163 // If true, the tab is in the foreground of the current activity.
164 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 // If true, the tab is in page loading state (after onPageStarted,
166 // before onPageFinsihed)
167 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700168 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700169 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800170 // The last reported progress of the current page
171 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000172 // The time the load started, used to find load page time
173 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700174 // Application identifier used to find tabs that another application wants
175 // to reuse.
176 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700177 // flag to indicate if tab should be closed on back
178 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700179 // flag to indicate if the tab was opened from an intent
180 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500181 // The listener that gets invoked when a download is started from the
182 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700183 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500184 // Listener used to know when we move forward or back in the history list.
185 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800186 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700187
188 // AsyncTask for downloading touch icons
189 DownloadTouchIcon mTouchIconLoader;
190
John Reck35e9dd62011-04-25 09:01:54 -0700191 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700192 private int mCaptureWidth;
193 private int mCaptureHeight;
194 private Bitmap mCapture;
195 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700196 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800197 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700198 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800199 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700200
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100201 /**
Tarun Nainaniac724562014-11-03 17:40:38 -0800202 * See {@link #clearBackStackWhenItemAdded(java.util.regex.Pattern)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100203 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100204 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100205
John Reck1cf4b792011-07-26 10:22:22 -0700206 private static synchronized Bitmap getDefaultFavicon(Context context) {
207 if (sDefaultFavicon == null) {
208 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800209 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700210 }
211 return sDefaultFavicon;
212 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800213
John Reck30c714c2010-12-16 17:30:34 -0800214 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700215 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800216 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700217 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800218 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100219 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100220 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
221 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800222 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100223 boolean mIsBookmarkedSite;
224 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800225
226 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700227 mIncognito = incognito;
228 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700229 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800230 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800231 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700232 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800233 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800234 }
Steve Block2466eff2011-10-03 15:33:09 +0100235 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800236 }
237
238 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700239 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700240 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800241 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100242 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800243 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100244 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800245 }
John Reck1cf4b792011-07-26 10:22:22 -0700246 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800247 }
John Reck1cf4b792011-07-26 10:22:22 -0700248
Grace Kloba22ac16e2009-10-07 18:00:23 -0700249 }
250
John Reck30c714c2010-12-16 17:30:34 -0800251 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700252 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800253
Grace Kloba22ac16e2009-10-07 18:00:23 -0700254 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700255 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700256 static final String CURRURL = "currentUrl";
257 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700258 static final String PARENTTAB = "parentTab";
259 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700260 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700261 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700262 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700263
Grace Kloba22ac16e2009-10-07 18:00:23 -0700264 // Container class for the next error dialog that needs to be displayed
265 private class ErrorDialog {
266 public final int mTitle;
267 public final String mDescription;
268 public final int mError;
269 ErrorDialog(int title, String desc, int error) {
270 mTitle = title;
271 mDescription = desc;
272 mError = error;
273 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700274 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700275
276 private void processNextError() {
277 if (mQueuedErrors == null) {
278 return;
279 }
280 // The first one is currently displayed so just remove it.
281 mQueuedErrors.removeFirst();
282 if (mQueuedErrors.size() == 0) {
283 mQueuedErrors = null;
284 return;
285 }
286 showError(mQueuedErrors.getFirst());
287 }
288
289 private DialogInterface.OnDismissListener mDialogListener =
290 new DialogInterface.OnDismissListener() {
291 public void onDismiss(DialogInterface d) {
292 processNextError();
293 }
294 };
295 private LinkedList<ErrorDialog> mQueuedErrors;
296
297 private void queueError(int err, String desc) {
298 if (mQueuedErrors == null) {
299 mQueuedErrors = new LinkedList<ErrorDialog>();
300 }
301 for (ErrorDialog d : mQueuedErrors) {
302 if (d.mError == err) {
303 // Already saw a similar error, ignore the new one.
304 return;
305 }
306 }
307 ErrorDialog errDialog = new ErrorDialog(
308 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
309 R.string.browserFrameFileErrorLabel :
310 R.string.browserFrameNetworkErrorLabel,
311 desc, err);
312 mQueuedErrors.addLast(errDialog);
313
314 // Show the dialog now if the queue was empty and it is in foreground
315 if (mQueuedErrors.size() == 1 && mInForeground) {
316 showError(errDialog);
317 }
318 }
319
320 private void showError(ErrorDialog errDialog) {
321 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700322 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700323 .setTitle(errDialog.mTitle)
324 .setMessage(errDialog.mDescription)
325 .setPositiveButton(R.string.ok, null)
326 .create();
327 d.setOnDismissListener(mDialogListener);
328 d.show();
329 }
330 }
331
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800332 protected void replaceCrashView(View view, View container) {
333 if (hasCrashed && (view == mMainView)) {
334 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
335 wrapper.removeAllViewsInLayout();
336 wrapper.addView(view);
337 hasCrashed = false;
338 }
Vivek Sekhar2868b8d2014-12-03 17:22:50 -0800339 mMainView.reload();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800340 }
341
342 protected void showCrashView() {
343 if (hasCrashed) {
344 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
345 Context.LAYOUT_INFLATER_SERVICE);
346 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
347 final FrameLayout wrapper =
348 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
349 wrapper.removeAllViewsInLayout();
350 wrapper.addView(crashLayout);
351 mContainer.requestFocus();
352 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
353 reloadBtn.setOnClickListener(new OnClickListener() {
354 @Override
355 public void onClick(View arg0) {
356 replaceCrashView(mMainView, mContainer);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800357 }
358 });
359 }
360 }
361
Grace Kloba22ac16e2009-10-07 18:00:23 -0700362 // -------------------------------------------------------------------------
363 // WebViewClient implementation for the main WebView
364 // -------------------------------------------------------------------------
365
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800366 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500367 private Message mDontResend;
368 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700369
370 private boolean providersDiffer(String url, String otherUrl) {
371 Uri uri1 = Uri.parse(url);
372 Uri uri2 = Uri.parse(otherUrl);
373 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
374 }
375
Grace Kloba22ac16e2009-10-07 18:00:23 -0700376 @Override
377 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700379 mPageFinished = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800380 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700381 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700382 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700383 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800384 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000385 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700386
387 // If we start a touch icon load and then load a new page, we don't
388 // want to cancel the current touch icon loader. But, we do want to
389 // create a new one when the touch icon url is known.
390 if (mTouchIconLoader != null) {
391 mTouchIconLoader.mTab = null;
392 mTouchIconLoader = null;
393 }
394
Panos Thomasb298aad2014-10-22 12:24:21 -0700395 // Loading a new page voids any ongoing Geolocation permission
396 // requests.
397 if (mGeolocationPermissionsPrompt != null) {
398 mGeolocationPermissionsPrompt.dismiss();
399 }
400
Grace Kloba22ac16e2009-10-07 18:00:23 -0700401 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800402 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500403
John Recke969cc52010-12-21 17:24:43 -0800404 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700405 }
406
407 @Override
408 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700409 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800410 if (!isPrivateBrowsingEnabled()) {
411 LogTag.logPageFinishedLoading(
412 url, SystemClock.uptimeMillis() - mLoadStartTime);
413 }
John Reck1cf4b792011-07-26 10:22:22 -0700414 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800415 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700416 }
417
418 // return true if want to hijack the url to let another app to handle it
419 @Override
420 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700421 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800422 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
423 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700424 } else {
425 return false;
426 }
427 }
428
Vivek Sekharb991edb2014-12-17 18:18:07 -0800429 @Override
430 public boolean shouldDownloadFavicon(WebView view, String url) {
431 return true;
432 }
433
Grace Kloba22ac16e2009-10-07 18:00:23 -0700434 /**
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) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800463 // Used for the syncCurrentState to use
464 // the failing url instead of using webview url
465 mReceivedError = true;
466
Grace Kloba22ac16e2009-10-07 18:00:23 -0700467 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
468 errorCode != WebViewClient.ERROR_CONNECT &&
469 errorCode != WebViewClient.ERROR_BAD_URL &&
470 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
471 errorCode != WebViewClient.ERROR_FILE) {
472 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500473
Selim Gurun3da06b82011-10-10 13:58:12 -0700474 // Don't log URLs when in private browsing mode
475 if (!isPrivateBrowsingEnabled()) {
476 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500477 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700478 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500479 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700480 }
481
482 /**
483 * Check with the user if it is ok to resend POST data as the page they
484 * are trying to navigate to is the result of a POST.
485 */
486 @Override
487 public void onFormResubmission(WebView view, final Message dontResend,
488 final Message resend) {
489 if (!mInForeground) {
490 dontResend.sendToTarget();
491 return;
492 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500493 if (mDontResend != null) {
494 Log.w(LOGTAG, "onFormResubmission should not be called again "
495 + "while dialog is still up");
496 dontResend.sendToTarget();
497 return;
498 }
499 mDontResend = dontResend;
500 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700501 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700502 R.string.browserFrameFormResubmitLabel).setMessage(
503 R.string.browserFrameFormResubmitMessage)
504 .setPositiveButton(R.string.ok,
505 new DialogInterface.OnClickListener() {
506 public void onClick(DialogInterface dialog,
507 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500508 if (mResend != null) {
509 mResend.sendToTarget();
510 mResend = null;
511 mDontResend = null;
512 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700513 }
514 }).setNegativeButton(R.string.cancel,
515 new DialogInterface.OnClickListener() {
516 public void onClick(DialogInterface dialog,
517 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500518 if (mDontResend != null) {
519 mDontResend.sendToTarget();
520 mResend = null;
521 mDontResend = null;
522 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700523 }
524 }).setOnCancelListener(new OnCancelListener() {
525 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500526 if (mDontResend != null) {
527 mDontResend.sendToTarget();
528 mResend = null;
529 mDontResend = null;
530 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700531 }
532 }).show();
533 }
534
535 /**
536 * Insert the url into the visited history database.
537 * @param url The url to be inserted.
538 * @param isReload True if this url is being reloaded.
539 * FIXME: Not sure what to do when reloading the page.
540 */
541 @Override
542 public void doUpdateVisitedHistory(WebView view, String url,
543 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800544 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700545 }
546
547 /**
548 * Displays SSL error(s) dialog to the user.
549 */
550 @Override
551 public void onReceivedSslError(final WebView view,
552 final SslErrorHandler handler, final SslError error) {
553 if (!mInForeground) {
554 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100555 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700556 return;
557 }
John Reck35e9dd62011-04-25 09:01:54 -0700558 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700559 new AlertDialog.Builder(mContext)
560 .setTitle(R.string.security_warning)
561 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200562 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700563 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700564 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700565 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700566 public void onClick(DialogInterface dialog,
567 int whichButton) {
568 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100569 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700570 }
John Reckcb28b2c2011-08-26 17:39:44 -0700571 })
572 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700573 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700574 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700575 public void onClick(DialogInterface dialog,
576 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700577 mWebViewController.showSslCertificateOnError(
578 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700579 }
John Reckcb28b2c2011-08-26 17:39:44 -0700580 })
581 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700582 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700583 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700584 public void onClick(DialogInterface dialog,
585 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800586 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700587 }
John Reckcb28b2c2011-08-26 17:39:44 -0700588 })
589 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700590 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700591 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700592 public void onCancel(DialogInterface dialog) {
593 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100594 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800595 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700596 }
John Reckcb28b2c2011-08-26 17:39:44 -0700597 })
598 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700599 } else {
600 handler.proceed();
601 }
602 }
603
604 /**
Steve Block4895b012011-10-03 16:26:46 +0100605 * Called when an SSL error occurred while loading a resource, but the
606 * WebView but chose to proceed anyway based on a decision retained
607 * from a previous response to onReceivedSslError(). We update our
608 * security state to reflect this.
609 */
610 @Override
611 public void onProceededAfterSslError(WebView view, SslError error) {
612 handleProceededAfterSslError(error);
613 }
614
615 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700616 * Displays client certificate request to the user.
617 */
618 @Override
619 public void onReceivedClientCertRequest(final WebView view,
620 final ClientCertRequestHandler handler, final String host_and_port) {
621 if (!mInForeground) {
622 handler.ignore();
623 return;
624 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700625 int colon = host_and_port.lastIndexOf(':');
626 String host;
627 int port;
628 if (colon == -1) {
629 host = host_and_port;
630 port = -1;
631 } else {
632 String portString = host_and_port.substring(colon + 1);
633 try {
634 port = Integer.parseInt(portString);
635 host = host_and_port.substring(0, colon);
636 } catch (NumberFormatException e) {
637 host = host_and_port;
638 port = -1;
639 }
640 }
Michael Kolb14612442011-06-24 13:06:29 -0700641 KeyChain.choosePrivateKeyAlias(
642 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700643 @Override public void alias(String alias) {
644 if (alias == null) {
645 handler.cancel();
646 return;
647 }
Michael Kolb14612442011-06-24 13:06:29 -0700648 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700649 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700650 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700651 }
652
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800653 @Override
654 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
655 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700656 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
657 hasCrashed = true;
658 showCrashView();
659 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800660 }
661
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700662 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700663 * Handles an HTTP authentication request.
664 *
665 * @param handler The authentication handler
666 * @param host The host
667 * @param realm The realm
668 */
669 @Override
670 public void onReceivedHttpAuthRequest(WebView view,
671 final HttpAuthHandler handler, final String host,
672 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700674 }
675
676 @Override
John Reck438bf462011-01-12 18:11:46 -0800677 public WebResourceResponse shouldInterceptRequest(WebView view,
678 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800679 //intercept if opening a new incognito tab - show the incognito welcome page
680 if (url.startsWith("browser:incognito")) {
681 Resources resourceHandle = mContext.getResources();
682 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700683 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800684 return new WebResourceResponse("text/html", "utf8", inStream);
685 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800686 WebResourceResponse res;
687 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
688 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
689 } else {
690 res = HomeProvider.shouldInterceptRequest(mContext, url);
691 }
John Reck438bf462011-01-12 18:11:46 -0800692 return res;
693 }
694
695 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700696 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
697 if (!mInForeground) {
698 return false;
699 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700701 }
702
703 @Override
704 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700706 return;
707 }
John Reck997b1b72012-04-19 18:08:25 -0700708 if (!mWebViewController.onUnhandledKeyEvent(event)) {
709 super.onUnhandledKeyEvent(view, event);
710 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700711 }
712 };
713
John Reck1cf4b792011-07-26 10:22:22 -0700714 private void syncCurrentState(WebView view, String url) {
715 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800716
717 if (mReceivedError) {
718 mCurrentState.mUrl = url;
719 mCurrentState.mOriginalUrl = url;
720 } else {
721 mCurrentState.mUrl = view.getUrl();
722 mCurrentState.mOriginalUrl = view.getOriginalUrl();
723 mCurrentState.mFavicon = view.getFavicon();
724 }
725
John Reck1cf4b792011-07-26 10:22:22 -0700726 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700727 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700728 }
John Reck1cf4b792011-07-26 10:22:22 -0700729 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800730
731
John Reck1cf4b792011-07-26 10:22:22 -0700732 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
733 // In case we stop when loading an HTTPS page from an HTTP page
734 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100735 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100736 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700737 }
John Reck502a3532011-08-16 14:21:46 -0700738 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700739 }
740
Tarun Nainani8eb00912014-07-17 12:28:32 -0700741
742 public boolean isTabFullScreen() {
743 return mFullScreen;
744 }
745
Vivek Sekharf96064b2014-07-28 16:32:34 -0700746 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700747 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700748 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700749 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700750 }
751
Sudheer Koganti24766882014-10-02 10:58:09 -0700752 public boolean exitFullscreen() {
753 if (mFullScreen) {
754 Controller controller = (Controller)mWebViewController;
755 controller.getUi().showFullscreen(false);
756 if (getWebView() != null)
757 getWebView().exitFullscreen();
758 mFullScreen = false;
759 return true;
760 }
761 return false;
762 }
763
764
765
766
Grace Kloba22ac16e2009-10-07 18:00:23 -0700767 // -------------------------------------------------------------------------
768 // WebChromeClient implementation for the main WebView
769 // -------------------------------------------------------------------------
770
771 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
772 // Helper method to create a new tab or sub window.
773 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700774 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700775 }
776
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700777 private void createWindow(final boolean dialog, final Message msg, final String url,
778 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700779 WebView.WebViewTransport transport =
780 (WebView.WebViewTransport) msg.obj;
781 if (dialog) {
782 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700783 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700784 transport.setWebView(mSubView);
785 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700786 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700787 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700788 // This is special case for rendering links on a webpage in
789 // a new tab. If opener is suppressed, the WebContents created
790 // by the content layer are not fully initialized. This check
791 // will prevent content layer from overriding WebContents
792 // created by new tab with the uninitialized instance.
793 if (!opener_suppressed) {
794 transport.setWebView(newTab.getWebView());
795 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700796 }
797 msg.sendToTarget();
798 }
799
800 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700801 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
802 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700803 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700804 }
805 }
806
807 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700808 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
809 float contentOffsetYPix,
810 float overdrawBottomHeightPix) {
811 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700812 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700813 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700814 }
815 }
816
817 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700818 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700819 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700820 }
821
822 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700823 public boolean onCreateWindow(WebView view, final boolean dialog,
824 final boolean userGesture, final Message resultMsg) {
825 // only allow new window or sub window for the foreground case
826 if (!mInForeground) {
827 return false;
828 }
829 // Short-circuit if we can't create any more tabs or sub windows.
830 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700831 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700832 .setTitle(R.string.too_many_subwindows_dialog_title)
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.too_many_subwindows_dialog_message)
835 .setPositiveButton(R.string.ok, null)
836 .show();
837 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700838 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700839 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700840 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200841 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700842 .setMessage(R.string.too_many_windows_dialog_message)
843 .setPositiveButton(R.string.ok, null)
844 .show();
845 return false;
846 }
847
848 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800849 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700850 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700851 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700852 createWindow(dialog, resultMsg, windowParams.mURL, true);
853 // This is special case for rendering links on a webpage in
854 // a new tab. If opener is suppressed, the WebContents created
855 // by the content layer are not fully initialized. Returning false
856 // will prevent content layer from overriding WebContents
857 // created by new tab with the uninitialized instance.
858 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700859 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700860
861 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700862 return true;
863 }
864
865 // Allow the popup and create the appropriate window.
866 final AlertDialog.OnClickListener allowListener =
867 new AlertDialog.OnClickListener() {
868 public void onClick(DialogInterface d,
869 int which) {
870 createWindow(dialog, resultMsg);
871 }
872 };
873
874 // Block the popup by returning a null WebView.
875 final AlertDialog.OnClickListener blockListener =
876 new AlertDialog.OnClickListener() {
877 public void onClick(DialogInterface d, int which) {
878 resultMsg.sendToTarget();
879 }
880 };
881
882 // Build a confirmation dialog to display to the user.
883 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700884 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200885 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700886 .setMessage(R.string.popup_window_attempt)
887 .setPositiveButton(R.string.allow, allowListener)
888 .setNegativeButton(R.string.block, blockListener)
889 .setCancelable(false)
890 .create();
891
892 // Show the confirmation dialog.
893 d.show();
894 return true;
895 }
896
897 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500898 public void onRequestFocus(WebView view) {
899 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700900 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500901 }
902 }
903
904 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700905 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700906 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700907 // JavaScript can only close popup window.
908 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700909 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700910 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700911 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700912 }
913 }
914
915 @Override
916 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800917 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800918 if (newProgress == 100) {
919 mInPageLoad = false;
920 }
John Reck30c714c2010-12-16 17:30:34 -0800921 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700922 if (mUpdateThumbnail && newProgress == 100) {
923 mUpdateThumbnail = false;
924 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700925 }
926
927 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500928 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800929 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700930 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700931 }
932
933 @Override
934 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800935 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700936 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700937 }
938
939 @Override
940 public void onReceivedTouchIconUrl(WebView view, String url,
941 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700942 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400943 // Let precomposed icons take precedence over non-composed
944 // icons.
945 if (precomposed && mTouchIconLoader != null) {
946 mTouchIconLoader.cancel(false);
947 mTouchIconLoader = null;
948 }
949 // Have only one async task at a time.
950 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700951 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700952 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400953 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700954 }
955 }
956
957 @Override
958 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800959 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700960 Activity activity = mWebViewController.getActivity();
961 if (activity != null) {
962 onShowCustomView(view, activity.getRequestedOrientation(), callback);
963 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400964 }
965
966 @Override
967 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800968 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700969 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400970 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700971 }
972
973 @Override
974 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700975 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700976 }
977
978 /**
979 * The origin has exceeded its database quota.
980 * @param url the URL that exceeded the quota
981 * @param databaseIdentifier the identifier of the database on which the
982 * transaction that caused the quota overflow was run
983 * @param currentQuota the current quota for the origin.
984 * @param estimatedSize the estimated size of the database.
985 * @param totalUsedQuota is the sum of all origins' quota.
986 * @param quotaUpdater The callback to run when a decision to allow or
987 * deny quota has been made. Don't forget to call this!
988 */
989 @Override
990 public void onExceededDatabaseQuota(String url,
991 String databaseIdentifier, long currentQuota, long estimatedSize,
992 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700993 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700994 .onExceededDatabaseQuota(url, databaseIdentifier,
995 currentQuota, estimatedSize, totalUsedQuota,
996 quotaUpdater);
997 }
998
999 /**
1000 * The Application Cache has exceeded its max size.
1001 * @param spaceNeeded is the amount of disk space that would be needed
1002 * in order for the last appcache operation to succeed.
1003 * @param totalUsedQuota is the sum of all origins' quota.
1004 * @param quotaUpdater A callback to inform the WebCore thread that a
1005 * new app cache size is available. This callback must always
1006 * be executed at some point to ensure that the sleeping
1007 * WebCore thread is woken up.
1008 */
1009 @Override
1010 public void onReachedMaxAppCacheSize(long spaceNeeded,
1011 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001012 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001013 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1014 quotaUpdater);
1015 }
1016
1017 /**
1018 * Instructs the browser to show a prompt to ask the user to set the
1019 * Geolocation permission state for the specified origin.
1020 * @param origin The origin for which Geolocation permissions are
1021 * requested.
1022 * @param callback The callback to call once the user has set the
1023 * Geolocation permission state.
1024 */
1025 @Override
1026 public void onGeolocationPermissionsShowPrompt(String origin,
1027 GeolocationPermissions.Callback callback) {
1028 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001029 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001030 }
1031 }
1032
1033 /**
1034 * Instructs the browser to hide the Geolocation permissions prompt.
1035 */
1036 @Override
1037 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001038 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001039 mGeolocationPermissionsPrompt.hide();
1040 }
1041 }
1042
Ben Murdoch65acc352009-11-19 18:16:04 +00001043 /* Adds a JavaScript error message to the system log and if the JS
1044 * console is enabled in the about:debug options, to that console
1045 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001046 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001047 */
1048 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001049 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -05001050 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001051 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001052
Ben Murdochc42addf2010-01-28 15:19:59 +00001053 String message = "Console: " + consoleMessage.message() + " "
1054 + consoleMessage.sourceId() + ":"
1055 + consoleMessage.lineNumber();
1056
1057 switch (consoleMessage.messageLevel()) {
1058 case TIP:
1059 Log.v(CONSOLE_LOGTAG, message);
1060 break;
1061 case LOG:
1062 Log.i(CONSOLE_LOGTAG, message);
1063 break;
1064 case WARNING:
1065 Log.w(CONSOLE_LOGTAG, message);
1066 break;
1067 case ERROR:
1068 Log.e(CONSOLE_LOGTAG, message);
1069 break;
1070 case DEBUG:
1071 Log.d(CONSOLE_LOGTAG, message);
1072 break;
1073 }
1074
1075 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001076 }
1077
1078 /**
1079 * Ask the browser for an icon to represent a <video> element.
1080 * This icon will be used if the Web page did not specify a poster attribute.
1081 * @return Bitmap The icon or null if no such icon is available.
1082 */
1083 @Override
1084 public Bitmap getDefaultVideoPoster() {
1085 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001086 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001087 }
1088 return null;
1089 }
1090
1091 /**
1092 * Ask the host application for a custom progress view to show while
1093 * a <video> is loading.
1094 * @return View The progress view.
1095 */
1096 @Override
1097 public View getVideoLoadingProgressView() {
1098 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001099 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001100 }
1101 return null;
1102 }
1103
1104 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001105 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001106 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001107 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001108 } else {
1109 uploadMsg.onReceiveValue(null);
1110 }
1111 }
1112
Vivek Sekharb54614f2014-05-01 19:03:37 -07001113 @Override
1114 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1115 boolean capture) {
1116 if (mInForeground) {
1117 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1118 } else {
1119 uploadFilePaths.onReceiveValue(null);
1120 }
1121 }
1122
Grace Kloba22ac16e2009-10-07 18:00:23 -07001123 /**
1124 * Deliver a list of already-visited URLs
1125 */
1126 @Override
1127 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001128 mWebViewController.getVisitedHistory(callback);
1129 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001130
1131 @Override
1132 public void setupAutoFill(Message message) {
1133 // Prompt the user to set up their profile.
1134 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001135 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1136 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001137 Context.LAYOUT_INFLATER_SERVICE);
1138 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1139
1140 builder.setView(layout)
1141 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1142 @Override
1143 public void onClick(DialogInterface dialog, int id) {
1144 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1145 R.id.setup_autofill_dialog_disable_autofill);
1146
1147 if (disableAutoFill.isChecked()) {
1148 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001149 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001150 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001151 R.string.autofill_setup_dialog_negative_toast,
1152 Toast.LENGTH_LONG).show();
1153 } else {
1154 // Take user to the AutoFill profile editor. When they return,
1155 // we will send the message that we pass here which will trigger
1156 // the form to get filled out with their new profile.
1157 mWebViewController.setupAutoFill(msg);
1158 }
1159 }
1160 })
1161 .setNegativeButton(R.string.cancel, null)
1162 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001163 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001164 };
1165
1166 // -------------------------------------------------------------------------
1167 // WebViewClient implementation for the sub window
1168 // -------------------------------------------------------------------------
1169
1170 // Subclass of WebViewClient used in subwindows to notify the main
1171 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001172 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001173 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001174 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001175 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001176
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001177 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001178 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001179 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001180 }
1181 @Override
1182 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1183 // Unlike the others, do not call mClient's version, which would
1184 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001185 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001186 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001187 }
1188 @Override
1189 public void doUpdateVisitedHistory(WebView view, String url,
1190 boolean isReload) {
1191 mClient.doUpdateVisitedHistory(view, url, isReload);
1192 }
1193 @Override
1194 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1195 return mClient.shouldOverrideUrlLoading(view, url);
1196 }
1197 @Override
1198 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1199 SslError error) {
1200 mClient.onReceivedSslError(view, handler, error);
1201 }
1202 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001203 public void onReceivedClientCertRequest(WebView view,
1204 ClientCertRequestHandler handler, String host_and_port) {
1205 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1206 }
1207 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001208 public void onReceivedHttpAuthRequest(WebView view,
1209 HttpAuthHandler handler, String host, String realm) {
1210 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1211 }
1212 @Override
1213 public void onFormResubmission(WebView view, Message dontResend,
1214 Message resend) {
1215 mClient.onFormResubmission(view, dontResend, resend);
1216 }
1217 @Override
1218 public void onReceivedError(WebView view, int errorCode,
1219 String description, String failingUrl) {
1220 mClient.onReceivedError(view, errorCode, description, failingUrl);
1221 }
1222 @Override
1223 public boolean shouldOverrideKeyEvent(WebView view,
1224 android.view.KeyEvent event) {
1225 return mClient.shouldOverrideKeyEvent(view, event);
1226 }
1227 @Override
1228 public void onUnhandledKeyEvent(WebView view,
1229 android.view.KeyEvent event) {
1230 mClient.onUnhandledKeyEvent(view, event);
1231 }
1232 }
1233
1234 // -------------------------------------------------------------------------
1235 // WebChromeClient implementation for the sub window
1236 // -------------------------------------------------------------------------
1237
1238 private class SubWindowChromeClient extends WebChromeClient {
1239 // The main WebChromeClient.
1240 private final WebChromeClient mClient;
1241
1242 SubWindowChromeClient(WebChromeClient client) {
1243 mClient = client;
1244 }
1245 @Override
1246 public void onProgressChanged(WebView view, int newProgress) {
1247 mClient.onProgressChanged(view, newProgress);
1248 }
1249 @Override
1250 public boolean onCreateWindow(WebView view, boolean dialog,
1251 boolean userGesture, android.os.Message resultMsg) {
1252 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1253 }
1254 @Override
1255 public void onCloseWindow(WebView window) {
1256 if (window != mSubView) {
1257 Log.e(LOGTAG, "Can't close the window");
1258 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001259 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001260 }
1261 }
1262
1263 // -------------------------------------------------------------------------
1264
1265 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001266 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001267 this(wvcontroller, w, null);
1268 }
1269
1270 Tab(WebViewController wvcontroller, Bundle state) {
1271 this(wvcontroller, null, state);
1272 }
1273
1274 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001275 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001276 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001277 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001278 mDataController = DataController.getInstance(mContext);
1279 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001280 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001281 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001282 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001283 mInForeground = false;
1284
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001285 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001286 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001287 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001288 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001289 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001290 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001291 }
1292 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001293 mWebBackForwardListClient = new WebBackForwardListClient() {
1294 @Override
1295 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001296 if (mClearHistoryUrlPattern != null) {
1297 boolean match =
1298 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001299 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001300 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1301 + item.getUrl() + "\n\t"
1302 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001303 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001304 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001305 if (mMainView != null) {
1306 mMainView.clearHistory();
1307 }
1308 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001309 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001310 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001311 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001312 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001313
John Reck1cf4b792011-07-26 10:22:22 -07001314 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1315 R.dimen.tab_thumbnail_width);
1316 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1317 R.dimen.tab_thumbnail_height);
1318 updateShouldCaptureThumbnails();
1319 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001320 if (getId() == -1) {
1321 mId = TabControl.getNextId();
1322 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001323 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001324 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001325 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001326 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001327 switch (m.what) {
1328 case MSG_CAPTURE:
1329 capture();
1330 break;
1331 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001332 }
1333 };
John Reck1cf4b792011-07-26 10:22:22 -07001334 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001335
Michael Kolb72864272012-05-03 15:42:15 -07001336 public boolean shouldUpdateThumbnail() {
1337 return mUpdateThumbnail;
1338 }
1339
Mathew Inwoode09305e2011-09-02 12:03:26 +01001340 /**
1341 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1342 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1343 * to overlapping IDs between the preloaded and restored tabs.
1344 */
1345 public void refreshIdAfterPreload() {
1346 mId = TabControl.getNextId();
1347 }
1348
John Reck1cf4b792011-07-26 10:22:22 -07001349 public void updateShouldCaptureThumbnails() {
1350 if (mWebViewController.shouldCaptureThumbnails()) {
1351 synchronized (Tab.this) {
1352 if (mCapture == null) {
1353 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1354 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001355 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001356 if (mInForeground) {
1357 postCapture();
1358 }
1359 }
1360 }
1361 } else {
1362 synchronized (Tab.this) {
1363 mCapture = null;
1364 deleteThumbnail();
1365 }
1366 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001367 }
1368
Michael Kolb14612442011-06-24 13:06:29 -07001369 public void setController(WebViewController ctl) {
1370 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001371 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001372 }
1373
Michael Kolbc831b632011-05-11 09:30:34 -07001374 public long getId() {
1375 return mId;
1376 }
1377
Michael Kolb91911a22012-01-17 11:21:25 -08001378 void setWebView(WebView w) {
1379 setWebView(w, true);
1380 }
1381
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001382 public boolean isNativeActive(){
1383 if (mMainView == null)
1384 return false;
1385 return true;
1386 }
1387
1388 public void setTimeStamp(){
1389 Date d = new Date();
1390 timestamp = (new Timestamp(d.getTime()));
1391 }
1392
1393 public Timestamp getTimestamp() {
1394 return timestamp;
1395 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001396 /**
1397 * Sets the WebView for this tab, correctly removing the old WebView from
1398 * the container view.
1399 */
Michael Kolb91911a22012-01-17 11:21:25 -08001400 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001401 if (mMainView == w) {
1402 return;
1403 }
Michael Kolba713ec82010-11-29 17:27:06 -08001404
Grace Kloba22ac16e2009-10-07 18:00:23 -07001405 // If the WebView is changing, the page will be reloaded, so any ongoing
1406 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001407 if (mGeolocationPermissionsPrompt != null) {
1408 mGeolocationPermissionsPrompt.hide();
1409 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001410
Michael Kolba713ec82010-11-29 17:27:06 -08001411 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001412
John Reck1cf4b792011-07-26 10:22:22 -07001413 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001414 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001415 if (w != null) {
1416 syncCurrentState(w, null);
1417 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001418 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001419 }
1420 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001421 // set the new one
1422 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001423 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001424 if (mMainView != null) {
1425 mMainView.setWebViewClient(mWebViewClient);
1426 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001427 // Attach DownloadManager so that downloads can start in an active
1428 // or a non-active window. This can happen when going to a site that
1429 // does a redirect after a period of time. The user could have
1430 // switched to another tab while waiting for the download to start.
1431 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001432 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001433 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001434 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001435 mMainView.setPictureListener(this);
1436 }
Michael Kolb91911a22012-01-17 11:21:25 -08001437 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001438 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001439 WebBackForwardList restoredState
1440 = mMainView.restoreState(mSavedState);
1441 if (restoredState == null || restoredState.getSize() == 0) {
1442 Log.w(LOGTAG, "Failed to restore WebView state!");
1443 loadUrl(mCurrentState.mOriginalUrl, null);
1444 }
John Reck1cf4b792011-07-26 10:22:22 -07001445 mSavedState = null;
1446 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001447 }
1448 }
1449
1450 /**
1451 * Destroy the tab's main WebView and subWindow if any
1452 */
1453 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001454
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001455 if (mPostponeDestroy) {
1456 mShouldDestroy = true;
1457 return;
1458 }
1459 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001460 if (mMainView != null) {
1461 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001462 // save the WebView to call destroy() after detach it from the tab
1463 WebView webView = mMainView;
1464 setWebView(null);
1465 webView.destroy();
1466 }
1467 }
1468
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001469 private boolean mPostponeDestroy = false;
1470 private boolean mShouldDestroy = false;
1471
1472 public void postponeDestroy() {
1473 mPostponeDestroy = true;
1474 }
1475
1476 public void performPostponedDestroy() {
1477 mPostponeDestroy = false;
1478 if (mShouldDestroy) {
1479 destroy();
1480 }
1481 }
1482
Grace Kloba22ac16e2009-10-07 18:00:23 -07001483 /**
1484 * Remove the tab from the parent
1485 */
1486 void removeFromTree() {
1487 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001488 if (mChildren != null) {
1489 for(Tab t : mChildren) {
1490 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001491 }
1492 }
1493 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001494 if (mParent != null) {
1495 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001496 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001497
1498 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001499 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001500 }
1501
1502 /**
1503 * Create a new subwindow unless a subwindow already exists.
1504 * @return True if a new subwindow was created. False if one already exists.
1505 */
1506 boolean createSubWindow() {
1507 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001508 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001509 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001510 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001511 mSubView.setWebChromeClient(new SubWindowChromeClient(
1512 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001513 // Set a different DownloadListener for the mSubView, since it will
1514 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001515 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001516 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001517 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001518 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001519 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001520 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001521 if (mSubView.copyBackForwardList().getSize() == 0) {
1522 // This subwindow was opened for the sole purpose of
1523 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001524 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001525 }
1526 }
1527 });
Michael Kolb14612442011-06-24 13:06:29 -07001528 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001529 return true;
1530 }
1531 return false;
1532 }
1533
1534 /**
1535 * Dismiss the subWindow for the tab.
1536 */
1537 void dismissSubWindow() {
1538 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001539 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001540 mSubView.destroy();
1541 mSubView = null;
1542 mSubViewContainer = null;
1543 }
1544 }
1545
Grace Kloba22ac16e2009-10-07 18:00:23 -07001546
1547 /**
1548 * Set the parent tab of this tab.
1549 */
Michael Kolbc831b632011-05-11 09:30:34 -07001550 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001551 if (parent == this) {
1552 throw new IllegalStateException("Cannot set parent to self!");
1553 }
Michael Kolbc831b632011-05-11 09:30:34 -07001554 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001555 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001556 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001557 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001558 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001559 if (mSavedState != null) {
1560 if (parent == null) {
1561 mSavedState.remove(PARENTTAB);
1562 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001563 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001564 }
1565 }
John Reckb0a86db2011-05-24 14:05:58 -07001566
1567 // Sync the WebView useragent with the parent
1568 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1569 != mSettings.hasDesktopUseragent(getWebView())) {
1570 mSettings.toggleDesktopUseragent(getWebView());
1571 }
John Reck52be4782011-08-26 15:37:29 -07001572
1573 if (parent != null && parent.getId() == getId()) {
1574 throw new IllegalStateException("Parent has same ID as child!");
1575 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001576 }
1577
1578 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001579 * If this Tab was created through another Tab, then this method returns
1580 * that Tab.
1581 * @return the Tab parent or null
1582 */
1583 public Tab getParent() {
1584 return mParent;
1585 }
1586
1587 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001588 * When a Tab is created through the content of another Tab, then we
1589 * associate the Tabs.
1590 * @param child the Tab that was created from this Tab
1591 */
1592 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001593 if (mChildren == null) {
1594 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001595 }
Michael Kolbc831b632011-05-11 09:30:34 -07001596 mChildren.add(child);
1597 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001598 }
1599
Michael Kolbc831b632011-05-11 09:30:34 -07001600 Vector<Tab> getChildren() {
1601 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001602 }
1603
1604 void resume() {
1605 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001606 if (mMainView.hasCrashed()) {
1607 // Reload if render process has crashed. This is done here so that
1608 // setFocus call sends wasShown message to correct render process.
1609 mMainView.reload();
1610 }
John Reck56c1fcf2011-08-17 10:15:16 -07001611 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001612 mMainView.onResume();
1613 if (mSubView != null) {
1614 mSubView.onResume();
1615 }
1616 }
1617 }
1618
John Reck56c1fcf2011-08-17 10:15:16 -07001619 private void setupHwAcceleration(View web) {
1620 if (web == null) return;
1621 BrowserSettings settings = BrowserSettings.getInstance();
1622 if (settings.isHardwareAccelerated()) {
1623 web.setLayerType(View.LAYER_TYPE_NONE, null);
1624 } else {
1625 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1626 }
1627 }
1628
Grace Kloba22ac16e2009-10-07 18:00:23 -07001629 void pause() {
1630 if (mMainView != null) {
1631 mMainView.onPause();
1632 if (mSubView != null) {
1633 mSubView.onPause();
1634 }
1635 }
1636 }
1637
1638 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001639 if (mInForeground) {
1640 return;
1641 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001642 mInForeground = true;
1643 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001644 Activity activity = mWebViewController.getActivity();
1645 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001646 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001647 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001648 }
1649 // Show the pending error dialog if the queue is not empty
1650 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1651 showError(mQueuedErrors.getFirst());
1652 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001653 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001654 }
1655
1656 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001657 if (!mInForeground) {
1658 return;
1659 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001660 mInForeground = false;
1661 pause();
1662 mMainView.setOnCreateContextMenuListener(null);
1663 if (mSubView != null) {
1664 mSubView.setOnCreateContextMenuListener(null);
1665 }
1666 }
1667
Michael Kolb8233fac2010-10-26 16:08:53 -07001668 boolean inForeground() {
1669 return mInForeground;
1670 }
1671
Grace Kloba22ac16e2009-10-07 18:00:23 -07001672 /**
1673 * Return the top window of this tab; either the subwindow if it is not
1674 * null or the main window.
1675 * @return The top window of this tab.
1676 */
1677 WebView getTopWindow() {
1678 if (mSubView != null) {
1679 return mSubView;
1680 }
1681 return mMainView;
1682 }
1683
1684 /**
1685 * Return the main window of this tab. Note: if a tab is freed in the
1686 * background, this can return null. It is only guaranteed to be
1687 * non-null for the current tab.
1688 * @return The main WebView of this tab.
1689 */
1690 WebView getWebView() {
1691 return mMainView;
1692 }
1693
Michael Kolba713ec82010-11-29 17:27:06 -08001694 void setViewContainer(View container) {
1695 mContainer = container;
1696 }
1697
Michael Kolb8233fac2010-10-26 16:08:53 -07001698 View getViewContainer() {
1699 return mContainer;
1700 }
1701
Grace Kloba22ac16e2009-10-07 18:00:23 -07001702 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001703 * Return whether private browsing is enabled for the main window of
1704 * this tab.
1705 * @return True if private browsing is enabled.
1706 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001707 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001708 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001709 }
1710
1711 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001712 * Return the subwindow of this tab or null if there is no subwindow.
1713 * @return The subwindow of this tab or null.
1714 */
1715 WebView getSubWebView() {
1716 return mSubView;
1717 }
1718
Michael Kolb1514bb72010-11-22 09:11:48 -08001719 void setSubWebView(WebView subView) {
1720 mSubView = subView;
1721 }
1722
Michael Kolb8233fac2010-10-26 16:08:53 -07001723 View getSubViewContainer() {
1724 return mSubViewContainer;
1725 }
1726
Michael Kolb1514bb72010-11-22 09:11:48 -08001727 void setSubViewContainer(View subViewContainer) {
1728 mSubViewContainer = subViewContainer;
1729 }
1730
Grace Kloba22ac16e2009-10-07 18:00:23 -07001731 /**
1732 * @return The geolocation permissions prompt for this tab.
1733 */
1734 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001735 if (mGeolocationPermissionsPrompt == null) {
1736 ViewStub stub = (ViewStub) mContainer
1737 .findViewById(R.id.geolocation_permissions_prompt);
1738 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1739 .inflate();
Panos Thomasb298aad2014-10-22 12:24:21 -07001740 mGeolocationPermissionsPrompt.init(mCurrentState.mIncognito);
Grace Kloba50c241e2010-04-20 11:07:50 -07001741 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001742 return mGeolocationPermissionsPrompt;
1743 }
1744
1745 /**
1746 * @return The application id string
1747 */
1748 String getAppId() {
1749 return mAppId;
1750 }
1751
1752 /**
1753 * Set the application id string
1754 * @param id
1755 */
1756 void setAppId(String id) {
1757 mAppId = id;
1758 }
1759
Michael Kolbe28b3472011-08-04 16:54:31 -07001760 boolean closeOnBack() {
1761 return mCloseOnBack;
1762 }
1763
1764 void setCloseOnBack(boolean close) {
1765 mCloseOnBack = close;
1766 }
1767
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001768 boolean getDerivedFromIntent() {
1769 return mDerivedFromIntent;
1770 }
1771
1772 void setDerivedFromIntent(boolean derived) {
1773 mDerivedFromIntent = derived;
1774 }
1775
Grace Kloba22ac16e2009-10-07 18:00:23 -07001776 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001777 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001778 }
1779
Tarun Nainani8eb00912014-07-17 12:28:32 -07001780
1781 protected void onPageFinished() {
1782 mPageFinished = true;
1783 }
1784
1785 public boolean getPageFinishedStatus() {
1786 return mPageFinished;
1787 }
1788
John Reck49a603c2011-03-03 09:33:05 -08001789 String getOriginalUrl() {
Vivek Sekhar361065a2014-11-25 15:34:35 -08001790 if (mMainView != null)
1791 return mMainView.getOriginalUrl();
John Reckdb22ec42011-06-29 11:31:24 -07001792 if (mCurrentState.mOriginalUrl == null) {
1793 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001794 }
John Reckdb22ec42011-06-29 11:31:24 -07001795 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001796 }
1797
Grace Kloba22ac16e2009-10-07 18:00:23 -07001798 /**
John Reck30c714c2010-12-16 17:30:34 -08001799 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001800 */
1801 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001802 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001803 }
1804
1805 /**
John Reck30c714c2010-12-16 17:30:34 -08001806 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001807 */
1808 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001809 if (mCurrentState.mFavicon != null) {
1810 return mCurrentState.mFavicon;
1811 }
1812 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001813 }
1814
John Recke969cc52010-12-21 17:24:43 -08001815 public boolean isBookmarkedSite() {
1816 return mCurrentState.mIsBookmarkedSite;
1817 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001818
Grace Kloba22ac16e2009-10-07 18:00:23 -07001819 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001820 * Sets the security state, clears the SSL certificate error and informs
1821 * the controller.
1822 */
Steve Block2466eff2011-10-03 15:33:09 +01001823 private void setSecurityState(SecurityState securityState) {
1824 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001825 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001826 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001827 }
1828
1829 /**
Steve Block2466eff2011-10-03 15:33:09 +01001830 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001831 */
Steve Block2466eff2011-10-03 15:33:09 +01001832 SecurityState getSecurityState() {
1833 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001834 }
1835
Steve Block08a6f0c2011-10-06 12:12:53 +01001836 /**
1837 * Gets the SSL certificate error, if any, for the page's main resource.
1838 * This is only non-null when the security state is
1839 * SECURITY_STATE_BAD_CERTIFICATE.
1840 */
1841 SslError getSslCertificateError() {
1842 return mCurrentState.mSslCertificateError;
1843 }
1844
John Reck30c714c2010-12-16 17:30:34 -08001845 int getLoadProgress() {
1846 if (mInPageLoad) {
1847 return mPageLoadProgress;
1848 }
1849 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001850 }
1851
1852 /**
1853 * @return TRUE if onPageStarted is called while onPageFinished is not
1854 * called yet.
1855 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001856 boolean inPageLoad() {
1857 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001858 }
1859
Grace Kloba22ac16e2009-10-07 18:00:23 -07001860 /**
John Reck1cf4b792011-07-26 10:22:22 -07001861 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001862 */
John Reck1cf4b792011-07-26 10:22:22 -07001863 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001864 // If the WebView is null it means we ran low on memory and we already
1865 // stored the saved state in mSavedState.
1866 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001867 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001868 }
John Reck6c2e2f32011-08-22 13:41:23 -07001869
1870 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001871 return null;
John Reck24f18262011-06-17 14:47:20 -07001872 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001873
1874 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001875 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1876 if (savedList == null || savedList.getSize() == 0) {
1877 Log.w(LOGTAG, "Failed to save back/forward list for "
1878 + mCurrentState.mUrl);
1879 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001880
Michael Kolbc831b632011-05-11 09:30:34 -07001881 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001882 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1883 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001884 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001885 if (mAppId != null) {
1886 mSavedState.putString(APPID, mAppId);
1887 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001888 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001889 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001890 if (mParent != null) {
1891 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001892 }
John Reckb0a86db2011-05-24 14:05:58 -07001893 mSavedState.putBoolean(USERAGENT,
1894 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001895 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001896 }
1897
1898 /*
1899 * Restore the state of the tab.
1900 */
John Reck1cf4b792011-07-26 10:22:22 -07001901 private void restoreState(Bundle b) {
1902 mSavedState = b;
1903 if (mSavedState == null) {
1904 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001905 }
1906 // Restore the internal state even if the WebView fails to restore.
1907 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001908 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001909 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001910 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001911 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001912 String url = b.getString(CURRURL);
1913 String title = b.getString(CURRTITLE);
1914 boolean incognito = b.getBoolean(INCOGNITO);
1915 mCurrentState = new PageState(mContext, incognito, url, null);
1916 mCurrentState.mTitle = title;
1917 synchronized (Tab.this) {
1918 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001919 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001920 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001921 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001922 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001923
John Reck8b9bb8b2012-03-08 13:19:40 -08001924 private void restoreUserAgent() {
1925 if (mMainView == null || mSavedState == null) {
1926 return;
1927 }
1928 if (mSavedState.getBoolean(USERAGENT)
1929 != mSettings.hasDesktopUseragent(mMainView)) {
1930 mSettings.toggleDesktopUseragent(mMainView);
1931 }
1932 }
1933
Leon Scroggins1961ed22010-12-07 15:22:21 -05001934 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001935 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001936 }
1937
John Recke969cc52010-12-21 17:24:43 -08001938 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1939 = new DataController.OnQueryUrlIsBookmark() {
1940 @Override
1941 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1942 if (mCurrentState.mUrl.equals(url)) {
1943 mCurrentState.mIsBookmarkedSite = isBookmark;
1944 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1945 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001946 }
John Recke969cc52010-12-21 17:24:43 -08001947 };
Michael Kolb1acef692011-03-08 14:12:06 -08001948
Michael Kolbeb95db42011-03-03 10:38:40 -08001949 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001950 synchronized (Tab.this) {
1951 return mCapture;
1952 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001953 }
1954
John Reck541f55a2011-06-07 16:34:43 -07001955 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001956 return false;
1957 }
1958
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001959 private static class SaveCallback implements ValueCallback<String> {
1960 boolean onReceiveValueCalled = false;
1961 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001962
1963 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001964 public void onReceiveValue(String path) {
1965 this.onReceiveValueCalled = true;
1966 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001967 synchronized (this) {
1968 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001969 }
John Reck541f55a2011-06-07 16:34:43 -07001970 }
John Reck68234a92012-04-19 15:27:12 -07001971
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001972 public String getPath() {
1973 return mPath;
1974 }
John Reck68234a92012-04-19 15:27:12 -07001975 }
1976
1977 /**
1978 * Must be called on the UI thread
1979 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001980 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001981 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001982 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001983 ContentValues values = new ContentValues();
1984 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1985 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001986 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001987 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
1988 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07001989 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07001990 return values;
John Reck541f55a2011-06-07 16:34:43 -07001991 }
1992
John Reck68234a92012-04-19 15:27:12 -07001993 /**
1994 * Probably want to call this on a background thread
1995 */
1996 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001997 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001998 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001999 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002000 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002001 try {
John Reck68234a92012-04-19 15:27:12 -07002002 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002003 web.saveViewState(filename, callback);
2004 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002005 }
John Reck68234a92012-04-19 15:27:12 -07002006 } catch (Exception e) {
2007 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002008 String path = callback.getPath();
2009 if (path != null) {
2010 File file = mContext.getFileStreamPath(path);
2011 if (file.exists() && !file.delete()) {
2012 file.deleteOnExit();
2013 }
John Reck68234a92012-04-19 15:27:12 -07002014 }
2015 return false;
2016 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002017
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002018 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002019 // could be that saving of file failed
2020 if (path == null) {
2021 return false;
2022 }
2023
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002024 File savedFile = new File(path);
2025 if (!savedFile.exists()) {
2026 return false;
John Reck68234a92012-04-19 15:27:12 -07002027 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002028 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2029 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002030 return true;
2031 }
2032
John Reck8cc92352011-07-06 17:41:52 -07002033 public byte[] compressBitmap(Bitmap bitmap) {
2034 if (bitmap == null) {
2035 return null;
2036 }
2037 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2038 bitmap.compress(CompressFormat.PNG, 100, stream);
2039 return stream.toByteArray();
2040 }
2041
John Reck26b18322011-06-21 13:08:58 -07002042 public void loadUrl(String url, Map<String, String> headers) {
2043 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002044 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002045 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002046 mMainView.loadUrl(url, headers);
2047 }
2048 }
2049
John Reck38b39652012-06-05 09:22:59 -07002050 public void disableUrlOverridingForLoad() {
2051 mDisableOverrideUrlLoading = true;
2052 }
2053
Michael Kolb9ef259a2011-07-12 15:33:08 -07002054 protected void capture() {
2055 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002056 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2057 return;
2058 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002059
2060 mMainView
2061 .getContentBitmapAsync(
2062 (float) mCaptureWidth / mMainView.getWidth(),
2063 new Rect(),
2064 new ValueCallback<Bitmap>() {
2065 @Override
2066 public void onReceiveValue(Bitmap bitmap) {
2067 onCaptureCallback(bitmap);
2068 }});
2069 }
2070
2071 private void onCaptureCallback(Bitmap bitmap) {
2072 if (mCapture == null || bitmap == null)
2073 return;
2074
Michael Kolb9ef259a2011-07-12 15:33:08 -07002075 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002076 mCapture.eraseColor(Color.WHITE);
2077 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002078
Michael Kolba3194d02011-09-07 11:23:51 -07002079 // manually anti-alias the edges for the tilt
2080 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2081 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2082 mCapture.getHeight(), sAlphaPaint);
2083 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2084 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2085 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002086 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002087 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002088 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002089 TabControl tc = mWebViewController.getTabControl();
2090 if (tc != null) {
2091 OnThumbnailUpdatedListener updateListener
2092 = tc.getOnThumbnailUpdatedListener();
2093 if (updateListener != null) {
2094 updateListener.onThumbnailUpdated(this);
2095 }
2096 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002097 }
2098
2099 @Override
2100 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002101 postCapture();
2102 }
2103
2104 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002105 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2106 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2107 }
2108 }
2109
John Reckef654f12011-07-12 16:42:08 -07002110 public boolean canGoBack() {
2111 return mMainView != null ? mMainView.canGoBack() : false;
2112 }
2113
2114 public boolean canGoForward() {
2115 return mMainView != null ? mMainView.canGoForward() : false;
2116 }
2117
2118 public void goBack() {
2119 if (mMainView != null) {
2120 mMainView.goBack();
2121 }
2122 }
2123
2124 public void goForward() {
2125 if (mMainView != null) {
2126 mMainView.goForward();
2127 }
2128 }
2129
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002130 /**
2131 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2132 * to be added to the stack.
2133 *
2134 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2135 * not appear in the back stack.
2136 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002137 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2138 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002139 }
2140
John Reck1cf4b792011-07-26 10:22:22 -07002141 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002142 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002143 }
2144
2145 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002146 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002147 }
2148
John Reck4eadc342011-10-31 14:04:10 -07002149 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002150 synchronized (Tab.this) {
2151 if (mCapture == null) {
2152 return;
2153 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002154 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002155 try {
2156 mCapture.copyPixelsFromBuffer(buffer);
2157 } catch (RuntimeException rex) {
2158 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2159 + buffer.capacity() + " blob: " + blob.length
2160 + "capture: " + mCapture.getByteCount());
2161 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002162 }
John Reck1cf4b792011-07-26 10:22:22 -07002163 }
2164 }
2165
John Reck52be4782011-08-26 15:37:29 -07002166 @Override
2167 public String toString() {
2168 StringBuilder builder = new StringBuilder(100);
2169 builder.append(mId);
2170 builder.append(") has parent: ");
2171 if (getParent() != null) {
2172 builder.append("true[");
2173 builder.append(getParent().getId());
2174 builder.append("]");
2175 } else {
2176 builder.append("false");
2177 }
2178 builder.append(", incog: ");
2179 builder.append(isPrivateBrowsingEnabled());
2180 if (!isPrivateBrowsingEnabled()) {
2181 builder.append(", title: ");
2182 builder.append(getTitle());
2183 builder.append(", url: ");
2184 builder.append(getUrl());
2185 }
2186 return builder.toString();
2187 }
2188
Steve Block4895b012011-10-03 16:26:46 +01002189 private void handleProceededAfterSslError(SslError error) {
2190 if (error.getUrl().equals(mCurrentState.mUrl)) {
2191 // The security state should currently be SECURITY_STATE_SECURE.
2192 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002193 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002194 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002195 // The page's main resource is secure and this error is for a
2196 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002197 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2198 }
2199 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002200}