blob: dd97960ff50395dca41f722bb9157a6d9f806d08 [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
17package com.android.browser;
18
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Grace Kloba22ac16e2009-10-07 18:00:23 -070020import android.app.AlertDialog;
Leon Scroggins58d56c62010-01-28 15:12:40 -050021import android.app.SearchManager;
Grace Kloba22ac16e2009-10-07 18:00:23 -070022import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070023import android.content.ContentValues;
John Reck30c714c2010-12-16 17:30:34 -080024import android.content.Context;
Grace Kloba22ac16e2009-10-07 18:00:23 -070025import android.content.DialogInterface;
Michael Kolbfe251992010-07-08 15:41:55 -070026import android.content.DialogInterface.OnCancelListener;
Jeff Hamilton8ce956c2010-08-17 11:13:53 -050027import android.content.Intent;
Grace Kloba22ac16e2009-10-07 18:00:23 -070028import android.graphics.Bitmap;
John Reck8cc92352011-07-06 17:41:52 -070029import android.graphics.Bitmap.CompressFormat;
Michael Kolb9ef259a2011-07-12 15:33:08 -070030import android.graphics.BitmapFactory;
31import android.graphics.Canvas;
Michael Kolbc3af0672011-08-09 10:24:41 -070032import android.graphics.Color;
Michael Kolba3194d02011-09-07 11:23:51 -070033import android.graphics.Paint;
Michael Kolb9ef259a2011-07-12 15:33:08 -070034import android.graphics.Picture;
Michael Kolba3194d02011-09-07 11:23:51 -070035import android.graphics.PorterDuff;
36import android.graphics.PorterDuffXfermode;
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;
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -050045import android.speech.RecognizerResultsIntent;
John Reck24f18262011-06-17 14:47:20 -070046import android.text.TextUtils;
Grace Kloba22ac16e2009-10-07 18:00:23 -070047import android.util.Log;
48import android.view.KeyEvent;
49import android.view.LayoutInflater;
50import android.view.View;
Grace Kloba50c241e2010-04-20 11:07:50 -070051import android.view.ViewStub;
Brian Carlstrom8862c1d2011-06-02 01:05:55 -070052import android.webkit.ClientCertRequestHandler;
Ben Murdochc42addf2010-01-28 15:19:59 +000053import android.webkit.ConsoleMessage;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -050054import android.webkit.DownloadListener;
Grace Kloba22ac16e2009-10-07 18:00:23 -070055import android.webkit.GeolocationPermissions;
56import android.webkit.HttpAuthHandler;
57import android.webkit.SslErrorHandler;
58import android.webkit.URLUtil;
59import android.webkit.ValueCallback;
John Reck6c2e2f32011-08-22 13:41:23 -070060import android.webkit.WebBackForwardList;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -050061import android.webkit.WebBackForwardListClient;
Grace Kloba22ac16e2009-10-07 18:00:23 -070062import android.webkit.WebChromeClient;
63import android.webkit.WebHistoryItem;
John Reck438bf462011-01-12 18:11:46 -080064import android.webkit.WebResourceResponse;
Grace Kloba22ac16e2009-10-07 18:00:23 -070065import android.webkit.WebStorage;
66import android.webkit.WebView;
Michael Kolb9ef259a2011-07-12 15:33:08 -070067import android.webkit.WebView.PictureListener;
Grace Kloba22ac16e2009-10-07 18:00:23 -070068import android.webkit.WebViewClient;
Ben Murdoch1d676b62011-01-17 12:54:24 +000069import android.widget.CheckBox;
Ben Murdoch8029a772010-11-16 11:58:21 +000070import android.widget.Toast;
Grace Kloba22ac16e2009-10-07 18:00:23 -070071
John Reck8ee633f2011-08-09 16:00:35 -070072import com.android.browser.TabControl.OnThumbnailUpdatedListener;
John Reck541f55a2011-06-07 16:34:43 -070073import com.android.browser.homepages.HomeProvider;
John Reck8cc92352011-07-06 17:41:52 -070074import com.android.browser.provider.SnapshotProvider.Snapshots;
John Reck541f55a2011-06-07 16:34:43 -070075import com.android.common.speech.LoggingEvents;
76
77import java.io.ByteArrayOutputStream;
John Reck1cf4b792011-07-26 10:22:22 -070078import java.nio.ByteBuffer;
Michael Kolbfe251992010-07-08 15:41:55 -070079import java.util.ArrayList;
80import java.util.HashMap;
81import java.util.Iterator;
82import java.util.LinkedList;
83import java.util.Map;
84import java.util.Vector;
Mathew Inwooda829d552011-09-02 14:16:25 +010085import java.util.regex.Pattern;
John Reck8cc92352011-07-06 17:41:52 -070086import java.util.zip.GZIPOutputStream;
Michael Kolbfe251992010-07-08 15:41:55 -070087
Grace Kloba22ac16e2009-10-07 18:00:23 -070088/**
89 * Class for maintaining Tabs with a main WebView and a subwindow.
90 */
Michael Kolb9ef259a2011-07-12 15:33:08 -070091class Tab implements PictureListener {
Michael Kolb8233fac2010-10-26 16:08:53 -070092
Grace Kloba22ac16e2009-10-07 18:00:23 -070093 // Log Tag
94 private static final String LOGTAG = "Tab";
Mathew Inwood1dd8e822011-08-03 14:34:29 +010095 private static final boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
Ben Murdochc42addf2010-01-28 15:19:59 +000096 // Special case the logtag for messages for the Console to make it easier to
97 // filter them and match the logtag used for these messages in older versions
98 // of the browser.
99 private static final String CONSOLE_LOGTAG = "browser";
100
Michael Kolb9ef259a2011-07-12 15:33:08 -0700101 private static final int MSG_CAPTURE = 42;
John Reck8ee633f2011-08-09 16:00:35 -0700102 private static final int CAPTURE_DELAY = 100;
Michael Kolba53c9892011-10-05 13:31:40 -0700103 private static final int INITIAL_PROGRESS = 5;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700104
John Reck1cf4b792011-07-26 10:22:22 -0700105 private static Bitmap sDefaultFavicon;
106
Michael Kolba3194d02011-09-07 11:23:51 -0700107 private static Paint sAlphaPaint = new Paint();
108 static {
109 sAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
110 sAlphaPaint.setColor(Color.TRANSPARENT);
111 }
112
Steve Block2466eff2011-10-03 15:33:09 +0100113 public enum SecurityState {
Steve Block4895b012011-10-03 16:26:46 +0100114 // The page's main resource does not use SSL. Note that we use this
115 // state irrespective of the SSL authentication state of sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100116 SECURITY_STATE_NOT_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100117 // The page's main resource uses SSL and the certificate is good. The
118 // same is true of all sub-resources.
Steve Block2466eff2011-10-03 15:33:09 +0100119 SECURITY_STATE_SECURE,
Steve Block4895b012011-10-03 16:26:46 +0100120 // The page's main resource uses SSL and the certificate is good, but
121 // some sub-resources either do not use SSL or have problems with their
122 // certificates.
Steve Block2466eff2011-10-03 15:33:09 +0100123 SECURITY_STATE_MIXED,
Steve Block4895b012011-10-03 16:26:46 +0100124 // The page's main resource uses SSL but there is a problem with its
125 // certificate.
126 SECURITY_STATE_BAD_CERTIFICATE,
John Reck30c714c2010-12-16 17:30:34 -0800127 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700128
Michael Kolb14612442011-06-24 13:06:29 -0700129 Context mContext;
John Reckd8c74522011-06-14 08:45:00 -0700130 protected WebViewController mWebViewController;
Michael Kolb8233fac2010-10-26 16:08:53 -0700131
Michael Kolbc831b632011-05-11 09:30:34 -0700132 // The tab ID
John Reckd8c74522011-06-14 08:45:00 -0700133 private long mId = -1;
Michael Kolbc831b632011-05-11 09:30:34 -0700134
Grace Kloba22ac16e2009-10-07 18:00:23 -0700135 // The Geolocation permissions prompt
136 private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
137 // Main WebView wrapper
Michael Kolba713ec82010-11-29 17:27:06 -0800138 private View mContainer;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700139 // Main WebView
140 private WebView mMainView;
141 // Subwindow container
142 private View mSubViewContainer;
143 // Subwindow WebView
144 private WebView mSubView;
145 // Saved bundle for when we are running low on memory. It contains the
146 // information needed to restore the WebView if the user goes back to the
147 // tab.
148 private Bundle mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700149 // Parent Tab. This is the Tab that created this Tab, or null if the Tab was
150 // created by the UI
Michael Kolbc831b632011-05-11 09:30:34 -0700151 private Tab mParent;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700152 // Tab that constructed by this Tab. This is used when this Tab is
153 // destroyed, it clears all mParentTab values in the children.
Michael Kolbc831b632011-05-11 09:30:34 -0700154 private Vector<Tab> mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700155 // If true, the tab is in the foreground of the current activity.
156 private boolean mInForeground;
Michael Kolb8233fac2010-10-26 16:08:53 -0700157 // If true, the tab is in page loading state (after onPageStarted,
158 // before onPageFinsihed)
159 private boolean mInPageLoad;
John Reck30c714c2010-12-16 17:30:34 -0800160 // The last reported progress of the current page
161 private int mPageLoadProgress;
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000162 // The time the load started, used to find load page time
163 private long mLoadStartTime;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700164 // Application identifier used to find tabs that another application wants
165 // to reuse.
166 private String mAppId;
Michael Kolbe28b3472011-08-04 16:54:31 -0700167 // flag to indicate if tab should be closed on back
168 private boolean mCloseOnBack;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700169 // Keep the original url around to avoid killing the old WebView if the url
170 // has not changed.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700171 // Error console for the tab
172 private ErrorConsoleView mErrorConsole;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -0500173 // The listener that gets invoked when a download is started from the
174 // mMainView
175 private final DownloadListener mDownloadListener;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500176 // Listener used to know when we move forward or back in the history list.
177 private final WebBackForwardListClient mWebBackForwardListClient;
John Recke969cc52010-12-21 17:24:43 -0800178 private DataController mDataController;
Patrick Scott92066772011-03-10 08:46:27 -0500179 // State of the auto-login request.
180 private DeviceAccountLogin mDeviceAccountLogin;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700181
182 // AsyncTask for downloading touch icons
183 DownloadTouchIcon mTouchIconLoader;
184
John Reck35e9dd62011-04-25 09:01:54 -0700185 private BrowserSettings mSettings;
Michael Kolb9ef259a2011-07-12 15:33:08 -0700186 private int mCaptureWidth;
187 private int mCaptureHeight;
188 private Bitmap mCapture;
189 private Handler mHandler;
190
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100191 /**
Mathew Inwood9ad1eac2011-09-15 11:29:50 +0100192 * See {@link #clearBackStackWhenItemAdded(String)}.
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100193 */
Mathew Inwooda829d552011-09-02 14:16:25 +0100194 private Pattern mClearHistoryUrlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +0100195
John Reck1cf4b792011-07-26 10:22:22 -0700196 private static synchronized Bitmap getDefaultFavicon(Context context) {
197 if (sDefaultFavicon == null) {
198 sDefaultFavicon = BitmapFactory.decodeResource(
199 context.getResources(), R.drawable.app_web_browser_sm);
200 }
201 return sDefaultFavicon;
202 }
Michael Kolbeb95db42011-03-03 10:38:40 -0800203
John Reck30c714c2010-12-16 17:30:34 -0800204 // All the state needed for a page
John Reckd8c74522011-06-14 08:45:00 -0700205 protected static class PageState {
John Reck30c714c2010-12-16 17:30:34 -0800206 String mUrl;
John Reckdb22ec42011-06-29 11:31:24 -0700207 String mOriginalUrl;
John Reck30c714c2010-12-16 17:30:34 -0800208 String mTitle;
Steve Block2466eff2011-10-03 15:33:09 +0100209 SecurityState mSecurityState;
Steve Block08a6f0c2011-10-06 12:12:53 +0100210 // This is non-null only when mSecurityState is SECURITY_STATE_BAD_CERTIFICATE.
211 SslError mSslCertificateError;
John Reck30c714c2010-12-16 17:30:34 -0800212 Bitmap mFavicon;
Steve Block08a6f0c2011-10-06 12:12:53 +0100213 boolean mIsBookmarkedSite;
214 boolean mIncognito;
John Reck30c714c2010-12-16 17:30:34 -0800215
216 PageState(Context c, boolean incognito) {
John Reck502a3532011-08-16 14:21:46 -0700217 mIncognito = incognito;
218 if (mIncognito) {
John Reckdb22ec42011-06-29 11:31:24 -0700219 mOriginalUrl = mUrl = "browser:incognito";
John Reck30c714c2010-12-16 17:30:34 -0800220 mTitle = c.getString(R.string.new_incognito_tab);
John Reck30c714c2010-12-16 17:30:34 -0800221 } else {
John Reckdb22ec42011-06-29 11:31:24 -0700222 mOriginalUrl = mUrl = "";
John Reck30c714c2010-12-16 17:30:34 -0800223 mTitle = c.getString(R.string.new_tab);
John Reck30c714c2010-12-16 17:30:34 -0800224 }
Steve Block2466eff2011-10-03 15:33:09 +0100225 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800226 }
227
228 PageState(Context c, boolean incognito, String url, Bitmap favicon) {
John Reck502a3532011-08-16 14:21:46 -0700229 mIncognito = incognito;
John Reckdb22ec42011-06-29 11:31:24 -0700230 mOriginalUrl = mUrl = url;
John Reck30c714c2010-12-16 17:30:34 -0800231 if (URLUtil.isHttpsUrl(url)) {
Steve Block2466eff2011-10-03 15:33:09 +0100232 mSecurityState = SecurityState.SECURITY_STATE_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800233 } else {
Steve Block2466eff2011-10-03 15:33:09 +0100234 mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
John Reck30c714c2010-12-16 17:30:34 -0800235 }
John Reck1cf4b792011-07-26 10:22:22 -0700236 mFavicon = favicon;
John Reck30c714c2010-12-16 17:30:34 -0800237 }
John Reck1cf4b792011-07-26 10:22:22 -0700238
Grace Kloba22ac16e2009-10-07 18:00:23 -0700239 }
240
John Reck30c714c2010-12-16 17:30:34 -0800241 // The current/loading page's state
John Reckd8c74522011-06-14 08:45:00 -0700242 protected PageState mCurrentState;
John Reck30c714c2010-12-16 17:30:34 -0800243
Grace Kloba22ac16e2009-10-07 18:00:23 -0700244 // Used for saving and restoring each Tab
Michael Kolbc831b632011-05-11 09:30:34 -0700245 static final String ID = "ID";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700246 static final String CURRURL = "currentUrl";
247 static final String CURRTITLE = "currentTitle";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700248 static final String PARENTTAB = "parentTab";
249 static final String APPID = "appid";
Elliott Slaughter3d6df162010-08-25 13:17:44 -0700250 static final String INCOGNITO = "privateBrowsingEnabled";
John Reckb0a86db2011-05-24 14:05:58 -0700251 static final String USERAGENT = "useragent";
Michael Kolbe28b3472011-08-04 16:54:31 -0700252 static final String CLOSEFLAG = "closeOnBack";
Grace Kloba22ac16e2009-10-07 18:00:23 -0700253
254 // -------------------------------------------------------------------------
255
Leon Scroggins58d56c62010-01-28 15:12:40 -0500256 /**
257 * Private information regarding the latest voice search. If the Tab is not
258 * in voice search mode, this will be null.
259 */
260 private VoiceSearchData mVoiceSearchData;
261 /**
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400262 * Remove voice search mode from this tab.
263 */
264 public void revertVoiceSearchMode() {
265 if (mVoiceSearchData != null) {
266 mVoiceSearchData = null;
267 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 mWebViewController.revertVoiceSearchMode(this);
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400269 }
270 }
271 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700272
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400273 /**
Leon Scroggins58d56c62010-01-28 15:12:40 -0500274 * Return whether the tab is in voice search mode.
275 */
276 public boolean isInVoiceSearchMode() {
277 return mVoiceSearchData != null;
278 }
279 /**
Leon Scroggins IIIc1f5ae22010-06-29 17:11:29 -0400280 * Return true if the Tab is in voice search mode and the voice search
281 * Intent came with a String identifying that Google provided the Intent.
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500282 */
283 public boolean voiceSearchSourceIsGoogle() {
284 return mVoiceSearchData != null && mVoiceSearchData.mSourceIsGoogle;
285 }
286 /**
Leon Scroggins58d56c62010-01-28 15:12:40 -0500287 * Get the title to display for the current voice search page. If the Tab
288 * is not in voice search mode, return null.
289 */
290 public String getVoiceDisplayTitle() {
291 if (mVoiceSearchData == null) return null;
292 return mVoiceSearchData.mLastVoiceSearchTitle;
293 }
294 /**
295 * Get the latest array of voice search results, to be passed to the
296 * BrowserProvider. If the Tab is not in voice search mode, return null.
297 */
298 public ArrayList<String> getVoiceSearchResults() {
299 if (mVoiceSearchData == null) return null;
300 return mVoiceSearchData.mVoiceSearchResults;
301 }
302 /**
303 * Activate voice search mode.
304 * @param intent Intent which has the results to use, or an index into the
305 * results when reusing the old results.
306 */
307 /* package */ void activateVoiceSearchMode(Intent intent) {
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500308 int index = 0;
Leon Scroggins58d56c62010-01-28 15:12:40 -0500309 ArrayList<String> results = intent.getStringArrayListExtra(
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -0500310 RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_STRINGS);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500311 if (results != null) {
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500312 ArrayList<String> urls = intent.getStringArrayListExtra(
313 RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_URLS);
314 ArrayList<String> htmls = intent.getStringArrayListExtra(
315 RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_HTML);
316 ArrayList<String> baseUrls = intent.getStringArrayListExtra(
317 RecognizerResultsIntent
318 .EXTRA_VOICE_SEARCH_RESULT_HTML_BASE_URLS);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500319 // This tab is now entering voice search mode for the first time, or
320 // a new voice search was done.
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500321 int size = results.size();
322 if (urls == null || size != urls.size()) {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500323 throw new AssertionError("improper extras passed in Intent");
324 }
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500325 if (htmls == null || htmls.size() != size || baseUrls == null ||
326 (baseUrls.size() != size && baseUrls.size() != 1)) {
327 // If either of these arrays are empty/incorrectly sized, ignore
328 // them.
329 htmls = null;
330 baseUrls = null;
331 }
332 mVoiceSearchData = new VoiceSearchData(results, urls, htmls,
333 baseUrls);
Leon Scroggins9df94972010-03-08 18:20:35 -0500334 mVoiceSearchData.mHeaders = intent.getParcelableArrayListExtra(
335 RecognizerResultsIntent
336 .EXTRA_VOICE_SEARCH_RESULT_HTTP_HEADERS);
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500337 mVoiceSearchData.mSourceIsGoogle = intent.getBooleanExtra(
338 VoiceSearchData.SOURCE_IS_GOOGLE, false);
Leon Scroggins2ee4a5a2010-03-15 16:56:57 -0400339 mVoiceSearchData.mVoiceSearchIntent = new Intent(intent);
Leon Scrogginse10dde52010-03-08 19:53:03 -0500340 }
341 String extraData = intent.getStringExtra(
342 SearchManager.EXTRA_DATA_KEY);
343 if (extraData != null) {
344 index = Integer.parseInt(extraData);
345 if (index >= mVoiceSearchData.mVoiceSearchResults.size()) {
346 throw new AssertionError("index must be less than "
347 + "size of mVoiceSearchResults");
348 }
349 if (mVoiceSearchData.mSourceIsGoogle) {
350 Intent logIntent = new Intent(
351 LoggingEvents.ACTION_LOG_EVENT);
352 logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
353 LoggingEvents.VoiceSearch.N_BEST_CHOOSE);
354 logIntent.putExtra(
355 LoggingEvents.VoiceSearch.EXTRA_N_BEST_CHOOSE_INDEX,
356 index);
Michael Kolb14612442011-06-24 13:06:29 -0700357 mContext.sendBroadcast(logIntent);
Leon Scrogginse10dde52010-03-08 19:53:03 -0500358 }
359 if (mVoiceSearchData.mVoiceSearchIntent != null) {
Leon Scroggins2ee4a5a2010-03-15 16:56:57 -0400360 // Copy the Intent, so that each history item will have its own
361 // Intent, with different (or none) extra data.
362 Intent latest = new Intent(mVoiceSearchData.mVoiceSearchIntent);
363 latest.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
364 mVoiceSearchData.mVoiceSearchIntent = latest;
Leon Scroggins58d56c62010-01-28 15:12:40 -0500365 }
366 }
367 mVoiceSearchData.mLastVoiceSearchTitle
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500368 = mVoiceSearchData.mVoiceSearchResults.get(index);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500369 if (mInForeground) {
Michael Kolb11d19782011-03-20 10:17:40 -0700370 mWebViewController.activateVoiceSearchMode(
371 mVoiceSearchData.mLastVoiceSearchTitle,
372 mVoiceSearchData.mVoiceSearchResults);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500373 }
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500374 if (mVoiceSearchData.mVoiceSearchHtmls != null) {
375 // When index was found it was already ensured that it was valid
376 String uriString = mVoiceSearchData.mVoiceSearchHtmls.get(index);
377 if (uriString != null) {
378 Uri dataUri = Uri.parse(uriString);
379 if (RecognizerResultsIntent.URI_SCHEME_INLINE.equals(
380 dataUri.getScheme())) {
381 // If there is only one base URL, use it. If there are
382 // more, there will be one for each index, so use the base
383 // URL corresponding to the index.
384 String baseUrl = mVoiceSearchData.mVoiceSearchBaseUrls.get(
385 mVoiceSearchData.mVoiceSearchBaseUrls.size() > 1 ?
386 index : 0);
387 mVoiceSearchData.mLastVoiceSearchUrl = baseUrl;
388 mMainView.loadDataWithBaseURL(baseUrl,
389 uriString.substring(RecognizerResultsIntent
390 .URI_SCHEME_INLINE.length() + 1), "text/html",
391 "utf-8", baseUrl);
392 return;
393 }
394 }
395 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500396 mVoiceSearchData.mLastVoiceSearchUrl
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500397 = mVoiceSearchData.mVoiceSearchUrls.get(index);
398 if (null == mVoiceSearchData.mLastVoiceSearchUrl) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 mVoiceSearchData.mLastVoiceSearchUrl = UrlUtils.smartUrlFilter(
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500400 mVoiceSearchData.mLastVoiceSearchTitle);
401 }
Leon Scroggins9df94972010-03-08 18:20:35 -0500402 Map<String, String> headers = null;
403 if (mVoiceSearchData.mHeaders != null) {
404 int bundleIndex = mVoiceSearchData.mHeaders.size() == 1 ? 0
405 : index;
406 Bundle bundle = mVoiceSearchData.mHeaders.get(bundleIndex);
407 if (bundle != null && !bundle.isEmpty()) {
408 Iterator<String> iter = bundle.keySet().iterator();
409 headers = new HashMap<String, String>();
410 while (iter.hasNext()) {
411 String key = iter.next();
412 headers.put(key, bundle.getString(key));
413 }
414 }
415 }
416 mMainView.loadUrl(mVoiceSearchData.mLastVoiceSearchUrl, headers);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500417 }
418 /* package */ static class VoiceSearchData {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500419 public VoiceSearchData(ArrayList<String> results,
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500420 ArrayList<String> urls, ArrayList<String> htmls,
421 ArrayList<String> baseUrls) {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500422 mVoiceSearchResults = results;
423 mVoiceSearchUrls = urls;
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500424 mVoiceSearchHtmls = htmls;
425 mVoiceSearchBaseUrls = baseUrls;
Leon Scroggins58d56c62010-01-28 15:12:40 -0500426 }
427 /*
428 * ArrayList of suggestions to be displayed when opening the
429 * SearchManager
430 */
431 public ArrayList<String> mVoiceSearchResults;
432 /*
433 * ArrayList of urls, associated with the suggestions in
434 * mVoiceSearchResults.
435 */
436 public ArrayList<String> mVoiceSearchUrls;
437 /*
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500438 * ArrayList holding content to load for each item in
439 * mVoiceSearchResults.
440 */
441 public ArrayList<String> mVoiceSearchHtmls;
442 /*
443 * ArrayList holding base urls for the items in mVoiceSearchResults.
444 * If non null, this will either have the same size as
445 * mVoiceSearchResults or have a size of 1, in which case all will use
446 * the same base url
447 */
448 public ArrayList<String> mVoiceSearchBaseUrls;
449 /*
Leon Scroggins58d56c62010-01-28 15:12:40 -0500450 * The last url provided by voice search. Used for comparison to see if
Leon Scroggins82c1baa2010-02-02 16:10:57 -0500451 * we are going to a page by some method besides voice search.
Leon Scroggins58d56c62010-01-28 15:12:40 -0500452 */
453 public String mLastVoiceSearchUrl;
454 /**
455 * The last title used for voice search. Needed to update the title bar
456 * when switching tabs.
457 */
458 public String mLastVoiceSearchTitle;
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500459 /**
460 * Whether the Intent which turned on voice search mode contained the
461 * String signifying that Google was the source.
462 */
463 public boolean mSourceIsGoogle;
464 /**
Leon Scroggins9df94972010-03-08 18:20:35 -0500465 * List of headers to be passed into the WebView containing location
466 * information
467 */
468 public ArrayList<Bundle> mHeaders;
469 /**
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500470 * The Intent used to invoke voice search. Placed on the
471 * WebHistoryItem so that when coming back to a previous voice search
472 * page we can again activate voice search.
473 */
Leon Scrogginse10dde52010-03-08 19:53:03 -0500474 public Intent mVoiceSearchIntent;
Leon Scroggins0c75a8e2010-03-03 16:40:58 -0500475 /**
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500476 * String used to identify Google as the source of voice search.
477 */
478 public static String SOURCE_IS_GOOGLE
479 = "android.speech.extras.SOURCE_IS_GOOGLE";
Leon Scroggins58d56c62010-01-28 15:12:40 -0500480 }
481
Grace Kloba22ac16e2009-10-07 18:00:23 -0700482 // Container class for the next error dialog that needs to be displayed
483 private class ErrorDialog {
484 public final int mTitle;
485 public final String mDescription;
486 public final int mError;
487 ErrorDialog(int title, String desc, int error) {
488 mTitle = title;
489 mDescription = desc;
490 mError = error;
491 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700492 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700493
494 private void processNextError() {
495 if (mQueuedErrors == null) {
496 return;
497 }
498 // The first one is currently displayed so just remove it.
499 mQueuedErrors.removeFirst();
500 if (mQueuedErrors.size() == 0) {
501 mQueuedErrors = null;
502 return;
503 }
504 showError(mQueuedErrors.getFirst());
505 }
506
507 private DialogInterface.OnDismissListener mDialogListener =
508 new DialogInterface.OnDismissListener() {
509 public void onDismiss(DialogInterface d) {
510 processNextError();
511 }
512 };
513 private LinkedList<ErrorDialog> mQueuedErrors;
514
515 private void queueError(int err, String desc) {
516 if (mQueuedErrors == null) {
517 mQueuedErrors = new LinkedList<ErrorDialog>();
518 }
519 for (ErrorDialog d : mQueuedErrors) {
520 if (d.mError == err) {
521 // Already saw a similar error, ignore the new one.
522 return;
523 }
524 }
525 ErrorDialog errDialog = new ErrorDialog(
526 err == WebViewClient.ERROR_FILE_NOT_FOUND ?
527 R.string.browserFrameFileErrorLabel :
528 R.string.browserFrameNetworkErrorLabel,
529 desc, err);
530 mQueuedErrors.addLast(errDialog);
531
532 // Show the dialog now if the queue was empty and it is in foreground
533 if (mQueuedErrors.size() == 1 && mInForeground) {
534 showError(errDialog);
535 }
536 }
537
538 private void showError(ErrorDialog errDialog) {
539 if (mInForeground) {
Michael Kolb14612442011-06-24 13:06:29 -0700540 AlertDialog d = new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700541 .setTitle(errDialog.mTitle)
542 .setMessage(errDialog.mDescription)
543 .setPositiveButton(R.string.ok, null)
544 .create();
545 d.setOnDismissListener(mDialogListener);
546 d.show();
547 }
548 }
549
550 // -------------------------------------------------------------------------
551 // WebViewClient implementation for the main WebView
552 // -------------------------------------------------------------------------
553
554 private final WebViewClient mWebViewClient = new WebViewClient() {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500555 private Message mDontResend;
556 private Message mResend;
Michael Kolb47bd1e42011-09-01 15:25:00 -0700557
558 private boolean providersDiffer(String url, String otherUrl) {
559 Uri uri1 = Uri.parse(url);
560 Uri uri2 = Uri.parse(otherUrl);
561 return !uri1.getEncodedAuthority().equals(uri2.getEncodedAuthority());
562 }
563
Grace Kloba22ac16e2009-10-07 18:00:23 -0700564 @Override
565 public void onPageStarted(WebView view, String url, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 mInPageLoad = true;
Michael Kolba53c9892011-10-05 13:31:40 -0700567 mPageLoadProgress = INITIAL_PROGRESS;
Michael Kolb14612442011-06-24 13:06:29 -0700568 mCurrentState = new PageState(mContext,
John Reck30c714c2010-12-16 17:30:34 -0800569 view.isPrivateBrowsingEnabled(), url, favicon);
Kristian Monsen4dce3bf2010-02-02 13:37:09 +0000570 mLoadStartTime = SystemClock.uptimeMillis();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500571 if (mVoiceSearchData != null
Michael Kolb47bd1e42011-09-01 15:25:00 -0700572 && providersDiffer(url, mVoiceSearchData.mLastVoiceSearchUrl)) {
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500573 if (mVoiceSearchData.mSourceIsGoogle) {
574 Intent i = new Intent(LoggingEvents.ACTION_LOG_EVENT);
575 i.putExtra(LoggingEvents.EXTRA_FLUSH, true);
Michael Kolb14612442011-06-24 13:06:29 -0700576 mContext.sendBroadcast(i);
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500577 }
Leon Scroggins III95d9bfd2010-09-14 14:02:36 -0400578 revertVoiceSearchMode();
Leon Scroggins58d56c62010-01-28 15:12:40 -0500579 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700580
Grace Kloba22ac16e2009-10-07 18:00:23 -0700581
582 // If we start a touch icon load and then load a new page, we don't
583 // want to cancel the current touch icon loader. But, we do want to
584 // create a new one when the touch icon url is known.
585 if (mTouchIconLoader != null) {
586 mTouchIconLoader.mTab = null;
587 mTouchIconLoader = null;
588 }
589
590 // reset the error console
591 if (mErrorConsole != null) {
592 mErrorConsole.clearErrorMessages();
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 if (mWebViewController.shouldShowErrorConsole()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700594 mErrorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
595 }
596 }
597
Patrick Scott92066772011-03-10 08:46:27 -0500598 // Cancel the auto-login process.
599 if (mDeviceAccountLogin != null) {
600 mDeviceAccountLogin.cancel();
601 mDeviceAccountLogin = null;
602 mWebViewController.hideAutoLogin(Tab.this);
603 }
604
Grace Kloba22ac16e2009-10-07 18:00:23 -0700605 // finally update the UI in the activity if it is in the foreground
John Reck324d4402011-01-11 16:56:42 -0800606 mWebViewController.onPageStarted(Tab.this, view, favicon);
Leon Scroggins4cd97792010-12-03 15:31:56 -0500607
John Recke969cc52010-12-21 17:24:43 -0800608 updateBookmarkedStatus();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700609 }
610
611 @Override
612 public void onPageFinished(WebView view, String url) {
John Recka1696282011-07-08 14:10:37 -0700613 if (!mInPageLoad) {
614 // In page navigation links (www.something.com#footer) will
615 // trigger an onPageFinished which we don't care about.
616 return;
617 }
John Reck5b691842010-11-29 11:21:13 -0800618 if (!isPrivateBrowsingEnabled()) {
619 LogTag.logPageFinishedLoading(
620 url, SystemClock.uptimeMillis() - mLoadStartTime);
621 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700622 mInPageLoad = false;
John Reck1cf4b792011-07-26 10:22:22 -0700623 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800624 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700625 }
626
627 // return true if want to hijack the url to let another app to handle it
628 @Override
629 public boolean shouldOverrideUrlLoading(WebView view, String url) {
Leon Scroggins IIIc1f5ae22010-06-29 17:11:29 -0400630 if (voiceSearchSourceIsGoogle()) {
631 // This method is called when the user clicks on a link.
632 // VoiceSearchMode is turned off when the user leaves the
633 // Google results page, so at this point the user must be on
634 // that page. If the user clicked a link on that page, assume
635 // that the voice search was effective, and broadcast an Intent
636 // so a receiver can take note of that fact.
637 Intent logIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT);
638 logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
639 LoggingEvents.VoiceSearch.RESULT_CLICKED);
Michael Kolb14612442011-06-24 13:06:29 -0700640 mContext.sendBroadcast(logIntent);
Leon Scroggins IIIc1f5ae22010-06-29 17:11:29 -0400641 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700642 if (mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800643 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
644 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700645 } else {
646 return false;
647 }
648 }
649
650 /**
Steve Block2466eff2011-10-03 15:33:09 +0100651 * Updates the security state. This method is called when we discover
652 * another resource to be loaded for this page (for example,
653 * javascript). While we update the security state, we do not update
654 * the lock icon until we are done loading, as it is slightly more
655 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700656 */
657 @Override
658 public void onLoadResource(WebView view, String url) {
659 if (url != null && url.length() > 0) {
660 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100661 // to update the security state:
662 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
663 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700664 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
665 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100666 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700667 }
668 }
669 }
670 }
671
672 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700673 * Show a dialog informing the user of the network error reported by
674 * WebCore if it is in the foreground.
675 */
676 @Override
677 public void onReceivedError(WebView view, int errorCode,
678 String description, String failingUrl) {
679 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
680 errorCode != WebViewClient.ERROR_CONNECT &&
681 errorCode != WebViewClient.ERROR_BAD_URL &&
682 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
683 errorCode != WebViewClient.ERROR_FILE) {
684 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500685
Selim Gurun3da06b82011-10-10 13:58:12 -0700686 // Don't log URLs when in private browsing mode
687 if (!isPrivateBrowsingEnabled()) {
688 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500689 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700690 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500691 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700692 }
693
694 /**
695 * Check with the user if it is ok to resend POST data as the page they
696 * are trying to navigate to is the result of a POST.
697 */
698 @Override
699 public void onFormResubmission(WebView view, final Message dontResend,
700 final Message resend) {
701 if (!mInForeground) {
702 dontResend.sendToTarget();
703 return;
704 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500705 if (mDontResend != null) {
706 Log.w(LOGTAG, "onFormResubmission should not be called again "
707 + "while dialog is still up");
708 dontResend.sendToTarget();
709 return;
710 }
711 mDontResend = dontResend;
712 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700713 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700714 R.string.browserFrameFormResubmitLabel).setMessage(
715 R.string.browserFrameFormResubmitMessage)
716 .setPositiveButton(R.string.ok,
717 new DialogInterface.OnClickListener() {
718 public void onClick(DialogInterface dialog,
719 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500720 if (mResend != null) {
721 mResend.sendToTarget();
722 mResend = null;
723 mDontResend = null;
724 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700725 }
726 }).setNegativeButton(R.string.cancel,
727 new DialogInterface.OnClickListener() {
728 public void onClick(DialogInterface dialog,
729 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500730 if (mDontResend != null) {
731 mDontResend.sendToTarget();
732 mResend = null;
733 mDontResend = null;
734 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700735 }
736 }).setOnCancelListener(new OnCancelListener() {
737 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500738 if (mDontResend != null) {
739 mDontResend.sendToTarget();
740 mResend = null;
741 mDontResend = null;
742 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700743 }
744 }).show();
745 }
746
747 /**
748 * Insert the url into the visited history database.
749 * @param url The url to be inserted.
750 * @param isReload True if this url is being reloaded.
751 * FIXME: Not sure what to do when reloading the page.
752 */
753 @Override
754 public void doUpdateVisitedHistory(WebView view, String url,
755 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800756 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700757 }
758
759 /**
760 * Displays SSL error(s) dialog to the user.
761 */
762 @Override
763 public void onReceivedSslError(final WebView view,
764 final SslErrorHandler handler, final SslError error) {
765 if (!mInForeground) {
766 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100767 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700768 return;
769 }
John Reck35e9dd62011-04-25 09:01:54 -0700770 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700771 new AlertDialog.Builder(mContext)
772 .setTitle(R.string.security_warning)
773 .setMessage(R.string.ssl_warnings_header)
774 .setIcon(android.R.drawable.ic_dialog_alert)
775 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700776 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700777 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700778 public void onClick(DialogInterface dialog,
779 int whichButton) {
780 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100781 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700782 }
John Reckcb28b2c2011-08-26 17:39:44 -0700783 })
784 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700785 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700786 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700787 public void onClick(DialogInterface dialog,
788 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700789 mWebViewController.showSslCertificateOnError(
790 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700791 }
John Reckcb28b2c2011-08-26 17:39:44 -0700792 })
793 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700794 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700795 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700796 public void onClick(DialogInterface dialog,
797 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800798 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700799 }
John Reckcb28b2c2011-08-26 17:39:44 -0700800 })
801 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700802 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700803 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700804 public void onCancel(DialogInterface dialog) {
805 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100806 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800807 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700808 }
John Reckcb28b2c2011-08-26 17:39:44 -0700809 })
810 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700811 } else {
812 handler.proceed();
813 }
814 }
815
816 /**
Steve Block4895b012011-10-03 16:26:46 +0100817 * Called when an SSL error occurred while loading a resource, but the
818 * WebView but chose to proceed anyway based on a decision retained
819 * from a previous response to onReceivedSslError(). We update our
820 * security state to reflect this.
821 */
822 @Override
823 public void onProceededAfterSslError(WebView view, SslError error) {
824 handleProceededAfterSslError(error);
825 }
826
827 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700828 * Displays client certificate request to the user.
829 */
830 @Override
831 public void onReceivedClientCertRequest(final WebView view,
832 final ClientCertRequestHandler handler, final String host_and_port) {
833 if (!mInForeground) {
834 handler.ignore();
835 return;
836 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700837 int colon = host_and_port.lastIndexOf(':');
838 String host;
839 int port;
840 if (colon == -1) {
841 host = host_and_port;
842 port = -1;
843 } else {
844 String portString = host_and_port.substring(colon + 1);
845 try {
846 port = Integer.parseInt(portString);
847 host = host_and_port.substring(0, colon);
848 } catch (NumberFormatException e) {
849 host = host_and_port;
850 port = -1;
851 }
852 }
Michael Kolb14612442011-06-24 13:06:29 -0700853 KeyChain.choosePrivateKeyAlias(
854 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700855 @Override public void alias(String alias) {
856 if (alias == null) {
857 handler.cancel();
858 return;
859 }
Michael Kolb14612442011-06-24 13:06:29 -0700860 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700861 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700862 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700863 }
864
865 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700866 * Handles an HTTP authentication request.
867 *
868 * @param handler The authentication handler
869 * @param host The host
870 * @param realm The realm
871 */
872 @Override
873 public void onReceivedHttpAuthRequest(WebView view,
874 final HttpAuthHandler handler, final String host,
875 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700876 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700877 }
878
879 @Override
John Reck438bf462011-01-12 18:11:46 -0800880 public WebResourceResponse shouldInterceptRequest(WebView view,
881 String url) {
882 WebResourceResponse res = HomeProvider.shouldInterceptRequest(
Michael Kolb14612442011-06-24 13:06:29 -0700883 mContext, url);
John Reck438bf462011-01-12 18:11:46 -0800884 return res;
885 }
886
887 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700888 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
889 if (!mInForeground) {
890 return false;
891 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700892 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700893 }
894
895 @Override
896 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700897 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700898 return;
899 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700900 mWebViewController.onUnhandledKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700901 }
Patrick Scott92066772011-03-10 08:46:27 -0500902
903 @Override
904 public void onReceivedLoginRequest(WebView view, String realm,
905 String account, String args) {
Michael Kolb14612442011-06-24 13:06:29 -0700906 new DeviceAccountLogin(mWebViewController.getActivity(), view, Tab.this, mWebViewController)
Patrick Scott92066772011-03-10 08:46:27 -0500907 .handleLogin(realm, account, args);
908 }
909
Grace Kloba22ac16e2009-10-07 18:00:23 -0700910 };
911
John Reck1cf4b792011-07-26 10:22:22 -0700912 private void syncCurrentState(WebView view, String url) {
913 // Sync state (in case of stop/timeout)
914 mCurrentState.mUrl = view.getUrl();
915 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700916 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700917 }
918 mCurrentState.mOriginalUrl = view.getOriginalUrl();
919 mCurrentState.mTitle = view.getTitle();
920 mCurrentState.mFavicon = view.getFavicon();
921 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
922 // In case we stop when loading an HTTPS page from an HTTP page
923 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100924 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100925 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700926 }
John Reck502a3532011-08-16 14:21:46 -0700927 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700928 }
929
Patrick Scott92066772011-03-10 08:46:27 -0500930 // Called by DeviceAccountLogin when the Tab needs to have the auto-login UI
931 // displayed.
932 void setDeviceAccountLogin(DeviceAccountLogin login) {
933 mDeviceAccountLogin = login;
934 }
935
936 // Returns non-null if the title bar should display the auto-login UI.
937 DeviceAccountLogin getDeviceAccountLogin() {
938 return mDeviceAccountLogin;
939 }
940
Grace Kloba22ac16e2009-10-07 18:00:23 -0700941 // -------------------------------------------------------------------------
942 // WebChromeClient implementation for the main WebView
943 // -------------------------------------------------------------------------
944
945 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
946 // Helper method to create a new tab or sub window.
947 private void createWindow(final boolean dialog, final Message msg) {
948 WebView.WebViewTransport transport =
949 (WebView.WebViewTransport) msg.obj;
950 if (dialog) {
951 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700952 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700953 transport.setWebView(mSubView);
954 } else {
Michael Kolb7bcafde2011-05-09 13:55:59 -0700955 final Tab newTab = mWebViewController.openTab(null,
John Reck5949c662011-05-27 09:52:29 -0700956 Tab.this, true, true);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700957 transport.setWebView(newTab.getWebView());
958 }
959 msg.sendToTarget();
960 }
961
962 @Override
963 public boolean onCreateWindow(WebView view, final boolean dialog,
964 final boolean userGesture, final Message resultMsg) {
965 // only allow new window or sub window for the foreground case
966 if (!mInForeground) {
967 return false;
968 }
969 // Short-circuit if we can't create any more tabs or sub windows.
970 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700971 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700972 .setTitle(R.string.too_many_subwindows_dialog_title)
973 .setIcon(android.R.drawable.ic_dialog_alert)
974 .setMessage(R.string.too_many_subwindows_dialog_message)
975 .setPositiveButton(R.string.ok, null)
976 .show();
977 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700978 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700979 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700980 .setTitle(R.string.too_many_windows_dialog_title)
981 .setIcon(android.R.drawable.ic_dialog_alert)
982 .setMessage(R.string.too_many_windows_dialog_message)
983 .setPositiveButton(R.string.ok, null)
984 .show();
985 return false;
986 }
987
988 // Short-circuit if this was a user gesture.
989 if (userGesture) {
990 createWindow(dialog, resultMsg);
991 return true;
992 }
993
994 // Allow the popup and create the appropriate window.
995 final AlertDialog.OnClickListener allowListener =
996 new AlertDialog.OnClickListener() {
997 public void onClick(DialogInterface d,
998 int which) {
999 createWindow(dialog, resultMsg);
1000 }
1001 };
1002
1003 // Block the popup by returning a null WebView.
1004 final AlertDialog.OnClickListener blockListener =
1005 new AlertDialog.OnClickListener() {
1006 public void onClick(DialogInterface d, int which) {
1007 resultMsg.sendToTarget();
1008 }
1009 };
1010
1011 // Build a confirmation dialog to display to the user.
1012 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -07001013 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -07001014 .setIcon(android.R.drawable.ic_dialog_alert)
1015 .setMessage(R.string.popup_window_attempt)
1016 .setPositiveButton(R.string.allow, allowListener)
1017 .setNegativeButton(R.string.block, blockListener)
1018 .setCancelable(false)
1019 .create();
1020
1021 // Show the confirmation dialog.
1022 d.show();
1023 return true;
1024 }
1025
1026 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -05001027 public void onRequestFocus(WebView view) {
1028 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -07001029 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -05001030 }
1031 }
1032
1033 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001034 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -07001035 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001036 // JavaScript can only close popup window.
1037 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -07001038 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001039 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001040 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001041 }
1042 }
1043
1044 @Override
1045 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -08001046 mPageLoadProgress = newProgress;
1047 mWebViewController.onProgressChanged(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001048 }
1049
1050 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -05001051 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -08001052 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -07001053 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001054 }
1055
1056 @Override
1057 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -08001058 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -07001059 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001060 }
1061
1062 @Override
1063 public void onReceivedTouchIconUrl(WebView view, String url,
1064 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -07001065 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -04001066 // Let precomposed icons take precedence over non-composed
1067 // icons.
1068 if (precomposed && mTouchIconLoader != null) {
1069 mTouchIconLoader.cancel(false);
1070 mTouchIconLoader = null;
1071 }
1072 // Have only one async task at a time.
1073 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001074 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -07001075 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -04001076 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001077 }
1078 }
1079
1080 @Override
1081 public void onShowCustomView(View view,
1082 WebChromeClient.CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -07001083 Activity activity = mWebViewController.getActivity();
1084 if (activity != null) {
1085 onShowCustomView(view, activity.getRequestedOrientation(), callback);
1086 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001087 }
1088
1089 @Override
1090 public void onShowCustomView(View view, int requestedOrientation,
1091 WebChromeClient.CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001092 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001093 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001094 }
1095
1096 @Override
1097 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -07001098 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001099 }
1100
1101 /**
1102 * The origin has exceeded its database quota.
1103 * @param url the URL that exceeded the quota
1104 * @param databaseIdentifier the identifier of the database on which the
1105 * transaction that caused the quota overflow was run
1106 * @param currentQuota the current quota for the origin.
1107 * @param estimatedSize the estimated size of the database.
1108 * @param totalUsedQuota is the sum of all origins' quota.
1109 * @param quotaUpdater The callback to run when a decision to allow or
1110 * deny quota has been made. Don't forget to call this!
1111 */
1112 @Override
1113 public void onExceededDatabaseQuota(String url,
1114 String databaseIdentifier, long currentQuota, long estimatedSize,
1115 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001116 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001117 .onExceededDatabaseQuota(url, databaseIdentifier,
1118 currentQuota, estimatedSize, totalUsedQuota,
1119 quotaUpdater);
1120 }
1121
1122 /**
1123 * The Application Cache has exceeded its max size.
1124 * @param spaceNeeded is the amount of disk space that would be needed
1125 * in order for the last appcache operation to succeed.
1126 * @param totalUsedQuota is the sum of all origins' quota.
1127 * @param quotaUpdater A callback to inform the WebCore thread that a
1128 * new app cache size is available. This callback must always
1129 * be executed at some point to ensure that the sleeping
1130 * WebCore thread is woken up.
1131 */
1132 @Override
1133 public void onReachedMaxAppCacheSize(long spaceNeeded,
1134 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001135 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001136 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1137 quotaUpdater);
1138 }
1139
1140 /**
1141 * Instructs the browser to show a prompt to ask the user to set the
1142 * Geolocation permission state for the specified origin.
1143 * @param origin The origin for which Geolocation permissions are
1144 * requested.
1145 * @param callback The callback to call once the user has set the
1146 * Geolocation permission state.
1147 */
1148 @Override
1149 public void onGeolocationPermissionsShowPrompt(String origin,
1150 GeolocationPermissions.Callback callback) {
1151 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001152 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001153 }
1154 }
1155
1156 /**
1157 * Instructs the browser to hide the Geolocation permissions prompt.
1158 */
1159 @Override
1160 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001161 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001162 mGeolocationPermissionsPrompt.hide();
1163 }
1164 }
1165
Ben Murdoch65acc352009-11-19 18:16:04 +00001166 /* Adds a JavaScript error message to the system log and if the JS
1167 * console is enabled in the about:debug options, to that console
1168 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001169 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001170 */
1171 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001172 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001173 if (mInForeground) {
1174 // call getErrorConsole(true) so it will create one if needed
1175 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001176 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001177 if (mWebViewController.shouldShowErrorConsole()
1178 && errorConsole.getShowState() !=
1179 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001180 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1181 }
1182 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001183
Jeff Hamilton47654f42010-09-07 09:57:51 -05001184 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001185 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001186
Ben Murdochc42addf2010-01-28 15:19:59 +00001187 String message = "Console: " + consoleMessage.message() + " "
1188 + consoleMessage.sourceId() + ":"
1189 + consoleMessage.lineNumber();
1190
1191 switch (consoleMessage.messageLevel()) {
1192 case TIP:
1193 Log.v(CONSOLE_LOGTAG, message);
1194 break;
1195 case LOG:
1196 Log.i(CONSOLE_LOGTAG, message);
1197 break;
1198 case WARNING:
1199 Log.w(CONSOLE_LOGTAG, message);
1200 break;
1201 case ERROR:
1202 Log.e(CONSOLE_LOGTAG, message);
1203 break;
1204 case DEBUG:
1205 Log.d(CONSOLE_LOGTAG, message);
1206 break;
1207 }
1208
1209 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001210 }
1211
1212 /**
1213 * Ask the browser for an icon to represent a <video> element.
1214 * This icon will be used if the Web page did not specify a poster attribute.
1215 * @return Bitmap The icon or null if no such icon is available.
1216 */
1217 @Override
1218 public Bitmap getDefaultVideoPoster() {
1219 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001220 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001221 }
1222 return null;
1223 }
1224
1225 /**
1226 * Ask the host application for a custom progress view to show while
1227 * a <video> is loading.
1228 * @return View The progress view.
1229 */
1230 @Override
1231 public View getVideoLoadingProgressView() {
1232 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001233 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001234 }
1235 return null;
1236 }
1237
1238 @Override
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01001239 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001240 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001241 mWebViewController.openFileChooser(uploadMsg, acceptType);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001242 } else {
1243 uploadMsg.onReceiveValue(null);
1244 }
1245 }
1246
1247 /**
1248 * Deliver a list of already-visited URLs
1249 */
1250 @Override
1251 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001252 mWebViewController.getVisitedHistory(callback);
1253 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001254
1255 @Override
1256 public void setupAutoFill(Message message) {
1257 // Prompt the user to set up their profile.
1258 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001259 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1260 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001261 Context.LAYOUT_INFLATER_SERVICE);
1262 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1263
1264 builder.setView(layout)
1265 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1266 @Override
1267 public void onClick(DialogInterface dialog, int id) {
1268 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1269 R.id.setup_autofill_dialog_disable_autofill);
1270
1271 if (disableAutoFill.isChecked()) {
1272 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001273 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001274 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001275 R.string.autofill_setup_dialog_negative_toast,
1276 Toast.LENGTH_LONG).show();
1277 } else {
1278 // Take user to the AutoFill profile editor. When they return,
1279 // we will send the message that we pass here which will trigger
1280 // the form to get filled out with their new profile.
1281 mWebViewController.setupAutoFill(msg);
1282 }
1283 }
1284 })
1285 .setNegativeButton(R.string.cancel, null)
1286 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001287 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001288 };
1289
1290 // -------------------------------------------------------------------------
1291 // WebViewClient implementation for the sub window
1292 // -------------------------------------------------------------------------
1293
1294 // Subclass of WebViewClient used in subwindows to notify the main
1295 // WebViewClient of certain WebView activities.
1296 private static class SubWindowClient extends WebViewClient {
1297 // The main WebViewClient.
1298 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001299 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001300
Michael Kolb8233fac2010-10-26 16:08:53 -07001301 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001302 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001303 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001304 }
1305 @Override
1306 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1307 // Unlike the others, do not call mClient's version, which would
1308 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001309 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001310 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001311 }
1312 @Override
1313 public void doUpdateVisitedHistory(WebView view, String url,
1314 boolean isReload) {
1315 mClient.doUpdateVisitedHistory(view, url, isReload);
1316 }
1317 @Override
1318 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1319 return mClient.shouldOverrideUrlLoading(view, url);
1320 }
1321 @Override
1322 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1323 SslError error) {
1324 mClient.onReceivedSslError(view, handler, error);
1325 }
1326 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001327 public void onReceivedClientCertRequest(WebView view,
1328 ClientCertRequestHandler handler, String host_and_port) {
1329 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1330 }
1331 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001332 public void onReceivedHttpAuthRequest(WebView view,
1333 HttpAuthHandler handler, String host, String realm) {
1334 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1335 }
1336 @Override
1337 public void onFormResubmission(WebView view, Message dontResend,
1338 Message resend) {
1339 mClient.onFormResubmission(view, dontResend, resend);
1340 }
1341 @Override
1342 public void onReceivedError(WebView view, int errorCode,
1343 String description, String failingUrl) {
1344 mClient.onReceivedError(view, errorCode, description, failingUrl);
1345 }
1346 @Override
1347 public boolean shouldOverrideKeyEvent(WebView view,
1348 android.view.KeyEvent event) {
1349 return mClient.shouldOverrideKeyEvent(view, event);
1350 }
1351 @Override
1352 public void onUnhandledKeyEvent(WebView view,
1353 android.view.KeyEvent event) {
1354 mClient.onUnhandledKeyEvent(view, event);
1355 }
1356 }
1357
1358 // -------------------------------------------------------------------------
1359 // WebChromeClient implementation for the sub window
1360 // -------------------------------------------------------------------------
1361
1362 private class SubWindowChromeClient extends WebChromeClient {
1363 // The main WebChromeClient.
1364 private final WebChromeClient mClient;
1365
1366 SubWindowChromeClient(WebChromeClient client) {
1367 mClient = client;
1368 }
1369 @Override
1370 public void onProgressChanged(WebView view, int newProgress) {
1371 mClient.onProgressChanged(view, newProgress);
1372 }
1373 @Override
1374 public boolean onCreateWindow(WebView view, boolean dialog,
1375 boolean userGesture, android.os.Message resultMsg) {
1376 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1377 }
1378 @Override
1379 public void onCloseWindow(WebView window) {
1380 if (window != mSubView) {
1381 Log.e(LOGTAG, "Can't close the window");
1382 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001383 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001384 }
1385 }
1386
1387 // -------------------------------------------------------------------------
1388
1389 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001390 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001391 this(wvcontroller, w, null);
1392 }
1393
1394 Tab(WebViewController wvcontroller, Bundle state) {
1395 this(wvcontroller, null, state);
1396 }
1397
1398 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001399 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001400 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001401 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001402 mDataController = DataController.getInstance(mContext);
1403 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001404 ? w.isPrivateBrowsingEnabled() : false);
Michael Kolb8233fac2010-10-26 16:08:53 -07001405 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001406 mInForeground = false;
1407
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001408 mDownloadListener = new DownloadListener() {
1409 public void onDownloadStart(String url, String userAgent,
1410 String contentDisposition, String mimetype,
1411 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001412 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001413 mimetype, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001414 }
1415 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001416 mWebBackForwardListClient = new WebBackForwardListClient() {
1417 @Override
1418 public void onNewHistoryItem(WebHistoryItem item) {
1419 if (isInVoiceSearchMode()) {
1420 item.setCustomData(mVoiceSearchData.mVoiceSearchIntent);
1421 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001422 if (mClearHistoryUrlPattern != null) {
1423 boolean match =
1424 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001425 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001426 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1427 + item.getUrl() + "\n\t"
1428 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001429 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001430 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001431 if (mMainView != null) {
1432 mMainView.clearHistory();
1433 }
1434 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001435 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001436 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001437 }
1438 @Override
1439 public void onIndexChanged(WebHistoryItem item, int index) {
1440 Object data = item.getCustomData();
1441 if (data != null && data instanceof Intent) {
1442 activateVoiceSearchMode((Intent) data);
1443 }
1444 }
1445 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001446
John Reck1cf4b792011-07-26 10:22:22 -07001447 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1448 R.dimen.tab_thumbnail_width);
1449 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1450 R.dimen.tab_thumbnail_height);
1451 updateShouldCaptureThumbnails();
1452 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001453 if (getId() == -1) {
1454 mId = TabControl.getNextId();
1455 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001456 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001457 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001458 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001459 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001460 switch (m.what) {
1461 case MSG_CAPTURE:
1462 capture();
1463 break;
1464 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001465 }
1466 };
John Reck1cf4b792011-07-26 10:22:22 -07001467 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001468
Mathew Inwoode09305e2011-09-02 12:03:26 +01001469 /**
1470 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1471 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1472 * to overlapping IDs between the preloaded and restored tabs.
1473 */
1474 public void refreshIdAfterPreload() {
1475 mId = TabControl.getNextId();
1476 }
1477
John Reck1cf4b792011-07-26 10:22:22 -07001478 public void updateShouldCaptureThumbnails() {
1479 if (mWebViewController.shouldCaptureThumbnails()) {
1480 synchronized (Tab.this) {
1481 if (mCapture == null) {
1482 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1483 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001484 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001485 if (mInForeground) {
1486 postCapture();
1487 }
1488 }
1489 }
1490 } else {
1491 synchronized (Tab.this) {
1492 mCapture = null;
1493 deleteThumbnail();
1494 }
1495 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001496 }
1497
Michael Kolb14612442011-06-24 13:06:29 -07001498 public void setController(WebViewController ctl) {
1499 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001500 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001501 }
1502
Michael Kolbc831b632011-05-11 09:30:34 -07001503 public long getId() {
1504 return mId;
1505 }
1506
Grace Kloba22ac16e2009-10-07 18:00:23 -07001507 /**
1508 * Sets the WebView for this tab, correctly removing the old WebView from
1509 * the container view.
1510 */
1511 void setWebView(WebView w) {
1512 if (mMainView == w) {
1513 return;
1514 }
Michael Kolba713ec82010-11-29 17:27:06 -08001515
Grace Kloba22ac16e2009-10-07 18:00:23 -07001516 // If the WebView is changing, the page will be reloaded, so any ongoing
1517 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001518 if (mGeolocationPermissionsPrompt != null) {
1519 mGeolocationPermissionsPrompt.hide();
1520 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001521
Michael Kolba713ec82010-11-29 17:27:06 -08001522 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001523
John Reck1cf4b792011-07-26 10:22:22 -07001524 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001525 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001526 if (w != null) {
1527 syncCurrentState(w, null);
1528 } else {
1529 mCurrentState = new PageState(mContext, false);
1530 }
1531 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001532 // set the new one
1533 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001534 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001535 if (mMainView != null) {
1536 mMainView.setWebViewClient(mWebViewClient);
1537 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001538 // Attach DownloadManager so that downloads can start in an active
1539 // or a non-active window. This can happen when going to a site that
1540 // does a redirect after a period of time. The user could have
1541 // switched to another tab while waiting for the download to start.
1542 mMainView.setDownloadListener(mDownloadListener);
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001543 mMainView.setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001544 TabControl tc = mWebViewController.getTabControl();
1545 if (tc != null && tc.getOnThumbnailUpdatedListener() != null) {
1546 mMainView.setPictureListener(this);
1547 }
John Reck1cf4b792011-07-26 10:22:22 -07001548 if (mSavedState != null) {
John Reck6c2e2f32011-08-22 13:41:23 -07001549 WebBackForwardList restoredState
1550 = mMainView.restoreState(mSavedState);
1551 if (restoredState == null || restoredState.getSize() == 0) {
1552 Log.w(LOGTAG, "Failed to restore WebView state!");
1553 loadUrl(mCurrentState.mOriginalUrl, null);
1554 }
John Reck1cf4b792011-07-26 10:22:22 -07001555 mSavedState = null;
1556 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001557 }
1558 }
1559
1560 /**
1561 * Destroy the tab's main WebView and subWindow if any
1562 */
1563 void destroy() {
1564 if (mMainView != null) {
1565 dismissSubWindow();
John Reckef654f12011-07-12 16:42:08 -07001566 // Make sure the embedded title bar isn't still attached
1567 mMainView.setEmbeddedTitleBar(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001568 // save the WebView to call destroy() after detach it from the tab
1569 WebView webView = mMainView;
1570 setWebView(null);
1571 webView.destroy();
1572 }
1573 }
1574
1575 /**
1576 * Remove the tab from the parent
1577 */
1578 void removeFromTree() {
1579 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001580 if (mChildren != null) {
1581 for(Tab t : mChildren) {
1582 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001583 }
1584 }
1585 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001586 if (mParent != null) {
1587 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001588 }
John Reck1cf4b792011-07-26 10:22:22 -07001589 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001590 }
1591
1592 /**
1593 * Create a new subwindow unless a subwindow already exists.
1594 * @return True if a new subwindow was created. False if one already exists.
1595 */
1596 boolean createSubWindow() {
1597 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001598 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001599 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001600 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001601 mSubView.setWebChromeClient(new SubWindowChromeClient(
1602 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001603 // Set a different DownloadListener for the mSubView, since it will
1604 // just need to dismiss the mSubView, rather than close the Tab
1605 mSubView.setDownloadListener(new DownloadListener() {
1606 public void onDownloadStart(String url, String userAgent,
1607 String contentDisposition, String mimetype,
1608 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001609 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001610 contentDisposition, mimetype, contentLength);
1611 if (mSubView.copyBackForwardList().getSize() == 0) {
1612 // This subwindow was opened for the sole purpose of
1613 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001614 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001615 }
1616 }
1617 });
Michael Kolb14612442011-06-24 13:06:29 -07001618 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001619 return true;
1620 }
1621 return false;
1622 }
1623
1624 /**
1625 * Dismiss the subWindow for the tab.
1626 */
1627 void dismissSubWindow() {
1628 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001629 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001630 mSubView.destroy();
1631 mSubView = null;
1632 mSubViewContainer = null;
1633 }
1634 }
1635
Grace Kloba22ac16e2009-10-07 18:00:23 -07001636
1637 /**
1638 * Set the parent tab of this tab.
1639 */
Michael Kolbc831b632011-05-11 09:30:34 -07001640 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001641 if (parent == this) {
1642 throw new IllegalStateException("Cannot set parent to self!");
1643 }
Michael Kolbc831b632011-05-11 09:30:34 -07001644 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001645 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001646 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001647 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001648 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001649 if (mSavedState != null) {
1650 if (parent == null) {
1651 mSavedState.remove(PARENTTAB);
1652 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001653 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001654 }
1655 }
John Reckb0a86db2011-05-24 14:05:58 -07001656
1657 // Sync the WebView useragent with the parent
1658 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1659 != mSettings.hasDesktopUseragent(getWebView())) {
1660 mSettings.toggleDesktopUseragent(getWebView());
1661 }
John Reck52be4782011-08-26 15:37:29 -07001662
1663 if (parent != null && parent.getId() == getId()) {
1664 throw new IllegalStateException("Parent has same ID as child!");
1665 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001666 }
1667
1668 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001669 * If this Tab was created through another Tab, then this method returns
1670 * that Tab.
1671 * @return the Tab parent or null
1672 */
1673 public Tab getParent() {
1674 return mParent;
1675 }
1676
1677 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001678 * When a Tab is created through the content of another Tab, then we
1679 * associate the Tabs.
1680 * @param child the Tab that was created from this Tab
1681 */
1682 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001683 if (mChildren == null) {
1684 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001685 }
Michael Kolbc831b632011-05-11 09:30:34 -07001686 mChildren.add(child);
1687 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001688 }
1689
Michael Kolbc831b632011-05-11 09:30:34 -07001690 Vector<Tab> getChildren() {
1691 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001692 }
1693
1694 void resume() {
1695 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001696 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001697 mMainView.onResume();
1698 if (mSubView != null) {
1699 mSubView.onResume();
1700 }
1701 }
1702 }
1703
John Reck56c1fcf2011-08-17 10:15:16 -07001704 private void setupHwAcceleration(View web) {
1705 if (web == null) return;
1706 BrowserSettings settings = BrowserSettings.getInstance();
1707 if (settings.isHardwareAccelerated()) {
1708 web.setLayerType(View.LAYER_TYPE_NONE, null);
1709 } else {
1710 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1711 }
1712 }
1713
Grace Kloba22ac16e2009-10-07 18:00:23 -07001714 void pause() {
1715 if (mMainView != null) {
1716 mMainView.onPause();
1717 if (mSubView != null) {
1718 mSubView.onPause();
1719 }
1720 }
1721 }
1722
1723 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001724 if (mInForeground) {
1725 return;
1726 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001727 mInForeground = true;
1728 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001729 Activity activity = mWebViewController.getActivity();
1730 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001731 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001732 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001733 }
1734 // Show the pending error dialog if the queue is not empty
1735 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1736 showError(mQueuedErrors.getFirst());
1737 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001738 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001739 }
1740
1741 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001742 if (!mInForeground) {
1743 return;
1744 }
John Reck52be4782011-08-26 15:37:29 -07001745 capture();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001746 mInForeground = false;
1747 pause();
1748 mMainView.setOnCreateContextMenuListener(null);
1749 if (mSubView != null) {
1750 mSubView.setOnCreateContextMenuListener(null);
1751 }
1752 }
1753
Michael Kolb8233fac2010-10-26 16:08:53 -07001754 boolean inForeground() {
1755 return mInForeground;
1756 }
1757
Grace Kloba22ac16e2009-10-07 18:00:23 -07001758 /**
1759 * Return the top window of this tab; either the subwindow if it is not
1760 * null or the main window.
1761 * @return The top window of this tab.
1762 */
1763 WebView getTopWindow() {
1764 if (mSubView != null) {
1765 return mSubView;
1766 }
1767 return mMainView;
1768 }
1769
1770 /**
1771 * Return the main window of this tab. Note: if a tab is freed in the
1772 * background, this can return null. It is only guaranteed to be
1773 * non-null for the current tab.
1774 * @return The main WebView of this tab.
1775 */
1776 WebView getWebView() {
1777 return mMainView;
1778 }
1779
Michael Kolba713ec82010-11-29 17:27:06 -08001780 void setViewContainer(View container) {
1781 mContainer = container;
1782 }
1783
Michael Kolb8233fac2010-10-26 16:08:53 -07001784 View getViewContainer() {
1785 return mContainer;
1786 }
1787
Grace Kloba22ac16e2009-10-07 18:00:23 -07001788 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001789 * Return whether private browsing is enabled for the main window of
1790 * this tab.
1791 * @return True if private browsing is enabled.
1792 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001793 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001794 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001795 }
1796
1797 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001798 * Return the subwindow of this tab or null if there is no subwindow.
1799 * @return The subwindow of this tab or null.
1800 */
1801 WebView getSubWebView() {
1802 return mSubView;
1803 }
1804
Michael Kolb1514bb72010-11-22 09:11:48 -08001805 void setSubWebView(WebView subView) {
1806 mSubView = subView;
1807 }
1808
Michael Kolb8233fac2010-10-26 16:08:53 -07001809 View getSubViewContainer() {
1810 return mSubViewContainer;
1811 }
1812
Michael Kolb1514bb72010-11-22 09:11:48 -08001813 void setSubViewContainer(View subViewContainer) {
1814 mSubViewContainer = subViewContainer;
1815 }
1816
Grace Kloba22ac16e2009-10-07 18:00:23 -07001817 /**
1818 * @return The geolocation permissions prompt for this tab.
1819 */
1820 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001821 if (mGeolocationPermissionsPrompt == null) {
1822 ViewStub stub = (ViewStub) mContainer
1823 .findViewById(R.id.geolocation_permissions_prompt);
1824 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1825 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001826 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001827 return mGeolocationPermissionsPrompt;
1828 }
1829
1830 /**
1831 * @return The application id string
1832 */
1833 String getAppId() {
1834 return mAppId;
1835 }
1836
1837 /**
1838 * Set the application id string
1839 * @param id
1840 */
1841 void setAppId(String id) {
1842 mAppId = id;
1843 }
1844
Michael Kolbe28b3472011-08-04 16:54:31 -07001845 boolean closeOnBack() {
1846 return mCloseOnBack;
1847 }
1848
1849 void setCloseOnBack(boolean close) {
1850 mCloseOnBack = close;
1851 }
1852
Grace Kloba22ac16e2009-10-07 18:00:23 -07001853 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001854 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001855 }
1856
John Reck49a603c2011-03-03 09:33:05 -08001857 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001858 if (mCurrentState.mOriginalUrl == null) {
1859 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001860 }
John Reckdb22ec42011-06-29 11:31:24 -07001861 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001862 }
1863
Grace Kloba22ac16e2009-10-07 18:00:23 -07001864 /**
John Reck30c714c2010-12-16 17:30:34 -08001865 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001866 */
1867 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001868 if (mCurrentState.mTitle == null && mInPageLoad) {
Michael Kolb14612442011-06-24 13:06:29 -07001869 return mContext.getString(R.string.title_bar_loading);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001870 }
John Reck30c714c2010-12-16 17:30:34 -08001871 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001872 }
1873
1874 /**
John Reck30c714c2010-12-16 17:30:34 -08001875 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001876 */
1877 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001878 if (mCurrentState.mFavicon != null) {
1879 return mCurrentState.mFavicon;
1880 }
1881 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001882 }
1883
John Recke969cc52010-12-21 17:24:43 -08001884 public boolean isBookmarkedSite() {
1885 return mCurrentState.mIsBookmarkedSite;
1886 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001887
Grace Kloba22ac16e2009-10-07 18:00:23 -07001888 /**
1889 * Return the tab's error console. Creates the console if createIfNEcessary
1890 * is true and we haven't already created the console.
1891 * @param createIfNecessary Flag to indicate if the console should be
1892 * created if it has not been already.
1893 * @return The tab's error console, or null if one has not been created and
1894 * createIfNecessary is false.
1895 */
1896 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1897 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001898 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001899 mErrorConsole.setWebView(mMainView);
1900 }
1901 return mErrorConsole;
1902 }
1903
Steve Block08a6f0c2011-10-06 12:12:53 +01001904 /**
1905 * Sets the security state, clears the SSL certificate error and informs
1906 * the controller.
1907 */
Steve Block2466eff2011-10-03 15:33:09 +01001908 private void setSecurityState(SecurityState securityState) {
1909 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001910 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001911 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001912 }
1913
1914 /**
Steve Block2466eff2011-10-03 15:33:09 +01001915 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001916 */
Steve Block2466eff2011-10-03 15:33:09 +01001917 SecurityState getSecurityState() {
1918 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001919 }
1920
Steve Block08a6f0c2011-10-06 12:12:53 +01001921 /**
1922 * Gets the SSL certificate error, if any, for the page's main resource.
1923 * This is only non-null when the security state is
1924 * SECURITY_STATE_BAD_CERTIFICATE.
1925 */
1926 SslError getSslCertificateError() {
1927 return mCurrentState.mSslCertificateError;
1928 }
1929
John Reck30c714c2010-12-16 17:30:34 -08001930 int getLoadProgress() {
1931 if (mInPageLoad) {
1932 return mPageLoadProgress;
1933 }
1934 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001935 }
1936
1937 /**
1938 * @return TRUE if onPageStarted is called while onPageFinished is not
1939 * called yet.
1940 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001941 boolean inPageLoad() {
1942 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001943 }
1944
1945 // force mInLoad to be false. This should only be called before closing the
1946 // tab to ensure BrowserActivity's pauseWebViewTimers() is called correctly.
Michael Kolb8233fac2010-10-26 16:08:53 -07001947 void clearInPageLoad() {
1948 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001949 }
1950
Grace Kloba22ac16e2009-10-07 18:00:23 -07001951 /**
John Reck1cf4b792011-07-26 10:22:22 -07001952 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001953 */
John Reck1cf4b792011-07-26 10:22:22 -07001954 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001955 // If the WebView is null it means we ran low on memory and we already
1956 // stored the saved state in mSavedState.
1957 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001958 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001959 }
John Reck6c2e2f32011-08-22 13:41:23 -07001960
1961 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001962 return null;
John Reck24f18262011-06-17 14:47:20 -07001963 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001964
1965 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001966 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1967 if (savedList == null || savedList.getSize() == 0) {
1968 Log.w(LOGTAG, "Failed to save back/forward list for "
1969 + mCurrentState.mUrl);
1970 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001971
Michael Kolbc831b632011-05-11 09:30:34 -07001972 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001973 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1974 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001975 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001976 if (mAppId != null) {
1977 mSavedState.putString(APPID, mAppId);
1978 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001979 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001980 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001981 if (mParent != null) {
1982 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001983 }
John Reckb0a86db2011-05-24 14:05:58 -07001984 mSavedState.putBoolean(USERAGENT,
1985 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001986 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001987 }
1988
1989 /*
1990 * Restore the state of the tab.
1991 */
John Reck1cf4b792011-07-26 10:22:22 -07001992 private void restoreState(Bundle b) {
1993 mSavedState = b;
1994 if (mSavedState == null) {
1995 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001996 }
1997 // Restore the internal state even if the WebView fails to restore.
1998 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001999 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002000 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07002001 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reckb0a86db2011-05-24 14:05:58 -07002002 if (b.getBoolean(USERAGENT)
2003 != mSettings.hasDesktopUseragent(getWebView())) {
2004 mSettings.toggleDesktopUseragent(getWebView());
2005 }
John Reck1cf4b792011-07-26 10:22:22 -07002006 String url = b.getString(CURRURL);
2007 String title = b.getString(CURRTITLE);
2008 boolean incognito = b.getBoolean(INCOGNITO);
2009 mCurrentState = new PageState(mContext, incognito, url, null);
2010 mCurrentState.mTitle = title;
2011 synchronized (Tab.this) {
2012 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07002013 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002014 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002015 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002016 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04002017
Leon Scroggins1961ed22010-12-07 15:22:21 -05002018 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08002019 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05002020 }
2021
John Recke969cc52010-12-21 17:24:43 -08002022 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
2023 = new DataController.OnQueryUrlIsBookmark() {
2024 @Override
2025 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
2026 if (mCurrentState.mUrl.equals(url)) {
2027 mCurrentState.mIsBookmarkedSite = isBookmark;
2028 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
2029 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05002030 }
John Recke969cc52010-12-21 17:24:43 -08002031 };
Michael Kolb1acef692011-03-08 14:12:06 -08002032
Michael Kolbeb95db42011-03-03 10:38:40 -08002033 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07002034 synchronized (Tab.this) {
2035 return mCapture;
2036 }
Michael Kolbeb95db42011-03-03 10:38:40 -08002037 }
2038
John Reck541f55a2011-06-07 16:34:43 -07002039 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07002040 return false;
2041 }
2042
John Reckd8c74522011-06-14 08:45:00 -07002043 public ContentValues createSnapshotValues() {
2044 if (mMainView == null) return null;
John Reck9d2718e2011-10-05 17:10:17 -07002045 SnapshotByteArrayOutputStream bos = new SnapshotByteArrayOutputStream();
John Reck8cc92352011-07-06 17:41:52 -07002046 try {
2047 GZIPOutputStream stream = new GZIPOutputStream(bos);
2048 if (!mMainView.saveViewState(stream)) {
2049 return null;
2050 }
2051 stream.flush();
2052 stream.close();
2053 } catch (Exception e) {
2054 Log.w(LOGTAG, "Failed to save view state", e);
John Reck541f55a2011-06-07 16:34:43 -07002055 return null;
2056 }
John Reck8cc92352011-07-06 17:41:52 -07002057 byte[] data = bos.toByteArray();
John Reckd8c74522011-06-14 08:45:00 -07002058 ContentValues values = new ContentValues();
2059 values.put(Snapshots.TITLE, mCurrentState.mTitle);
2060 values.put(Snapshots.URL, mCurrentState.mUrl);
2061 values.put(Snapshots.VIEWSTATE, data);
2062 values.put(Snapshots.BACKGROUND, mMainView.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07002063 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2064 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
2065 Bitmap screenshot = Controller.createScreenshot(mMainView,
2066 Controller.getDesiredThumbnailWidth(mContext),
2067 Controller.getDesiredThumbnailHeight(mContext));
2068 values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
John Reckd8c74522011-06-14 08:45:00 -07002069 return values;
John Reck541f55a2011-06-07 16:34:43 -07002070 }
2071
John Reck8cc92352011-07-06 17:41:52 -07002072 public byte[] compressBitmap(Bitmap bitmap) {
2073 if (bitmap == null) {
2074 return null;
2075 }
2076 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2077 bitmap.compress(CompressFormat.PNG, 100, stream);
2078 return stream.toByteArray();
2079 }
2080
John Reck26b18322011-06-21 13:08:58 -07002081 public void loadUrl(String url, Map<String, String> headers) {
2082 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002083 mPageLoadProgress = INITIAL_PROGRESS;
2084 mInPageLoad = true;
Michael Kolb14612442011-06-24 13:06:29 -07002085 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002086 mWebViewController.onPageStarted(this, mMainView, null);
2087 mMainView.loadUrl(url, headers);
2088 }
2089 }
2090
Michael Kolb9ef259a2011-07-12 15:33:08 -07002091 protected void capture() {
2092 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002093 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2094 return;
2095 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002096 Canvas c = new Canvas(mCapture);
2097 final int left = mMainView.getScrollX();
2098 final int top = mMainView.getScrollY() + mMainView.getVisibleTitleHeight();
Michael Kolba3194d02011-09-07 11:23:51 -07002099 int state = c.save();
Michael Kolb9ef259a2011-07-12 15:33:08 -07002100 c.translate(-left, -top);
2101 float scale = mCaptureWidth / (float) mMainView.getWidth();
2102 c.scale(scale, scale, left, top);
John Reck8ee633f2011-08-09 16:00:35 -07002103 if (mMainView instanceof BrowserWebView) {
2104 ((BrowserWebView)mMainView).drawContent(c);
2105 } else {
2106 mMainView.draw(c);
2107 }
Michael Kolba3194d02011-09-07 11:23:51 -07002108 c.restoreToCount(state);
2109 // manually anti-alias the edges for the tilt
2110 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2111 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2112 mCapture.getHeight(), sAlphaPaint);
2113 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2114 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2115 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002116 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002117 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002118 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002119 TabControl tc = mWebViewController.getTabControl();
2120 if (tc != null) {
2121 OnThumbnailUpdatedListener updateListener
2122 = tc.getOnThumbnailUpdatedListener();
2123 if (updateListener != null) {
2124 updateListener.onThumbnailUpdated(this);
2125 }
2126 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002127 }
2128
2129 @Override
2130 public void onNewPicture(WebView view, Picture picture) {
2131 //update screenshot
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}