blob: c4260dad67604fe5e4791cf4296c37f2c54fdeab [file] [log] [blame]
Grace Kloba22ac16e2009-10-07 18:00:23 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Grace Kloba22ac16e2009-10-07 18:00:23 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
21import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070022import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080023import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.DialogInterface.OnCancelListener;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070027import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070028import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070029import android.graphics.BitmapFactory;
30import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070032import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070033import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070034import android.graphics.PorterDuff;
35import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070036import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070037import android.net.Uri;
38import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070039import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070040import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070041import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000042import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070043import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070044import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070045import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070046import android.util.Log;
47import android.view.KeyEvent;
48import android.view.LayoutInflater;
49import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070050import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080051import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070054import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080055import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070056import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057import android.webkit.WebChromeClient.CustomViewCallback;
58import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000059import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000060import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import android.widget.FrameLayout;
62import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070063
Bijan Amirzada41242f22014-03-21 12:12:18 -070064import com.android.browser.TabControl.OnThumbnailUpdatedListener;
65import com.android.browser.homepages.HomeProvider;
66import com.android.browser.mynavigation.MyNavigationUtil;
67import com.android.browser.provider.MyNavigationProvider;
68import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069
70import org.codeaurora.swe.BrowserDownloadListener;
71import org.codeaurora.swe.ClientCertRequestHandler;
72import org.codeaurora.swe.HttpAuthHandler;
73import org.codeaurora.swe.SslErrorHandler;
74import org.codeaurora.swe.WebBackForwardList;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080075import org.codeaurora.swe.WebChromeClient;
76import org.codeaurora.swe.WebHistoryItem;
77import org.codeaurora.swe.WebView;
78import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070079import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080080import org.codeaurora.swe.WebViewClient;
81
John Reck541f55a2011-06-07 16:34:43 -070082import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070083import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080084import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070085import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070086import java.util.LinkedList;
87import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070088import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070089import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010090import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080091import java.sql.Timestamp;
92import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070093
Grace Kloba22ac16e2009-10-07 18:00:23 -070094/**
95 * Class for maintaining Tabs with a main WebView and a subwindow.
96 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070097class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070098
Grace Kloba22ac16e2009-10-07 18:00:23 -070099 // Log Tag
100 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700101 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000102 // Special case the logtag for messages for the Console to make it easier to
103 // filter them and match the logtag used for these messages in older versions
104 // of the browser.
105 private static final String CONSOLE_LOGTAG = "browser";
106
Michael Kolb9ef259a2011-07-12 15:33:08 -0700107 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800108 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700109 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700110
John Reck1cf4b792011-07-26 10:22:22 -0700111 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800112 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700113
Michael Kolba3194d02011-09-07 11:23:51 -0700114 private static Paint sAlphaPaint = new Paint();
115 static {
116 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
117 sAlphaPaint.setColor(Color.TRANSPARENT);
118 }
119
Steve Block2466eff2011-10-03 15:33:09 +0100120 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100121 // The page's main resource does not use SSL. Note that we use this
122 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100123 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100124 // The page's main resource uses SSL and the certificate is good. The
125 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100126 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100127 // The page's main resource uses SSL and the certificate is good, but
128 // some sub-resources either do not use SSL or have problems with their
129 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100130 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100131 // The page's main resource uses SSL but there is a problem with its
132 // certificate.
133 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800134 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700135
Michael Kolb14612442011-06-24 13:06:29 -0700136 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700137 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700138
Michael Kolbc831b632011-05-11 09:30:34 -0700139 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700140 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700141
Grace Kloba22ac16e2009-10-07 18:00:23 -0700142 // The Geolocation permissions prompt
143 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
144 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800145 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700146 // Main WebView
147 private WebView mMainView;
148 // Subwindow container
149 private View mSubViewContainer;
150 // Subwindow WebView
151 private WebView mSubView;
152 // Saved bundle for when we are running low on memory. It contains the
153 // information needed to restore the WebView if the user goes back to the
154 // tab.
155 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700156 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
157 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700158 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700159 // Tab that constructed by this Tab. This is used when this Tab is
160 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700161 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700162 // If true, the tab is in the foreground of the current activity.
163 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700164 // If true, the tab is in page loading state (after onPageStarted,
165 // before onPageFinsihed)
166 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700167 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700168 private boolean mDisableOverrideUrlLoading;
Pankaj Garg79878492015-04-01 14:48:21 -0700169 private boolean mFirstVisualPixelPainted = false;
John Reck30c714c2010-12-16 17:30:34 -0800170 // The last reported progress of the current page
171 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000172 // The time the load started, used to find load page time
173 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700174 // Application identifier used to find tabs that another application wants
175 // to reuse.
176 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700177 // flag to indicate if tab should be closed on back
178 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700179 // flag to indicate if the tab was opened from an intent
180 private boolean mDerivedFromIntent = false;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500181 // The listener that gets invoked when a download is started from the
182 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700183 private final BrowserDownloadListener mDownloadListener;
John Recke969cc52010-12-21 17:24:43 -0800184 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700185
186 // AsyncTask for downloading touch icons
187 DownloadTouchIcon mTouchIconLoader;
188
John Reck35e9dd62011-04-25 09:01:54 -0700189 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700190 private int mCaptureWidth;
191 private int mCaptureHeight;
192 private Bitmap mCapture;
193 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700194 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800195 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700196 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800197 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700198
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -0700199 // determine if webview is destroyed to MemoryMonitor
200 private boolean mWebViewDestroyedByMemoryMonitor;
201
202
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100203
John Reck1cf4b792011-07-26 10:22:22 -0700204 private static synchronized Bitmap getDefaultFavicon(Context context) {
205 if (sDefaultFavicon == null) {
206 sDefaultFavicon = BitmapFactory.decodeResource(
Enrico Rosd6efa972014-12-02 19:49:59 -0800207 context.getResources(), R.drawable.ic_deco_favicon_normal);
John Reck1cf4b792011-07-26 10:22:22 -0700208 }
209 return sDefaultFavicon;
210 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800211
John Reck30c714c2010-12-16 17:30:34 -0800212 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700213 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800214 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700215 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800216 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100217 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100218 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
219 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800220 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100221 boolean mIsBookmarkedSite;
222 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800223
224 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700225 mIncognito = incognito;
226 if (mIncognito) {
Vivek Sekhared791da2015-02-22 12:39:05 -0800227 mOriginalUrl = mUrl = "chrome://incognito";
John Reck30c714c2010-12-16 17:30:34 -0800228 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800229 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700230 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800231 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800232 }
Steve Block2466eff2011-10-03 15:33:09 +0100233 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800234 }
235
236 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700237 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700238 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800239 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100240 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800241 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100242 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800243 }
John Reck1cf4b792011-07-26 10:22:22 -0700244 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800245 }
John Reck1cf4b792011-07-26 10:22:22 -0700246
Grace Kloba22ac16e2009-10-07 18:00:23 -0700247 }
248
John Reck30c714c2010-12-16 17:30:34 -0800249 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700250 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800251
Grace Kloba22ac16e2009-10-07 18:00:23 -0700252 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700253 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700254 static final String CURRURL = "currentUrl";
255 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700256 static final String PARENTTAB = "parentTab";
257 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700258 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700259 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700260 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700261
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 // Container class for the next error dialog that needs to be displayed
263 private class ErrorDialog {
264 public final int mTitle;
265 public final String mDescription;
266 public final int mError;
267 ErrorDialog(int title, String desc, int error) {
268 mTitle = title;
269 mDescription = desc;
270 mError = error;
271 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700272 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700273
274 private void processNextError() {
275 if (mQueuedErrors == null) {
276 return;
277 }
278 // The first one is currently displayed so just remove it.
279 mQueuedErrors.removeFirst();
280 if (mQueuedErrors.size() == 0) {
281 mQueuedErrors = null;
282 return;
283 }
284 showError(mQueuedErrors.getFirst());
285 }
286
287 private DialogInterface.OnDismissListener mDialogListener =
288 new DialogInterface.OnDismissListener() {
289 public void onDismiss(DialogInterface d) {
290 processNextError();
291 }
292 };
293 private LinkedList<ErrorDialog> mQueuedErrors;
294
295 private void queueError(int err, String desc) {
296 if (mQueuedErrors == null) {
297 mQueuedErrors = new LinkedList<ErrorDialog>();
298 }
299 for (ErrorDialog d : mQueuedErrors) {
300 if (d.mError == err) {
301 // Already saw a similar error, ignore the new one.
302 return;
303 }
304 }
305 ErrorDialog errDialog = new ErrorDialog(
306 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
307 R.string.browserFrameFileErrorLabel :
308 R.string.browserFrameNetworkErrorLabel,
309 desc, err);
310 mQueuedErrors.addLast(errDialog);
311
312 // Show the dialog now if the queue was empty and it is in foreground
313 if (mQueuedErrors.size() == 1 && mInForeground) {
314 showError(errDialog);
315 }
316 }
317
318 private void showError(ErrorDialog errDialog) {
319 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700320 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700321 .setTitle(errDialog.mTitle)
322 .setMessage(errDialog.mDescription)
323 .setPositiveButton(R.string.ok, null)
324 .create();
325 d.setOnDismissListener(mDialogListener);
326 d.show();
327 }
328 }
329
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800330 protected void replaceCrashView(View view, View container) {
331 if (hasCrashed && (view == mMainView)) {
332 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
333 wrapper.removeAllViewsInLayout();
334 wrapper.addView(view);
335 hasCrashed = false;
336 }
Vivek Sekhar2868b8d2014-12-03 17:22:50 -0800337 mMainView.reload();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800338 }
339
340 protected void showCrashView() {
341 if (hasCrashed) {
342 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
343 Context.LAYOUT_INFLATER_SERVICE);
344 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
345 final FrameLayout wrapper =
346 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
347 wrapper.removeAllViewsInLayout();
348 wrapper.addView(crashLayout);
349 mContainer.requestFocus();
350 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
351 reloadBtn.setOnClickListener(new OnClickListener() {
352 @Override
353 public void onClick(View arg0) {
354 replaceCrashView(mMainView, mContainer);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800355 }
356 });
357 }
358 }
359
Pankaj Garg18186a92015-03-31 14:59:33 -0700360 public void setNetworkAvailable(boolean networkUp) {
361 if (networkUp && mReceivedError && (mMainView != null)) {
362 mMainView.reload();
363 }
364 }
365
Grace Kloba22ac16e2009-10-07 18:00:23 -0700366 // -------------------------------------------------------------------------
367 // WebViewClient implementation for the main WebView
368 // -------------------------------------------------------------------------
369
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800370 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500371 private Message mDontResend;
372 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700373
374 private boolean providersDiffer(String url, String otherUrl) {
375 Uri uri1 = Uri.parse(url);
376 Uri uri2 = Uri.parse(otherUrl);
377 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
378 }
379
Grace Kloba22ac16e2009-10-07 18:00:23 -0700380 @Override
381 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700383 mPageFinished = false;
Pankaj Garg79878492015-04-01 14:48:21 -0700384 mFirstVisualPixelPainted = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800385 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700386 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700387 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700388 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800389 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000390 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700391
392 // If we start a touch icon load and then load a new page, we don't
393 // want to cancel the current touch icon loader. But, we do want to
394 // create a new one when the touch icon url is known.
395 if (mTouchIconLoader != null) {
396 mTouchIconLoader.mTab = null;
397 mTouchIconLoader = null;
398 }
399
Panos Thomasb298aad2014-10-22 12:24:21 -0700400 // Loading a new page voids any ongoing Geolocation permission
401 // requests.
402 if (mGeolocationPermissionsPrompt != null) {
403 mGeolocationPermissionsPrompt.dismiss();
404 }
405
Grace Kloba22ac16e2009-10-07 18:00:23 -0700406 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800407 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500408
John Recke969cc52010-12-21 17:24:43 -0800409 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700410 }
411
412 @Override
413 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700414 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800415 if (!isPrivateBrowsingEnabled()) {
416 LogTag.logPageFinishedLoading(
417 url, SystemClock.uptimeMillis() - mLoadStartTime);
418 }
John Reck1cf4b792011-07-26 10:22:22 -0700419 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800420 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700421 }
422
Pankaj Garg79878492015-04-01 14:48:21 -0700423 @Override
424 public void onFirstVisualPixel(WebView view) {
425 mFirstVisualPixelPainted = true;
426 }
427
Grace Kloba22ac16e2009-10-07 18:00:23 -0700428 // return true if want to hijack the url to let another app to handle it
429 @Override
430 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700431 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800432 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
433 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700434 } else {
435 return false;
436 }
437 }
438
Vivek Sekharb991edb2014-12-17 18:18:07 -0800439 @Override
440 public boolean shouldDownloadFavicon(WebView view, String url) {
441 return true;
442 }
443
Grace Kloba22ac16e2009-10-07 18:00:23 -0700444 /**
Steve Block2466eff2011-10-03 15:33:09 +0100445 * Updates the security state. This method is called when we discover
446 * another resource to be loaded for this page (for example,
447 * javascript). While we update the security state, we do not update
448 * the lock icon until we are done loading, as it is slightly more
449 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700450 */
451 @Override
452 public void onLoadResource(WebView view, String url) {
453 if (url != null && url.length() > 0) {
454 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100455 // to update the security state:
456 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
457 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700458 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
459 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100460 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700461 }
462 }
463 }
464 }
465
466 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700467 * Show a dialog informing the user of the network error reported by
468 * WebCore if it is in the foreground.
469 */
470 @Override
471 public void onReceivedError(WebView view, int errorCode,
472 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800473 // Used for the syncCurrentState to use
474 // the failing url instead of using webview url
475 mReceivedError = true;
476
Grace Kloba22ac16e2009-10-07 18:00:23 -0700477 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
478 errorCode != WebViewClient.ERROR_CONNECT &&
479 errorCode != WebViewClient.ERROR_BAD_URL &&
480 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
481 errorCode != WebViewClient.ERROR_FILE) {
482 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500483
Selim Gurun3da06b82011-10-10 13:58:12 -0700484 // Don't log URLs when in private browsing mode
485 if (!isPrivateBrowsingEnabled()) {
486 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500487 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700488 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500489 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700490 }
491
492 /**
493 * Check with the user if it is ok to resend POST data as the page they
494 * are trying to navigate to is the result of a POST.
495 */
496 @Override
497 public void onFormResubmission(WebView view, final Message dontResend,
498 final Message resend) {
499 if (!mInForeground) {
500 dontResend.sendToTarget();
501 return;
502 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500503 if (mDontResend != null) {
504 Log.w(LOGTAG, "onFormResubmission should not be called again "
505 + "while dialog is still up");
506 dontResend.sendToTarget();
507 return;
508 }
509 mDontResend = dontResend;
510 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700511 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700512 R.string.browserFrameFormResubmitLabel).setMessage(
513 R.string.browserFrameFormResubmitMessage)
514 .setPositiveButton(R.string.ok,
515 new DialogInterface.OnClickListener() {
516 public void onClick(DialogInterface dialog,
517 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500518 if (mResend != null) {
519 mResend.sendToTarget();
520 mResend = null;
521 mDontResend = null;
522 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700523 }
524 }).setNegativeButton(R.string.cancel,
525 new DialogInterface.OnClickListener() {
526 public void onClick(DialogInterface dialog,
527 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500528 if (mDontResend != null) {
529 mDontResend.sendToTarget();
530 mResend = null;
531 mDontResend = null;
532 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700533 }
534 }).setOnCancelListener(new OnCancelListener() {
535 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500536 if (mDontResend != null) {
537 mDontResend.sendToTarget();
538 mResend = null;
539 mDontResend = null;
540 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700541 }
542 }).show();
543 }
544
545 /**
546 * Insert the url into the visited history database.
547 * @param url The url to be inserted.
548 * @param isReload True if this url is being reloaded.
549 * FIXME: Not sure what to do when reloading the page.
550 */
551 @Override
552 public void doUpdateVisitedHistory(WebView view, String url,
553 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800554 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700555 }
556
557 /**
558 * Displays SSL error(s) dialog to the user.
559 */
560 @Override
561 public void onReceivedSslError(final WebView view,
562 final SslErrorHandler handler, final SslError error) {
563 if (!mInForeground) {
564 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100565 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700566 return;
567 }
John Reck35e9dd62011-04-25 09:01:54 -0700568 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700569 new AlertDialog.Builder(mContext)
570 .setTitle(R.string.security_warning)
571 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200572 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700573 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700574 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700575 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700576 public void onClick(DialogInterface dialog,
577 int whichButton) {
578 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100579 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580 }
John Reckcb28b2c2011-08-26 17:39:44 -0700581 })
582 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700583 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700584 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700585 public void onClick(DialogInterface dialog,
586 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700587 mWebViewController.showSslCertificateOnError(
588 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700589 }
John Reckcb28b2c2011-08-26 17:39:44 -0700590 })
591 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700592 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700593 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700594 public void onClick(DialogInterface dialog,
595 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800596 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700597 }
John Reckcb28b2c2011-08-26 17:39:44 -0700598 })
599 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700600 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700601 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700602 public void onCancel(DialogInterface dialog) {
603 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100604 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800605 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700606 }
John Reckcb28b2c2011-08-26 17:39:44 -0700607 })
608 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700609 } else {
610 handler.proceed();
611 }
612 }
613
614 /**
Steve Block4895b012011-10-03 16:26:46 +0100615 * Called when an SSL error occurred while loading a resource, but the
616 * WebView but chose to proceed anyway based on a decision retained
617 * from a previous response to onReceivedSslError(). We update our
618 * security state to reflect this.
619 */
620 @Override
621 public void onProceededAfterSslError(WebView view, SslError error) {
622 handleProceededAfterSslError(error);
623 }
624
625 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700626 * Displays client certificate request to the user.
627 */
628 @Override
629 public void onReceivedClientCertRequest(final WebView view,
630 final ClientCertRequestHandler handler, final String host_and_port) {
631 if (!mInForeground) {
632 handler.ignore();
633 return;
634 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700635 int colon = host_and_port.lastIndexOf(':');
636 String host;
637 int port;
638 if (colon == -1) {
639 host = host_and_port;
640 port = -1;
641 } else {
642 String portString = host_and_port.substring(colon + 1);
643 try {
644 port = Integer.parseInt(portString);
645 host = host_and_port.substring(0, colon);
646 } catch (NumberFormatException e) {
647 host = host_and_port;
648 port = -1;
649 }
650 }
Michael Kolb14612442011-06-24 13:06:29 -0700651 KeyChain.choosePrivateKeyAlias(
652 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700653 @Override public void alias(String alias) {
654 if (alias == null) {
655 handler.cancel();
656 return;
657 }
Michael Kolb14612442011-06-24 13:06:29 -0700658 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700659 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700660 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700661 }
662
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800663 @Override
664 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
665 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700666 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
667 hasCrashed = true;
668 showCrashView();
669 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800670 }
671
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700672 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700673 * Handles an HTTP authentication request.
674 *
675 * @param handler The authentication handler
676 * @param host The host
677 * @param realm The realm
678 */
679 @Override
680 public void onReceivedHttpAuthRequest(WebView view,
681 final HttpAuthHandler handler, final String host,
682 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700683 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700684 }
685
686 @Override
John Reck438bf462011-01-12 18:11:46 -0800687 public WebResourceResponse shouldInterceptRequest(WebView view,
688 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800689 //intercept if opening a new incognito tab - show the incognito welcome page
Vivek Sekhared791da2015-02-22 12:39:05 -0800690 if (url.startsWith("chrome://incognito")) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800691 Resources resourceHandle = mContext.getResources();
692 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700693 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800694 return new WebResourceResponse("text/html", "utf8", inStream);
695 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800696 WebResourceResponse res;
697 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
698 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
699 } else {
700 res = HomeProvider.shouldInterceptRequest(mContext, url);
701 }
John Reck438bf462011-01-12 18:11:46 -0800702 return res;
703 }
704
705 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700706 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
707 if (!mInForeground) {
708 return false;
709 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700710 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700711 }
712
713 @Override
714 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700716 return;
717 }
John Reck997b1b72012-04-19 18:08:25 -0700718 if (!mWebViewController.onUnhandledKeyEvent(event)) {
719 super.onUnhandledKeyEvent(view, event);
720 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700721 }
Vivek Sekhared791da2015-02-22 12:39:05 -0800722 //SWE-download-file
723 @Override
724 public void onDownloadStart(String url,
725 String userAgent,
726 String contentDisposition,
727 String mimeType,
728 long contentLength) {
729 if (mDownloadListener != null) {
730 if (mDownloadListener instanceof BrowserDownloadListener) {
731 ((BrowserDownloadListener) mDownloadListener).onDownloadStart(url,
732 userAgent, contentDisposition, mimeType, contentLength);
733 } else {
734 mDownloadListener.onDownloadStart(url, userAgent,
735 contentDisposition, mimeType, contentLength);
736 }
737 }
738 }
739 //SWE-download-file
Grace Kloba22ac16e2009-10-07 18:00:23 -0700740 };
741
John Reck1cf4b792011-07-26 10:22:22 -0700742 private void syncCurrentState(WebView view, String url) {
743 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800744
745 if (mReceivedError) {
746 mCurrentState.mUrl = url;
747 mCurrentState.mOriginalUrl = url;
748 } else {
749 mCurrentState.mUrl = view.getUrl();
750 mCurrentState.mOriginalUrl = view.getOriginalUrl();
751 mCurrentState.mFavicon = view.getFavicon();
752 }
753
John Reck1cf4b792011-07-26 10:22:22 -0700754 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700755 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700756 }
John Reck1cf4b792011-07-26 10:22:22 -0700757 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800758
759
John Reck1cf4b792011-07-26 10:22:22 -0700760 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
761 // In case we stop when loading an HTTPS page from an HTTP page
762 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100763 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100764 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700765 }
John Reck502a3532011-08-16 14:21:46 -0700766 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700767 }
768
Tarun Nainani8eb00912014-07-17 12:28:32 -0700769
770 public boolean isTabFullScreen() {
771 return mFullScreen;
772 }
773
Vivek Sekharf96064b2014-07-28 16:32:34 -0700774 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700775 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700776 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700777 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700778 }
779
Sudheer Koganti24766882014-10-02 10:58:09 -0700780 public boolean exitFullscreen() {
781 if (mFullScreen) {
782 Controller controller = (Controller)mWebViewController;
783 controller.getUi().showFullscreen(false);
784 if (getWebView() != null)
785 getWebView().exitFullscreen();
786 mFullScreen = false;
787 return true;
788 }
789 return false;
790 }
791
792
793
794
Grace Kloba22ac16e2009-10-07 18:00:23 -0700795 // -------------------------------------------------------------------------
796 // WebChromeClient implementation for the main WebView
797 // -------------------------------------------------------------------------
798
799 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
800 // Helper method to create a new tab or sub window.
801 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700802 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700803 }
804
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700805 private void createWindow(final boolean dialog, final Message msg, final String url,
806 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700807 WebView.WebViewTransport transport =
808 (WebView.WebViewTransport) msg.obj;
809 if (dialog) {
810 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700811 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700812 transport.setWebView(mSubView);
813 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700814 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700815 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700816 // This is special case for rendering links on a webpage in
817 // a new tab. If opener is suppressed, the WebContents created
818 // by the content layer are not fully initialized. This check
819 // will prevent content layer from overriding WebContents
820 // created by new tab with the uninitialized instance.
821 if (!opener_suppressed) {
822 transport.setWebView(newTab.getWebView());
823 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700824 }
825 msg.sendToTarget();
826 }
827
828 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700829 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
830 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700831 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700832 }
833 }
834
835 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700836 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
837 float contentOffsetYPix,
838 float overdrawBottomHeightPix) {
839 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700840 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700841 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700842 }
843 }
844
845 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700846 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700847 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700848 }
849
850 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700851 public boolean onCreateWindow(WebView view, final boolean dialog,
852 final boolean userGesture, final Message resultMsg) {
853 // only allow new window or sub window for the foreground case
854 if (!mInForeground) {
855 return false;
856 }
857 // Short-circuit if we can't create any more tabs or sub windows.
858 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700859 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700860 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200861 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700862 .setMessage(R.string.too_many_subwindows_dialog_message)
863 .setPositiveButton(R.string.ok, null)
864 .show();
865 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700866 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700867 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700868 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200869 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700870 .setMessage(R.string.too_many_windows_dialog_message)
871 .setPositiveButton(R.string.ok, null)
872 .show();
873 return false;
874 }
875
876 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800877 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700878 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700879 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700880 createWindow(dialog, resultMsg, windowParams.mURL, true);
881 // This is special case for rendering links on a webpage in
882 // a new tab. If opener is suppressed, the WebContents created
883 // by the content layer are not fully initialized. Returning false
884 // will prevent content layer from overriding WebContents
885 // created by new tab with the uninitialized instance.
886 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700887 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700888
889 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700890 return true;
891 }
892
893 // Allow the popup and create the appropriate window.
894 final AlertDialog.OnClickListener allowListener =
895 new AlertDialog.OnClickListener() {
896 public void onClick(DialogInterface d,
897 int which) {
898 createWindow(dialog, resultMsg);
899 }
900 };
901
902 // Block the popup by returning a null WebView.
903 final AlertDialog.OnClickListener blockListener =
904 new AlertDialog.OnClickListener() {
905 public void onClick(DialogInterface d, int which) {
906 resultMsg.sendToTarget();
907 }
908 };
909
910 // Build a confirmation dialog to display to the user.
911 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700912 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200913 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700914 .setMessage(R.string.popup_window_attempt)
915 .setPositiveButton(R.string.allow, allowListener)
916 .setNegativeButton(R.string.block, blockListener)
917 .setCancelable(false)
918 .create();
919
920 // Show the confirmation dialog.
921 d.show();
922 return true;
923 }
924
925 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500926 public void onRequestFocus(WebView view) {
927 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700928 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500929 }
930 }
931
932 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700933 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700934 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700935 // JavaScript can only close popup window.
936 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700937 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700938 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700939 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700940 }
941 }
942
943 @Override
944 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800945 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800946 if (newProgress == 100) {
947 mInPageLoad = false;
948 }
John Reck30c714c2010-12-16 17:30:34 -0800949 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700950 if (mUpdateThumbnail && newProgress == 100) {
951 mUpdateThumbnail = false;
952 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700953 }
954
955 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500956 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800957 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700958 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700959 }
960
961 @Override
962 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800963 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700964 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700965 }
966
967 @Override
968 public void onReceivedTouchIconUrl(WebView view, String url,
969 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700970 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400971 // Let precomposed icons take precedence over non-composed
972 // icons.
973 if (precomposed && mTouchIconLoader != null) {
974 mTouchIconLoader.cancel(false);
975 mTouchIconLoader = null;
976 }
977 // Have only one async task at a time.
978 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700979 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700980 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400981 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700982 }
983 }
984
985 @Override
986 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800987 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700988 Activity activity = mWebViewController.getActivity();
989 if (activity != null) {
990 onShowCustomView(view, activity.getRequestedOrientation(), callback);
991 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400992 }
993
994 @Override
995 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800996 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700997 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400998 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700999 }
1000
1001 @Override
1002 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -07001003 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001004 }
1005
1006 /**
1007 * The origin has exceeded its database quota.
1008 * @param url the URL that exceeded the quota
1009 * @param databaseIdentifier the identifier of the database on which the
1010 * transaction that caused the quota overflow was run
1011 * @param currentQuota the current quota for the origin.
1012 * @param estimatedSize the estimated size of the database.
1013 * @param totalUsedQuota is the sum of all origins' quota.
1014 * @param quotaUpdater The callback to run when a decision to allow or
1015 * deny quota has been made. Don't forget to call this!
1016 */
1017 @Override
1018 public void onExceededDatabaseQuota(String url,
1019 String databaseIdentifier, long currentQuota, long estimatedSize,
1020 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001021 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001022 .onExceededDatabaseQuota(url, databaseIdentifier,
1023 currentQuota, estimatedSize, totalUsedQuota,
1024 quotaUpdater);
1025 }
1026
1027 /**
1028 * The Application Cache has exceeded its max size.
1029 * @param spaceNeeded is the amount of disk space that would be needed
1030 * in order for the last appcache operation to succeed.
1031 * @param totalUsedQuota is the sum of all origins' quota.
1032 * @param quotaUpdater A callback to inform the WebCore thread that a
1033 * new app cache size is available. This callback must always
1034 * be executed at some point to ensure that the sleeping
1035 * WebCore thread is woken up.
1036 */
1037 @Override
1038 public void onReachedMaxAppCacheSize(long spaceNeeded,
1039 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001040 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001041 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1042 quotaUpdater);
1043 }
1044
1045 /**
1046 * Instructs the browser to show a prompt to ask the user to set the
1047 * Geolocation permission state for the specified origin.
1048 * @param origin The origin for which Geolocation permissions are
1049 * requested.
1050 * @param callback The callback to call once the user has set the
1051 * Geolocation permission state.
1052 */
1053 @Override
1054 public void onGeolocationPermissionsShowPrompt(String origin,
1055 GeolocationPermissions.Callback callback) {
1056 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001057 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001058 }
1059 }
1060
1061 /**
1062 * Instructs the browser to hide the Geolocation permissions prompt.
1063 */
1064 @Override
1065 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001066 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001067 mGeolocationPermissionsPrompt.hide();
1068 }
1069 }
1070
Ben Murdoch65acc352009-11-19 18:16:04 +00001071 /* Adds a JavaScript error message to the system log and if the JS
1072 * console is enabled in the about:debug options, to that console
1073 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001074 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001075 */
1076 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001077 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Jeff Hamilton47654f42010-09-07 09:57:51 -05001078 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001079 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001080
Ben Murdochc42addf2010-01-28 15:19:59 +00001081 String message = "Console: " + consoleMessage.message() + " "
1082 + consoleMessage.sourceId() + ":"
1083 + consoleMessage.lineNumber();
1084
1085 switch (consoleMessage.messageLevel()) {
1086 case TIP:
1087 Log.v(CONSOLE_LOGTAG, message);
1088 break;
1089 case LOG:
1090 Log.i(CONSOLE_LOGTAG, message);
1091 break;
1092 case WARNING:
1093 Log.w(CONSOLE_LOGTAG, message);
1094 break;
1095 case ERROR:
1096 Log.e(CONSOLE_LOGTAG, message);
1097 break;
1098 case DEBUG:
1099 Log.d(CONSOLE_LOGTAG, message);
1100 break;
1101 }
1102
1103 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001104 }
1105
1106 /**
1107 * Ask the browser for an icon to represent a <video> element.
1108 * This icon will be used if the Web page did not specify a poster attribute.
1109 * @return Bitmap The icon or null if no such icon is available.
1110 */
1111 @Override
1112 public Bitmap getDefaultVideoPoster() {
1113 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001114 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001115 }
1116 return null;
1117 }
1118
1119 /**
1120 * Ask the host application for a custom progress view to show while
1121 * a <video> is loading.
1122 * @return View The progress view.
1123 */
1124 @Override
1125 public View getVideoLoadingProgressView() {
1126 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001127 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001128 }
1129 return null;
1130 }
1131
1132 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001133 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001134 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001135 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001136 } else {
1137 uploadMsg.onReceiveValue(null);
1138 }
1139 }
1140
Vivek Sekharb54614f2014-05-01 19:03:37 -07001141 @Override
1142 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1143 boolean capture) {
1144 if (mInForeground) {
1145 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1146 } else {
1147 uploadFilePaths.onReceiveValue(null);
1148 }
1149 }
1150
Grace Kloba22ac16e2009-10-07 18:00:23 -07001151 /**
1152 * Deliver a list of already-visited URLs
1153 */
1154 @Override
1155 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001156 mWebViewController.getVisitedHistory(callback);
1157 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001158
1159 @Override
1160 public void setupAutoFill(Message message) {
1161 // Prompt the user to set up their profile.
1162 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001163 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1164 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001165 Context.LAYOUT_INFLATER_SERVICE);
1166 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1167
1168 builder.setView(layout)
1169 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1170 @Override
1171 public void onClick(DialogInterface dialog, int id) {
1172 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1173 R.id.setup_autofill_dialog_disable_autofill);
1174
1175 if (disableAutoFill.isChecked()) {
1176 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001177 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001178 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001179 R.string.autofill_setup_dialog_negative_toast,
1180 Toast.LENGTH_LONG).show();
1181 } else {
1182 // Take user to the AutoFill profile editor. When they return,
1183 // we will send the message that we pass here which will trigger
1184 // the form to get filled out with their new profile.
1185 mWebViewController.setupAutoFill(msg);
1186 }
1187 }
1188 })
1189 .setNegativeButton(R.string.cancel, null)
1190 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001191 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001192 };
1193
1194 // -------------------------------------------------------------------------
1195 // WebViewClient implementation for the sub window
1196 // -------------------------------------------------------------------------
1197
1198 // Subclass of WebViewClient used in subwindows to notify the main
1199 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001200 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001201 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001202 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001203 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001204
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001205 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001206 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001207 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001208 }
1209 @Override
1210 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1211 // Unlike the others, do not call mClient's version, which would
1212 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001213 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001214 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001215 }
1216 @Override
1217 public void doUpdateVisitedHistory(WebView view, String url,
1218 boolean isReload) {
1219 mClient.doUpdateVisitedHistory(view, url, isReload);
1220 }
1221 @Override
1222 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1223 return mClient.shouldOverrideUrlLoading(view, url);
1224 }
1225 @Override
1226 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1227 SslError error) {
1228 mClient.onReceivedSslError(view, handler, error);
1229 }
1230 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001231 public void onReceivedClientCertRequest(WebView view,
1232 ClientCertRequestHandler handler, String host_and_port) {
1233 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1234 }
1235 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001236 public void onReceivedHttpAuthRequest(WebView view,
1237 HttpAuthHandler handler, String host, String realm) {
1238 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1239 }
1240 @Override
1241 public void onFormResubmission(WebView view, Message dontResend,
1242 Message resend) {
1243 mClient.onFormResubmission(view, dontResend, resend);
1244 }
1245 @Override
1246 public void onReceivedError(WebView view, int errorCode,
1247 String description, String failingUrl) {
1248 mClient.onReceivedError(view, errorCode, description, failingUrl);
1249 }
1250 @Override
1251 public boolean shouldOverrideKeyEvent(WebView view,
1252 android.view.KeyEvent event) {
1253 return mClient.shouldOverrideKeyEvent(view, event);
1254 }
1255 @Override
1256 public void onUnhandledKeyEvent(WebView view,
1257 android.view.KeyEvent event) {
1258 mClient.onUnhandledKeyEvent(view, event);
1259 }
1260 }
1261
1262 // -------------------------------------------------------------------------
1263 // WebChromeClient implementation for the sub window
1264 // -------------------------------------------------------------------------
1265
1266 private class SubWindowChromeClient extends WebChromeClient {
1267 // The main WebChromeClient.
1268 private final WebChromeClient mClient;
1269
1270 SubWindowChromeClient(WebChromeClient client) {
1271 mClient = client;
1272 }
1273 @Override
1274 public void onProgressChanged(WebView view, int newProgress) {
1275 mClient.onProgressChanged(view, newProgress);
1276 }
1277 @Override
1278 public boolean onCreateWindow(WebView view, boolean dialog,
1279 boolean userGesture, android.os.Message resultMsg) {
1280 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1281 }
1282 @Override
1283 public void onCloseWindow(WebView window) {
1284 if (window != mSubView) {
1285 Log.e(LOGTAG, "Can't close the window");
1286 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001287 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001288 }
1289 }
1290
1291 // -------------------------------------------------------------------------
1292
1293 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001294 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001295 this(wvcontroller, w, null);
1296 }
1297
1298 Tab(WebViewController wvcontroller, Bundle state) {
1299 this(wvcontroller, null, state);
1300 }
1301
1302 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001303 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001304 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001305 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001306 mDataController = DataController.getInstance(mContext);
1307 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001308 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001309 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001310 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001311 mInForeground = false;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001312 mWebViewDestroyedByMemoryMonitor = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001313
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001314 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001315 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001316 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001317 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001318 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001319 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001320 }
1321 };
1322
John Reck1cf4b792011-07-26 10:22:22 -07001323 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1324 R.dimen.tab_thumbnail_width);
1325 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1326 R.dimen.tab_thumbnail_height);
1327 updateShouldCaptureThumbnails();
1328 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001329 if (getId() == -1) {
1330 mId = TabControl.getNextId();
1331 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001332 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001333 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001334 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001335 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001336 switch (m.what) {
1337 case MSG_CAPTURE:
1338 capture();
1339 break;
1340 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001341 }
1342 };
John Reck1cf4b792011-07-26 10:22:22 -07001343 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001344
Michael Kolb72864272012-05-03 15:42:15 -07001345 public boolean shouldUpdateThumbnail() {
1346 return mUpdateThumbnail;
1347 }
1348
Mathew Inwoode09305e2011-09-02 12:03:26 +01001349 /**
1350 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1351 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1352 * to overlapping IDs between the preloaded and restored tabs.
1353 */
1354 public void refreshIdAfterPreload() {
1355 mId = TabControl.getNextId();
1356 }
1357
John Reck1cf4b792011-07-26 10:22:22 -07001358 public void updateShouldCaptureThumbnails() {
1359 if (mWebViewController.shouldCaptureThumbnails()) {
1360 synchronized (Tab.this) {
1361 if (mCapture == null) {
1362 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1363 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001364 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001365 if (mInForeground) {
1366 postCapture();
1367 }
1368 }
1369 }
1370 } else {
1371 synchronized (Tab.this) {
1372 mCapture = null;
1373 deleteThumbnail();
1374 }
1375 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001376 }
1377
Michael Kolb14612442011-06-24 13:06:29 -07001378 public void setController(WebViewController ctl) {
1379 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001380 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001381 }
1382
Michael Kolbc831b632011-05-11 09:30:34 -07001383 public long getId() {
1384 return mId;
1385 }
1386
Michael Kolb91911a22012-01-17 11:21:25 -08001387 void setWebView(WebView w) {
1388 setWebView(w, true);
1389 }
1390
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001391 public boolean isNativeActive(){
1392 if (mMainView == null)
1393 return false;
1394 return true;
1395 }
1396
1397 public void setTimeStamp(){
1398 Date d = new Date();
1399 timestamp = (new Timestamp(d.getTime()));
1400 }
1401
1402 public Timestamp getTimestamp() {
1403 return timestamp;
1404 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001405 /**
1406 * Sets the WebView for this tab, correctly removing the old WebView from
1407 * the container view.
1408 */
Michael Kolb91911a22012-01-17 11:21:25 -08001409 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001410 if (mMainView == w) {
1411 return;
1412 }
Michael Kolba713ec82010-11-29 17:27:06 -08001413
Grace Kloba22ac16e2009-10-07 18:00:23 -07001414 // If the WebView is changing, the page will be reloaded, so any ongoing
1415 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001416 if (mGeolocationPermissionsPrompt != null) {
1417 mGeolocationPermissionsPrompt.hide();
1418 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001419
Michael Kolba713ec82010-11-29 17:27:06 -08001420 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001421
John Reck1cf4b792011-07-26 10:22:22 -07001422 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001423 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001424 if (w != null) {
1425 syncCurrentState(w, null);
1426 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001427 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001428
1429 if (mWebViewDestroyedByMemoryMonitor) {
1430 /*
1431 * If tab was destroyed as a result of the MemoryMonitor
1432 * then we need to restore the state properties
1433 * from the old WebView (mMainView)
1434 */
1435 syncCurrentState(mMainView, null);
1436 mWebViewDestroyedByMemoryMonitor = false;
1437 }
John Reck1cf4b792011-07-26 10:22:22 -07001438 }
1439 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001440 // set the new one
1441 mMainView = w;
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001442
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001443 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001444 if (mMainView != null) {
1445 mMainView.setWebViewClient(mWebViewClient);
1446 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001447 // Attach DownloadManager so that downloads can start in an active
1448 // or a non-active window. This can happen when going to a site that
1449 // does a redirect after a period of time. The user could have
1450 // switched to another tab while waiting for the download to start.
1451 mMainView.setDownloadListener(mDownloadListener);
John Reck8ee633f2011-08-09 16:00:35 -07001452 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001453 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001454 mMainView.setPictureListener(this);
1455 }
Michael Kolb91911a22012-01-17 11:21:25 -08001456 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001457 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001458 WebBackForwardList restoredState
1459 = mMainView.restoreState(mSavedState);
1460 if (restoredState == null || restoredState.getSize() == 0) {
1461 Log.w(LOGTAG, "Failed to restore WebView state!");
1462 loadUrl(mCurrentState.mOriginalUrl, null);
1463 }
John Reck1cf4b792011-07-26 10:22:22 -07001464 mSavedState = null;
1465 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001466 }
1467 }
1468
Axesh R. Ajmera2fa0ba12015-03-17 18:18:36 -07001469 public void destroyThroughMemoryMonitor() {
1470 mWebViewDestroyedByMemoryMonitor = true;
1471 destroy();
1472 }
1473
Grace Kloba22ac16e2009-10-07 18:00:23 -07001474 /**
1475 * Destroy the tab's main WebView and subWindow if any
1476 */
1477 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001478
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001479 if (mPostponeDestroy) {
1480 mShouldDestroy = true;
1481 return;
1482 }
1483 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001484 if (mMainView != null) {
1485 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001486 // save the WebView to call destroy() after detach it from the tab
1487 WebView webView = mMainView;
1488 setWebView(null);
1489 webView.destroy();
1490 }
1491 }
1492
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001493 private boolean mPostponeDestroy = false;
1494 private boolean mShouldDestroy = false;
1495
1496 public void postponeDestroy() {
1497 mPostponeDestroy = true;
1498 }
1499
1500 public void performPostponedDestroy() {
1501 mPostponeDestroy = false;
1502 if (mShouldDestroy) {
1503 destroy();
1504 }
1505 }
1506
Grace Kloba22ac16e2009-10-07 18:00:23 -07001507 /**
1508 * Remove the tab from the parent
1509 */
1510 void removeFromTree() {
1511 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001512 if (mChildren != null) {
1513 for(Tab t : mChildren) {
1514 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001515 }
1516 }
1517 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001518 if (mParent != null) {
1519 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001520 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001521
1522 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001523 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001524 }
1525
1526 /**
1527 * Create a new subwindow unless a subwindow already exists.
1528 * @return True if a new subwindow was created. False if one already exists.
1529 */
1530 boolean createSubWindow() {
1531 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001532 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001533 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001534 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001535 mSubView.setWebChromeClient(new SubWindowChromeClient(
1536 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001537 // Set a different DownloadListener for the mSubView, since it will
1538 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001539 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001540 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001541 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001542 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001543 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001544 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001545 if (mSubView.copyBackForwardList().getSize() == 0) {
1546 // This subwindow was opened for the sole purpose of
1547 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001548 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001549 }
1550 }
1551 });
Michael Kolb14612442011-06-24 13:06:29 -07001552 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001553 return true;
1554 }
1555 return false;
1556 }
1557
1558 /**
1559 * Dismiss the subWindow for the tab.
1560 */
1561 void dismissSubWindow() {
1562 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001563 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001564 mSubView.destroy();
1565 mSubView = null;
1566 mSubViewContainer = null;
1567 }
1568 }
1569
Grace Kloba22ac16e2009-10-07 18:00:23 -07001570
1571 /**
1572 * Set the parent tab of this tab.
1573 */
Michael Kolbc831b632011-05-11 09:30:34 -07001574 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001575 if (parent == this) {
1576 throw new IllegalStateException("Cannot set parent to self!");
1577 }
Michael Kolbc831b632011-05-11 09:30:34 -07001578 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001579 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001580 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001581 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001582 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001583 if (mSavedState != null) {
1584 if (parent == null) {
1585 mSavedState.remove(PARENTTAB);
1586 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001587 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001588 }
1589 }
John Reckb0a86db2011-05-24 14:05:58 -07001590
1591 // Sync the WebView useragent with the parent
1592 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1593 != mSettings.hasDesktopUseragent(getWebView())) {
1594 mSettings.toggleDesktopUseragent(getWebView());
1595 }
John Reck52be4782011-08-26 15:37:29 -07001596
1597 if (parent != null && parent.getId() == getId()) {
1598 throw new IllegalStateException("Parent has same ID as child!");
1599 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001600 }
1601
1602 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001603 * If this Tab was created through another Tab, then this method returns
1604 * that Tab.
1605 * @return the Tab parent or null
1606 */
1607 public Tab getParent() {
1608 return mParent;
1609 }
1610
1611 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001612 * When a Tab is created through the content of another Tab, then we
1613 * associate the Tabs.
1614 * @param child the Tab that was created from this Tab
1615 */
1616 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001617 if (mChildren == null) {
1618 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001619 }
Michael Kolbc831b632011-05-11 09:30:34 -07001620 mChildren.add(child);
1621 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001622 }
1623
Michael Kolbc831b632011-05-11 09:30:34 -07001624 Vector<Tab> getChildren() {
1625 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001626 }
1627
1628 void resume() {
1629 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001630 if (mMainView.hasCrashed()) {
1631 // Reload if render process has crashed. This is done here so that
1632 // setFocus call sends wasShown message to correct render process.
Vivek Sekhared791da2015-02-22 12:39:05 -08001633 mMainView.setNeedsReload(true);
Pankaj Garg60221af2014-09-23 17:57:50 -07001634 }
John Reck56c1fcf2011-08-17 10:15:16 -07001635 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001636 mMainView.onResume();
1637 if (mSubView != null) {
1638 mSubView.onResume();
1639 }
1640 }
1641 }
1642
John Reck56c1fcf2011-08-17 10:15:16 -07001643 private void setupHwAcceleration(View web) {
1644 if (web == null) return;
1645 BrowserSettings settings = BrowserSettings.getInstance();
1646 if (settings.isHardwareAccelerated()) {
1647 web.setLayerType(View.LAYER_TYPE_NONE, null);
1648 } else {
1649 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1650 }
1651 }
1652
Grace Kloba22ac16e2009-10-07 18:00:23 -07001653 void pause() {
1654 if (mMainView != null) {
1655 mMainView.onPause();
1656 if (mSubView != null) {
1657 mSubView.onPause();
1658 }
1659 }
1660 }
1661
1662 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001663 if (mInForeground) {
1664 return;
1665 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001666 mInForeground = true;
1667 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001668 Activity activity = mWebViewController.getActivity();
1669 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001670 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001671 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001672 }
1673 // Show the pending error dialog if the queue is not empty
1674 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1675 showError(mQueuedErrors.getFirst());
1676 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001677 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001678 }
1679
1680 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001681 if (!mInForeground) {
1682 return;
1683 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001684 mInForeground = false;
1685 pause();
1686 mMainView.setOnCreateContextMenuListener(null);
1687 if (mSubView != null) {
1688 mSubView.setOnCreateContextMenuListener(null);
1689 }
1690 }
1691
Michael Kolb8233fac2010-10-26 16:08:53 -07001692 boolean inForeground() {
1693 return mInForeground;
1694 }
1695
Grace Kloba22ac16e2009-10-07 18:00:23 -07001696 /**
1697 * Return the top window of this tab; either the subwindow if it is not
1698 * null or the main window.
1699 * @return The top window of this tab.
1700 */
1701 WebView getTopWindow() {
1702 if (mSubView != null) {
1703 return mSubView;
1704 }
1705 return mMainView;
1706 }
1707
1708 /**
1709 * Return the main window of this tab. Note: if a tab is freed in the
1710 * background, this can return null. It is only guaranteed to be
1711 * non-null for the current tab.
1712 * @return The main WebView of this tab.
1713 */
1714 WebView getWebView() {
1715 return mMainView;
1716 }
1717
Michael Kolba713ec82010-11-29 17:27:06 -08001718 void setViewContainer(View container) {
1719 mContainer = container;
1720 }
1721
Michael Kolb8233fac2010-10-26 16:08:53 -07001722 View getViewContainer() {
1723 return mContainer;
1724 }
1725
Grace Kloba22ac16e2009-10-07 18:00:23 -07001726 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001727 * Return whether private browsing is enabled for the main window of
1728 * this tab.
1729 * @return True if private browsing is enabled.
1730 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001731 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001732 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001733 }
1734
1735 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001736 * Return the subwindow of this tab or null if there is no subwindow.
1737 * @return The subwindow of this tab or null.
1738 */
1739 WebView getSubWebView() {
1740 return mSubView;
1741 }
1742
Michael Kolb1514bb72010-11-22 09:11:48 -08001743 void setSubWebView(WebView subView) {
1744 mSubView = subView;
1745 }
1746
Michael Kolb8233fac2010-10-26 16:08:53 -07001747 View getSubViewContainer() {
1748 return mSubViewContainer;
1749 }
1750
Michael Kolb1514bb72010-11-22 09:11:48 -08001751 void setSubViewContainer(View subViewContainer) {
1752 mSubViewContainer = subViewContainer;
1753 }
1754
Grace Kloba22ac16e2009-10-07 18:00:23 -07001755 /**
1756 * @return The geolocation permissions prompt for this tab.
1757 */
1758 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001759 if (mGeolocationPermissionsPrompt == null) {
1760 ViewStub stub = (ViewStub) mContainer
1761 .findViewById(R.id.geolocation_permissions_prompt);
1762 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1763 .inflate();
Panos Thomasb298aad2014-10-22 12:24:21 -07001764 mGeolocationPermissionsPrompt.init(mCurrentState.mIncognito);
Grace Kloba50c241e2010-04-20 11:07:50 -07001765 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001766 return mGeolocationPermissionsPrompt;
1767 }
1768
1769 /**
1770 * @return The application id string
1771 */
1772 String getAppId() {
1773 return mAppId;
1774 }
1775
1776 /**
1777 * Set the application id string
1778 * @param id
1779 */
1780 void setAppId(String id) {
1781 mAppId = id;
1782 }
1783
Michael Kolbe28b3472011-08-04 16:54:31 -07001784 boolean closeOnBack() {
1785 return mCloseOnBack;
1786 }
1787
1788 void setCloseOnBack(boolean close) {
1789 mCloseOnBack = close;
1790 }
1791
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001792 boolean getDerivedFromIntent() {
1793 return mDerivedFromIntent;
1794 }
1795
1796 void setDerivedFromIntent(boolean derived) {
1797 mDerivedFromIntent = derived;
1798 }
1799
Grace Kloba22ac16e2009-10-07 18:00:23 -07001800 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001801 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001802 }
1803
Tarun Nainani8eb00912014-07-17 12:28:32 -07001804
1805 protected void onPageFinished() {
1806 mPageFinished = true;
1807 }
1808
1809 public boolean getPageFinishedStatus() {
1810 return mPageFinished;
1811 }
1812
John Reck49a603c2011-03-03 09:33:05 -08001813 String getOriginalUrl() {
Vivek Sekhar361065a2014-11-25 15:34:35 -08001814 if (mMainView != null)
1815 return mMainView.getOriginalUrl();
John Reckdb22ec42011-06-29 11:31:24 -07001816 if (mCurrentState.mOriginalUrl == null) {
1817 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001818 }
John Reckdb22ec42011-06-29 11:31:24 -07001819 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001820 }
1821
Grace Kloba22ac16e2009-10-07 18:00:23 -07001822 /**
John Reck30c714c2010-12-16 17:30:34 -08001823 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001824 */
1825 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001826 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001827 }
1828
1829 /**
John Reck30c714c2010-12-16 17:30:34 -08001830 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001831 */
1832 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001833 if (mCurrentState.mFavicon != null) {
1834 return mCurrentState.mFavicon;
1835 }
1836 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001837 }
1838
John Recke969cc52010-12-21 17:24:43 -08001839 public boolean isBookmarkedSite() {
1840 return mCurrentState.mIsBookmarkedSite;
1841 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001842
Grace Kloba22ac16e2009-10-07 18:00:23 -07001843 /**
Steve Block08a6f0c2011-10-06 12:12:53 +01001844 * Sets the security state, clears the SSL certificate error and informs
1845 * the controller.
1846 */
Steve Block2466eff2011-10-03 15:33:09 +01001847 private void setSecurityState(SecurityState securityState) {
1848 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001849 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001850 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001851 }
1852
1853 /**
Steve Block2466eff2011-10-03 15:33:09 +01001854 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001855 */
Steve Block2466eff2011-10-03 15:33:09 +01001856 SecurityState getSecurityState() {
1857 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001858 }
1859
Steve Block08a6f0c2011-10-06 12:12:53 +01001860 /**
1861 * Gets the SSL certificate error, if any, for the page's main resource.
1862 * This is only non-null when the security state is
1863 * SECURITY_STATE_BAD_CERTIFICATE.
1864 */
1865 SslError getSslCertificateError() {
1866 return mCurrentState.mSslCertificateError;
1867 }
1868
John Reck30c714c2010-12-16 17:30:34 -08001869 int getLoadProgress() {
1870 if (mInPageLoad) {
1871 return mPageLoadProgress;
1872 }
1873 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001874 }
1875
1876 /**
1877 * @return TRUE if onPageStarted is called while onPageFinished is not
1878 * called yet.
1879 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001880 boolean inPageLoad() {
1881 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001882 }
1883
Grace Kloba22ac16e2009-10-07 18:00:23 -07001884 /**
John Reck1cf4b792011-07-26 10:22:22 -07001885 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001886 */
John Reck1cf4b792011-07-26 10:22:22 -07001887 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001888 // If the WebView is null it means we ran low on memory and we already
1889 // stored the saved state in mSavedState.
1890 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001891 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001892 }
John Reck6c2e2f32011-08-22 13:41:23 -07001893
1894 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001895 return null;
John Reck24f18262011-06-17 14:47:20 -07001896 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001897
1898 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001899 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1900 if (savedList == null || savedList.getSize() == 0) {
1901 Log.w(LOGTAG, "Failed to save back/forward list for "
1902 + mCurrentState.mUrl);
1903 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001904
Michael Kolbc831b632011-05-11 09:30:34 -07001905 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001906 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1907 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001908 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001909 if (mAppId != null) {
1910 mSavedState.putString(APPID, mAppId);
1911 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001912 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001913 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001914 if (mParent != null) {
1915 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001916 }
John Reckb0a86db2011-05-24 14:05:58 -07001917 mSavedState.putBoolean(USERAGENT,
1918 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001919 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001920 }
1921
1922 /*
1923 * Restore the state of the tab.
1924 */
John Reck1cf4b792011-07-26 10:22:22 -07001925 private void restoreState(Bundle b) {
1926 mSavedState = b;
1927 if (mSavedState == null) {
1928 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001929 }
1930 // Restore the internal state even if the WebView fails to restore.
1931 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001932 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001933 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001934 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001935 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001936 String url = b.getString(CURRURL);
1937 String title = b.getString(CURRTITLE);
1938 boolean incognito = b.getBoolean(INCOGNITO);
1939 mCurrentState = new PageState(mContext, incognito, url, null);
1940 mCurrentState.mTitle = title;
1941 synchronized (Tab.this) {
1942 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001943 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001944 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001945 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001946 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001947
John Reck8b9bb8b2012-03-08 13:19:40 -08001948 private void restoreUserAgent() {
1949 if (mMainView == null || mSavedState == null) {
1950 return;
1951 }
1952 if (mSavedState.getBoolean(USERAGENT)
1953 != mSettings.hasDesktopUseragent(mMainView)) {
1954 mSettings.toggleDesktopUseragent(mMainView);
1955 }
1956 }
1957
Leon Scroggins1961ed22010-12-07 15:22:21 -05001958 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001959 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001960 }
1961
John Recke969cc52010-12-21 17:24:43 -08001962 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1963 = new DataController.OnQueryUrlIsBookmark() {
1964 @Override
1965 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1966 if (mCurrentState.mUrl.equals(url)) {
1967 mCurrentState.mIsBookmarkedSite = isBookmark;
1968 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1969 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001970 }
John Recke969cc52010-12-21 17:24:43 -08001971 };
Michael Kolb1acef692011-03-08 14:12:06 -08001972
Michael Kolbeb95db42011-03-03 10:38:40 -08001973 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001974 synchronized (Tab.this) {
1975 return mCapture;
1976 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001977 }
1978
John Reck541f55a2011-06-07 16:34:43 -07001979 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001980 return false;
1981 }
1982
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001983 private static class SaveCallback implements ValueCallback<String> {
1984 boolean onReceiveValueCalled = false;
1985 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001986
1987 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001988 public void onReceiveValue(String path) {
1989 this.onReceiveValueCalled = true;
1990 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001991 synchronized (this) {
1992 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001993 }
John Reck541f55a2011-06-07 16:34:43 -07001994 }
John Reck68234a92012-04-19 15:27:12 -07001995
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001996 public String getPath() {
1997 return mPath;
1998 }
John Reck68234a92012-04-19 15:27:12 -07001999 }
2000
2001 /**
2002 * Must be called on the UI thread
2003 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07002004 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002005 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002006 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07002007 ContentValues values = new ContentValues();
2008 values.put(Snapshots.TITLE, mCurrentState.mTitle);
2009 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07002010 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07002011 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2012 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07002013 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07002014 return values;
John Reck541f55a2011-06-07 16:34:43 -07002015 }
2016
John Reck68234a92012-04-19 15:27:12 -07002017 /**
2018 * Probably want to call this on a background thread
2019 */
2020 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002021 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002022 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002023 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002024 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002025 try {
John Reck68234a92012-04-19 15:27:12 -07002026 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002027 web.saveViewState(filename, callback);
2028 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002029 }
John Reck68234a92012-04-19 15:27:12 -07002030 } catch (Exception e) {
2031 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002032 String path = callback.getPath();
2033 if (path != null) {
2034 File file = mContext.getFileStreamPath(path);
2035 if (file.exists() && !file.delete()) {
2036 file.deleteOnExit();
2037 }
John Reck68234a92012-04-19 15:27:12 -07002038 }
2039 return false;
2040 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002041
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002042 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002043 // could be that saving of file failed
2044 if (path == null) {
2045 return false;
2046 }
2047
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002048 File savedFile = new File(path);
2049 if (!savedFile.exists()) {
2050 return false;
John Reck68234a92012-04-19 15:27:12 -07002051 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002052 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2053 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002054 return true;
2055 }
2056
John Reck8cc92352011-07-06 17:41:52 -07002057 public byte[] compressBitmap(Bitmap bitmap) {
2058 if (bitmap == null) {
2059 return null;
2060 }
2061 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2062 bitmap.compress(CompressFormat.PNG, 100, stream);
2063 return stream.toByteArray();
2064 }
2065
John Reck26b18322011-06-21 13:08:58 -07002066 public void loadUrl(String url, Map<String, String> headers) {
2067 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002068 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002069 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002070 mMainView.loadUrl(url, headers);
2071 }
2072 }
2073
John Reck38b39652012-06-05 09:22:59 -07002074 public void disableUrlOverridingForLoad() {
2075 mDisableOverrideUrlLoading = true;
2076 }
2077
Michael Kolb9ef259a2011-07-12 15:33:08 -07002078 protected void capture() {
2079 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002080 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2081 return;
2082 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002083
Pankaj Garg79878492015-04-01 14:48:21 -07002084 if (!mFirstVisualPixelPainted) {
2085 mCapture = Bitmap.createBitmap(
2086 mCaptureWidth,
2087 mCaptureHeight,
2088 Bitmap.Config.RGB_565);
2089 mCapture.eraseColor(Color.WHITE);
2090
2091 mHandler.removeMessages(MSG_CAPTURE);
2092
2093 TabControl tc = mWebViewController.getTabControl();
2094 if (tc != null) {
2095 OnThumbnailUpdatedListener updateListener
2096 = tc.getOnThumbnailUpdatedListener();
2097 if (updateListener != null) {
2098 updateListener.onThumbnailUpdated(this);
2099 }
2100 }
2101 return;
2102 }
2103
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002104 mMainView
2105 .getContentBitmapAsync(
2106 (float) mCaptureWidth / mMainView.getWidth(),
2107 new Rect(),
2108 new ValueCallback<Bitmap>() {
2109 @Override
2110 public void onReceiveValue(Bitmap bitmap) {
2111 onCaptureCallback(bitmap);
2112 }});
2113 }
2114
2115 private void onCaptureCallback(Bitmap bitmap) {
2116 if (mCapture == null || bitmap == null)
2117 return;
2118
Michael Kolb9ef259a2011-07-12 15:33:08 -07002119 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002120 mCapture.eraseColor(Color.WHITE);
2121 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002122
Michael Kolba3194d02011-09-07 11:23:51 -07002123 // manually anti-alias the edges for the tilt
2124 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2125 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2126 mCapture.getHeight(), sAlphaPaint);
2127 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2128 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2129 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002130 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002131 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002132 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002133 TabControl tc = mWebViewController.getTabControl();
2134 if (tc != null) {
2135 OnThumbnailUpdatedListener updateListener
2136 = tc.getOnThumbnailUpdatedListener();
2137 if (updateListener != null) {
2138 updateListener.onThumbnailUpdated(this);
2139 }
2140 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002141 }
2142
2143 @Override
2144 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002145 postCapture();
2146 }
2147
2148 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002149 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2150 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2151 }
2152 }
2153
John Reckef654f12011-07-12 16:42:08 -07002154 public boolean canGoBack() {
2155 return mMainView != null ? mMainView.canGoBack() : false;
2156 }
2157
2158 public boolean canGoForward() {
2159 return mMainView != null ? mMainView.canGoForward() : false;
2160 }
2161
2162 public void goBack() {
2163 if (mMainView != null) {
2164 mMainView.goBack();
2165 }
2166 }
2167
2168 public void goForward() {
2169 if (mMainView != null) {
2170 mMainView.goForward();
2171 }
2172 }
2173
John Reck1cf4b792011-07-26 10:22:22 -07002174 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002175 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002176 }
2177
2178 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002179 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002180 }
2181
John Reck4eadc342011-10-31 14:04:10 -07002182 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002183 synchronized (Tab.this) {
2184 if (mCapture == null) {
2185 return;
2186 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002187 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002188 try {
2189 mCapture.copyPixelsFromBuffer(buffer);
2190 } catch (RuntimeException rex) {
2191 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2192 + buffer.capacity() + " blob: " + blob.length
2193 + "capture: " + mCapture.getByteCount());
2194 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002195 }
John Reck1cf4b792011-07-26 10:22:22 -07002196 }
2197 }
2198
John Reck52be4782011-08-26 15:37:29 -07002199 @Override
2200 public String toString() {
2201 StringBuilder builder = new StringBuilder(100);
2202 builder.append(mId);
2203 builder.append(") has parent: ");
2204 if (getParent() != null) {
2205 builder.append("true[");
2206 builder.append(getParent().getId());
2207 builder.append("]");
2208 } else {
2209 builder.append("false");
2210 }
2211 builder.append(", incog: ");
2212 builder.append(isPrivateBrowsingEnabled());
2213 if (!isPrivateBrowsingEnabled()) {
2214 builder.append(", title: ");
2215 builder.append(getTitle());
2216 builder.append(", url: ");
2217 builder.append(getUrl());
2218 }
2219 return builder.toString();
2220 }
2221
Steve Block4895b012011-10-03 16:26:46 +01002222 private void handleProceededAfterSslError(SslError error) {
2223 if (error.getUrl().equals(mCurrentState.mUrl)) {
2224 // The security state should currently be SECURITY_STATE_SECURE.
2225 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002226 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002227 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002228 // The page's main resource is secure and this error is for a
2229 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002230 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2231 }
2232 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002233}