blob: 99644137ac971b74ec071a72094682aa264920c9 [file] [log] [blame]
Grace Kloba22ac16e2009-10-07 18:00:23 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Grace Kloba22ac16e2009-10-07 18:00:23 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
21import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070022import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080023import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070024import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070025import android.content.DialogInterface.OnCancelListener;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080026import android.content.res.Resources;
Grace Kloba22ac16e2009-10-07 18:00:23 -070027import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070028import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070029import android.graphics.BitmapFactory;
30import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070032import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070033import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070034import android.graphics.PorterDuff;
35import android.graphics.PorterDuffXfermode;
Tarun Nainaniea28dde2014-08-27 17:25:09 -070036import android.graphics.Rect;
Grace Kloba22ac16e2009-10-07 18:00:23 -070037import android.net.Uri;
38import android.net.http.SslError;
Grace Kloba22ac16e2009-10-07 18:00:23 -070039import android.os.Bundle;
Michael Kolb9ef259a2011-07-12 15:33:08 -070040import android.os.Handler;
Grace Kloba22ac16e2009-10-07 18:00:23 -070041import android.os.Message;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +000042import android.os.SystemClock;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070043import android.security.KeyChain;
Brian Carlstromaa09cd82011-06-09 16:04:40 -070044import android.security.KeyChainAliasCallback;
John Reck24f18262011-06-17 14:47:20 -070045import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070046import android.util.Log;
47import android.view.KeyEvent;
48import android.view.LayoutInflater;
49import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070050import android.view.ViewStub;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080051import android.view.View.OnClickListener;
Ben Murdochc42addf2010-01-28 15:19:59 +000052import android.webkit.ConsoleMessage;
Grace Kloba22ac16e2009-10-07 18:00:23 -070053import android.webkit.GeolocationPermissions;
Grace Kloba22ac16e2009-10-07 18:00:23 -070054import android.webkit.URLUtil;
John Reck438bf462011-01-12 18:11:46 -080055import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070056import android.webkit.WebStorage;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080057import android.webkit.WebChromeClient.CustomViewCallback;
58import android.webkit.ValueCallback;
Ben Murdoch1d676b62011-01-17 12:54:24 +000059import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000060import android.widget.Toast;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080061import android.widget.FrameLayout;
62import android.widget.Button;
Grace Kloba22ac16e2009-10-07 18:00:23 -070063
Bijan Amirzada41242f22014-03-21 12:12:18 -070064import com.android.browser.TabControl.OnThumbnailUpdatedListener;
65import com.android.browser.homepages.HomeProvider;
66import com.android.browser.mynavigation.MyNavigationUtil;
67import com.android.browser.provider.MyNavigationProvider;
68import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080069
70import org.codeaurora.swe.BrowserDownloadListener;
71import org.codeaurora.swe.ClientCertRequestHandler;
72import org.codeaurora.swe.HttpAuthHandler;
73import org.codeaurora.swe.SslErrorHandler;
74import org.codeaurora.swe.WebBackForwardList;
75import org.codeaurora.swe.WebBackForwardListClient;
76import org.codeaurora.swe.WebChromeClient;
77import org.codeaurora.swe.WebHistoryItem;
78import org.codeaurora.swe.WebView;
79import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070080import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080081import org.codeaurora.swe.WebViewClient;
82
John Reck541f55a2011-06-07 16:34:43 -070083import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070084import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080085import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070086import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070087import java.util.LinkedList;
88import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070089import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070090import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010091import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080092import java.sql.Timestamp;
93import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070094
Grace Kloba22ac16e2009-10-07 18:00:23 -070095/**
96 * Class for maintaining Tabs with a main WebView and a subwindow.
97 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070098class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070099
Grace Kloba22ac16e2009-10-07 18:00:23 -0700100 // Log Tag
101 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700102 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000103 // Special case the logtag for messages for the Console to make it easier to
104 // filter them and match the logtag used for these messages in older versions
105 // of the browser.
106 private static final String CONSOLE_LOGTAG = "browser";
107
Michael Kolb9ef259a2011-07-12 15:33:08 -0700108 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800109 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700110 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700111
John Reck1cf4b792011-07-26 10:22:22 -0700112 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800113 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700114
Michael Kolba3194d02011-09-07 11:23:51 -0700115 private static Paint sAlphaPaint = new Paint();
116 static {
117 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
118 sAlphaPaint.setColor(Color.TRANSPARENT);
119 }
120
Steve Block2466eff2011-10-03 15:33:09 +0100121 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100122 // The page's main resource does not use SSL. Note that we use this
123 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100124 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100125 // The page's main resource uses SSL and the certificate is good. The
126 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100127 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100128 // The page's main resource uses SSL and the certificate is good, but
129 // some sub-resources either do not use SSL or have problems with their
130 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100131 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100132 // The page's main resource uses SSL but there is a problem with its
133 // certificate.
134 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800135 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700136
Michael Kolb14612442011-06-24 13:06:29 -0700137 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700138 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700139
Michael Kolbc831b632011-05-11 09:30:34 -0700140 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700141 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700142
Grace Kloba22ac16e2009-10-07 18:00:23 -0700143 // The Geolocation permissions prompt
144 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
145 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800146 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700147 // Main WebView
148 private WebView mMainView;
149 // Subwindow container
150 private View mSubViewContainer;
151 // Subwindow WebView
152 private WebView mSubView;
153 // Saved bundle for when we are running low on memory. It contains the
154 // information needed to restore the WebView if the user goes back to the
155 // tab.
156 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700157 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
158 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700159 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700160 // Tab that constructed by this Tab. This is used when this Tab is
161 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700162 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700163 // If true, the tab is in the foreground of the current activity.
164 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700165 // If true, the tab is in page loading state (after onPageStarted,
166 // before onPageFinsihed)
167 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700168 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700169 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800170 // The last reported progress of the current page
171 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000172 // The time the load started, used to find load page time
173 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700174 // Application identifier used to find tabs that another application wants
175 // to reuse.
176 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700177 // flag to indicate if tab should be closed on back
178 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700179 // flag to indicate if the tab was opened from an intent
180 private boolean mDerivedFromIntent = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700181 // Keep the original url around to avoid killing the old WebView if the url
182 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700183 // Error console for the tab
184 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500185 // The listener that gets invoked when a download is started from the
186 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700187 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500188 // Listener used to know when we move forward or back in the history list.
189 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800190 private DataController mDataController;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700191
192 // AsyncTask for downloading touch icons
193 DownloadTouchIcon mTouchIconLoader;
194
John Reck35e9dd62011-04-25 09:01:54 -0700195 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700196 private int mCaptureWidth;
197 private int mCaptureHeight;
198 private Bitmap mCapture;
199 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700200 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800201 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700202 private boolean mFullScreen = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800203 private boolean mReceivedError;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700204
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100205 /**
Tarun Nainaniac724562014-11-03 17:40:38 -0800206 * See {@link #clearBackStackWhenItemAdded(java.util.regex.Pattern)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100207 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100208 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100209
John Reck1cf4b792011-07-26 10:22:22 -0700210 private static synchronized Bitmap getDefaultFavicon(Context context) {
211 if (sDefaultFavicon == null) {
212 sDefaultFavicon = BitmapFactory.decodeResource(
213 context.getResources(), R.drawable.app_web_browser_sm);
214 }
215 return sDefaultFavicon;
216 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800217
John Reck30c714c2010-12-16 17:30:34 -0800218 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700219 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800220 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700221 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800222 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100223 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100224 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
225 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800226 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100227 boolean mIsBookmarkedSite;
228 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800229
230 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700231 mIncognito = incognito;
232 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700233 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800234 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800235 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700236 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800237 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800238 }
Steve Block2466eff2011-10-03 15:33:09 +0100239 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800240 }
241
242 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700243 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700244 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800245 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100246 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800247 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100248 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800249 }
John Reck1cf4b792011-07-26 10:22:22 -0700250 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800251 }
John Reck1cf4b792011-07-26 10:22:22 -0700252
Grace Kloba22ac16e2009-10-07 18:00:23 -0700253 }
254
John Reck30c714c2010-12-16 17:30:34 -0800255 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700256 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800257
Grace Kloba22ac16e2009-10-07 18:00:23 -0700258 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700259 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700260 static final String CURRURL = "currentUrl";
261 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 static final String PARENTTAB = "parentTab";
263 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700264 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700265 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700266 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700267
Grace Kloba22ac16e2009-10-07 18:00:23 -0700268 // Container class for the next error dialog that needs to be displayed
269 private class ErrorDialog {
270 public final int mTitle;
271 public final String mDescription;
272 public final int mError;
273 ErrorDialog(int title, String desc, int error) {
274 mTitle = title;
275 mDescription = desc;
276 mError = error;
277 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700279
280 private void processNextError() {
281 if (mQueuedErrors == null) {
282 return;
283 }
284 // The first one is currently displayed so just remove it.
285 mQueuedErrors.removeFirst();
286 if (mQueuedErrors.size() == 0) {
287 mQueuedErrors = null;
288 return;
289 }
290 showError(mQueuedErrors.getFirst());
291 }
292
293 private DialogInterface.OnDismissListener mDialogListener =
294 new DialogInterface.OnDismissListener() {
295 public void onDismiss(DialogInterface d) {
296 processNextError();
297 }
298 };
299 private LinkedList<ErrorDialog> mQueuedErrors;
300
301 private void queueError(int err, String desc) {
302 if (mQueuedErrors == null) {
303 mQueuedErrors = new LinkedList<ErrorDialog>();
304 }
305 for (ErrorDialog d : mQueuedErrors) {
306 if (d.mError == err) {
307 // Already saw a similar error, ignore the new one.
308 return;
309 }
310 }
311 ErrorDialog errDialog = new ErrorDialog(
312 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
313 R.string.browserFrameFileErrorLabel :
314 R.string.browserFrameNetworkErrorLabel,
315 desc, err);
316 mQueuedErrors.addLast(errDialog);
317
318 // Show the dialog now if the queue was empty and it is in foreground
319 if (mQueuedErrors.size() == 1 && mInForeground) {
320 showError(errDialog);
321 }
322 }
323
324 private void showError(ErrorDialog errDialog) {
325 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700326 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700327 .setTitle(errDialog.mTitle)
328 .setMessage(errDialog.mDescription)
329 .setPositiveButton(R.string.ok, null)
330 .create();
331 d.setOnDismissListener(mDialogListener);
332 d.show();
333 }
334 }
335
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800336 protected void replaceCrashView(View view, View container) {
337 if (hasCrashed && (view == mMainView)) {
338 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
339 wrapper.removeAllViewsInLayout();
340 wrapper.addView(view);
341 hasCrashed = false;
342 }
343 }
344
345 protected void showCrashView() {
346 if (hasCrashed) {
347 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
348 Context.LAYOUT_INFLATER_SERVICE);
349 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
350 final FrameLayout wrapper =
351 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
352 wrapper.removeAllViewsInLayout();
353 wrapper.addView(crashLayout);
354 mContainer.requestFocus();
355 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
356 reloadBtn.setOnClickListener(new OnClickListener() {
357 @Override
358 public void onClick(View arg0) {
359 replaceCrashView(mMainView, mContainer);
360 mMainView.reload();
361 }
362 });
363 }
364 }
365
Grace Kloba22ac16e2009-10-07 18:00:23 -0700366 // -------------------------------------------------------------------------
367 // WebViewClient implementation for the main WebView
368 // -------------------------------------------------------------------------
369
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800370 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500371 private Message mDontResend;
372 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700373
374 private boolean providersDiffer(String url, String otherUrl) {
375 Uri uri1 = Uri.parse(url);
376 Uri uri2 = Uri.parse(otherUrl);
377 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
378 }
379
Grace Kloba22ac16e2009-10-07 18:00:23 -0700380 @Override
381 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700383 mPageFinished = false;
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800384 mReceivedError = false;
Michael Kolb72864272012-05-03 15:42:15 -0700385 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700386 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700387 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800388 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000389 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700390
391 // If we start a touch icon load and then load a new page, we don't
392 // want to cancel the current touch icon loader. But, we do want to
393 // create a new one when the touch icon url is known.
394 if (mTouchIconLoader != null) {
395 mTouchIconLoader.mTab = null;
396 mTouchIconLoader = null;
397 }
398
399 // reset the error console
400 if (mErrorConsole != null) {
401 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700403 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
404 }
405 }
406
Grace Kloba22ac16e2009-10-07 18:00:23 -0700407 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800408 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500409
John Recke969cc52010-12-21 17:24:43 -0800410 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700411 }
412
413 @Override
414 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700415 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800416 if (!isPrivateBrowsingEnabled()) {
417 LogTag.logPageFinishedLoading(
418 url, SystemClock.uptimeMillis() - mLoadStartTime);
419 }
John Reck1cf4b792011-07-26 10:22:22 -0700420 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800421 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700422 }
423
424 // return true if want to hijack the url to let another app to handle it
425 @Override
426 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700427 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800428 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
429 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700430 } else {
431 return false;
432 }
433 }
434
435 /**
Steve Block2466eff2011-10-03 15:33:09 +0100436 * Updates the security state. This method is called when we discover
437 * another resource to be loaded for this page (for example,
438 * javascript). While we update the security state, we do not update
439 * the lock icon until we are done loading, as it is slightly more
440 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700441 */
442 @Override
443 public void onLoadResource(WebView view, String url) {
444 if (url != null && url.length() > 0) {
445 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100446 // to update the security state:
447 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
448 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700449 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
450 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100451 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700452 }
453 }
454 }
455 }
456
457 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700458 * Show a dialog informing the user of the network error reported by
459 * WebCore if it is in the foreground.
460 */
461 @Override
462 public void onReceivedError(WebView view, int errorCode,
463 String description, String failingUrl) {
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800464 // Used for the syncCurrentState to use
465 // the failing url instead of using webview url
466 mReceivedError = true;
467
Grace Kloba22ac16e2009-10-07 18:00:23 -0700468 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
469 errorCode != WebViewClient.ERROR_CONNECT &&
470 errorCode != WebViewClient.ERROR_BAD_URL &&
471 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
472 errorCode != WebViewClient.ERROR_FILE) {
473 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500474
Selim Gurun3da06b82011-10-10 13:58:12 -0700475 // Don't log URLs when in private browsing mode
476 if (!isPrivateBrowsingEnabled()) {
477 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500478 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700479 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500480 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700481 }
482
483 /**
484 * Check with the user if it is ok to resend POST data as the page they
485 * are trying to navigate to is the result of a POST.
486 */
487 @Override
488 public void onFormResubmission(WebView view, final Message dontResend,
489 final Message resend) {
490 if (!mInForeground) {
491 dontResend.sendToTarget();
492 return;
493 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500494 if (mDontResend != null) {
495 Log.w(LOGTAG, "onFormResubmission should not be called again "
496 + "while dialog is still up");
497 dontResend.sendToTarget();
498 return;
499 }
500 mDontResend = dontResend;
501 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700502 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700503 R.string.browserFrameFormResubmitLabel).setMessage(
504 R.string.browserFrameFormResubmitMessage)
505 .setPositiveButton(R.string.ok,
506 new DialogInterface.OnClickListener() {
507 public void onClick(DialogInterface dialog,
508 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500509 if (mResend != null) {
510 mResend.sendToTarget();
511 mResend = null;
512 mDontResend = null;
513 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700514 }
515 }).setNegativeButton(R.string.cancel,
516 new DialogInterface.OnClickListener() {
517 public void onClick(DialogInterface dialog,
518 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500519 if (mDontResend != null) {
520 mDontResend.sendToTarget();
521 mResend = null;
522 mDontResend = null;
523 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700524 }
525 }).setOnCancelListener(new OnCancelListener() {
526 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500527 if (mDontResend != null) {
528 mDontResend.sendToTarget();
529 mResend = null;
530 mDontResend = null;
531 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700532 }
533 }).show();
534 }
535
536 /**
537 * Insert the url into the visited history database.
538 * @param url The url to be inserted.
539 * @param isReload True if this url is being reloaded.
540 * FIXME: Not sure what to do when reloading the page.
541 */
542 @Override
543 public void doUpdateVisitedHistory(WebView view, String url,
544 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800545 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700546 }
547
548 /**
549 * Displays SSL error(s) dialog to the user.
550 */
551 @Override
552 public void onReceivedSslError(final WebView view,
553 final SslErrorHandler handler, final SslError error) {
554 if (!mInForeground) {
555 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100556 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700557 return;
558 }
John Reck35e9dd62011-04-25 09:01:54 -0700559 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700560 new AlertDialog.Builder(mContext)
561 .setTitle(R.string.security_warning)
562 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200563 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700564 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700565 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700566 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700567 public void onClick(DialogInterface dialog,
568 int whichButton) {
569 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100570 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700571 }
John Reckcb28b2c2011-08-26 17:39:44 -0700572 })
573 .setNeutralButton(R.string.view_certificate,
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) {
John Reckcb28b2c2011-08-26 17:39:44 -0700578 mWebViewController.showSslCertificateOnError(
579 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580 }
John Reckcb28b2c2011-08-26 17:39:44 -0700581 })
582 .setNegativeButton(R.string.ssl_go_back,
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 Reck30c714c2010-12-16 17:30:34 -0800587 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700588 }
John Reckcb28b2c2011-08-26 17:39:44 -0700589 })
590 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700591 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700592 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700593 public void onCancel(DialogInterface dialog) {
594 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100595 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800596 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700597 }
John Reckcb28b2c2011-08-26 17:39:44 -0700598 })
599 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700600 } else {
601 handler.proceed();
602 }
603 }
604
605 /**
Steve Block4895b012011-10-03 16:26:46 +0100606 * Called when an SSL error occurred while loading a resource, but the
607 * WebView but chose to proceed anyway based on a decision retained
608 * from a previous response to onReceivedSslError(). We update our
609 * security state to reflect this.
610 */
611 @Override
612 public void onProceededAfterSslError(WebView view, SslError error) {
613 handleProceededAfterSslError(error);
614 }
615
616 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700617 * Displays client certificate request to the user.
618 */
619 @Override
620 public void onReceivedClientCertRequest(final WebView view,
621 final ClientCertRequestHandler handler, final String host_and_port) {
622 if (!mInForeground) {
623 handler.ignore();
624 return;
625 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700626 int colon = host_and_port.lastIndexOf(':');
627 String host;
628 int port;
629 if (colon == -1) {
630 host = host_and_port;
631 port = -1;
632 } else {
633 String portString = host_and_port.substring(colon + 1);
634 try {
635 port = Integer.parseInt(portString);
636 host = host_and_port.substring(0, colon);
637 } catch (NumberFormatException e) {
638 host = host_and_port;
639 port = -1;
640 }
641 }
Michael Kolb14612442011-06-24 13:06:29 -0700642 KeyChain.choosePrivateKeyAlias(
643 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700644 @Override public void alias(String alias) {
645 if (alias == null) {
646 handler.cancel();
647 return;
648 }
Michael Kolb14612442011-06-24 13:06:29 -0700649 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700650 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700651 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700652 }
653
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800654 @Override
655 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
656 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700657 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
658 hasCrashed = true;
659 showCrashView();
660 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800661 }
662
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700663 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700664 * Handles an HTTP authentication request.
665 *
666 * @param handler The authentication handler
667 * @param host The host
668 * @param realm The realm
669 */
670 @Override
671 public void onReceivedHttpAuthRequest(WebView view,
672 final HttpAuthHandler handler, final String host,
673 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700674 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700675 }
676
677 @Override
John Reck438bf462011-01-12 18:11:46 -0800678 public WebResourceResponse shouldInterceptRequest(WebView view,
679 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800680 //intercept if opening a new incognito tab - show the incognito welcome page
681 if (url.startsWith("browser:incognito")) {
682 Resources resourceHandle = mContext.getResources();
683 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700684 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800685 return new WebResourceResponse("text/html", "utf8", inStream);
686 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800687 WebResourceResponse res;
688 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
689 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
690 } else {
691 res = HomeProvider.shouldInterceptRequest(mContext, url);
692 }
John Reck438bf462011-01-12 18:11:46 -0800693 return res;
694 }
695
696 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700697 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
698 if (!mInForeground) {
699 return false;
700 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700701 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700702 }
703
704 @Override
705 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700706 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700707 return;
708 }
John Reck997b1b72012-04-19 18:08:25 -0700709 if (!mWebViewController.onUnhandledKeyEvent(event)) {
710 super.onUnhandledKeyEvent(view, event);
711 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700712 }
713 };
714
John Reck1cf4b792011-07-26 10:22:22 -0700715 private void syncCurrentState(WebView view, String url) {
716 // Sync state (in case of stop/timeout)
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800717
718 if (mReceivedError) {
719 mCurrentState.mUrl = url;
720 mCurrentState.mOriginalUrl = url;
721 } else {
722 mCurrentState.mUrl = view.getUrl();
723 mCurrentState.mOriginalUrl = view.getOriginalUrl();
724 mCurrentState.mFavicon = view.getFavicon();
725 }
726
John Reck1cf4b792011-07-26 10:22:22 -0700727 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700728 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700729 }
John Reck1cf4b792011-07-26 10:22:22 -0700730 mCurrentState.mTitle = view.getTitle();
Axesh R. Ajmera57120962014-11-13 13:37:24 -0800731
732
John Reck1cf4b792011-07-26 10:22:22 -0700733 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
734 // In case we stop when loading an HTTPS page from an HTTP page
735 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100736 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100737 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700738 }
John Reck502a3532011-08-16 14:21:46 -0700739 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700740 }
741
Tarun Nainani8eb00912014-07-17 12:28:32 -0700742
743 public boolean isTabFullScreen() {
744 return mFullScreen;
745 }
746
Vivek Sekharf96064b2014-07-28 16:32:34 -0700747 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700748 Controller controller = (Controller)mWebViewController;
Sudheer Koganti24766882014-10-02 10:58:09 -0700749 controller.getUi().showFullscreen(fullScreen);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700750 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700751 }
752
Sudheer Koganti24766882014-10-02 10:58:09 -0700753 public boolean exitFullscreen() {
754 if (mFullScreen) {
755 Controller controller = (Controller)mWebViewController;
756 controller.getUi().showFullscreen(false);
757 if (getWebView() != null)
758 getWebView().exitFullscreen();
759 mFullScreen = false;
760 return true;
761 }
762 return false;
763 }
764
765
766
767
Grace Kloba22ac16e2009-10-07 18:00:23 -0700768 // -------------------------------------------------------------------------
769 // WebChromeClient implementation for the main WebView
770 // -------------------------------------------------------------------------
771
772 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
773 // Helper method to create a new tab or sub window.
774 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700775 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700776 }
777
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700778 private void createWindow(final boolean dialog, final Message msg, final String url,
779 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700780 WebView.WebViewTransport transport =
781 (WebView.WebViewTransport) msg.obj;
782 if (dialog) {
783 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700784 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700785 transport.setWebView(mSubView);
786 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700787 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700788 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700789 // This is special case for rendering links on a webpage in
790 // a new tab. If opener is suppressed, the WebContents created
791 // by the content layer are not fully initialized. This check
792 // will prevent content layer from overriding WebContents
793 // created by new tab with the uninitialized instance.
794 if (!opener_suppressed) {
795 transport.setWebView(newTab.getWebView());
796 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700797 }
798 msg.sendToTarget();
799 }
800
801 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700802 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
803 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700804 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700805 }
806 }
807
808 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700809 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
810 float contentOffsetYPix,
811 float overdrawBottomHeightPix) {
812 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700813 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700814 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700815 }
816 }
817
818 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700819 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700820 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700821 }
822
823 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700824 public boolean onCreateWindow(WebView view, final boolean dialog,
825 final boolean userGesture, final Message resultMsg) {
826 // only allow new window or sub window for the foreground case
827 if (!mInForeground) {
828 return false;
829 }
830 // Short-circuit if we can't create any more tabs or sub windows.
831 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700832 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700833 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200834 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700835 .setMessage(R.string.too_many_subwindows_dialog_message)
836 .setPositiveButton(R.string.ok, null)
837 .show();
838 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700839 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700840 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700841 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200842 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700843 .setMessage(R.string.too_many_windows_dialog_message)
844 .setPositiveButton(R.string.ok, null)
845 .show();
846 return false;
847 }
848
849 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800850 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700851 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700852 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700853 createWindow(dialog, resultMsg, windowParams.mURL, true);
854 // This is special case for rendering links on a webpage in
855 // a new tab. If opener is suppressed, the WebContents created
856 // by the content layer are not fully initialized. Returning false
857 // will prevent content layer from overriding WebContents
858 // created by new tab with the uninitialized instance.
859 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700860 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700861
862 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700863 return true;
864 }
865
866 // Allow the popup and create the appropriate window.
867 final AlertDialog.OnClickListener allowListener =
868 new AlertDialog.OnClickListener() {
869 public void onClick(DialogInterface d,
870 int which) {
871 createWindow(dialog, resultMsg);
872 }
873 };
874
875 // Block the popup by returning a null WebView.
876 final AlertDialog.OnClickListener blockListener =
877 new AlertDialog.OnClickListener() {
878 public void onClick(DialogInterface d, int which) {
879 resultMsg.sendToTarget();
880 }
881 };
882
883 // Build a confirmation dialog to display to the user.
884 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700885 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200886 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700887 .setMessage(R.string.popup_window_attempt)
888 .setPositiveButton(R.string.allow, allowListener)
889 .setNegativeButton(R.string.block, blockListener)
890 .setCancelable(false)
891 .create();
892
893 // Show the confirmation dialog.
894 d.show();
895 return true;
896 }
897
898 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500899 public void onRequestFocus(WebView view) {
900 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700901 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500902 }
903 }
904
905 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700906 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700907 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700908 // JavaScript can only close popup window.
909 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700910 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700911 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700912 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700913 }
914 }
915
916 @Override
917 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800918 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800919 if (newProgress == 100) {
920 mInPageLoad = false;
921 }
John Reck30c714c2010-12-16 17:30:34 -0800922 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700923 if (mUpdateThumbnail && newProgress == 100) {
924 mUpdateThumbnail = false;
925 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700926 }
927
928 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500929 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800930 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700931 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700932 }
933
934 @Override
935 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800936 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700937 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700938 }
939
940 @Override
941 public void onReceivedTouchIconUrl(WebView view, String url,
942 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700943 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400944 // Let precomposed icons take precedence over non-composed
945 // icons.
946 if (precomposed && mTouchIconLoader != null) {
947 mTouchIconLoader.cancel(false);
948 mTouchIconLoader = null;
949 }
950 // Have only one async task at a time.
951 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700952 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700953 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400954 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700955 }
956 }
957
958 @Override
959 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800960 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700961 Activity activity = mWebViewController.getActivity();
962 if (activity != null) {
963 onShowCustomView(view, activity.getRequestedOrientation(), callback);
964 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400965 }
966
967 @Override
968 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800969 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700970 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400971 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700972 }
973
974 @Override
975 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700976 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700977 }
978
979 /**
980 * The origin has exceeded its database quota.
981 * @param url the URL that exceeded the quota
982 * @param databaseIdentifier the identifier of the database on which the
983 * transaction that caused the quota overflow was run
984 * @param currentQuota the current quota for the origin.
985 * @param estimatedSize the estimated size of the database.
986 * @param totalUsedQuota is the sum of all origins' quota.
987 * @param quotaUpdater The callback to run when a decision to allow or
988 * deny quota has been made. Don't forget to call this!
989 */
990 @Override
991 public void onExceededDatabaseQuota(String url,
992 String databaseIdentifier, long currentQuota, long estimatedSize,
993 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700994 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700995 .onExceededDatabaseQuota(url, databaseIdentifier,
996 currentQuota, estimatedSize, totalUsedQuota,
997 quotaUpdater);
998 }
999
1000 /**
1001 * The Application Cache has exceeded its max size.
1002 * @param spaceNeeded is the amount of disk space that would be needed
1003 * in order for the last appcache operation to succeed.
1004 * @param totalUsedQuota is the sum of all origins' quota.
1005 * @param quotaUpdater A callback to inform the WebCore thread that a
1006 * new app cache size is available. This callback must always
1007 * be executed at some point to ensure that the sleeping
1008 * WebCore thread is woken up.
1009 */
1010 @Override
1011 public void onReachedMaxAppCacheSize(long spaceNeeded,
1012 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001013 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001014 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1015 quotaUpdater);
1016 }
1017
1018 /**
1019 * Instructs the browser to show a prompt to ask the user to set the
1020 * Geolocation permission state for the specified origin.
1021 * @param origin The origin for which Geolocation permissions are
1022 * requested.
1023 * @param callback The callback to call once the user has set the
1024 * Geolocation permission state.
1025 */
1026 @Override
1027 public void onGeolocationPermissionsShowPrompt(String origin,
1028 GeolocationPermissions.Callback callback) {
1029 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001030 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001031 }
1032 }
1033
1034 /**
1035 * Instructs the browser to hide the Geolocation permissions prompt.
1036 */
1037 @Override
1038 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001039 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001040 mGeolocationPermissionsPrompt.hide();
1041 }
1042 }
1043
Ben Murdoch65acc352009-11-19 18:16:04 +00001044 /* Adds a JavaScript error message to the system log and if the JS
1045 * console is enabled in the about:debug options, to that console
1046 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001047 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001048 */
1049 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001050 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001051 if (mInForeground) {
1052 // call getErrorConsole(true) so it will create one if needed
1053 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001054 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001055 if (mWebViewController.shouldShowErrorConsole()
1056 && errorConsole.getShowState() !=
1057 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001058 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1059 }
1060 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001061
Jeff Hamilton47654f42010-09-07 09:57:51 -05001062 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001063 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001064
Ben Murdochc42addf2010-01-28 15:19:59 +00001065 String message = "Console: " + consoleMessage.message() + " "
1066 + consoleMessage.sourceId() + ":"
1067 + consoleMessage.lineNumber();
1068
1069 switch (consoleMessage.messageLevel()) {
1070 case TIP:
1071 Log.v(CONSOLE_LOGTAG, message);
1072 break;
1073 case LOG:
1074 Log.i(CONSOLE_LOGTAG, message);
1075 break;
1076 case WARNING:
1077 Log.w(CONSOLE_LOGTAG, message);
1078 break;
1079 case ERROR:
1080 Log.e(CONSOLE_LOGTAG, message);
1081 break;
1082 case DEBUG:
1083 Log.d(CONSOLE_LOGTAG, message);
1084 break;
1085 }
1086
1087 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001088 }
1089
1090 /**
1091 * Ask the browser for an icon to represent a <video> element.
1092 * This icon will be used if the Web page did not specify a poster attribute.
1093 * @return Bitmap The icon or null if no such icon is available.
1094 */
1095 @Override
1096 public Bitmap getDefaultVideoPoster() {
1097 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001098 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001099 }
1100 return null;
1101 }
1102
1103 /**
1104 * Ask the host application for a custom progress view to show while
1105 * a <video> is loading.
1106 * @return View The progress view.
1107 */
1108 @Override
1109 public View getVideoLoadingProgressView() {
1110 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001111 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001112 }
1113 return null;
1114 }
1115
1116 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001117 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001118 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001119 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001120 } else {
1121 uploadMsg.onReceiveValue(null);
1122 }
1123 }
1124
Vivek Sekharb54614f2014-05-01 19:03:37 -07001125 @Override
1126 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1127 boolean capture) {
1128 if (mInForeground) {
1129 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1130 } else {
1131 uploadFilePaths.onReceiveValue(null);
1132 }
1133 }
1134
Grace Kloba22ac16e2009-10-07 18:00:23 -07001135 /**
1136 * Deliver a list of already-visited URLs
1137 */
1138 @Override
1139 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001140 mWebViewController.getVisitedHistory(callback);
1141 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001142
1143 @Override
1144 public void setupAutoFill(Message message) {
1145 // Prompt the user to set up their profile.
1146 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001147 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1148 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001149 Context.LAYOUT_INFLATER_SERVICE);
1150 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1151
1152 builder.setView(layout)
1153 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1154 @Override
1155 public void onClick(DialogInterface dialog, int id) {
1156 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1157 R.id.setup_autofill_dialog_disable_autofill);
1158
1159 if (disableAutoFill.isChecked()) {
1160 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001161 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001162 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001163 R.string.autofill_setup_dialog_negative_toast,
1164 Toast.LENGTH_LONG).show();
1165 } else {
1166 // Take user to the AutoFill profile editor. When they return,
1167 // we will send the message that we pass here which will trigger
1168 // the form to get filled out with their new profile.
1169 mWebViewController.setupAutoFill(msg);
1170 }
1171 }
1172 })
1173 .setNegativeButton(R.string.cancel, null)
1174 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001175 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001176 };
1177
1178 // -------------------------------------------------------------------------
1179 // WebViewClient implementation for the sub window
1180 // -------------------------------------------------------------------------
1181
1182 // Subclass of WebViewClient used in subwindows to notify the main
1183 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001184 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001185 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001186 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001187 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001188
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001189 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001190 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001191 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001192 }
1193 @Override
1194 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1195 // Unlike the others, do not call mClient's version, which would
1196 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001197 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001198 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001199 }
1200 @Override
1201 public void doUpdateVisitedHistory(WebView view, String url,
1202 boolean isReload) {
1203 mClient.doUpdateVisitedHistory(view, url, isReload);
1204 }
1205 @Override
1206 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1207 return mClient.shouldOverrideUrlLoading(view, url);
1208 }
1209 @Override
1210 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1211 SslError error) {
1212 mClient.onReceivedSslError(view, handler, error);
1213 }
1214 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001215 public void onReceivedClientCertRequest(WebView view,
1216 ClientCertRequestHandler handler, String host_and_port) {
1217 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1218 }
1219 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001220 public void onReceivedHttpAuthRequest(WebView view,
1221 HttpAuthHandler handler, String host, String realm) {
1222 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1223 }
1224 @Override
1225 public void onFormResubmission(WebView view, Message dontResend,
1226 Message resend) {
1227 mClient.onFormResubmission(view, dontResend, resend);
1228 }
1229 @Override
1230 public void onReceivedError(WebView view, int errorCode,
1231 String description, String failingUrl) {
1232 mClient.onReceivedError(view, errorCode, description, failingUrl);
1233 }
1234 @Override
1235 public boolean shouldOverrideKeyEvent(WebView view,
1236 android.view.KeyEvent event) {
1237 return mClient.shouldOverrideKeyEvent(view, event);
1238 }
1239 @Override
1240 public void onUnhandledKeyEvent(WebView view,
1241 android.view.KeyEvent event) {
1242 mClient.onUnhandledKeyEvent(view, event);
1243 }
1244 }
1245
1246 // -------------------------------------------------------------------------
1247 // WebChromeClient implementation for the sub window
1248 // -------------------------------------------------------------------------
1249
1250 private class SubWindowChromeClient extends WebChromeClient {
1251 // The main WebChromeClient.
1252 private final WebChromeClient mClient;
1253
1254 SubWindowChromeClient(WebChromeClient client) {
1255 mClient = client;
1256 }
1257 @Override
1258 public void onProgressChanged(WebView view, int newProgress) {
1259 mClient.onProgressChanged(view, newProgress);
1260 }
1261 @Override
1262 public boolean onCreateWindow(WebView view, boolean dialog,
1263 boolean userGesture, android.os.Message resultMsg) {
1264 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1265 }
1266 @Override
1267 public void onCloseWindow(WebView window) {
1268 if (window != mSubView) {
1269 Log.e(LOGTAG, "Can't close the window");
1270 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001271 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001272 }
1273 }
1274
1275 // -------------------------------------------------------------------------
1276
1277 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001278 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001279 this(wvcontroller, w, null);
1280 }
1281
1282 Tab(WebViewController wvcontroller, Bundle state) {
1283 this(wvcontroller, null, state);
1284 }
1285
1286 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001287 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001288 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001289 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001290 mDataController = DataController.getInstance(mContext);
1291 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001292 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001293 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001294 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001295 mInForeground = false;
1296
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001297 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001298 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001299 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001300 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001301 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001302 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001303 }
1304 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001305 mWebBackForwardListClient = new WebBackForwardListClient() {
1306 @Override
1307 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001308 if (mClearHistoryUrlPattern != null) {
1309 boolean match =
1310 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001311 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001312 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1313 + item.getUrl() + "\n\t"
1314 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001315 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001316 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001317 if (mMainView != null) {
1318 mMainView.clearHistory();
1319 }
1320 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001321 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001322 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001323 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001324 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001325
John Reck1cf4b792011-07-26 10:22:22 -07001326 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1327 R.dimen.tab_thumbnail_width);
1328 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1329 R.dimen.tab_thumbnail_height);
1330 updateShouldCaptureThumbnails();
1331 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001332 if (getId() == -1) {
1333 mId = TabControl.getNextId();
1334 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001335 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001336 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001337 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001338 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001339 switch (m.what) {
1340 case MSG_CAPTURE:
1341 capture();
1342 break;
1343 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001344 }
1345 };
John Reck1cf4b792011-07-26 10:22:22 -07001346 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001347
Michael Kolb72864272012-05-03 15:42:15 -07001348 public boolean shouldUpdateThumbnail() {
1349 return mUpdateThumbnail;
1350 }
1351
Mathew Inwoode09305e2011-09-02 12:03:26 +01001352 /**
1353 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1354 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1355 * to overlapping IDs between the preloaded and restored tabs.
1356 */
1357 public void refreshIdAfterPreload() {
1358 mId = TabControl.getNextId();
1359 }
1360
John Reck1cf4b792011-07-26 10:22:22 -07001361 public void updateShouldCaptureThumbnails() {
1362 if (mWebViewController.shouldCaptureThumbnails()) {
1363 synchronized (Tab.this) {
1364 if (mCapture == null) {
1365 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1366 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001367 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001368 if (mInForeground) {
1369 postCapture();
1370 }
1371 }
1372 }
1373 } else {
1374 synchronized (Tab.this) {
1375 mCapture = null;
1376 deleteThumbnail();
1377 }
1378 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001379 }
1380
Michael Kolb14612442011-06-24 13:06:29 -07001381 public void setController(WebViewController ctl) {
1382 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001383 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001384 }
1385
Michael Kolbc831b632011-05-11 09:30:34 -07001386 public long getId() {
1387 return mId;
1388 }
1389
Michael Kolb91911a22012-01-17 11:21:25 -08001390 void setWebView(WebView w) {
1391 setWebView(w, true);
1392 }
1393
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001394 public boolean isNativeActive(){
1395 if (mMainView == null)
1396 return false;
1397 return true;
1398 }
1399
1400 public void setTimeStamp(){
1401 Date d = new Date();
1402 timestamp = (new Timestamp(d.getTime()));
1403 }
1404
1405 public Timestamp getTimestamp() {
1406 return timestamp;
1407 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001408 /**
1409 * Sets the WebView for this tab, correctly removing the old WebView from
1410 * the container view.
1411 */
Michael Kolb91911a22012-01-17 11:21:25 -08001412 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001413 if (mMainView == w) {
1414 return;
1415 }
Michael Kolba713ec82010-11-29 17:27:06 -08001416
Grace Kloba22ac16e2009-10-07 18:00:23 -07001417 // If the WebView is changing, the page will be reloaded, so any ongoing
1418 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001419 if (mGeolocationPermissionsPrompt != null) {
1420 mGeolocationPermissionsPrompt.hide();
1421 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001422
Michael Kolba713ec82010-11-29 17:27:06 -08001423 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001424
John Reck1cf4b792011-07-26 10:22:22 -07001425 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001426 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001427 if (w != null) {
1428 syncCurrentState(w, null);
1429 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001430 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001431 }
1432 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001433 // set the new one
1434 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001435 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001436 if (mMainView != null) {
1437 mMainView.setWebViewClient(mWebViewClient);
1438 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001439 // Attach DownloadManager so that downloads can start in an active
1440 // or a non-active window. This can happen when going to a site that
1441 // does a redirect after a period of time. The user could have
1442 // switched to another tab while waiting for the download to start.
1443 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001444 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001445 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001446 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001447 mMainView.setPictureListener(this);
1448 }
Michael Kolb91911a22012-01-17 11:21:25 -08001449 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001450 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001451 WebBackForwardList restoredState
1452 = mMainView.restoreState(mSavedState);
1453 if (restoredState == null || restoredState.getSize() == 0) {
1454 Log.w(LOGTAG, "Failed to restore WebView state!");
1455 loadUrl(mCurrentState.mOriginalUrl, null);
1456 }
John Reck1cf4b792011-07-26 10:22:22 -07001457 mSavedState = null;
1458 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001459 }
1460 }
1461
1462 /**
1463 * Destroy the tab's main WebView and subWindow if any
1464 */
1465 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001466
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001467 if (mPostponeDestroy) {
1468 mShouldDestroy = true;
1469 return;
1470 }
1471 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001472 if (mMainView != null) {
1473 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001474 // save the WebView to call destroy() after detach it from the tab
1475 WebView webView = mMainView;
1476 setWebView(null);
1477 webView.destroy();
1478 }
1479 }
1480
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001481 private boolean mPostponeDestroy = false;
1482 private boolean mShouldDestroy = false;
1483
1484 public void postponeDestroy() {
1485 mPostponeDestroy = true;
1486 }
1487
1488 public void performPostponedDestroy() {
1489 mPostponeDestroy = false;
1490 if (mShouldDestroy) {
1491 destroy();
1492 }
1493 }
1494
Grace Kloba22ac16e2009-10-07 18:00:23 -07001495 /**
1496 * Remove the tab from the parent
1497 */
1498 void removeFromTree() {
1499 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001500 if (mChildren != null) {
1501 for(Tab t : mChildren) {
1502 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001503 }
1504 }
1505 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001506 if (mParent != null) {
1507 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001508 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001509
1510 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001511 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001512 }
1513
1514 /**
1515 * Create a new subwindow unless a subwindow already exists.
1516 * @return True if a new subwindow was created. False if one already exists.
1517 */
1518 boolean createSubWindow() {
1519 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001520 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001521 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001522 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001523 mSubView.setWebChromeClient(new SubWindowChromeClient(
1524 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001525 // Set a different DownloadListener for the mSubView, since it will
1526 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001527 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001528 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001529 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001530 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001531 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001532 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001533 if (mSubView.copyBackForwardList().getSize() == 0) {
1534 // This subwindow was opened for the sole purpose of
1535 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001536 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001537 }
1538 }
1539 });
Michael Kolb14612442011-06-24 13:06:29 -07001540 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001541 return true;
1542 }
1543 return false;
1544 }
1545
1546 /**
1547 * Dismiss the subWindow for the tab.
1548 */
1549 void dismissSubWindow() {
1550 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001551 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001552 mSubView.destroy();
1553 mSubView = null;
1554 mSubViewContainer = null;
1555 }
1556 }
1557
Grace Kloba22ac16e2009-10-07 18:00:23 -07001558
1559 /**
1560 * Set the parent tab of this tab.
1561 */
Michael Kolbc831b632011-05-11 09:30:34 -07001562 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001563 if (parent == this) {
1564 throw new IllegalStateException("Cannot set parent to self!");
1565 }
Michael Kolbc831b632011-05-11 09:30:34 -07001566 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001567 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001568 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001569 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001570 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001571 if (mSavedState != null) {
1572 if (parent == null) {
1573 mSavedState.remove(PARENTTAB);
1574 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001575 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001576 }
1577 }
John Reckb0a86db2011-05-24 14:05:58 -07001578
1579 // Sync the WebView useragent with the parent
1580 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1581 != mSettings.hasDesktopUseragent(getWebView())) {
1582 mSettings.toggleDesktopUseragent(getWebView());
1583 }
John Reck52be4782011-08-26 15:37:29 -07001584
1585 if (parent != null && parent.getId() == getId()) {
1586 throw new IllegalStateException("Parent has same ID as child!");
1587 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001588 }
1589
1590 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001591 * If this Tab was created through another Tab, then this method returns
1592 * that Tab.
1593 * @return the Tab parent or null
1594 */
1595 public Tab getParent() {
1596 return mParent;
1597 }
1598
1599 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001600 * When a Tab is created through the content of another Tab, then we
1601 * associate the Tabs.
1602 * @param child the Tab that was created from this Tab
1603 */
1604 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001605 if (mChildren == null) {
1606 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001607 }
Michael Kolbc831b632011-05-11 09:30:34 -07001608 mChildren.add(child);
1609 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001610 }
1611
Michael Kolbc831b632011-05-11 09:30:34 -07001612 Vector<Tab> getChildren() {
1613 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001614 }
1615
1616 void resume() {
1617 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001618 if (mMainView.hasCrashed()) {
1619 // Reload if render process has crashed. This is done here so that
1620 // setFocus call sends wasShown message to correct render process.
1621 mMainView.reload();
1622 }
John Reck56c1fcf2011-08-17 10:15:16 -07001623 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001624 mMainView.onResume();
1625 if (mSubView != null) {
1626 mSubView.onResume();
1627 }
1628 }
1629 }
1630
John Reck56c1fcf2011-08-17 10:15:16 -07001631 private void setupHwAcceleration(View web) {
1632 if (web == null) return;
1633 BrowserSettings settings = BrowserSettings.getInstance();
1634 if (settings.isHardwareAccelerated()) {
1635 web.setLayerType(View.LAYER_TYPE_NONE, null);
1636 } else {
1637 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1638 }
1639 }
1640
Grace Kloba22ac16e2009-10-07 18:00:23 -07001641 void pause() {
1642 if (mMainView != null) {
1643 mMainView.onPause();
1644 if (mSubView != null) {
1645 mSubView.onPause();
1646 }
1647 }
1648 }
1649
1650 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001651 if (mInForeground) {
1652 return;
1653 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001654 mInForeground = true;
1655 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001656 Activity activity = mWebViewController.getActivity();
1657 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001658 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001659 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001660 }
1661 // Show the pending error dialog if the queue is not empty
1662 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1663 showError(mQueuedErrors.getFirst());
1664 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001665 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001666 }
1667
1668 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001669 if (!mInForeground) {
1670 return;
1671 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001672 mInForeground = false;
1673 pause();
1674 mMainView.setOnCreateContextMenuListener(null);
1675 if (mSubView != null) {
1676 mSubView.setOnCreateContextMenuListener(null);
1677 }
1678 }
1679
Michael Kolb8233fac2010-10-26 16:08:53 -07001680 boolean inForeground() {
1681 return mInForeground;
1682 }
1683
Grace Kloba22ac16e2009-10-07 18:00:23 -07001684 /**
1685 * Return the top window of this tab; either the subwindow if it is not
1686 * null or the main window.
1687 * @return The top window of this tab.
1688 */
1689 WebView getTopWindow() {
1690 if (mSubView != null) {
1691 return mSubView;
1692 }
1693 return mMainView;
1694 }
1695
1696 /**
1697 * Return the main window of this tab. Note: if a tab is freed in the
1698 * background, this can return null. It is only guaranteed to be
1699 * non-null for the current tab.
1700 * @return The main WebView of this tab.
1701 */
1702 WebView getWebView() {
1703 return mMainView;
1704 }
1705
Michael Kolba713ec82010-11-29 17:27:06 -08001706 void setViewContainer(View container) {
1707 mContainer = container;
1708 }
1709
Michael Kolb8233fac2010-10-26 16:08:53 -07001710 View getViewContainer() {
1711 return mContainer;
1712 }
1713
Grace Kloba22ac16e2009-10-07 18:00:23 -07001714 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001715 * Return whether private browsing is enabled for the main window of
1716 * this tab.
1717 * @return True if private browsing is enabled.
1718 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001719 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001720 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001721 }
1722
1723 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001724 * Return the subwindow of this tab or null if there is no subwindow.
1725 * @return The subwindow of this tab or null.
1726 */
1727 WebView getSubWebView() {
1728 return mSubView;
1729 }
1730
Michael Kolb1514bb72010-11-22 09:11:48 -08001731 void setSubWebView(WebView subView) {
1732 mSubView = subView;
1733 }
1734
Michael Kolb8233fac2010-10-26 16:08:53 -07001735 View getSubViewContainer() {
1736 return mSubViewContainer;
1737 }
1738
Michael Kolb1514bb72010-11-22 09:11:48 -08001739 void setSubViewContainer(View subViewContainer) {
1740 mSubViewContainer = subViewContainer;
1741 }
1742
Grace Kloba22ac16e2009-10-07 18:00:23 -07001743 /**
1744 * @return The geolocation permissions prompt for this tab.
1745 */
1746 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001747 if (mGeolocationPermissionsPrompt == null) {
1748 ViewStub stub = (ViewStub) mContainer
1749 .findViewById(R.id.geolocation_permissions_prompt);
1750 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1751 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001752 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001753 return mGeolocationPermissionsPrompt;
1754 }
1755
1756 /**
1757 * @return The application id string
1758 */
1759 String getAppId() {
1760 return mAppId;
1761 }
1762
1763 /**
1764 * Set the application id string
1765 * @param id
1766 */
1767 void setAppId(String id) {
1768 mAppId = id;
1769 }
1770
Michael Kolbe28b3472011-08-04 16:54:31 -07001771 boolean closeOnBack() {
1772 return mCloseOnBack;
1773 }
1774
1775 void setCloseOnBack(boolean close) {
1776 mCloseOnBack = close;
1777 }
1778
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001779 boolean getDerivedFromIntent() {
1780 return mDerivedFromIntent;
1781 }
1782
1783 void setDerivedFromIntent(boolean derived) {
1784 mDerivedFromIntent = derived;
1785 }
1786
Grace Kloba22ac16e2009-10-07 18:00:23 -07001787 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001788 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001789 }
1790
Tarun Nainani8eb00912014-07-17 12:28:32 -07001791
1792 protected void onPageFinished() {
1793 mPageFinished = true;
1794 }
1795
1796 public boolean getPageFinishedStatus() {
1797 return mPageFinished;
1798 }
1799
John Reck49a603c2011-03-03 09:33:05 -08001800 String getOriginalUrl() {
Vivek Sekhar361065a2014-11-25 15:34:35 -08001801 if (mMainView != null)
1802 return mMainView.getOriginalUrl();
John Reckdb22ec42011-06-29 11:31:24 -07001803 if (mCurrentState.mOriginalUrl == null) {
1804 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001805 }
John Reckdb22ec42011-06-29 11:31:24 -07001806 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001807 }
1808
Grace Kloba22ac16e2009-10-07 18:00:23 -07001809 /**
John Reck30c714c2010-12-16 17:30:34 -08001810 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001811 */
1812 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001813 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001814 }
1815
1816 /**
John Reck30c714c2010-12-16 17:30:34 -08001817 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001818 */
1819 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001820 if (mCurrentState.mFavicon != null) {
1821 return mCurrentState.mFavicon;
1822 }
1823 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001824 }
1825
John Recke969cc52010-12-21 17:24:43 -08001826 public boolean isBookmarkedSite() {
1827 return mCurrentState.mIsBookmarkedSite;
1828 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001829
Grace Kloba22ac16e2009-10-07 18:00:23 -07001830 /**
1831 * Return the tab's error console. Creates the console if createIfNEcessary
1832 * is true and we haven't already created the console.
1833 * @param createIfNecessary Flag to indicate if the console should be
1834 * created if it has not been already.
1835 * @return The tab's error console, or null if one has not been created and
1836 * createIfNecessary is false.
1837 */
1838 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1839 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001840 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001841 mErrorConsole.setWebView(mMainView);
1842 }
1843 return mErrorConsole;
1844 }
1845
Steve Block08a6f0c2011-10-06 12:12:53 +01001846 /**
1847 * Sets the security state, clears the SSL certificate error and informs
1848 * the controller.
1849 */
Steve Block2466eff2011-10-03 15:33:09 +01001850 private void setSecurityState(SecurityState securityState) {
1851 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001852 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001853 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001854 }
1855
1856 /**
Steve Block2466eff2011-10-03 15:33:09 +01001857 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001858 */
Steve Block2466eff2011-10-03 15:33:09 +01001859 SecurityState getSecurityState() {
1860 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001861 }
1862
Steve Block08a6f0c2011-10-06 12:12:53 +01001863 /**
1864 * Gets the SSL certificate error, if any, for the page's main resource.
1865 * This is only non-null when the security state is
1866 * SECURITY_STATE_BAD_CERTIFICATE.
1867 */
1868 SslError getSslCertificateError() {
1869 return mCurrentState.mSslCertificateError;
1870 }
1871
John Reck30c714c2010-12-16 17:30:34 -08001872 int getLoadProgress() {
1873 if (mInPageLoad) {
1874 return mPageLoadProgress;
1875 }
1876 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001877 }
1878
1879 /**
1880 * @return TRUE if onPageStarted is called while onPageFinished is not
1881 * called yet.
1882 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001883 boolean inPageLoad() {
1884 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001885 }
1886
Grace Kloba22ac16e2009-10-07 18:00:23 -07001887 /**
John Reck1cf4b792011-07-26 10:22:22 -07001888 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001889 */
John Reck1cf4b792011-07-26 10:22:22 -07001890 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001891 // If the WebView is null it means we ran low on memory and we already
1892 // stored the saved state in mSavedState.
1893 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001894 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001895 }
John Reck6c2e2f32011-08-22 13:41:23 -07001896
1897 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001898 return null;
John Reck24f18262011-06-17 14:47:20 -07001899 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001900
1901 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001902 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1903 if (savedList == null || savedList.getSize() == 0) {
1904 Log.w(LOGTAG, "Failed to save back/forward list for "
1905 + mCurrentState.mUrl);
1906 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001907
Michael Kolbc831b632011-05-11 09:30:34 -07001908 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001909 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1910 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001911 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001912 if (mAppId != null) {
1913 mSavedState.putString(APPID, mAppId);
1914 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001915 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001916 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001917 if (mParent != null) {
1918 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001919 }
John Reckb0a86db2011-05-24 14:05:58 -07001920 mSavedState.putBoolean(USERAGENT,
1921 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001922 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001923 }
1924
1925 /*
1926 * Restore the state of the tab.
1927 */
John Reck1cf4b792011-07-26 10:22:22 -07001928 private void restoreState(Bundle b) {
1929 mSavedState = b;
1930 if (mSavedState == null) {
1931 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001932 }
1933 // Restore the internal state even if the WebView fails to restore.
1934 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001935 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001936 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001937 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001938 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001939 String url = b.getString(CURRURL);
1940 String title = b.getString(CURRTITLE);
1941 boolean incognito = b.getBoolean(INCOGNITO);
1942 mCurrentState = new PageState(mContext, incognito, url, null);
1943 mCurrentState.mTitle = title;
1944 synchronized (Tab.this) {
1945 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001946 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001947 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001948 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001949 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001950
John Reck8b9bb8b2012-03-08 13:19:40 -08001951 private void restoreUserAgent() {
1952 if (mMainView == null || mSavedState == null) {
1953 return;
1954 }
1955 if (mSavedState.getBoolean(USERAGENT)
1956 != mSettings.hasDesktopUseragent(mMainView)) {
1957 mSettings.toggleDesktopUseragent(mMainView);
1958 }
1959 }
1960
Leon Scroggins1961ed22010-12-07 15:22:21 -05001961 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001962 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001963 }
1964
John Recke969cc52010-12-21 17:24:43 -08001965 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1966 = new DataController.OnQueryUrlIsBookmark() {
1967 @Override
1968 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1969 if (mCurrentState.mUrl.equals(url)) {
1970 mCurrentState.mIsBookmarkedSite = isBookmark;
1971 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1972 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001973 }
John Recke969cc52010-12-21 17:24:43 -08001974 };
Michael Kolb1acef692011-03-08 14:12:06 -08001975
Michael Kolbeb95db42011-03-03 10:38:40 -08001976 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001977 synchronized (Tab.this) {
1978 return mCapture;
1979 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001980 }
1981
John Reck541f55a2011-06-07 16:34:43 -07001982 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001983 return false;
1984 }
1985
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001986 private static class SaveCallback implements ValueCallback<String> {
1987 boolean onReceiveValueCalled = false;
1988 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001989
1990 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001991 public void onReceiveValue(String path) {
1992 this.onReceiveValueCalled = true;
1993 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001994 synchronized (this) {
1995 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001996 }
John Reck541f55a2011-06-07 16:34:43 -07001997 }
John Reck68234a92012-04-19 15:27:12 -07001998
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001999 public String getPath() {
2000 return mPath;
2001 }
John Reck68234a92012-04-19 15:27:12 -07002002 }
2003
2004 /**
2005 * Must be called on the UI thread
2006 */
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07002007 public ContentValues createSnapshotValues(Bitmap bm) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002008 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002009 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07002010 ContentValues values = new ContentValues();
2011 values.put(Snapshots.TITLE, mCurrentState.mTitle);
2012 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07002013 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07002014 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2015 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Vivek Sekhar46c3ec02014-10-09 17:28:57 -07002016 values.put(Snapshots.THUMBNAIL, compressBitmap(bm));
John Reckd8c74522011-06-14 08:45:00 -07002017 return values;
John Reck541f55a2011-06-07 16:34:43 -07002018 }
2019
John Reck68234a92012-04-19 15:27:12 -07002020 /**
2021 * Probably want to call this on a background thread
2022 */
2023 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002024 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002025 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002026 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002027 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002028 try {
John Reck68234a92012-04-19 15:27:12 -07002029 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002030 web.saveViewState(filename, callback);
2031 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002032 }
John Reck68234a92012-04-19 15:27:12 -07002033 } catch (Exception e) {
2034 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002035 String path = callback.getPath();
2036 if (path != null) {
2037 File file = mContext.getFileStreamPath(path);
2038 if (file.exists() && !file.delete()) {
2039 file.deleteOnExit();
2040 }
John Reck68234a92012-04-19 15:27:12 -07002041 }
2042 return false;
2043 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002044
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002045 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002046 // could be that saving of file failed
2047 if (path == null) {
2048 return false;
2049 }
2050
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002051 File savedFile = new File(path);
2052 if (!savedFile.exists()) {
2053 return false;
John Reck68234a92012-04-19 15:27:12 -07002054 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002055 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2056 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002057 return true;
2058 }
2059
John Reck8cc92352011-07-06 17:41:52 -07002060 public byte[] compressBitmap(Bitmap bitmap) {
2061 if (bitmap == null) {
2062 return null;
2063 }
2064 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2065 bitmap.compress(CompressFormat.PNG, 100, stream);
2066 return stream.toByteArray();
2067 }
2068
John Reck26b18322011-06-21 13:08:58 -07002069 public void loadUrl(String url, Map<String, String> headers) {
2070 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002071 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002072 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002073 mMainView.loadUrl(url, headers);
2074 }
2075 }
2076
John Reck38b39652012-06-05 09:22:59 -07002077 public void disableUrlOverridingForLoad() {
2078 mDisableOverrideUrlLoading = true;
2079 }
2080
Michael Kolb9ef259a2011-07-12 15:33:08 -07002081 protected void capture() {
2082 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002083 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2084 return;
2085 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002086
2087 mMainView
2088 .getContentBitmapAsync(
2089 (float) mCaptureWidth / mMainView.getWidth(),
2090 new Rect(),
2091 new ValueCallback<Bitmap>() {
2092 @Override
2093 public void onReceiveValue(Bitmap bitmap) {
2094 onCaptureCallback(bitmap);
2095 }});
2096 }
2097
2098 private void onCaptureCallback(Bitmap bitmap) {
2099 if (mCapture == null || bitmap == null)
2100 return;
2101
Michael Kolb9ef259a2011-07-12 15:33:08 -07002102 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002103 mCapture.eraseColor(Color.WHITE);
2104 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002105
Michael Kolba3194d02011-09-07 11:23:51 -07002106 // manually anti-alias the edges for the tilt
2107 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2108 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2109 mCapture.getHeight(), sAlphaPaint);
2110 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2111 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2112 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002113 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002114 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002115 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002116 TabControl tc = mWebViewController.getTabControl();
2117 if (tc != null) {
2118 OnThumbnailUpdatedListener updateListener
2119 = tc.getOnThumbnailUpdatedListener();
2120 if (updateListener != null) {
2121 updateListener.onThumbnailUpdated(this);
2122 }
2123 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002124 }
2125
2126 @Override
2127 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002128 postCapture();
2129 }
2130
2131 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002132 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2133 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2134 }
2135 }
2136
John Reckef654f12011-07-12 16:42:08 -07002137 public boolean canGoBack() {
2138 return mMainView != null ? mMainView.canGoBack() : false;
2139 }
2140
2141 public boolean canGoForward() {
2142 return mMainView != null ? mMainView.canGoForward() : false;
2143 }
2144
2145 public void goBack() {
2146 if (mMainView != null) {
2147 mMainView.goBack();
2148 }
2149 }
2150
2151 public void goForward() {
2152 if (mMainView != null) {
2153 mMainView.goForward();
2154 }
2155 }
2156
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002157 /**
2158 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2159 * to be added to the stack.
2160 *
2161 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2162 * not appear in the back stack.
2163 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002164 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2165 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002166 }
2167
John Reck1cf4b792011-07-26 10:22:22 -07002168 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002169 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002170 }
2171
2172 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002173 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002174 }
2175
John Reck4eadc342011-10-31 14:04:10 -07002176 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002177 synchronized (Tab.this) {
2178 if (mCapture == null) {
2179 return;
2180 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002181 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002182 try {
2183 mCapture.copyPixelsFromBuffer(buffer);
2184 } catch (RuntimeException rex) {
2185 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2186 + buffer.capacity() + " blob: " + blob.length
2187 + "capture: " + mCapture.getByteCount());
2188 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002189 }
John Reck1cf4b792011-07-26 10:22:22 -07002190 }
2191 }
2192
John Reck52be4782011-08-26 15:37:29 -07002193 @Override
2194 public String toString() {
2195 StringBuilder builder = new StringBuilder(100);
2196 builder.append(mId);
2197 builder.append(") has parent: ");
2198 if (getParent() != null) {
2199 builder.append("true[");
2200 builder.append(getParent().getId());
2201 builder.append("]");
2202 } else {
2203 builder.append("false");
2204 }
2205 builder.append(", incog: ");
2206 builder.append(isPrivateBrowsingEnabled());
2207 if (!isPrivateBrowsingEnabled()) {
2208 builder.append(", title: ");
2209 builder.append(getTitle());
2210 builder.append(", url: ");
2211 builder.append(getUrl());
2212 }
2213 return builder.toString();
2214 }
2215
Steve Block4895b012011-10-03 16:26:46 +01002216 private void handleProceededAfterSslError(SslError error) {
2217 if (error.getUrl().equals(mCurrentState.mUrl)) {
2218 // The security state should currently be SECURITY_STATE_SECURE.
2219 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002220 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002221 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002222 // The page's main resource is secure and this error is for a
2223 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002224 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2225 }
2226 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002227}