blob: 861d68f7c0467be2f2c2e9c640f5abdd457a4348 [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.R;
65import com.android.browser.TabControl.OnThumbnailUpdatedListener;
66import com.android.browser.homepages.HomeProvider;
67import com.android.browser.mynavigation.MyNavigationUtil;
68import com.android.browser.provider.MyNavigationProvider;
69import com.android.browser.provider.SnapshotProvider.Snapshots;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080070
71import org.codeaurora.swe.BrowserDownloadListener;
72import org.codeaurora.swe.ClientCertRequestHandler;
73import org.codeaurora.swe.HttpAuthHandler;
74import org.codeaurora.swe.SslErrorHandler;
75import org.codeaurora.swe.WebBackForwardList;
76import org.codeaurora.swe.WebBackForwardListClient;
77import org.codeaurora.swe.WebChromeClient;
78import org.codeaurora.swe.WebHistoryItem;
79import org.codeaurora.swe.WebView;
80import org.codeaurora.swe.WebView.PictureListener;
Pankaj Garg1c7380d2014-08-27 14:17:12 -070081import org.codeaurora.swe.WebView.CreateWindowParams;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080082import org.codeaurora.swe.WebViewClient;
83
John Reck541f55a2011-06-07 16:34:43 -070084import java.io.ByteArrayOutputStream;
John Reck2b71d6d2012-04-18 17:42:06 -070085import java.io.File;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080086import java.io.InputStream;
John Reck1cf4b792011-07-26 10:22:22 -070087import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070088import java.util.LinkedList;
89import java.util.Map;
John Reck2b71d6d2012-04-18 17:42:06 -070090import java.util.UUID;
Michael Kolbfe251992010-07-08 15:41:55 -070091import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010092import java.util.regex.Pattern;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080093import java.sql.Timestamp;
94import java.util.Date;
Michael Kolbfe251992010-07-08 15:41:55 -070095
Grace Kloba22ac16e2009-10-07 18:00:23 -070096/**
97 * Class for maintaining Tabs with a main WebView and a subwindow.
98 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070099class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Grace Kloba22ac16e2009-10-07 18:00:23 -0700101 // Log Tag
102 private static final String LOGTAG = "Tab";
Bijan Amirzada41242f22014-03-21 12:12:18 -0700103 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +0000104 // Special case the logtag for messages for the Console to make it easier to
105 // filter them and match the logtag used for these messages in older versions
106 // of the browser.
107 private static final String CONSOLE_LOGTAG = "browser";
108
Michael Kolb9ef259a2011-07-12 15:33:08 -0700109 private static final int MSG_CAPTURE = 42;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800110 private static final int CAPTURE_DELAY = 1000;
Michael Kolba53c9892011-10-05 13:31:40 -0700111 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700112
John Reck1cf4b792011-07-26 10:22:22 -0700113 private static Bitmap sDefaultFavicon;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800114 protected boolean hasCrashed = false;
John Reck1cf4b792011-07-26 10:22:22 -0700115
Michael Kolba3194d02011-09-07 11:23:51 -0700116 private static Paint sAlphaPaint = new Paint();
117 static {
118 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
119 sAlphaPaint.setColor(Color.TRANSPARENT);
120 }
121
Steve Block2466eff2011-10-03 15:33:09 +0100122 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100123 // The page's main resource does not use SSL. Note that we use this
124 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100125 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100126 // The page's main resource uses SSL and the certificate is good. The
127 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100128 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100129 // The page's main resource uses SSL and the certificate is good, but
130 // some sub-resources either do not use SSL or have problems with their
131 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100132 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100133 // The page's main resource uses SSL but there is a problem with its
134 // certificate.
135 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800136 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700137
Michael Kolb14612442011-06-24 13:06:29 -0700138 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700139 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700140
Michael Kolbc831b632011-05-11 09:30:34 -0700141 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700142 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700143
Grace Kloba22ac16e2009-10-07 18:00:23 -0700144 // The Geolocation permissions prompt
145 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
146 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800147 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700148 // Main WebView
149 private WebView mMainView;
150 // Subwindow container
151 private View mSubViewContainer;
152 // Subwindow WebView
153 private WebView mSubView;
154 // Saved bundle for when we are running low on memory. It contains the
155 // information needed to restore the WebView if the user goes back to the
156 // tab.
157 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700158 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
159 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700160 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700161 // Tab that constructed by this Tab. This is used when this Tab is
162 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700163 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700164 // If true, the tab is in the foreground of the current activity.
165 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700166 // If true, the tab is in page loading state (after onPageStarted,
167 // before onPageFinsihed)
168 private boolean mInPageLoad;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700169 private boolean mPageFinished;
John Reck38b39652012-06-05 09:22:59 -0700170 private boolean mDisableOverrideUrlLoading;
John Reck30c714c2010-12-16 17:30:34 -0800171 // The last reported progress of the current page
172 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000173 // The time the load started, used to find load page time
174 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700175 // Application identifier used to find tabs that another application wants
176 // to reuse.
177 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700178 // flag to indicate if tab should be closed on back
179 private boolean mCloseOnBack;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700180 // flag to indicate if the tab was opened from an intent
181 private boolean mDerivedFromIntent = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700182 // Keep the original url around to avoid killing the old WebView if the url
183 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700184 // Error console for the tab
185 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500186 // The listener that gets invoked when a download is started from the
187 // mMainView
Selim Gurun0b3d66f2012-08-29 13:08:13 -0700188 private final BrowserDownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500189 // Listener used to know when we move forward or back in the history list.
190 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800191 private DataController mDataController;
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700192 //Indicates if a JS interface was created for a specific url
193 private boolean mJsInterfaceEnabled = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700194
195 // AsyncTask for downloading touch icons
196 DownloadTouchIcon mTouchIconLoader;
197
John Reck35e9dd62011-04-25 09:01:54 -0700198 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700199 private int mCaptureWidth;
200 private int mCaptureHeight;
201 private Bitmap mCapture;
202 private Handler mHandler;
Michael Kolb72864272012-05-03 15:42:15 -0700203 private boolean mUpdateThumbnail;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800204 private Timestamp timestamp;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700205 private boolean mFullScreen = false;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700206
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100207 /**
Mathew Inwood9ad1eac2011-09-15 11:29:50 +0100208 * See {@link #clearBackStackWhenItemAdded(String)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100209 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100210 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100211
John Reck1cf4b792011-07-26 10:22:22 -0700212 private static synchronized Bitmap getDefaultFavicon(Context context) {
213 if (sDefaultFavicon == null) {
214 sDefaultFavicon = BitmapFactory.decodeResource(
215 context.getResources(), R.drawable.app_web_browser_sm);
216 }
217 return sDefaultFavicon;
218 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800219
John Reck30c714c2010-12-16 17:30:34 -0800220 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700221 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800222 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700223 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800224 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100225 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100226 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
227 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800228 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100229 boolean mIsBookmarkedSite;
230 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800231
232 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700233 mIncognito = incognito;
234 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700235 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800236 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800237 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700238 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800239 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800240 }
Steve Block2466eff2011-10-03 15:33:09 +0100241 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800242 }
243
244 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700245 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700246 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800247 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100248 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800249 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100250 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800251 }
John Reck1cf4b792011-07-26 10:22:22 -0700252 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800253 }
John Reck1cf4b792011-07-26 10:22:22 -0700254
Grace Kloba22ac16e2009-10-07 18:00:23 -0700255 }
256
John Reck30c714c2010-12-16 17:30:34 -0800257 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700258 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800259
Grace Kloba22ac16e2009-10-07 18:00:23 -0700260 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700261 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700262 static final String CURRURL = "currentUrl";
263 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700264 static final String PARENTTAB = "parentTab";
265 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700266 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700267 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700268 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700269
Grace Kloba22ac16e2009-10-07 18:00:23 -0700270 // Container class for the next error dialog that needs to be displayed
271 private class ErrorDialog {
272 public final int mTitle;
273 public final String mDescription;
274 public final int mError;
275 ErrorDialog(int title, String desc, int error) {
276 mTitle = title;
277 mDescription = desc;
278 mError = error;
279 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700280 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700281
282 private void processNextError() {
283 if (mQueuedErrors == null) {
284 return;
285 }
286 // The first one is currently displayed so just remove it.
287 mQueuedErrors.removeFirst();
288 if (mQueuedErrors.size() == 0) {
289 mQueuedErrors = null;
290 return;
291 }
292 showError(mQueuedErrors.getFirst());
293 }
294
295 private DialogInterface.OnDismissListener mDialogListener =
296 new DialogInterface.OnDismissListener() {
297 public void onDismiss(DialogInterface d) {
298 processNextError();
299 }
300 };
301 private LinkedList<ErrorDialog> mQueuedErrors;
302
303 private void queueError(int err, String desc) {
304 if (mQueuedErrors == null) {
305 mQueuedErrors = new LinkedList<ErrorDialog>();
306 }
307 for (ErrorDialog d : mQueuedErrors) {
308 if (d.mError == err) {
309 // Already saw a similar error, ignore the new one.
310 return;
311 }
312 }
313 ErrorDialog errDialog = new ErrorDialog(
314 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
315 R.string.browserFrameFileErrorLabel :
316 R.string.browserFrameNetworkErrorLabel,
317 desc, err);
318 mQueuedErrors.addLast(errDialog);
319
320 // Show the dialog now if the queue was empty and it is in foreground
321 if (mQueuedErrors.size() == 1 && mInForeground) {
322 showError(errDialog);
323 }
324 }
325
326 private void showError(ErrorDialog errDialog) {
327 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700328 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700329 .setTitle(errDialog.mTitle)
330 .setMessage(errDialog.mDescription)
331 .setPositiveButton(R.string.ok, null)
332 .create();
333 d.setOnDismissListener(mDialogListener);
334 d.show();
335 }
336 }
337
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800338 protected void replaceCrashView(View view, View container) {
339 if (hasCrashed && (view == mMainView)) {
340 final FrameLayout wrapper = (FrameLayout) container.findViewById(R.id.webview_wrapper);
341 wrapper.removeAllViewsInLayout();
342 wrapper.addView(view);
343 hasCrashed = false;
344 }
345 }
346
347 protected void showCrashView() {
348 if (hasCrashed) {
349 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
350 Context.LAYOUT_INFLATER_SERVICE);
351 final View crashLayout = inflater.inflate(R.layout.browser_tab_crash, null);
352 final FrameLayout wrapper =
353 (FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
354 wrapper.removeAllViewsInLayout();
355 wrapper.addView(crashLayout);
356 mContainer.requestFocus();
357 Button reloadBtn = (Button) crashLayout.findViewById(R.id.browser_crash_reload_btn);
358 reloadBtn.setOnClickListener(new OnClickListener() {
359 @Override
360 public void onClick(View arg0) {
361 replaceCrashView(mMainView, mContainer);
362 mMainView.reload();
363 }
364 });
365 }
366 }
367
Grace Kloba22ac16e2009-10-07 18:00:23 -0700368 // -------------------------------------------------------------------------
369 // WebViewClient implementation for the main WebView
370 // -------------------------------------------------------------------------
371
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800372 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500373 private Message mDontResend;
374 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700375
376 private boolean providersDiffer(String url, String otherUrl) {
377 Uri uri1 = Uri.parse(url);
378 Uri uri2 = Uri.parse(otherUrl);
379 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
380 }
381
Grace Kloba22ac16e2009-10-07 18:00:23 -0700382 @Override
383 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 mInPageLoad = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700385 mPageFinished = false;
Michael Kolb72864272012-05-03 15:42:15 -0700386 mUpdateThumbnail = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700387 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700388 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800389 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000390 mLoadStartTime = SystemClock.uptimeMillis();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700391
392 // If we start a touch icon load and then load a new page, we don't
393 // want to cancel the current touch icon loader. But, we do want to
394 // create a new one when the touch icon url is known.
395 if (mTouchIconLoader != null) {
396 mTouchIconLoader.mTab = null;
397 mTouchIconLoader = null;
398 }
399
400 // reset the error console
401 if (mErrorConsole != null) {
402 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700403 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700404 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
405 }
406 }
407
Grace Kloba22ac16e2009-10-07 18:00:23 -0700408 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800409 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500410
John Recke969cc52010-12-21 17:24:43 -0800411 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700412 }
413
414 @Override
415 public void onPageFinished(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700416 mDisableOverrideUrlLoading = false;
John Reck5b691842010-11-29 11:21:13 -0800417 if (!isPrivateBrowsingEnabled()) {
418 LogTag.logPageFinishedLoading(
419 url, SystemClock.uptimeMillis() - mLoadStartTime);
420 }
John Reck1cf4b792011-07-26 10:22:22 -0700421 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800422 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700423 }
424
425 // return true if want to hijack the url to let another app to handle it
426 @Override
427 public boolean shouldOverrideUrlLoading(WebView view, String url) {
John Reck38b39652012-06-05 09:22:59 -0700428 if (!mDisableOverrideUrlLoading && mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800429 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
430 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700431 } else {
432 return false;
433 }
434 }
435
436 /**
Steve Block2466eff2011-10-03 15:33:09 +0100437 * Updates the security state. This method is called when we discover
438 * another resource to be loaded for this page (for example,
439 * javascript). While we update the security state, we do not update
440 * the lock icon until we are done loading, as it is slightly more
441 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700442 */
443 @Override
444 public void onLoadResource(WebView view, String url) {
445 if (url != null && url.length() > 0) {
446 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100447 // to update the security state:
448 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
449 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700450 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
451 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100452 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700453 }
454 }
455 }
456 }
457
458 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700459 * Show a dialog informing the user of the network error reported by
460 * WebCore if it is in the foreground.
461 */
462 @Override
463 public void onReceivedError(WebView view, int errorCode,
464 String description, String failingUrl) {
465 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
466 errorCode != WebViewClient.ERROR_CONNECT &&
467 errorCode != WebViewClient.ERROR_BAD_URL &&
468 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
469 errorCode != WebViewClient.ERROR_FILE) {
470 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500471
Selim Gurun3da06b82011-10-10 13:58:12 -0700472 // Don't log URLs when in private browsing mode
473 if (!isPrivateBrowsingEnabled()) {
474 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500475 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700476 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500477 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700478 }
479
480 /**
481 * Check with the user if it is ok to resend POST data as the page they
482 * are trying to navigate to is the result of a POST.
483 */
484 @Override
485 public void onFormResubmission(WebView view, final Message dontResend,
486 final Message resend) {
487 if (!mInForeground) {
488 dontResend.sendToTarget();
489 return;
490 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500491 if (mDontResend != null) {
492 Log.w(LOGTAG, "onFormResubmission should not be called again "
493 + "while dialog is still up");
494 dontResend.sendToTarget();
495 return;
496 }
497 mDontResend = dontResend;
498 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700499 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700500 R.string.browserFrameFormResubmitLabel).setMessage(
501 R.string.browserFrameFormResubmitMessage)
502 .setPositiveButton(R.string.ok,
503 new DialogInterface.OnClickListener() {
504 public void onClick(DialogInterface dialog,
505 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500506 if (mResend != null) {
507 mResend.sendToTarget();
508 mResend = null;
509 mDontResend = null;
510 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700511 }
512 }).setNegativeButton(R.string.cancel,
513 new DialogInterface.OnClickListener() {
514 public void onClick(DialogInterface dialog,
515 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500516 if (mDontResend != null) {
517 mDontResend.sendToTarget();
518 mResend = null;
519 mDontResend = null;
520 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700521 }
522 }).setOnCancelListener(new OnCancelListener() {
523 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500524 if (mDontResend != null) {
525 mDontResend.sendToTarget();
526 mResend = null;
527 mDontResend = null;
528 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700529 }
530 }).show();
531 }
532
533 /**
534 * Insert the url into the visited history database.
535 * @param url The url to be inserted.
536 * @param isReload True if this url is being reloaded.
537 * FIXME: Not sure what to do when reloading the page.
538 */
539 @Override
540 public void doUpdateVisitedHistory(WebView view, String url,
541 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800542 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700543 }
544
545 /**
546 * Displays SSL error(s) dialog to the user.
547 */
548 @Override
549 public void onReceivedSslError(final WebView view,
550 final SslErrorHandler handler, final SslError error) {
551 if (!mInForeground) {
552 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100553 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700554 return;
555 }
John Reck35e9dd62011-04-25 09:01:54 -0700556 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700557 new AlertDialog.Builder(mContext)
558 .setTitle(R.string.security_warning)
559 .setMessage(R.string.ssl_warnings_header)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200560 .setIconAttribute(android.R.attr.alertDialogIcon)
John Reckcb28b2c2011-08-26 17:39:44 -0700561 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700562 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700563 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700564 public void onClick(DialogInterface dialog,
565 int whichButton) {
566 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100567 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700568 }
John Reckcb28b2c2011-08-26 17:39:44 -0700569 })
570 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700571 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700572 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700573 public void onClick(DialogInterface dialog,
574 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700575 mWebViewController.showSslCertificateOnError(
576 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700577 }
John Reckcb28b2c2011-08-26 17:39:44 -0700578 })
579 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700581 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700582 public void onClick(DialogInterface dialog,
583 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800584 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700585 }
John Reckcb28b2c2011-08-26 17:39:44 -0700586 })
587 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700588 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700589 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700590 public void onCancel(DialogInterface dialog) {
591 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100592 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800593 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700594 }
John Reckcb28b2c2011-08-26 17:39:44 -0700595 })
596 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700597 } else {
598 handler.proceed();
599 }
600 }
601
602 /**
Steve Block4895b012011-10-03 16:26:46 +0100603 * Called when an SSL error occurred while loading a resource, but the
604 * WebView but chose to proceed anyway based on a decision retained
605 * from a previous response to onReceivedSslError(). We update our
606 * security state to reflect this.
607 */
608 @Override
609 public void onProceededAfterSslError(WebView view, SslError error) {
610 handleProceededAfterSslError(error);
611 }
612
613 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700614 * Displays client certificate request to the user.
615 */
616 @Override
617 public void onReceivedClientCertRequest(final WebView view,
618 final ClientCertRequestHandler handler, final String host_and_port) {
619 if (!mInForeground) {
620 handler.ignore();
621 return;
622 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700623 int colon = host_and_port.lastIndexOf(':');
624 String host;
625 int port;
626 if (colon == -1) {
627 host = host_and_port;
628 port = -1;
629 } else {
630 String portString = host_and_port.substring(colon + 1);
631 try {
632 port = Integer.parseInt(portString);
633 host = host_and_port.substring(0, colon);
634 } catch (NumberFormatException e) {
635 host = host_and_port;
636 port = -1;
637 }
638 }
Michael Kolb14612442011-06-24 13:06:29 -0700639 KeyChain.choosePrivateKeyAlias(
640 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700641 @Override public void alias(String alias) {
642 if (alias == null) {
643 handler.cancel();
644 return;
645 }
Michael Kolb14612442011-06-24 13:06:29 -0700646 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700647 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700648 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700649 }
650
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800651 @Override
652 public void onRendererCrash(WebView view, boolean crashedWhileOomProtected) {
653 Log.e(LOGTAG, "Tab Crashed");
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700654 if (mWebViewController.getTabControl().getCurrentTab() == Tab.this) {
655 hasCrashed = true;
656 showCrashView();
657 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800658 }
659
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700660 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700661 * Handles an HTTP authentication request.
662 *
663 * @param handler The authentication handler
664 * @param host The host
665 * @param realm The realm
666 */
667 @Override
668 public void onReceivedHttpAuthRequest(WebView view,
669 final HttpAuthHandler handler, final String host,
670 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700671 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700672 }
673
674 @Override
John Reck438bf462011-01-12 18:11:46 -0800675 public WebResourceResponse shouldInterceptRequest(WebView view,
676 String url) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800677 //intercept if opening a new incognito tab - show the incognito welcome page
678 if (url.startsWith("browser:incognito")) {
679 Resources resourceHandle = mContext.getResources();
680 InputStream inStream = resourceHandle.openRawResource(
Bijan Amirzada41242f22014-03-21 12:12:18 -0700681 com.android.browser.R.raw.incognito_mode_start_page);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800682 return new WebResourceResponse("text/html", "utf8", inStream);
683 }
kaiyiz6e5b3e02013-08-19 20:02:01 +0800684 WebResourceResponse res;
685 if (MyNavigationUtil.MY_NAVIGATION.equals(url)) {
686 res = MyNavigationProvider.shouldInterceptRequest(mContext, url);
687 } else {
688 res = HomeProvider.shouldInterceptRequest(mContext, url);
689 }
John Reck438bf462011-01-12 18:11:46 -0800690 return res;
691 }
692
693 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700694 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
695 if (!mInForeground) {
696 return false;
697 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700699 }
700
701 @Override
702 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700704 return;
705 }
John Reck997b1b72012-04-19 18:08:25 -0700706 if (!mWebViewController.onUnhandledKeyEvent(event)) {
707 super.onUnhandledKeyEvent(view, event);
708 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700709 }
710 };
711
John Reck1cf4b792011-07-26 10:22:22 -0700712 private void syncCurrentState(WebView view, String url) {
713 // Sync state (in case of stop/timeout)
714 mCurrentState.mUrl = view.getUrl();
715 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700716 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700717 }
718 mCurrentState.mOriginalUrl = view.getOriginalUrl();
719 mCurrentState.mTitle = view.getTitle();
720 mCurrentState.mFavicon = view.getFavicon();
721 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
722 // In case we stop when loading an HTTPS page from an HTTP page
723 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100724 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100725 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700726 }
John Reck502a3532011-08-16 14:21:46 -0700727 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700728 }
729
Tarun Nainani8eb00912014-07-17 12:28:32 -0700730
731 public boolean isTabFullScreen() {
732 return mFullScreen;
733 }
734
Vivek Sekharf96064b2014-07-28 16:32:34 -0700735 protected void setTabFullscreen(boolean fullScreen) {
Tarun Nainani8eb00912014-07-17 12:28:32 -0700736 Controller controller = (Controller)mWebViewController;
737
738 if (!mSettings.useFullscreen())
739 controller.getUi().setFullscreen(fullScreen);
740
741 if (getWebView() != null) {
742 if (fullScreen)
743 getWebView().updateTopControls(true, false, true);
744 else if (!mSettings.useQuickControls())
745 getWebView().updateTopControls(true, true, true);
Vivek Sekharf96064b2014-07-28 16:32:34 -0700746 }
Tarun Nainani8eb00912014-07-17 12:28:32 -0700747
748 mFullScreen = fullScreen;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700749 }
750
Grace Kloba22ac16e2009-10-07 18:00:23 -0700751 // -------------------------------------------------------------------------
752 // WebChromeClient implementation for the main WebView
753 // -------------------------------------------------------------------------
754
755 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
756 // Helper method to create a new tab or sub window.
757 private void createWindow(final boolean dialog, final Message msg) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700758 this.createWindow(dialog, msg, null, false);
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700759 }
760
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700761 private void createWindow(final boolean dialog, final Message msg, final String url,
762 final boolean opener_suppressed) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700763 WebView.WebViewTransport transport =
764 (WebView.WebViewTransport) msg.obj;
765 if (dialog) {
766 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700767 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700768 transport.setWebView(mSubView);
769 } else {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700770 final Tab newTab = mWebViewController.openTab(url,
John Reck5949c662011-05-27 09:52:29 -0700771 Tab.this, true, true);
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700772 // This is special case for rendering links on a webpage in
773 // a new tab. If opener is suppressed, the WebContents created
774 // by the content layer are not fully initialized. This check
775 // will prevent content layer from overriding WebContents
776 // created by new tab with the uninitialized instance.
777 if (!opener_suppressed) {
778 transport.setWebView(newTab.getWebView());
779 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700780 }
781 msg.sendToTarget();
782 }
783
784 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700785 public void toggleFullscreenModeForTab(boolean enterFullscreen) {
786 if (mWebViewController instanceof Controller) {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700787 setTabFullscreen(enterFullscreen);
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700788 }
789 }
790
791 @Override
Tarun Nainani8eb00912014-07-17 12:28:32 -0700792 public void onOffsetsForFullscreenChanged(float topControlsOffsetYPix,
793 float contentOffsetYPix,
794 float overdrawBottomHeightPix) {
795 if (mWebViewController instanceof Controller) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700796 Controller controller = (Controller)mWebViewController;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700797 controller.getUi().translateTitleBar(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700798 }
799 }
800
801 @Override
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700802 public boolean isTabFullScreen() {
Vivek Sekharf96064b2014-07-28 16:32:34 -0700803 return mFullScreen;
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700804 }
805
806 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700807 public boolean onCreateWindow(WebView view, final boolean dialog,
808 final boolean userGesture, final Message resultMsg) {
809 // only allow new window or sub window for the foreground case
810 if (!mInForeground) {
811 return false;
812 }
813 // Short-circuit if we can't create any more tabs or sub windows.
814 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700815 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700816 .setTitle(R.string.too_many_subwindows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200817 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700818 .setMessage(R.string.too_many_subwindows_dialog_message)
819 .setPositiveButton(R.string.ok, null)
820 .show();
821 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700822 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700823 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700824 .setTitle(R.string.too_many_windows_dialog_title)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200825 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700826 .setMessage(R.string.too_many_windows_dialog_message)
827 .setPositiveButton(R.string.ok, null)
828 .show();
829 return false;
830 }
831
832 // Short-circuit if this was a user gesture.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800833 if (userGesture || !mSettings.blockPopupWindows()) {
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700834 CreateWindowParams windowParams = view.getCreateWindowParams();
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700835 if (windowParams.mOpenerSuppressed) {
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700836 createWindow(dialog, resultMsg, windowParams.mURL, true);
837 // This is special case for rendering links on a webpage in
838 // a new tab. If opener is suppressed, the WebContents created
839 // by the content layer are not fully initialized. Returning false
840 // will prevent content layer from overriding WebContents
841 // created by new tab with the uninitialized instance.
842 return false;
Pankaj Garg1c7380d2014-08-27 14:17:12 -0700843 }
Pankaj Garg0c73c7c2014-09-23 15:07:22 -0700844
845 createWindow(dialog, resultMsg);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700846 return true;
847 }
848
849 // Allow the popup and create the appropriate window.
850 final AlertDialog.OnClickListener allowListener =
851 new AlertDialog.OnClickListener() {
852 public void onClick(DialogInterface d,
853 int which) {
854 createWindow(dialog, resultMsg);
855 }
856 };
857
858 // Block the popup by returning a null WebView.
859 final AlertDialog.OnClickListener blockListener =
860 new AlertDialog.OnClickListener() {
861 public void onClick(DialogInterface d, int which) {
862 resultMsg.sendToTarget();
863 }
864 };
865
866 // Build a confirmation dialog to display to the user.
867 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -0700868 new AlertDialog.Builder(mContext)
Björn Lundén2aa8ba22012-05-31 23:05:56 +0200869 .setIconAttribute(android.R.attr.alertDialogIcon)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700870 .setMessage(R.string.popup_window_attempt)
871 .setPositiveButton(R.string.allow, allowListener)
872 .setNegativeButton(R.string.block, blockListener)
873 .setCancelable(false)
874 .create();
875
876 // Show the confirmation dialog.
877 d.show();
878 return true;
879 }
880
881 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -0500882 public void onRequestFocus(WebView view) {
883 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700884 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -0500885 }
886 }
887
888 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700889 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -0700890 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700891 // JavaScript can only close popup window.
892 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -0700893 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700894 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700895 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700896 }
897 }
898
899 @Override
900 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -0800901 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800902 if (newProgress == 100) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800903 Log.i(CONSOLE_LOGTAG, "SWE Pageload Progress = 100");
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800904 mInPageLoad = false;
905 }
John Reck30c714c2010-12-16 17:30:34 -0800906 mWebViewController.onProgressChanged(Tab.this);
Michael Kolb72864272012-05-03 15:42:15 -0700907 if (mUpdateThumbnail && newProgress == 100) {
908 mUpdateThumbnail = false;
909 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700910 }
911
912 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -0500913 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800914 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -0700915 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700916 }
917
918 @Override
919 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800920 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -0700921 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700922 }
923
924 @Override
925 public void onReceivedTouchIconUrl(WebView view, String url,
926 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -0700927 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400928 // Let precomposed icons take precedence over non-composed
929 // icons.
930 if (precomposed && mTouchIconLoader != null) {
931 mTouchIconLoader.cancel(false);
932 mTouchIconLoader = null;
933 }
934 // Have only one async task at a time.
935 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700936 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -0700937 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -0400938 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700939 }
940 }
941
942 @Override
943 public void onShowCustomView(View view,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800944 CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -0700945 Activity activity = mWebViewController.getActivity();
946 if (activity != null) {
947 onShowCustomView(view, activity.getRequestedOrientation(), callback);
948 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400949 }
950
951 @Override
952 public void onShowCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800953 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700954 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400955 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700956 }
957
958 @Override
959 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700960 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700961 }
962
963 /**
964 * The origin has exceeded its database quota.
965 * @param url the URL that exceeded the quota
966 * @param databaseIdentifier the identifier of the database on which the
967 * transaction that caused the quota overflow was run
968 * @param currentQuota the current quota for the origin.
969 * @param estimatedSize the estimated size of the database.
970 * @param totalUsedQuota is the sum of all origins' quota.
971 * @param quotaUpdater The callback to run when a decision to allow or
972 * deny quota has been made. Don't forget to call this!
973 */
974 @Override
975 public void onExceededDatabaseQuota(String url,
976 String databaseIdentifier, long currentQuota, long estimatedSize,
977 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700978 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700979 .onExceededDatabaseQuota(url, databaseIdentifier,
980 currentQuota, estimatedSize, totalUsedQuota,
981 quotaUpdater);
982 }
983
984 /**
985 * The Application Cache has exceeded its max size.
986 * @param spaceNeeded is the amount of disk space that would be needed
987 * in order for the last appcache operation to succeed.
988 * @param totalUsedQuota is the sum of all origins' quota.
989 * @param quotaUpdater A callback to inform the WebCore thread that a
990 * new app cache size is available. This callback must always
991 * be executed at some point to ensure that the sleeping
992 * WebCore thread is woken up.
993 */
994 @Override
995 public void onReachedMaxAppCacheSize(long spaceNeeded,
996 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -0700997 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -0700998 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
999 quotaUpdater);
1000 }
1001
1002 /**
1003 * Instructs the browser to show a prompt to ask the user to set the
1004 * Geolocation permission state for the specified origin.
1005 * @param origin The origin for which Geolocation permissions are
1006 * requested.
1007 * @param callback The callback to call once the user has set the
1008 * Geolocation permission state.
1009 */
1010 @Override
1011 public void onGeolocationPermissionsShowPrompt(String origin,
1012 GeolocationPermissions.Callback callback) {
1013 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001014 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001015 }
1016 }
1017
1018 /**
1019 * Instructs the browser to hide the Geolocation permissions prompt.
1020 */
1021 @Override
1022 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001023 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001024 mGeolocationPermissionsPrompt.hide();
1025 }
1026 }
1027
Ben Murdoch65acc352009-11-19 18:16:04 +00001028 /* Adds a JavaScript error message to the system log and if the JS
1029 * console is enabled in the about:debug options, to that console
1030 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001031 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001032 */
1033 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001034 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001035 if (mInForeground) {
1036 // call getErrorConsole(true) so it will create one if needed
1037 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001038 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001039 if (mWebViewController.shouldShowErrorConsole()
1040 && errorConsole.getShowState() !=
1041 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001042 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1043 }
1044 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001045
Jeff Hamilton47654f42010-09-07 09:57:51 -05001046 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001047 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001048
Ben Murdochc42addf2010-01-28 15:19:59 +00001049 String message = "Console: " + consoleMessage.message() + " "
1050 + consoleMessage.sourceId() + ":"
1051 + consoleMessage.lineNumber();
1052
1053 switch (consoleMessage.messageLevel()) {
1054 case TIP:
1055 Log.v(CONSOLE_LOGTAG, message);
1056 break;
1057 case LOG:
1058 Log.i(CONSOLE_LOGTAG, message);
1059 break;
1060 case WARNING:
1061 Log.w(CONSOLE_LOGTAG, message);
1062 break;
1063 case ERROR:
1064 Log.e(CONSOLE_LOGTAG, message);
1065 break;
1066 case DEBUG:
1067 Log.d(CONSOLE_LOGTAG, message);
1068 break;
1069 }
1070
1071 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001072 }
1073
1074 /**
1075 * Ask the browser for an icon to represent a <video> element.
1076 * This icon will be used if the Web page did not specify a poster attribute.
1077 * @return Bitmap The icon or null if no such icon is available.
1078 */
1079 @Override
1080 public Bitmap getDefaultVideoPoster() {
1081 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001082 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001083 }
1084 return null;
1085 }
1086
1087 /**
1088 * Ask the host application for a custom progress view to show while
1089 * a <video> is loading.
1090 * @return View The progress view.
1091 */
1092 @Override
1093 public View getVideoLoadingProgressView() {
1094 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001095 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001096 }
1097 return null;
1098 }
1099
1100 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00001101 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001102 if (mInForeground) {
Ben Murdoch8cad4132012-01-11 10:56:43 +00001103 mWebViewController.openFileChooser(uploadMsg, acceptType, capture);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001104 } else {
1105 uploadMsg.onReceiveValue(null);
1106 }
1107 }
1108
Vivek Sekharb54614f2014-05-01 19:03:37 -07001109 @Override
1110 public void showFileChooser(ValueCallback<String[]> uploadFilePaths, String acceptTypes,
1111 boolean capture) {
1112 if (mInForeground) {
1113 mWebViewController.showFileChooser(uploadFilePaths, acceptTypes, capture);
1114 } else {
1115 uploadFilePaths.onReceiveValue(null);
1116 }
1117 }
1118
Grace Kloba22ac16e2009-10-07 18:00:23 -07001119 /**
1120 * Deliver a list of already-visited URLs
1121 */
1122 @Override
1123 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001124 mWebViewController.getVisitedHistory(callback);
1125 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001126
1127 @Override
1128 public void setupAutoFill(Message message) {
1129 // Prompt the user to set up their profile.
1130 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001131 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1132 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001133 Context.LAYOUT_INFLATER_SERVICE);
1134 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1135
1136 builder.setView(layout)
1137 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1138 @Override
1139 public void onClick(DialogInterface dialog, int id) {
1140 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1141 R.id.setup_autofill_dialog_disable_autofill);
1142
1143 if (disableAutoFill.isChecked()) {
1144 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001145 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001146 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001147 R.string.autofill_setup_dialog_negative_toast,
1148 Toast.LENGTH_LONG).show();
1149 } else {
1150 // Take user to the AutoFill profile editor. When they return,
1151 // we will send the message that we pass here which will trigger
1152 // the form to get filled out with their new profile.
1153 mWebViewController.setupAutoFill(msg);
1154 }
1155 }
1156 })
1157 .setNegativeButton(R.string.cancel, null)
1158 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001159 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001160 };
1161
1162 // -------------------------------------------------------------------------
1163 // WebViewClient implementation for the sub window
1164 // -------------------------------------------------------------------------
1165
1166 // Subclass of WebViewClient used in subwindows to notify the main
1167 // WebViewClient of certain WebView activities.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001168 private static class SubWindowClient extends WebViewClient {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001169 // The main WebViewClient.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001170 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001171 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001172
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001173 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001174 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001175 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001176 }
1177 @Override
1178 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1179 // Unlike the others, do not call mClient's version, which would
1180 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001181 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001182 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001183 }
1184 @Override
1185 public void doUpdateVisitedHistory(WebView view, String url,
1186 boolean isReload) {
1187 mClient.doUpdateVisitedHistory(view, url, isReload);
1188 }
1189 @Override
1190 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1191 return mClient.shouldOverrideUrlLoading(view, url);
1192 }
1193 @Override
1194 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1195 SslError error) {
1196 mClient.onReceivedSslError(view, handler, error);
1197 }
1198 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001199 public void onReceivedClientCertRequest(WebView view,
1200 ClientCertRequestHandler handler, String host_and_port) {
1201 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1202 }
1203 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001204 public void onReceivedHttpAuthRequest(WebView view,
1205 HttpAuthHandler handler, String host, String realm) {
1206 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1207 }
1208 @Override
1209 public void onFormResubmission(WebView view, Message dontResend,
1210 Message resend) {
1211 mClient.onFormResubmission(view, dontResend, resend);
1212 }
1213 @Override
1214 public void onReceivedError(WebView view, int errorCode,
1215 String description, String failingUrl) {
1216 mClient.onReceivedError(view, errorCode, description, failingUrl);
1217 }
1218 @Override
1219 public boolean shouldOverrideKeyEvent(WebView view,
1220 android.view.KeyEvent event) {
1221 return mClient.shouldOverrideKeyEvent(view, event);
1222 }
1223 @Override
1224 public void onUnhandledKeyEvent(WebView view,
1225 android.view.KeyEvent event) {
1226 mClient.onUnhandledKeyEvent(view, event);
1227 }
1228 }
1229
1230 // -------------------------------------------------------------------------
1231 // WebChromeClient implementation for the sub window
1232 // -------------------------------------------------------------------------
1233
1234 private class SubWindowChromeClient extends WebChromeClient {
1235 // The main WebChromeClient.
1236 private final WebChromeClient mClient;
1237
1238 SubWindowChromeClient(WebChromeClient client) {
1239 mClient = client;
1240 }
1241 @Override
1242 public void onProgressChanged(WebView view, int newProgress) {
1243 mClient.onProgressChanged(view, newProgress);
1244 }
1245 @Override
1246 public boolean onCreateWindow(WebView view, boolean dialog,
1247 boolean userGesture, android.os.Message resultMsg) {
1248 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1249 }
1250 @Override
1251 public void onCloseWindow(WebView window) {
1252 if (window != mSubView) {
1253 Log.e(LOGTAG, "Can't close the window");
1254 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001255 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001256 }
1257 }
1258
1259 // -------------------------------------------------------------------------
1260
1261 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001262 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001263 this(wvcontroller, w, null);
1264 }
1265
1266 Tab(WebViewController wvcontroller, Bundle state) {
1267 this(wvcontroller, null, state);
1268 }
1269
1270 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001271 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001272 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001273 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001274 mDataController = DataController.getInstance(mContext);
1275 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001276 ? w.isPrivateBrowsingEnabled() : false);
Tarun Nainani8084c822014-06-25 13:38:06 -07001277 setTimeStamp();
Michael Kolb8233fac2010-10-26 16:08:53 -07001278 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001279 mInForeground = false;
1280
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001281 mDownloadListener = new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001282 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001283 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001284 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001285 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001286 mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001287 }
1288 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001289 mWebBackForwardListClient = new WebBackForwardListClient() {
1290 @Override
1291 public void onNewHistoryItem(WebHistoryItem item) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001292 if (mClearHistoryUrlPattern != null) {
1293 boolean match =
1294 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001295 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001296 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1297 + item.getUrl() + "\n\t"
1298 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001299 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001300 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001301 if (mMainView != null) {
1302 mMainView.clearHistory();
1303 }
1304 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001305 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001306 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001307 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001308 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001309
John Reck1cf4b792011-07-26 10:22:22 -07001310 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1311 R.dimen.tab_thumbnail_width);
1312 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1313 R.dimen.tab_thumbnail_height);
1314 updateShouldCaptureThumbnails();
1315 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001316 if (getId() == -1) {
1317 mId = TabControl.getNextId();
1318 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001319 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001320 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001321 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001322 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001323 switch (m.what) {
1324 case MSG_CAPTURE:
1325 capture();
1326 break;
1327 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001328 }
1329 };
John Reck1cf4b792011-07-26 10:22:22 -07001330 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001331
Michael Kolb72864272012-05-03 15:42:15 -07001332 public boolean shouldUpdateThumbnail() {
1333 return mUpdateThumbnail;
1334 }
1335
Mathew Inwoode09305e2011-09-02 12:03:26 +01001336 /**
1337 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1338 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1339 * to overlapping IDs between the preloaded and restored tabs.
1340 */
1341 public void refreshIdAfterPreload() {
1342 mId = TabControl.getNextId();
1343 }
1344
John Reck1cf4b792011-07-26 10:22:22 -07001345 public void updateShouldCaptureThumbnails() {
1346 if (mWebViewController.shouldCaptureThumbnails()) {
1347 synchronized (Tab.this) {
1348 if (mCapture == null) {
1349 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1350 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001351 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001352 if (mInForeground) {
1353 postCapture();
1354 }
1355 }
1356 }
1357 } else {
1358 synchronized (Tab.this) {
1359 mCapture = null;
1360 deleteThumbnail();
1361 }
1362 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001363 }
1364
Michael Kolb14612442011-06-24 13:06:29 -07001365 public void setController(WebViewController ctl) {
1366 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001367 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001368 }
1369
Michael Kolbc831b632011-05-11 09:30:34 -07001370 public long getId() {
1371 return mId;
1372 }
1373
Michael Kolb91911a22012-01-17 11:21:25 -08001374 void setWebView(WebView w) {
1375 setWebView(w, true);
1376 }
1377
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001378 public boolean isNativeActive(){
1379 if (mMainView == null)
1380 return false;
1381 return true;
1382 }
1383
1384 public void setTimeStamp(){
1385 Date d = new Date();
1386 timestamp = (new Timestamp(d.getTime()));
1387 }
1388
1389 public Timestamp getTimestamp() {
1390 return timestamp;
1391 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001392 /**
1393 * Sets the WebView for this tab, correctly removing the old WebView from
1394 * the container view.
1395 */
Michael Kolb91911a22012-01-17 11:21:25 -08001396 void setWebView(WebView w, boolean restore) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001397 if (mMainView == w) {
1398 return;
1399 }
Michael Kolba713ec82010-11-29 17:27:06 -08001400
Grace Kloba22ac16e2009-10-07 18:00:23 -07001401 // If the WebView is changing, the page will be reloaded, so any ongoing
1402 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001403 if (mGeolocationPermissionsPrompt != null) {
1404 mGeolocationPermissionsPrompt.hide();
1405 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001406
Michael Kolba713ec82010-11-29 17:27:06 -08001407 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001408
John Reck1cf4b792011-07-26 10:22:22 -07001409 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001410 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001411 if (w != null) {
1412 syncCurrentState(w, null);
1413 } else {
Panos Thomasa9a5a582014-03-18 19:20:08 -07001414 mCurrentState = new PageState(mContext, mMainView.isPrivateBrowsingEnabled());
John Reck1cf4b792011-07-26 10:22:22 -07001415 }
1416 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001417 // set the new one
1418 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001419 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001420 if (mMainView != null) {
1421 mMainView.setWebViewClient(mWebViewClient);
1422 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001423 // Attach DownloadManager so that downloads can start in an active
1424 // or a non-active window. This can happen when going to a site that
1425 // does a redirect after a period of time. The user could have
1426 // switched to another tab while waiting for the download to start.
1427 mMainView.setDownloadListener(mDownloadListener);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001428 getWebView().setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001429 TabControl tc = mWebViewController.getTabControl();
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001430 if (tc != null /*&& tc.getOnThumbnailUpdatedListener() != null*/) {
John Reck8ee633f2011-08-09 16:00:35 -07001431 mMainView.setPictureListener(this);
1432 }
Michael Kolb91911a22012-01-17 11:21:25 -08001433 if (restore && (mSavedState != null)) {
John Reck8b9bb8b2012-03-08 13:19:40 -08001434 restoreUserAgent();
John Reck6c2e2f32011-08-22 13:41:23 -07001435 WebBackForwardList restoredState
1436 = mMainView.restoreState(mSavedState);
1437 if (restoredState == null || restoredState.getSize() == 0) {
1438 Log.w(LOGTAG, "Failed to restore WebView state!");
1439 loadUrl(mCurrentState.mOriginalUrl, null);
1440 }
John Reck1cf4b792011-07-26 10:22:22 -07001441 mSavedState = null;
1442 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001443 }
1444 }
1445
1446 /**
1447 * Destroy the tab's main WebView and subWindow if any
1448 */
1449 void destroy() {
Tarun Nainani2c1dd7c2014-07-05 16:40:12 -07001450
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001451 if (mPostponeDestroy) {
1452 mShouldDestroy = true;
1453 return;
1454 }
1455 mShouldDestroy = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001456 if (mMainView != null) {
1457 dismissSubWindow();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001458 // save the WebView to call destroy() after detach it from the tab
1459 WebView webView = mMainView;
1460 setWebView(null);
1461 webView.destroy();
1462 }
1463 }
1464
Matthew Huib7f2e9c2014-04-16 11:12:37 -04001465 private boolean mPostponeDestroy = false;
1466 private boolean mShouldDestroy = false;
1467
1468 public void postponeDestroy() {
1469 mPostponeDestroy = true;
1470 }
1471
1472 public void performPostponedDestroy() {
1473 mPostponeDestroy = false;
1474 if (mShouldDestroy) {
1475 destroy();
1476 }
1477 }
1478
Grace Kloba22ac16e2009-10-07 18:00:23 -07001479 /**
1480 * Remove the tab from the parent
1481 */
1482 void removeFromTree() {
1483 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001484 if (mChildren != null) {
1485 for(Tab t : mChildren) {
1486 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001487 }
1488 }
1489 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001490 if (mParent != null) {
1491 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001492 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07001493
1494 mCapture = null;
John Reck1cf4b792011-07-26 10:22:22 -07001495 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001496 }
1497
1498 /**
1499 * Create a new subwindow unless a subwindow already exists.
1500 * @return True if a new subwindow was created. False if one already exists.
1501 */
1502 boolean createSubWindow() {
1503 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001504 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001505 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001506 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001507 mSubView.setWebChromeClient(new SubWindowChromeClient(
1508 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001509 // Set a different DownloadListener for the mSubView, since it will
1510 // just need to dismiss the mSubView, rather than close the Tab
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001511 mSubView.setDownloadListener(new BrowserDownloadListener() {
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001512 public void onDownloadStart(String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001513 String contentDisposition, String mimetype, String referer,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001514 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001515 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001516 contentDisposition, mimetype, referer, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001517 if (mSubView.copyBackForwardList().getSize() == 0) {
1518 // This subwindow was opened for the sole purpose of
1519 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001520 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001521 }
1522 }
1523 });
Michael Kolb14612442011-06-24 13:06:29 -07001524 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001525 return true;
1526 }
1527 return false;
1528 }
1529
1530 /**
1531 * Dismiss the subWindow for the tab.
1532 */
1533 void dismissSubWindow() {
1534 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001535 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001536 mSubView.destroy();
1537 mSubView = null;
1538 mSubViewContainer = null;
1539 }
1540 }
1541
Grace Kloba22ac16e2009-10-07 18:00:23 -07001542
1543 /**
1544 * Set the parent tab of this tab.
1545 */
Michael Kolbc831b632011-05-11 09:30:34 -07001546 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001547 if (parent == this) {
1548 throw new IllegalStateException("Cannot set parent to self!");
1549 }
Michael Kolbc831b632011-05-11 09:30:34 -07001550 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001551 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001552 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001553 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001554 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001555 if (mSavedState != null) {
1556 if (parent == null) {
1557 mSavedState.remove(PARENTTAB);
1558 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001559 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001560 }
1561 }
John Reckb0a86db2011-05-24 14:05:58 -07001562
1563 // Sync the WebView useragent with the parent
1564 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1565 != mSettings.hasDesktopUseragent(getWebView())) {
1566 mSettings.toggleDesktopUseragent(getWebView());
1567 }
John Reck52be4782011-08-26 15:37:29 -07001568
1569 if (parent != null && parent.getId() == getId()) {
1570 throw new IllegalStateException("Parent has same ID as child!");
1571 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001572 }
1573
1574 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001575 * If this Tab was created through another Tab, then this method returns
1576 * that Tab.
1577 * @return the Tab parent or null
1578 */
1579 public Tab getParent() {
1580 return mParent;
1581 }
1582
1583 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001584 * When a Tab is created through the content of another Tab, then we
1585 * associate the Tabs.
1586 * @param child the Tab that was created from this Tab
1587 */
1588 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001589 if (mChildren == null) {
1590 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001591 }
Michael Kolbc831b632011-05-11 09:30:34 -07001592 mChildren.add(child);
1593 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001594 }
1595
Michael Kolbc831b632011-05-11 09:30:34 -07001596 Vector<Tab> getChildren() {
1597 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001598 }
1599
1600 void resume() {
1601 if (mMainView != null) {
Pankaj Garg60221af2014-09-23 17:57:50 -07001602 if (mMainView.hasCrashed()) {
1603 // Reload if render process has crashed. This is done here so that
1604 // setFocus call sends wasShown message to correct render process.
1605 mMainView.reload();
1606 }
John Reck56c1fcf2011-08-17 10:15:16 -07001607 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001608 mMainView.onResume();
1609 if (mSubView != null) {
1610 mSubView.onResume();
1611 }
1612 }
1613 }
1614
John Reck56c1fcf2011-08-17 10:15:16 -07001615 private void setupHwAcceleration(View web) {
1616 if (web == null) return;
1617 BrowserSettings settings = BrowserSettings.getInstance();
1618 if (settings.isHardwareAccelerated()) {
1619 web.setLayerType(View.LAYER_TYPE_NONE, null);
1620 } else {
1621 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1622 }
1623 }
1624
Grace Kloba22ac16e2009-10-07 18:00:23 -07001625 void pause() {
1626 if (mMainView != null) {
1627 mMainView.onPause();
1628 if (mSubView != null) {
1629 mSubView.onPause();
1630 }
1631 }
1632 }
1633
1634 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001635 if (mInForeground) {
1636 return;
1637 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001638 mInForeground = true;
1639 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001640 Activity activity = mWebViewController.getActivity();
1641 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001642 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001643 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001644 }
1645 // Show the pending error dialog if the queue is not empty
1646 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1647 showError(mQueuedErrors.getFirst());
1648 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001649 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001650 }
1651
1652 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001653 if (!mInForeground) {
1654 return;
1655 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001656 mInForeground = false;
1657 pause();
1658 mMainView.setOnCreateContextMenuListener(null);
1659 if (mSubView != null) {
1660 mSubView.setOnCreateContextMenuListener(null);
1661 }
1662 }
1663
Michael Kolb8233fac2010-10-26 16:08:53 -07001664 boolean inForeground() {
1665 return mInForeground;
1666 }
1667
Grace Kloba22ac16e2009-10-07 18:00:23 -07001668 /**
1669 * Return the top window of this tab; either the subwindow if it is not
1670 * null or the main window.
1671 * @return The top window of this tab.
1672 */
1673 WebView getTopWindow() {
1674 if (mSubView != null) {
1675 return mSubView;
1676 }
1677 return mMainView;
1678 }
1679
1680 /**
1681 * Return the main window of this tab. Note: if a tab is freed in the
1682 * background, this can return null. It is only guaranteed to be
1683 * non-null for the current tab.
1684 * @return The main WebView of this tab.
1685 */
1686 WebView getWebView() {
1687 return mMainView;
1688 }
1689
Michael Kolba713ec82010-11-29 17:27:06 -08001690 void setViewContainer(View container) {
1691 mContainer = container;
1692 }
1693
Michael Kolb8233fac2010-10-26 16:08:53 -07001694 View getViewContainer() {
1695 return mContainer;
1696 }
1697
Grace Kloba22ac16e2009-10-07 18:00:23 -07001698 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001699 * Return whether private browsing is enabled for the main window of
1700 * this tab.
1701 * @return True if private browsing is enabled.
1702 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001703 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001704 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001705 }
1706
1707 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001708 * Return the subwindow of this tab or null if there is no subwindow.
1709 * @return The subwindow of this tab or null.
1710 */
1711 WebView getSubWebView() {
1712 return mSubView;
1713 }
1714
Michael Kolb1514bb72010-11-22 09:11:48 -08001715 void setSubWebView(WebView subView) {
1716 mSubView = subView;
1717 }
1718
Michael Kolb8233fac2010-10-26 16:08:53 -07001719 View getSubViewContainer() {
1720 return mSubViewContainer;
1721 }
1722
Michael Kolb1514bb72010-11-22 09:11:48 -08001723 void setSubViewContainer(View subViewContainer) {
1724 mSubViewContainer = subViewContainer;
1725 }
1726
Grace Kloba22ac16e2009-10-07 18:00:23 -07001727 /**
1728 * @return The geolocation permissions prompt for this tab.
1729 */
1730 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001731 if (mGeolocationPermissionsPrompt == null) {
1732 ViewStub stub = (ViewStub) mContainer
1733 .findViewById(R.id.geolocation_permissions_prompt);
1734 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1735 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001736 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001737 return mGeolocationPermissionsPrompt;
1738 }
1739
1740 /**
1741 * @return The application id string
1742 */
1743 String getAppId() {
1744 return mAppId;
1745 }
1746
1747 /**
1748 * Set the application id string
1749 * @param id
1750 */
1751 void setAppId(String id) {
1752 mAppId = id;
1753 }
1754
Michael Kolbe28b3472011-08-04 16:54:31 -07001755 boolean closeOnBack() {
1756 return mCloseOnBack;
1757 }
1758
1759 void setCloseOnBack(boolean close) {
1760 mCloseOnBack = close;
1761 }
1762
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07001763 boolean getDerivedFromIntent() {
1764 return mDerivedFromIntent;
1765 }
1766
1767 void setDerivedFromIntent(boolean derived) {
1768 mDerivedFromIntent = derived;
1769 }
1770
Grace Kloba22ac16e2009-10-07 18:00:23 -07001771 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001772 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001773 }
1774
Tarun Nainani8eb00912014-07-17 12:28:32 -07001775
1776 protected void onPageFinished() {
1777 mPageFinished = true;
1778 }
1779
1780 public boolean getPageFinishedStatus() {
1781 return mPageFinished;
1782 }
1783
John Reck49a603c2011-03-03 09:33:05 -08001784 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001785 if (mCurrentState.mOriginalUrl == null) {
1786 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001787 }
John Reckdb22ec42011-06-29 11:31:24 -07001788 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001789 }
1790
Grace Kloba22ac16e2009-10-07 18:00:23 -07001791 /**
John Reck30c714c2010-12-16 17:30:34 -08001792 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001793 */
1794 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001795 if (mCurrentState.mTitle == null && mInPageLoad) {
Michael Kolb14612442011-06-24 13:06:29 -07001796 return mContext.getString(R.string.title_bar_loading);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001797 }
John Reck30c714c2010-12-16 17:30:34 -08001798 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001799 }
1800
1801 /**
John Reck30c714c2010-12-16 17:30:34 -08001802 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001803 */
1804 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001805 if (mCurrentState.mFavicon != null) {
1806 return mCurrentState.mFavicon;
1807 }
1808 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001809 }
1810
John Recke969cc52010-12-21 17:24:43 -08001811 public boolean isBookmarkedSite() {
1812 return mCurrentState.mIsBookmarkedSite;
1813 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001814
Grace Kloba22ac16e2009-10-07 18:00:23 -07001815 /**
1816 * Return the tab's error console. Creates the console if createIfNEcessary
1817 * is true and we haven't already created the console.
1818 * @param createIfNecessary Flag to indicate if the console should be
1819 * created if it has not been already.
1820 * @return The tab's error console, or null if one has not been created and
1821 * createIfNecessary is false.
1822 */
1823 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1824 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001825 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001826 mErrorConsole.setWebView(mMainView);
1827 }
1828 return mErrorConsole;
1829 }
1830
Steve Block08a6f0c2011-10-06 12:12:53 +01001831 /**
1832 * Sets the security state, clears the SSL certificate error and informs
1833 * the controller.
1834 */
Steve Block2466eff2011-10-03 15:33:09 +01001835 private void setSecurityState(SecurityState securityState) {
1836 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001837 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001838 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001839 }
1840
1841 /**
Steve Block2466eff2011-10-03 15:33:09 +01001842 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001843 */
Steve Block2466eff2011-10-03 15:33:09 +01001844 SecurityState getSecurityState() {
1845 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001846 }
1847
Steve Block08a6f0c2011-10-06 12:12:53 +01001848 /**
1849 * Gets the SSL certificate error, if any, for the page's main resource.
1850 * This is only non-null when the security state is
1851 * SECURITY_STATE_BAD_CERTIFICATE.
1852 */
1853 SslError getSslCertificateError() {
1854 return mCurrentState.mSslCertificateError;
1855 }
1856
John Reck30c714c2010-12-16 17:30:34 -08001857 int getLoadProgress() {
1858 if (mInPageLoad) {
1859 return mPageLoadProgress;
1860 }
1861 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001862 }
1863
1864 /**
1865 * @return TRUE if onPageStarted is called while onPageFinished is not
1866 * called yet.
1867 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001868 boolean inPageLoad() {
1869 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001870 }
1871
Grace Kloba22ac16e2009-10-07 18:00:23 -07001872 /**
John Reck1cf4b792011-07-26 10:22:22 -07001873 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001874 */
John Reck1cf4b792011-07-26 10:22:22 -07001875 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001876 // If the WebView is null it means we ran low on memory and we already
1877 // stored the saved state in mSavedState.
1878 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001879 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001880 }
John Reck6c2e2f32011-08-22 13:41:23 -07001881
1882 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001883 return null;
John Reck24f18262011-06-17 14:47:20 -07001884 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001885
1886 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001887 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1888 if (savedList == null || savedList.getSize() == 0) {
1889 Log.w(LOGTAG, "Failed to save back/forward list for "
1890 + mCurrentState.mUrl);
1891 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001892
Michael Kolbc831b632011-05-11 09:30:34 -07001893 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001894 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1895 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001896 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001897 if (mAppId != null) {
1898 mSavedState.putString(APPID, mAppId);
1899 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001900 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001901 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001902 if (mParent != null) {
1903 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001904 }
John Reckb0a86db2011-05-24 14:05:58 -07001905 mSavedState.putBoolean(USERAGENT,
1906 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001907 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001908 }
1909
1910 /*
1911 * Restore the state of the tab.
1912 */
John Reck1cf4b792011-07-26 10:22:22 -07001913 private void restoreState(Bundle b) {
1914 mSavedState = b;
1915 if (mSavedState == null) {
1916 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001917 }
1918 // Restore the internal state even if the WebView fails to restore.
1919 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001920 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001921 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001922 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reck8b9bb8b2012-03-08 13:19:40 -08001923 restoreUserAgent();
John Reck1cf4b792011-07-26 10:22:22 -07001924 String url = b.getString(CURRURL);
1925 String title = b.getString(CURRTITLE);
1926 boolean incognito = b.getBoolean(INCOGNITO);
1927 mCurrentState = new PageState(mContext, incognito, url, null);
1928 mCurrentState.mTitle = title;
1929 synchronized (Tab.this) {
1930 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07001931 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07001932 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001933 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001934 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04001935
John Reck8b9bb8b2012-03-08 13:19:40 -08001936 private void restoreUserAgent() {
1937 if (mMainView == null || mSavedState == null) {
1938 return;
1939 }
1940 if (mSavedState.getBoolean(USERAGENT)
1941 != mSettings.hasDesktopUseragent(mMainView)) {
1942 mSettings.toggleDesktopUseragent(mMainView);
1943 }
1944 }
1945
Leon Scroggins1961ed22010-12-07 15:22:21 -05001946 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08001947 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05001948 }
1949
John Recke969cc52010-12-21 17:24:43 -08001950 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
1951 = new DataController.OnQueryUrlIsBookmark() {
1952 @Override
1953 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
1954 if (mCurrentState.mUrl.equals(url)) {
1955 mCurrentState.mIsBookmarkedSite = isBookmark;
1956 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
1957 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001958 }
John Recke969cc52010-12-21 17:24:43 -08001959 };
Michael Kolb1acef692011-03-08 14:12:06 -08001960
Michael Kolbeb95db42011-03-03 10:38:40 -08001961 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07001962 synchronized (Tab.this) {
1963 return mCapture;
1964 }
Michael Kolbeb95db42011-03-03 10:38:40 -08001965 }
1966
John Reck541f55a2011-06-07 16:34:43 -07001967 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07001968 return false;
1969 }
1970
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001971 private static class SaveCallback implements ValueCallback<String> {
1972 boolean onReceiveValueCalled = false;
1973 private String mPath;
John Reck68234a92012-04-19 15:27:12 -07001974
1975 @Override
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001976 public void onReceiveValue(String path) {
1977 this.onReceiveValueCalled = true;
1978 this.mPath = path;
John Reck68234a92012-04-19 15:27:12 -07001979 synchronized (this) {
1980 notifyAll();
John Reck8cc92352011-07-06 17:41:52 -07001981 }
John Reck541f55a2011-06-07 16:34:43 -07001982 }
John Reck68234a92012-04-19 15:27:12 -07001983
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001984 public String getPath() {
1985 return mPath;
1986 }
John Reck68234a92012-04-19 15:27:12 -07001987 }
1988
1989 /**
1990 * Must be called on the UI thread
1991 */
1992 public ContentValues createSnapshotValues() {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08001993 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07001994 if (web == null) return null;
John Reckd8c74522011-06-14 08:45:00 -07001995 ContentValues values = new ContentValues();
1996 values.put(Snapshots.TITLE, mCurrentState.mTitle);
1997 values.put(Snapshots.URL, mCurrentState.mUrl);
John Reck68234a92012-04-19 15:27:12 -07001998 values.put(Snapshots.BACKGROUND, web.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07001999 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2000 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
Tarun Nainani8eb00912014-07-17 12:28:32 -07002001 Bitmap screenshot = Controller.createScreenshot(web,
2002 Controller.getDesiredThumbnailWidth(mWebViewController.getActivity()),
2003 Controller.getDesiredThumbnailHeight(mWebViewController.getActivity()));
2004 values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
John Reckd8c74522011-06-14 08:45:00 -07002005 return values;
John Reck541f55a2011-06-07 16:34:43 -07002006 }
2007
John Reck68234a92012-04-19 15:27:12 -07002008 /**
2009 * Probably want to call this on a background thread
2010 */
2011 public boolean saveViewState(ContentValues values) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002012 WebView web = getWebView();
John Reck68234a92012-04-19 15:27:12 -07002013 if (web == null) return false;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002014 String filename = UUID.randomUUID().toString();
John Reck68234a92012-04-19 15:27:12 -07002015 SaveCallback callback = new SaveCallback();
John Reck68234a92012-04-19 15:27:12 -07002016 try {
John Reck68234a92012-04-19 15:27:12 -07002017 synchronized (callback) {
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002018 web.saveViewState(filename, callback);
2019 callback.wait();
John Reck68234a92012-04-19 15:27:12 -07002020 }
John Reck68234a92012-04-19 15:27:12 -07002021 } catch (Exception e) {
2022 Log.w(LOGTAG, "Failed to save view state", e);
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002023 String path = callback.getPath();
2024 if (path != null) {
2025 File file = mContext.getFileStreamPath(path);
2026 if (file.exists() && !file.delete()) {
2027 file.deleteOnExit();
2028 }
John Reck68234a92012-04-19 15:27:12 -07002029 }
2030 return false;
2031 }
Tarun Nainani8eb00912014-07-17 12:28:32 -07002032
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002033 String path = callback.getPath();
Tarun Nainani8eb00912014-07-17 12:28:32 -07002034 // could be that saving of file failed
2035 if (path == null) {
2036 return false;
2037 }
2038
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002039 File savedFile = new File(path);
2040 if (!savedFile.exists()) {
2041 return false;
John Reck68234a92012-04-19 15:27:12 -07002042 }
Bijan Amirzada9b1e9882014-02-26 17:15:46 -08002043 values.put(Snapshots.VIEWSTATE_PATH, path.substring(path.lastIndexOf('/') + 1));
2044 values.put(Snapshots.VIEWSTATE_SIZE, savedFile.length());
John Reck68234a92012-04-19 15:27:12 -07002045 return true;
2046 }
2047
John Reck8cc92352011-07-06 17:41:52 -07002048 public byte[] compressBitmap(Bitmap bitmap) {
2049 if (bitmap == null) {
2050 return null;
2051 }
2052 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2053 bitmap.compress(CompressFormat.PNG, 100, stream);
2054 return stream.toByteArray();
2055 }
2056
John Reck26b18322011-06-21 13:08:58 -07002057 public void loadUrl(String url, Map<String, String> headers) {
2058 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002059 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -07002060 mCurrentState = new PageState(mContext, false, url, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002061 handleJsInterface(mMainView, url);
John Reck26b18322011-06-21 13:08:58 -07002062 mMainView.loadUrl(url, headers);
2063 }
2064 }
2065
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002066 public void handleJsInterface(WebView webview, String url){
2067 if (url != null &&
2068 url.equals(mContext.getResources().getString(R.string.homepage_base)) &&
2069 url.startsWith("file:///")) {
2070 mJsInterfaceEnabled = true;
2071 webview.getSettings().setJavaScriptEnabled(true);
2072 webview.addJavascriptInterface(mContext, "default_homepage");
2073 } else {
2074 if (mJsInterfaceEnabled) {
2075 webview.removeJavascriptInterface("default_homepage");
2076 mJsInterfaceEnabled = false;
2077 }
2078 }
2079 }
2080
John Reck38b39652012-06-05 09:22:59 -07002081 public void disableUrlOverridingForLoad() {
2082 mDisableOverrideUrlLoading = true;
2083 }
2084
Michael Kolb9ef259a2011-07-12 15:33:08 -07002085 protected void capture() {
2086 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002087 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2088 return;
2089 }
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002090
2091 mMainView
2092 .getContentBitmapAsync(
2093 (float) mCaptureWidth / mMainView.getWidth(),
2094 new Rect(),
2095 new ValueCallback<Bitmap>() {
2096 @Override
2097 public void onReceiveValue(Bitmap bitmap) {
2098 onCaptureCallback(bitmap);
2099 }});
2100 }
2101
2102 private void onCaptureCallback(Bitmap bitmap) {
2103 if (mCapture == null || bitmap == null)
2104 return;
2105
Michael Kolb9ef259a2011-07-12 15:33:08 -07002106 Canvas c = new Canvas(mCapture);
Tarun Nainaniea28dde2014-08-27 17:25:09 -07002107 mCapture.eraseColor(Color.WHITE);
2108 c.drawBitmap(bitmap, 0, 0, null);
Axesh R. Ajmera2e241242014-05-19 15:53:38 -07002109
Michael Kolba3194d02011-09-07 11:23:51 -07002110 // manually anti-alias the edges for the tilt
2111 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2112 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2113 mCapture.getHeight(), sAlphaPaint);
2114 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2115 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2116 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002117 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002118 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002119 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002120 TabControl tc = mWebViewController.getTabControl();
2121 if (tc != null) {
2122 OnThumbnailUpdatedListener updateListener
2123 = tc.getOnThumbnailUpdatedListener();
2124 if (updateListener != null) {
2125 updateListener.onThumbnailUpdated(this);
2126 }
2127 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002128 }
2129
2130 @Override
2131 public void onNewPicture(WebView view, Picture picture) {
John Reck1cf4b792011-07-26 10:22:22 -07002132 postCapture();
2133 }
2134
2135 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002136 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2137 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2138 }
2139 }
2140
John Reckef654f12011-07-12 16:42:08 -07002141 public boolean canGoBack() {
2142 return mMainView != null ? mMainView.canGoBack() : false;
2143 }
2144
2145 public boolean canGoForward() {
2146 return mMainView != null ? mMainView.canGoForward() : false;
2147 }
2148
2149 public void goBack() {
2150 if (mMainView != null) {
2151 mMainView.goBack();
2152 }
2153 }
2154
2155 public void goForward() {
2156 if (mMainView != null) {
2157 mMainView.goForward();
2158 }
2159 }
2160
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002161 /**
2162 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2163 * to be added to the stack.
2164 *
2165 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2166 * not appear in the back stack.
2167 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002168 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2169 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002170 }
2171
John Reck1cf4b792011-07-26 10:22:22 -07002172 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002173 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002174 }
2175
2176 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002177 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002178 }
2179
John Reck4eadc342011-10-31 14:04:10 -07002180 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002181 synchronized (Tab.this) {
2182 if (mCapture == null) {
2183 return;
2184 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002185 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002186 try {
2187 mCapture.copyPixelsFromBuffer(buffer);
2188 } catch (RuntimeException rex) {
2189 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2190 + buffer.capacity() + " blob: " + blob.length
2191 + "capture: " + mCapture.getByteCount());
2192 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002193 }
John Reck1cf4b792011-07-26 10:22:22 -07002194 }
2195 }
2196
John Reck52be4782011-08-26 15:37:29 -07002197 @Override
2198 public String toString() {
2199 StringBuilder builder = new StringBuilder(100);
2200 builder.append(mId);
2201 builder.append(") has parent: ");
2202 if (getParent() != null) {
2203 builder.append("true[");
2204 builder.append(getParent().getId());
2205 builder.append("]");
2206 } else {
2207 builder.append("false");
2208 }
2209 builder.append(", incog: ");
2210 builder.append(isPrivateBrowsingEnabled());
2211 if (!isPrivateBrowsingEnabled()) {
2212 builder.append(", title: ");
2213 builder.append(getTitle());
2214 builder.append(", url: ");
2215 builder.append(getUrl());
2216 }
2217 return builder.toString();
2218 }
2219
Steve Block4895b012011-10-03 16:26:46 +01002220 private void handleProceededAfterSslError(SslError error) {
2221 if (error.getUrl().equals(mCurrentState.mUrl)) {
2222 // The security state should currently be SECURITY_STATE_SECURE.
2223 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002224 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002225 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002226 // The page's main resource is secure and this error is for a
2227 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002228 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2229 }
2230 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002231}