blob: a7598c2c6f1139f9601895eb97b6610ad38afa47 [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 Reck5b691842010-11-29 11:21:13 -0800613 if (!isPrivateBrowsingEnabled()) {
614 LogTag.logPageFinishedLoading(
615 url, SystemClock.uptimeMillis() - mLoadStartTime);
616 }
John Reck1cf4b792011-07-26 10:22:22 -0700617 syncCurrentState(view, url);
John Reck324d4402011-01-11 16:56:42 -0800618 mWebViewController.onPageFinished(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700619 }
620
621 // return true if want to hijack the url to let another app to handle it
622 @Override
623 public boolean shouldOverrideUrlLoading(WebView view, String url) {
Leon Scroggins IIIc1f5ae22010-06-29 17:11:29 -0400624 if (voiceSearchSourceIsGoogle()) {
625 // This method is called when the user clicks on a link.
626 // VoiceSearchMode is turned off when the user leaves the
627 // Google results page, so at this point the user must be on
628 // that page. If the user clicked a link on that page, assume
629 // that the voice search was effective, and broadcast an Intent
630 // so a receiver can take note of that fact.
631 Intent logIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT);
632 logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
633 LoggingEvents.VoiceSearch.RESULT_CLICKED);
Michael Kolb14612442011-06-24 13:06:29 -0700634 mContext.sendBroadcast(logIntent);
Leon Scroggins IIIc1f5ae22010-06-29 17:11:29 -0400635 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700636 if (mInForeground) {
Michael Kolb18eb3772010-12-10 14:29:51 -0800637 return mWebViewController.shouldOverrideUrlLoading(Tab.this,
638 view, url);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700639 } else {
640 return false;
641 }
642 }
643
644 /**
Steve Block2466eff2011-10-03 15:33:09 +0100645 * Updates the security state. This method is called when we discover
646 * another resource to be loaded for this page (for example,
647 * javascript). While we update the security state, we do not update
648 * the lock icon until we are done loading, as it is slightly more
649 * secure this way.
Grace Kloba22ac16e2009-10-07 18:00:23 -0700650 */
651 @Override
652 public void onLoadResource(WebView view, String url) {
653 if (url != null && url.length() > 0) {
654 // It is only if the page claims to be secure that we may have
Steve Block2466eff2011-10-03 15:33:09 +0100655 // to update the security state:
656 if (mCurrentState.mSecurityState == SecurityState.SECURITY_STATE_SECURE) {
657 // If NOT a 'safe' url, change the state to mixed content!
Grace Kloba22ac16e2009-10-07 18:00:23 -0700658 if (!(URLUtil.isHttpsUrl(url) || URLUtil.isDataUrl(url)
659 || URLUtil.isAboutUrl(url))) {
Steve Block2466eff2011-10-03 15:33:09 +0100660 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_MIXED;
Grace Kloba22ac16e2009-10-07 18:00:23 -0700661 }
662 }
663 }
664 }
665
666 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700667 * Show a dialog informing the user of the network error reported by
668 * WebCore if it is in the foreground.
669 */
670 @Override
671 public void onReceivedError(WebView view, int errorCode,
672 String description, String failingUrl) {
673 if (errorCode != WebViewClient.ERROR_HOST_LOOKUP &&
674 errorCode != WebViewClient.ERROR_CONNECT &&
675 errorCode != WebViewClient.ERROR_BAD_URL &&
676 errorCode != WebViewClient.ERROR_UNSUPPORTED_SCHEME &&
677 errorCode != WebViewClient.ERROR_FILE) {
678 queueError(errorCode, description);
Jeff Hamilton47654f42010-09-07 09:57:51 -0500679
Selim Gurun3da06b82011-10-10 13:58:12 -0700680 // Don't log URLs when in private browsing mode
681 if (!isPrivateBrowsingEnabled()) {
682 Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
Jeff Hamilton47654f42010-09-07 09:57:51 -0500683 + " " + description);
Selim Gurun3da06b82011-10-10 13:58:12 -0700684 }
Jeff Hamilton47654f42010-09-07 09:57:51 -0500685 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700686 }
687
688 /**
689 * Check with the user if it is ok to resend POST data as the page they
690 * are trying to navigate to is the result of a POST.
691 */
692 @Override
693 public void onFormResubmission(WebView view, final Message dontResend,
694 final Message resend) {
695 if (!mInForeground) {
696 dontResend.sendToTarget();
697 return;
698 }
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500699 if (mDontResend != null) {
700 Log.w(LOGTAG, "onFormResubmission should not be called again "
701 + "while dialog is still up");
702 dontResend.sendToTarget();
703 return;
704 }
705 mDontResend = dontResend;
706 mResend = resend;
Michael Kolb14612442011-06-24 13:06:29 -0700707 new AlertDialog.Builder(mContext).setTitle(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700708 R.string.browserFrameFormResubmitLabel).setMessage(
709 R.string.browserFrameFormResubmitMessage)
710 .setPositiveButton(R.string.ok,
711 new DialogInterface.OnClickListener() {
712 public void onClick(DialogInterface dialog,
713 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500714 if (mResend != null) {
715 mResend.sendToTarget();
716 mResend = null;
717 mDontResend = null;
718 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700719 }
720 }).setNegativeButton(R.string.cancel,
721 new DialogInterface.OnClickListener() {
722 public void onClick(DialogInterface dialog,
723 int which) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500724 if (mDontResend != null) {
725 mDontResend.sendToTarget();
726 mResend = null;
727 mDontResend = null;
728 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700729 }
730 }).setOnCancelListener(new OnCancelListener() {
731 public void onCancel(DialogInterface dialog) {
Leon Scroggins4a64a8a2010-03-02 17:57:40 -0500732 if (mDontResend != null) {
733 mDontResend.sendToTarget();
734 mResend = null;
735 mDontResend = null;
736 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700737 }
738 }).show();
739 }
740
741 /**
742 * Insert the url into the visited history database.
743 * @param url The url to be inserted.
744 * @param isReload True if this url is being reloaded.
745 * FIXME: Not sure what to do when reloading the page.
746 */
747 @Override
748 public void doUpdateVisitedHistory(WebView view, String url,
749 boolean isReload) {
John Reck324d4402011-01-11 16:56:42 -0800750 mWebViewController.doUpdateVisitedHistory(Tab.this, isReload);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700751 }
752
753 /**
754 * Displays SSL error(s) dialog to the user.
755 */
756 @Override
757 public void onReceivedSslError(final WebView view,
758 final SslErrorHandler handler, final SslError error) {
759 if (!mInForeground) {
760 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100761 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700762 return;
763 }
John Reck35e9dd62011-04-25 09:01:54 -0700764 if (mSettings.showSecurityWarnings()) {
John Reckcb28b2c2011-08-26 17:39:44 -0700765 new AlertDialog.Builder(mContext)
766 .setTitle(R.string.security_warning)
767 .setMessage(R.string.ssl_warnings_header)
768 .setIcon(android.R.drawable.ic_dialog_alert)
769 .setPositiveButton(R.string.ssl_continue,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700770 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700771 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700772 public void onClick(DialogInterface dialog,
773 int whichButton) {
774 handler.proceed();
Steve Block4895b012011-10-03 16:26:46 +0100775 handleProceededAfterSslError(error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700776 }
John Reckcb28b2c2011-08-26 17:39:44 -0700777 })
778 .setNeutralButton(R.string.view_certificate,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700779 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700780 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700781 public void onClick(DialogInterface dialog,
782 int whichButton) {
John Reckcb28b2c2011-08-26 17:39:44 -0700783 mWebViewController.showSslCertificateOnError(
784 view, handler, error);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700785 }
John Reckcb28b2c2011-08-26 17:39:44 -0700786 })
787 .setNegativeButton(R.string.ssl_go_back,
Grace Kloba22ac16e2009-10-07 18:00:23 -0700788 new DialogInterface.OnClickListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700789 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700790 public void onClick(DialogInterface dialog,
791 int whichButton) {
John Reck30c714c2010-12-16 17:30:34 -0800792 dialog.cancel();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700793 }
John Reckcb28b2c2011-08-26 17:39:44 -0700794 })
795 .setOnCancelListener(
Grace Kloba22ac16e2009-10-07 18:00:23 -0700796 new DialogInterface.OnCancelListener() {
John Reckcb28b2c2011-08-26 17:39:44 -0700797 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700798 public void onCancel(DialogInterface dialog) {
799 handler.cancel();
Steve Block2466eff2011-10-03 15:33:09 +0100800 setSecurityState(SecurityState.SECURITY_STATE_NOT_SECURE);
John Reck30c714c2010-12-16 17:30:34 -0800801 mWebViewController.onUserCanceledSsl(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700802 }
John Reckcb28b2c2011-08-26 17:39:44 -0700803 })
804 .show();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700805 } else {
806 handler.proceed();
807 }
808 }
809
810 /**
Steve Block4895b012011-10-03 16:26:46 +0100811 * Called when an SSL error occurred while loading a resource, but the
812 * WebView but chose to proceed anyway based on a decision retained
813 * from a previous response to onReceivedSslError(). We update our
814 * security state to reflect this.
815 */
816 @Override
817 public void onProceededAfterSslError(WebView view, SslError error) {
818 handleProceededAfterSslError(error);
819 }
820
821 /**
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700822 * Displays client certificate request to the user.
823 */
824 @Override
825 public void onReceivedClientCertRequest(final WebView view,
826 final ClientCertRequestHandler handler, final String host_and_port) {
827 if (!mInForeground) {
828 handler.ignore();
829 return;
830 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700831 int colon = host_and_port.lastIndexOf(':');
832 String host;
833 int port;
834 if (colon == -1) {
835 host = host_and_port;
836 port = -1;
837 } else {
838 String portString = host_and_port.substring(colon + 1);
839 try {
840 port = Integer.parseInt(portString);
841 host = host_and_port.substring(0, colon);
842 } catch (NumberFormatException e) {
843 host = host_and_port;
844 port = -1;
845 }
846 }
Michael Kolb14612442011-06-24 13:06:29 -0700847 KeyChain.choosePrivateKeyAlias(
848 mWebViewController.getActivity(), new KeyChainAliasCallback() {
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700849 @Override public void alias(String alias) {
850 if (alias == null) {
851 handler.cancel();
852 return;
853 }
Michael Kolb14612442011-06-24 13:06:29 -0700854 new KeyChainLookup(mContext, handler, alias).execute();
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700855 }
Brian Carlstrom6d85fab2011-06-24 14:26:46 -0700856 }, null, null, host, port, null);
Brian Carlstrom8862c1d2011-06-02 01:05:55 -0700857 }
858
859 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -0700860 * Handles an HTTP authentication request.
861 *
862 * @param handler The authentication handler
863 * @param host The host
864 * @param realm The realm
865 */
866 @Override
867 public void onReceivedHttpAuthRequest(WebView view,
868 final HttpAuthHandler handler, final String host,
869 final String realm) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700870 mWebViewController.onReceivedHttpAuthRequest(Tab.this, view, handler, host, realm);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700871 }
872
873 @Override
John Reck438bf462011-01-12 18:11:46 -0800874 public WebResourceResponse shouldInterceptRequest(WebView view,
875 String url) {
876 WebResourceResponse res = HomeProvider.shouldInterceptRequest(
Michael Kolb14612442011-06-24 13:06:29 -0700877 mContext, url);
John Reck438bf462011-01-12 18:11:46 -0800878 return res;
879 }
880
881 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -0700882 public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
883 if (!mInForeground) {
884 return false;
885 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700886 return mWebViewController.shouldOverrideKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700887 }
888
889 @Override
890 public void onUnhandledKeyEvent(WebView view, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700891 if (!mInForeground) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700892 return;
893 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700894 mWebViewController.onUnhandledKeyEvent(event);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700895 }
Patrick Scott92066772011-03-10 08:46:27 -0500896
897 @Override
898 public void onReceivedLoginRequest(WebView view, String realm,
899 String account, String args) {
Michael Kolb14612442011-06-24 13:06:29 -0700900 new DeviceAccountLogin(mWebViewController.getActivity(), view, Tab.this, mWebViewController)
Patrick Scott92066772011-03-10 08:46:27 -0500901 .handleLogin(realm, account, args);
902 }
903
Grace Kloba22ac16e2009-10-07 18:00:23 -0700904 };
905
John Reck1cf4b792011-07-26 10:22:22 -0700906 private void syncCurrentState(WebView view, String url) {
907 // Sync state (in case of stop/timeout)
908 mCurrentState.mUrl = view.getUrl();
909 if (mCurrentState.mUrl == null) {
John Reck8bcafc12011-08-29 16:43:02 -0700910 mCurrentState.mUrl = "";
John Reck1cf4b792011-07-26 10:22:22 -0700911 }
912 mCurrentState.mOriginalUrl = view.getOriginalUrl();
913 mCurrentState.mTitle = view.getTitle();
914 mCurrentState.mFavicon = view.getFavicon();
915 if (!URLUtil.isHttpsUrl(mCurrentState.mUrl)) {
916 // In case we stop when loading an HTTPS page from an HTTP page
917 // but before a provisional load occurred
Steve Block2466eff2011-10-03 15:33:09 +0100918 mCurrentState.mSecurityState = SecurityState.SECURITY_STATE_NOT_SECURE;
Steve Block08a6f0c2011-10-06 12:12:53 +0100919 mCurrentState.mSslCertificateError = null;
John Reck1cf4b792011-07-26 10:22:22 -0700920 }
John Reck502a3532011-08-16 14:21:46 -0700921 mCurrentState.mIncognito = view.isPrivateBrowsingEnabled();
John Reck1cf4b792011-07-26 10:22:22 -0700922 }
923
Patrick Scott92066772011-03-10 08:46:27 -0500924 // Called by DeviceAccountLogin when the Tab needs to have the auto-login UI
925 // displayed.
926 void setDeviceAccountLogin(DeviceAccountLogin login) {
927 mDeviceAccountLogin = login;
928 }
929
930 // Returns non-null if the title bar should display the auto-login UI.
931 DeviceAccountLogin getDeviceAccountLogin() {
932 return mDeviceAccountLogin;
933 }
934
Grace Kloba22ac16e2009-10-07 18:00:23 -0700935 // -------------------------------------------------------------------------
936 // WebChromeClient implementation for the main WebView
937 // -------------------------------------------------------------------------
938
939 private final WebChromeClient mWebChromeClient = new WebChromeClient() {
940 // Helper method to create a new tab or sub window.
941 private void createWindow(final boolean dialog, final Message msg) {
942 WebView.WebViewTransport transport =
943 (WebView.WebViewTransport) msg.obj;
944 if (dialog) {
945 createSubWindow();
Michael Kolb8233fac2010-10-26 16:08:53 -0700946 mWebViewController.attachSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700947 transport.setWebView(mSubView);
948 } else {
Michael Kolb7bcafde2011-05-09 13:55:59 -0700949 final Tab newTab = mWebViewController.openTab(null,
John Reck5949c662011-05-27 09:52:29 -0700950 Tab.this, true, true);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700951 transport.setWebView(newTab.getWebView());
952 }
953 msg.sendToTarget();
954 }
955
956 @Override
957 public boolean onCreateWindow(WebView view, final boolean dialog,
958 final boolean userGesture, final Message resultMsg) {
959 // only allow new window or sub window for the foreground case
960 if (!mInForeground) {
961 return false;
962 }
963 // Short-circuit if we can't create any more tabs or sub windows.
964 if (dialog && mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -0700965 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700966 .setTitle(R.string.too_many_subwindows_dialog_title)
967 .setIcon(android.R.drawable.ic_dialog_alert)
968 .setMessage(R.string.too_many_subwindows_dialog_message)
969 .setPositiveButton(R.string.ok, null)
970 .show();
971 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700972 } else if (!mWebViewController.getTabControl().canCreateNewTab()) {
Michael Kolb14612442011-06-24 13:06:29 -0700973 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -0700974 .setTitle(R.string.too_many_windows_dialog_title)
975 .setIcon(android.R.drawable.ic_dialog_alert)
976 .setMessage(R.string.too_many_windows_dialog_message)
977 .setPositiveButton(R.string.ok, null)
978 .show();
979 return false;
980 }
981
982 // Short-circuit if this was a user gesture.
983 if (userGesture) {
984 createWindow(dialog, resultMsg);
985 return true;
986 }
987
988 // Allow the popup and create the appropriate window.
989 final AlertDialog.OnClickListener allowListener =
990 new AlertDialog.OnClickListener() {
991 public void onClick(DialogInterface d,
992 int which) {
993 createWindow(dialog, resultMsg);
994 }
995 };
996
997 // Block the popup by returning a null WebView.
998 final AlertDialog.OnClickListener blockListener =
999 new AlertDialog.OnClickListener() {
1000 public void onClick(DialogInterface d, int which) {
1001 resultMsg.sendToTarget();
1002 }
1003 };
1004
1005 // Build a confirmation dialog to display to the user.
1006 final AlertDialog d =
Michael Kolb14612442011-06-24 13:06:29 -07001007 new AlertDialog.Builder(mContext)
Grace Kloba22ac16e2009-10-07 18:00:23 -07001008 .setIcon(android.R.drawable.ic_dialog_alert)
1009 .setMessage(R.string.popup_window_attempt)
1010 .setPositiveButton(R.string.allow, allowListener)
1011 .setNegativeButton(R.string.block, blockListener)
1012 .setCancelable(false)
1013 .create();
1014
1015 // Show the confirmation dialog.
1016 d.show();
1017 return true;
1018 }
1019
1020 @Override
Patrick Scotteb5061b2009-11-18 15:00:30 -05001021 public void onRequestFocus(WebView view) {
1022 if (!mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -07001023 mWebViewController.switchToTab(Tab.this);
Patrick Scotteb5061b2009-11-18 15:00:30 -05001024 }
1025 }
1026
1027 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001028 public void onCloseWindow(WebView window) {
Michael Kolbc831b632011-05-11 09:30:34 -07001029 if (mParent != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001030 // JavaScript can only close popup window.
1031 if (mInForeground) {
Michael Kolbc831b632011-05-11 09:30:34 -07001032 mWebViewController.switchToTab(mParent);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001033 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001034 mWebViewController.closeTab(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001035 }
1036 }
1037
1038 @Override
1039 public void onProgressChanged(WebView view, int newProgress) {
John Reck30c714c2010-12-16 17:30:34 -08001040 mPageLoadProgress = newProgress;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001041 if (newProgress == 100) {
1042 mInPageLoad = false;
1043 }
John Reck30c714c2010-12-16 17:30:34 -08001044 mWebViewController.onProgressChanged(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001045 }
1046
1047 @Override
Leon Scroggins21d9b902010-03-11 09:33:11 -05001048 public void onReceivedTitle(WebView view, final String title) {
John Reck30c714c2010-12-16 17:30:34 -08001049 mCurrentState.mTitle = title;
Michael Kolb8233fac2010-10-26 16:08:53 -07001050 mWebViewController.onReceivedTitle(Tab.this, title);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001051 }
1052
1053 @Override
1054 public void onReceivedIcon(WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -08001055 mCurrentState.mFavicon = icon;
Michael Kolb8233fac2010-10-26 16:08:53 -07001056 mWebViewController.onFavicon(Tab.this, view, icon);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001057 }
1058
1059 @Override
1060 public void onReceivedTouchIconUrl(WebView view, String url,
1061 boolean precomposed) {
Michael Kolb14612442011-06-24 13:06:29 -07001062 final ContentResolver cr = mContext.getContentResolver();
Leon Scrogginsc8393d92010-04-23 14:58:16 -04001063 // Let precomposed icons take precedence over non-composed
1064 // icons.
1065 if (precomposed && mTouchIconLoader != null) {
1066 mTouchIconLoader.cancel(false);
1067 mTouchIconLoader = null;
1068 }
1069 // Have only one async task at a time.
1070 if (mTouchIconLoader == null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001071 mTouchIconLoader = new DownloadTouchIcon(Tab.this,
Michael Kolb14612442011-06-24 13:06:29 -07001072 mContext, cr, view);
Leon Scrogginsc8393d92010-04-23 14:58:16 -04001073 mTouchIconLoader.execute(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001074 }
1075 }
1076
1077 @Override
1078 public void onShowCustomView(View view,
1079 WebChromeClient.CustomViewCallback callback) {
Michael Kolb14612442011-06-24 13:06:29 -07001080 Activity activity = mWebViewController.getActivity();
1081 if (activity != null) {
1082 onShowCustomView(view, activity.getRequestedOrientation(), callback);
1083 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001084 }
1085
1086 @Override
1087 public void onShowCustomView(View view, int requestedOrientation,
1088 WebChromeClient.CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001089 if (mInForeground) mWebViewController.showCustomView(Tab.this, view,
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001090 requestedOrientation, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001091 }
1092
1093 @Override
1094 public void onHideCustomView() {
Michael Kolb8233fac2010-10-26 16:08:53 -07001095 if (mInForeground) mWebViewController.hideCustomView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001096 }
1097
1098 /**
1099 * The origin has exceeded its database quota.
1100 * @param url the URL that exceeded the quota
1101 * @param databaseIdentifier the identifier of the database on which the
1102 * transaction that caused the quota overflow was run
1103 * @param currentQuota the current quota for the origin.
1104 * @param estimatedSize the estimated size of the database.
1105 * @param totalUsedQuota is the sum of all origins' quota.
1106 * @param quotaUpdater The callback to run when a decision to allow or
1107 * deny quota has been made. Don't forget to call this!
1108 */
1109 @Override
1110 public void onExceededDatabaseQuota(String url,
1111 String databaseIdentifier, long currentQuota, long estimatedSize,
1112 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001113 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001114 .onExceededDatabaseQuota(url, databaseIdentifier,
1115 currentQuota, estimatedSize, totalUsedQuota,
1116 quotaUpdater);
1117 }
1118
1119 /**
1120 * The Application Cache has exceeded its max size.
1121 * @param spaceNeeded is the amount of disk space that would be needed
1122 * in order for the last appcache operation to succeed.
1123 * @param totalUsedQuota is the sum of all origins' quota.
1124 * @param quotaUpdater A callback to inform the WebCore thread that a
1125 * new app cache size is available. This callback must always
1126 * be executed at some point to ensure that the sleeping
1127 * WebCore thread is woken up.
1128 */
1129 @Override
1130 public void onReachedMaxAppCacheSize(long spaceNeeded,
1131 long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
John Reck35e9dd62011-04-25 09:01:54 -07001132 mSettings.getWebStorageSizeManager()
Grace Kloba22ac16e2009-10-07 18:00:23 -07001133 .onReachedMaxAppCacheSize(spaceNeeded, totalUsedQuota,
1134 quotaUpdater);
1135 }
1136
1137 /**
1138 * Instructs the browser to show a prompt to ask the user to set the
1139 * Geolocation permission state for the specified origin.
1140 * @param origin The origin for which Geolocation permissions are
1141 * requested.
1142 * @param callback The callback to call once the user has set the
1143 * Geolocation permission state.
1144 */
1145 @Override
1146 public void onGeolocationPermissionsShowPrompt(String origin,
1147 GeolocationPermissions.Callback callback) {
1148 if (mInForeground) {
Grace Kloba50c241e2010-04-20 11:07:50 -07001149 getGeolocationPermissionsPrompt().show(origin, callback);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001150 }
1151 }
1152
1153 /**
1154 * Instructs the browser to hide the Geolocation permissions prompt.
1155 */
1156 @Override
1157 public void onGeolocationPermissionsHidePrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001158 if (mInForeground && mGeolocationPermissionsPrompt != null) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001159 mGeolocationPermissionsPrompt.hide();
1160 }
1161 }
1162
Ben Murdoch65acc352009-11-19 18:16:04 +00001163 /* Adds a JavaScript error message to the system log and if the JS
1164 * console is enabled in the about:debug options, to that console
1165 * also.
Ben Murdochc42addf2010-01-28 15:19:59 +00001166 * @param consoleMessage the message object.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001167 */
1168 @Override
Ben Murdochc42addf2010-01-28 15:19:59 +00001169 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001170 if (mInForeground) {
1171 // call getErrorConsole(true) so it will create one if needed
1172 ErrorConsoleView errorConsole = getErrorConsole(true);
Ben Murdochc42addf2010-01-28 15:19:59 +00001173 errorConsole.addErrorMessage(consoleMessage);
Michael Kolb8233fac2010-10-26 16:08:53 -07001174 if (mWebViewController.shouldShowErrorConsole()
1175 && errorConsole.getShowState() !=
1176 ErrorConsoleView.SHOW_MAXIMIZED) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001177 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1178 }
1179 }
Ben Murdochc42addf2010-01-28 15:19:59 +00001180
Jeff Hamilton47654f42010-09-07 09:57:51 -05001181 // Don't log console messages in private browsing mode
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001182 if (isPrivateBrowsingEnabled()) return true;
Jeff Hamilton47654f42010-09-07 09:57:51 -05001183
Ben Murdochc42addf2010-01-28 15:19:59 +00001184 String message = "Console: " + consoleMessage.message() + " "
1185 + consoleMessage.sourceId() + ":"
1186 + consoleMessage.lineNumber();
1187
1188 switch (consoleMessage.messageLevel()) {
1189 case TIP:
1190 Log.v(CONSOLE_LOGTAG, message);
1191 break;
1192 case LOG:
1193 Log.i(CONSOLE_LOGTAG, message);
1194 break;
1195 case WARNING:
1196 Log.w(CONSOLE_LOGTAG, message);
1197 break;
1198 case ERROR:
1199 Log.e(CONSOLE_LOGTAG, message);
1200 break;
1201 case DEBUG:
1202 Log.d(CONSOLE_LOGTAG, message);
1203 break;
1204 }
1205
1206 return true;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001207 }
1208
1209 /**
1210 * Ask the browser for an icon to represent a <video> element.
1211 * This icon will be used if the Web page did not specify a poster attribute.
1212 * @return Bitmap The icon or null if no such icon is available.
1213 */
1214 @Override
1215 public Bitmap getDefaultVideoPoster() {
1216 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001217 return mWebViewController.getDefaultVideoPoster();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001218 }
1219 return null;
1220 }
1221
1222 /**
1223 * Ask the host application for a custom progress view to show while
1224 * a <video> is loading.
1225 * @return View The progress view.
1226 */
1227 @Override
1228 public View getVideoLoadingProgressView() {
1229 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001230 return mWebViewController.getVideoLoadingProgressView();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001231 }
1232 return null;
1233 }
1234
1235 @Override
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01001236 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001237 if (mInForeground) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001238 mWebViewController.openFileChooser(uploadMsg, acceptType);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001239 } else {
1240 uploadMsg.onReceiveValue(null);
1241 }
1242 }
1243
1244 /**
1245 * Deliver a list of already-visited URLs
1246 */
1247 @Override
1248 public void getVisitedHistory(final ValueCallback<String[]> callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001249 mWebViewController.getVisitedHistory(callback);
1250 }
Ben Murdoch8029a772010-11-16 11:58:21 +00001251
1252 @Override
1253 public void setupAutoFill(Message message) {
1254 // Prompt the user to set up their profile.
1255 final Message msg = message;
Michael Kolb14612442011-06-24 13:06:29 -07001256 AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
1257 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
Ben Murdoch1d676b62011-01-17 12:54:24 +00001258 Context.LAYOUT_INFLATER_SERVICE);
1259 final View layout = inflater.inflate(R.layout.setup_autofill_dialog, null);
1260
1261 builder.setView(layout)
1262 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1263 @Override
1264 public void onClick(DialogInterface dialog, int id) {
1265 CheckBox disableAutoFill = (CheckBox) layout.findViewById(
1266 R.id.setup_autofill_dialog_disable_autofill);
1267
1268 if (disableAutoFill.isChecked()) {
1269 // Disable autofill and show a toast with how to turn it on again.
John Reck35e9dd62011-04-25 09:01:54 -07001270 mSettings.setAutofillEnabled(false);
Michael Kolb14612442011-06-24 13:06:29 -07001271 Toast.makeText(mContext,
Ben Murdoch1d676b62011-01-17 12:54:24 +00001272 R.string.autofill_setup_dialog_negative_toast,
1273 Toast.LENGTH_LONG).show();
1274 } else {
1275 // Take user to the AutoFill profile editor. When they return,
1276 // we will send the message that we pass here which will trigger
1277 // the form to get filled out with their new profile.
1278 mWebViewController.setupAutoFill(msg);
1279 }
1280 }
1281 })
1282 .setNegativeButton(R.string.cancel, null)
1283 .show();
Ben Murdoch8029a772010-11-16 11:58:21 +00001284 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001285 };
1286
1287 // -------------------------------------------------------------------------
1288 // WebViewClient implementation for the sub window
1289 // -------------------------------------------------------------------------
1290
1291 // Subclass of WebViewClient used in subwindows to notify the main
1292 // WebViewClient of certain WebView activities.
1293 private static class SubWindowClient extends WebViewClient {
1294 // The main WebViewClient.
1295 private final WebViewClient mClient;
Michael Kolb8233fac2010-10-26 16:08:53 -07001296 private final WebViewController mController;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001297
Michael Kolb8233fac2010-10-26 16:08:53 -07001298 SubWindowClient(WebViewClient client, WebViewController controller) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001299 mClient = client;
Michael Kolb8233fac2010-10-26 16:08:53 -07001300 mController = controller;
Leon Scroggins III211ba542010-04-19 13:21:13 -04001301 }
1302 @Override
1303 public void onPageStarted(WebView view, String url, Bitmap favicon) {
1304 // Unlike the others, do not call mClient's version, which would
1305 // change the progress bar. However, we do want to remove the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001306 // find or select dialog.
Michael Kolb8233fac2010-10-26 16:08:53 -07001307 mController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001308 }
1309 @Override
1310 public void doUpdateVisitedHistory(WebView view, String url,
1311 boolean isReload) {
1312 mClient.doUpdateVisitedHistory(view, url, isReload);
1313 }
1314 @Override
1315 public boolean shouldOverrideUrlLoading(WebView view, String url) {
1316 return mClient.shouldOverrideUrlLoading(view, url);
1317 }
1318 @Override
1319 public void onReceivedSslError(WebView view, SslErrorHandler handler,
1320 SslError error) {
1321 mClient.onReceivedSslError(view, handler, error);
1322 }
1323 @Override
Brian Carlstrom8862c1d2011-06-02 01:05:55 -07001324 public void onReceivedClientCertRequest(WebView view,
1325 ClientCertRequestHandler handler, String host_and_port) {
1326 mClient.onReceivedClientCertRequest(view, handler, host_and_port);
1327 }
1328 @Override
Grace Kloba22ac16e2009-10-07 18:00:23 -07001329 public void onReceivedHttpAuthRequest(WebView view,
1330 HttpAuthHandler handler, String host, String realm) {
1331 mClient.onReceivedHttpAuthRequest(view, handler, host, realm);
1332 }
1333 @Override
1334 public void onFormResubmission(WebView view, Message dontResend,
1335 Message resend) {
1336 mClient.onFormResubmission(view, dontResend, resend);
1337 }
1338 @Override
1339 public void onReceivedError(WebView view, int errorCode,
1340 String description, String failingUrl) {
1341 mClient.onReceivedError(view, errorCode, description, failingUrl);
1342 }
1343 @Override
1344 public boolean shouldOverrideKeyEvent(WebView view,
1345 android.view.KeyEvent event) {
1346 return mClient.shouldOverrideKeyEvent(view, event);
1347 }
1348 @Override
1349 public void onUnhandledKeyEvent(WebView view,
1350 android.view.KeyEvent event) {
1351 mClient.onUnhandledKeyEvent(view, event);
1352 }
1353 }
1354
1355 // -------------------------------------------------------------------------
1356 // WebChromeClient implementation for the sub window
1357 // -------------------------------------------------------------------------
1358
1359 private class SubWindowChromeClient extends WebChromeClient {
1360 // The main WebChromeClient.
1361 private final WebChromeClient mClient;
1362
1363 SubWindowChromeClient(WebChromeClient client) {
1364 mClient = client;
1365 }
1366 @Override
1367 public void onProgressChanged(WebView view, int newProgress) {
1368 mClient.onProgressChanged(view, newProgress);
1369 }
1370 @Override
1371 public boolean onCreateWindow(WebView view, boolean dialog,
1372 boolean userGesture, android.os.Message resultMsg) {
1373 return mClient.onCreateWindow(view, dialog, userGesture, resultMsg);
1374 }
1375 @Override
1376 public void onCloseWindow(WebView window) {
1377 if (window != mSubView) {
1378 Log.e(LOGTAG, "Can't close the window");
1379 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001380 mWebViewController.dismissSubWindow(Tab.this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001381 }
1382 }
1383
1384 // -------------------------------------------------------------------------
1385
1386 // Construct a new tab
Michael Kolb7bcafde2011-05-09 13:55:59 -07001387 Tab(WebViewController wvcontroller, WebView w) {
John Reck1cf4b792011-07-26 10:22:22 -07001388 this(wvcontroller, w, null);
1389 }
1390
1391 Tab(WebViewController wvcontroller, Bundle state) {
1392 this(wvcontroller, null, state);
1393 }
1394
1395 Tab(WebViewController wvcontroller, WebView w, Bundle state) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001396 mWebViewController = wvcontroller;
Michael Kolb14612442011-06-24 13:06:29 -07001397 mContext = mWebViewController.getContext();
John Reck35e9dd62011-04-25 09:01:54 -07001398 mSettings = BrowserSettings.getInstance();
Michael Kolb14612442011-06-24 13:06:29 -07001399 mDataController = DataController.getInstance(mContext);
1400 mCurrentState = new PageState(mContext, w != null
John Reck847b5322011-04-14 17:02:18 -07001401 ? w.isPrivateBrowsingEnabled() : false);
Michael Kolb8233fac2010-10-26 16:08:53 -07001402 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001403 mInForeground = false;
1404
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001405 mDownloadListener = new DownloadListener() {
1406 public void onDownloadStart(String url, String userAgent,
1407 String contentDisposition, String mimetype,
1408 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001409 mWebViewController.onDownloadStart(Tab.this, url, userAgent, contentDisposition,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001410 mimetype, contentLength);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001411 }
1412 };
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001413 mWebBackForwardListClient = new WebBackForwardListClient() {
1414 @Override
1415 public void onNewHistoryItem(WebHistoryItem item) {
1416 if (isInVoiceSearchMode()) {
1417 item.setCustomData(mVoiceSearchData.mVoiceSearchIntent);
1418 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001419 if (mClearHistoryUrlPattern != null) {
1420 boolean match =
1421 mClearHistoryUrlPattern.matcher(item.getOriginalUrl()).matches();
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001422 if (LOGD_ENABLED) {
Mathew Inwooda829d552011-09-02 14:16:25 +01001423 Log.d(LOGTAG, "onNewHistoryItem: match=" + match + "\n\t"
1424 + item.getUrl() + "\n\t"
1425 + mClearHistoryUrlPattern);
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001426 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001427 if (match) {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001428 if (mMainView != null) {
1429 mMainView.clearHistory();
1430 }
1431 }
Mathew Inwooda829d552011-09-02 14:16:25 +01001432 mClearHistoryUrlPattern = null;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001433 }
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001434 }
1435 @Override
1436 public void onIndexChanged(WebHistoryItem item, int index) {
1437 Object data = item.getCustomData();
1438 if (data != null && data instanceof Intent) {
1439 activateVoiceSearchMode((Intent) data);
1440 }
1441 }
1442 };
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001443
John Reck1cf4b792011-07-26 10:22:22 -07001444 mCaptureWidth = mContext.getResources().getDimensionPixelSize(
1445 R.dimen.tab_thumbnail_width);
1446 mCaptureHeight = mContext.getResources().getDimensionPixelSize(
1447 R.dimen.tab_thumbnail_height);
1448 updateShouldCaptureThumbnails();
1449 restoreState(state);
John Reck52be4782011-08-26 15:37:29 -07001450 if (getId() == -1) {
1451 mId = TabControl.getNextId();
1452 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001453 setWebView(w);
Michael Kolb9ef259a2011-07-12 15:33:08 -07001454 mHandler = new Handler() {
Mathew Inwood1dd8e822011-08-03 14:34:29 +01001455 @Override
Michael Kolb9ef259a2011-07-12 15:33:08 -07001456 public void handleMessage(Message m) {
John Reck1cf4b792011-07-26 10:22:22 -07001457 switch (m.what) {
1458 case MSG_CAPTURE:
1459 capture();
1460 break;
1461 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001462 }
1463 };
John Reck1cf4b792011-07-26 10:22:22 -07001464 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07001465
Mathew Inwoode09305e2011-09-02 12:03:26 +01001466 /**
1467 * This is used to get a new ID when the tab has been preloaded, before it is displayed and
1468 * added to TabControl. Preloaded tabs can be created before restoreInstanceState, leading
1469 * to overlapping IDs between the preloaded and restored tabs.
1470 */
1471 public void refreshIdAfterPreload() {
1472 mId = TabControl.getNextId();
1473 }
1474
John Reck1cf4b792011-07-26 10:22:22 -07001475 public void updateShouldCaptureThumbnails() {
1476 if (mWebViewController.shouldCaptureThumbnails()) {
1477 synchronized (Tab.this) {
1478 if (mCapture == null) {
1479 mCapture = Bitmap.createBitmap(mCaptureWidth, mCaptureHeight,
1480 Bitmap.Config.RGB_565);
Michael Kolbc3af0672011-08-09 10:24:41 -07001481 mCapture.eraseColor(Color.WHITE);
John Reck1cf4b792011-07-26 10:22:22 -07001482 if (mInForeground) {
1483 postCapture();
1484 }
1485 }
1486 }
1487 } else {
1488 synchronized (Tab.this) {
1489 mCapture = null;
1490 deleteThumbnail();
1491 }
1492 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001493 }
1494
Michael Kolb14612442011-06-24 13:06:29 -07001495 public void setController(WebViewController ctl) {
1496 mWebViewController = ctl;
John Reck1cf4b792011-07-26 10:22:22 -07001497 updateShouldCaptureThumbnails();
Michael Kolb14612442011-06-24 13:06:29 -07001498 }
1499
Michael Kolbc831b632011-05-11 09:30:34 -07001500 public long getId() {
1501 return mId;
1502 }
1503
Grace Kloba22ac16e2009-10-07 18:00:23 -07001504 /**
1505 * Sets the WebView for this tab, correctly removing the old WebView from
1506 * the container view.
1507 */
1508 void setWebView(WebView w) {
1509 if (mMainView == w) {
1510 return;
1511 }
Michael Kolba713ec82010-11-29 17:27:06 -08001512
Grace Kloba22ac16e2009-10-07 18:00:23 -07001513 // If the WebView is changing, the page will be reloaded, so any ongoing
1514 // Geolocation permission requests are void.
Grace Kloba50c241e2010-04-20 11:07:50 -07001515 if (mGeolocationPermissionsPrompt != null) {
1516 mGeolocationPermissionsPrompt.hide();
1517 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001518
Michael Kolba713ec82010-11-29 17:27:06 -08001519 mWebViewController.onSetWebView(this, w);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001520
John Reck1cf4b792011-07-26 10:22:22 -07001521 if (mMainView != null) {
John Reck8ee633f2011-08-09 16:00:35 -07001522 mMainView.setPictureListener(null);
John Reck1cf4b792011-07-26 10:22:22 -07001523 if (w != null) {
1524 syncCurrentState(w, null);
1525 } else {
1526 mCurrentState = new PageState(mContext, false);
1527 }
1528 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001529 // set the new one
1530 mMainView = w;
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001531 // attach the WebViewClient, WebChromeClient and DownloadListener
Grace Kloba22ac16e2009-10-07 18:00:23 -07001532 if (mMainView != null) {
1533 mMainView.setWebViewClient(mWebViewClient);
1534 mMainView.setWebChromeClient(mWebChromeClient);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001535 // Attach DownloadManager so that downloads can start in an active
1536 // or a non-active window. This can happen when going to a site that
1537 // does a redirect after a period of time. The user could have
1538 // switched to another tab while waiting for the download to start.
1539 mMainView.setDownloadListener(mDownloadListener);
Leon Scroggins0c75a8e2010-03-03 16:40:58 -05001540 mMainView.setWebBackForwardListClient(mWebBackForwardListClient);
John Reck8ee633f2011-08-09 16:00:35 -07001541 TabControl tc = mWebViewController.getTabControl();
1542 if (tc != null && tc.getOnThumbnailUpdatedListener() != null) {
1543 mMainView.setPictureListener(this);
1544 }
John Reck1cf4b792011-07-26 10:22:22 -07001545 if (mSavedState != null) {
John Reck6c2e2f32011-08-22 13:41:23 -07001546 WebBackForwardList restoredState
1547 = mMainView.restoreState(mSavedState);
1548 if (restoredState == null || restoredState.getSize() == 0) {
1549 Log.w(LOGTAG, "Failed to restore WebView state!");
1550 loadUrl(mCurrentState.mOriginalUrl, null);
1551 }
John Reck1cf4b792011-07-26 10:22:22 -07001552 mSavedState = null;
1553 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001554 }
1555 }
1556
1557 /**
1558 * Destroy the tab's main WebView and subWindow if any
1559 */
1560 void destroy() {
1561 if (mMainView != null) {
1562 dismissSubWindow();
John Reckef654f12011-07-12 16:42:08 -07001563 // Make sure the embedded title bar isn't still attached
1564 mMainView.setEmbeddedTitleBar(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001565 // save the WebView to call destroy() after detach it from the tab
1566 WebView webView = mMainView;
1567 setWebView(null);
1568 webView.destroy();
1569 }
1570 }
1571
1572 /**
1573 * Remove the tab from the parent
1574 */
1575 void removeFromTree() {
1576 // detach the children
Michael Kolbc831b632011-05-11 09:30:34 -07001577 if (mChildren != null) {
1578 for(Tab t : mChildren) {
1579 t.setParent(null);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001580 }
1581 }
1582 // remove itself from the parent list
Michael Kolbc831b632011-05-11 09:30:34 -07001583 if (mParent != null) {
1584 mParent.mChildren.remove(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001585 }
John Reck1cf4b792011-07-26 10:22:22 -07001586 deleteThumbnail();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001587 }
1588
1589 /**
1590 * Create a new subwindow unless a subwindow already exists.
1591 * @return True if a new subwindow was created. False if one already exists.
1592 */
1593 boolean createSubWindow() {
1594 if (mSubView == null) {
Michael Kolb1514bb72010-11-22 09:11:48 -08001595 mWebViewController.createSubWindow(this);
Leon Scroggins III211ba542010-04-19 13:21:13 -04001596 mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
Michael Kolb8233fac2010-10-26 16:08:53 -07001597 mWebViewController));
Grace Kloba22ac16e2009-10-07 18:00:23 -07001598 mSubView.setWebChromeClient(new SubWindowChromeClient(
1599 mWebChromeClient));
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001600 // Set a different DownloadListener for the mSubView, since it will
1601 // just need to dismiss the mSubView, rather than close the Tab
1602 mSubView.setDownloadListener(new DownloadListener() {
1603 public void onDownloadStart(String url, String userAgent,
1604 String contentDisposition, String mimetype,
1605 long contentLength) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001606 mWebViewController.onDownloadStart(Tab.this, url, userAgent,
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001607 contentDisposition, mimetype, contentLength);
1608 if (mSubView.copyBackForwardList().getSize() == 0) {
1609 // This subwindow was opened for the sole purpose of
1610 // downloading a file. Remove it.
Michael Kolb8233fac2010-10-26 16:08:53 -07001611 mWebViewController.dismissSubWindow(Tab.this);
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05001612 }
1613 }
1614 });
Michael Kolb14612442011-06-24 13:06:29 -07001615 mSubView.setOnCreateContextMenuListener(mWebViewController.getActivity());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001616 return true;
1617 }
1618 return false;
1619 }
1620
1621 /**
1622 * Dismiss the subWindow for the tab.
1623 */
1624 void dismissSubWindow() {
1625 if (mSubView != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001626 mWebViewController.endActionMode();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001627 mSubView.destroy();
1628 mSubView = null;
1629 mSubViewContainer = null;
1630 }
1631 }
1632
Grace Kloba22ac16e2009-10-07 18:00:23 -07001633
1634 /**
1635 * Set the parent tab of this tab.
1636 */
Michael Kolbc831b632011-05-11 09:30:34 -07001637 void setParent(Tab parent) {
John Reck52be4782011-08-26 15:37:29 -07001638 if (parent == this) {
1639 throw new IllegalStateException("Cannot set parent to self!");
1640 }
Michael Kolbc831b632011-05-11 09:30:34 -07001641 mParent = parent;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001642 // This tab may have been freed due to low memory. If that is the case,
Michael Kolbc831b632011-05-11 09:30:34 -07001643 // the parent tab id is already saved. If we are changing that id
Grace Kloba22ac16e2009-10-07 18:00:23 -07001644 // (most likely due to removing the parent tab) we must update the
Michael Kolbc831b632011-05-11 09:30:34 -07001645 // parent tab id in the saved Bundle.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001646 if (mSavedState != null) {
1647 if (parent == null) {
1648 mSavedState.remove(PARENTTAB);
1649 } else {
Michael Kolbc831b632011-05-11 09:30:34 -07001650 mSavedState.putLong(PARENTTAB, parent.getId());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001651 }
1652 }
John Reckb0a86db2011-05-24 14:05:58 -07001653
1654 // Sync the WebView useragent with the parent
1655 if (parent != null && mSettings.hasDesktopUseragent(parent.getWebView())
1656 != mSettings.hasDesktopUseragent(getWebView())) {
1657 mSettings.toggleDesktopUseragent(getWebView());
1658 }
John Reck52be4782011-08-26 15:37:29 -07001659
1660 if (parent != null && parent.getId() == getId()) {
1661 throw new IllegalStateException("Parent has same ID as child!");
1662 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001663 }
1664
1665 /**
Michael Kolbc831b632011-05-11 09:30:34 -07001666 * If this Tab was created through another Tab, then this method returns
1667 * that Tab.
1668 * @return the Tab parent or null
1669 */
1670 public Tab getParent() {
1671 return mParent;
1672 }
1673
1674 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001675 * When a Tab is created through the content of another Tab, then we
1676 * associate the Tabs.
1677 * @param child the Tab that was created from this Tab
1678 */
1679 void addChildTab(Tab child) {
Michael Kolbc831b632011-05-11 09:30:34 -07001680 if (mChildren == null) {
1681 mChildren = new Vector<Tab>();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001682 }
Michael Kolbc831b632011-05-11 09:30:34 -07001683 mChildren.add(child);
1684 child.setParent(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001685 }
1686
Michael Kolbc831b632011-05-11 09:30:34 -07001687 Vector<Tab> getChildren() {
1688 return mChildren;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001689 }
1690
1691 void resume() {
1692 if (mMainView != null) {
John Reck56c1fcf2011-08-17 10:15:16 -07001693 setupHwAcceleration(mMainView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001694 mMainView.onResume();
1695 if (mSubView != null) {
1696 mSubView.onResume();
1697 }
1698 }
1699 }
1700
John Reck56c1fcf2011-08-17 10:15:16 -07001701 private void setupHwAcceleration(View web) {
1702 if (web == null) return;
1703 BrowserSettings settings = BrowserSettings.getInstance();
1704 if (settings.isHardwareAccelerated()) {
1705 web.setLayerType(View.LAYER_TYPE_NONE, null);
1706 } else {
1707 web.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
1708 }
1709 }
1710
Grace Kloba22ac16e2009-10-07 18:00:23 -07001711 void pause() {
1712 if (mMainView != null) {
1713 mMainView.onPause();
1714 if (mSubView != null) {
1715 mSubView.onPause();
1716 }
1717 }
1718 }
1719
1720 void putInForeground() {
John Reck8ee633f2011-08-09 16:00:35 -07001721 if (mInForeground) {
1722 return;
1723 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001724 mInForeground = true;
1725 resume();
Michael Kolb14612442011-06-24 13:06:29 -07001726 Activity activity = mWebViewController.getActivity();
1727 mMainView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001728 if (mSubView != null) {
Michael Kolb14612442011-06-24 13:06:29 -07001729 mSubView.setOnCreateContextMenuListener(activity);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001730 }
1731 // Show the pending error dialog if the queue is not empty
1732 if (mQueuedErrors != null && mQueuedErrors.size() > 0) {
1733 showError(mQueuedErrors.getFirst());
1734 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05001735 mWebViewController.bookmarkedStatusHasChanged(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001736 }
1737
1738 void putInBackground() {
John Reck8ee633f2011-08-09 16:00:35 -07001739 if (!mInForeground) {
1740 return;
1741 }
John Reck52be4782011-08-26 15:37:29 -07001742 capture();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001743 mInForeground = false;
1744 pause();
1745 mMainView.setOnCreateContextMenuListener(null);
1746 if (mSubView != null) {
1747 mSubView.setOnCreateContextMenuListener(null);
1748 }
1749 }
1750
Michael Kolb8233fac2010-10-26 16:08:53 -07001751 boolean inForeground() {
1752 return mInForeground;
1753 }
1754
Grace Kloba22ac16e2009-10-07 18:00:23 -07001755 /**
1756 * Return the top window of this tab; either the subwindow if it is not
1757 * null or the main window.
1758 * @return The top window of this tab.
1759 */
1760 WebView getTopWindow() {
1761 if (mSubView != null) {
1762 return mSubView;
1763 }
1764 return mMainView;
1765 }
1766
1767 /**
1768 * Return the main window of this tab. Note: if a tab is freed in the
1769 * background, this can return null. It is only guaranteed to be
1770 * non-null for the current tab.
1771 * @return The main WebView of this tab.
1772 */
1773 WebView getWebView() {
1774 return mMainView;
1775 }
1776
Michael Kolba713ec82010-11-29 17:27:06 -08001777 void setViewContainer(View container) {
1778 mContainer = container;
1779 }
1780
Michael Kolb8233fac2010-10-26 16:08:53 -07001781 View getViewContainer() {
1782 return mContainer;
1783 }
1784
Grace Kloba22ac16e2009-10-07 18:00:23 -07001785 /**
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001786 * Return whether private browsing is enabled for the main window of
1787 * this tab.
1788 * @return True if private browsing is enabled.
1789 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001790 boolean isPrivateBrowsingEnabled() {
John Reck502a3532011-08-16 14:21:46 -07001791 return mCurrentState.mIncognito;
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001792 }
1793
1794 /**
Grace Kloba22ac16e2009-10-07 18:00:23 -07001795 * Return the subwindow of this tab or null if there is no subwindow.
1796 * @return The subwindow of this tab or null.
1797 */
1798 WebView getSubWebView() {
1799 return mSubView;
1800 }
1801
Michael Kolb1514bb72010-11-22 09:11:48 -08001802 void setSubWebView(WebView subView) {
1803 mSubView = subView;
1804 }
1805
Michael Kolb8233fac2010-10-26 16:08:53 -07001806 View getSubViewContainer() {
1807 return mSubViewContainer;
1808 }
1809
Michael Kolb1514bb72010-11-22 09:11:48 -08001810 void setSubViewContainer(View subViewContainer) {
1811 mSubViewContainer = subViewContainer;
1812 }
1813
Grace Kloba22ac16e2009-10-07 18:00:23 -07001814 /**
1815 * @return The geolocation permissions prompt for this tab.
1816 */
1817 GeolocationPermissionsPrompt getGeolocationPermissionsPrompt() {
Grace Kloba50c241e2010-04-20 11:07:50 -07001818 if (mGeolocationPermissionsPrompt == null) {
1819 ViewStub stub = (ViewStub) mContainer
1820 .findViewById(R.id.geolocation_permissions_prompt);
1821 mGeolocationPermissionsPrompt = (GeolocationPermissionsPrompt) stub
1822 .inflate();
Grace Kloba50c241e2010-04-20 11:07:50 -07001823 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001824 return mGeolocationPermissionsPrompt;
1825 }
1826
1827 /**
1828 * @return The application id string
1829 */
1830 String getAppId() {
1831 return mAppId;
1832 }
1833
1834 /**
1835 * Set the application id string
1836 * @param id
1837 */
1838 void setAppId(String id) {
1839 mAppId = id;
1840 }
1841
Michael Kolbe28b3472011-08-04 16:54:31 -07001842 boolean closeOnBack() {
1843 return mCloseOnBack;
1844 }
1845
1846 void setCloseOnBack(boolean close) {
1847 mCloseOnBack = close;
1848 }
1849
Grace Kloba22ac16e2009-10-07 18:00:23 -07001850 String getUrl() {
John Reck324d4402011-01-11 16:56:42 -08001851 return UrlUtils.filteredUrl(mCurrentState.mUrl);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001852 }
1853
John Reck49a603c2011-03-03 09:33:05 -08001854 String getOriginalUrl() {
John Reckdb22ec42011-06-29 11:31:24 -07001855 if (mCurrentState.mOriginalUrl == null) {
1856 return getUrl();
John Reck49a603c2011-03-03 09:33:05 -08001857 }
John Reckdb22ec42011-06-29 11:31:24 -07001858 return UrlUtils.filteredUrl(mCurrentState.mOriginalUrl);
John Reck49a603c2011-03-03 09:33:05 -08001859 }
1860
Grace Kloba22ac16e2009-10-07 18:00:23 -07001861 /**
John Reck30c714c2010-12-16 17:30:34 -08001862 * Get the title of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001863 */
1864 String getTitle() {
John Reck30c714c2010-12-16 17:30:34 -08001865 if (mCurrentState.mTitle == null && mInPageLoad) {
Michael Kolb14612442011-06-24 13:06:29 -07001866 return mContext.getString(R.string.title_bar_loading);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001867 }
John Reck30c714c2010-12-16 17:30:34 -08001868 return mCurrentState.mTitle;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001869 }
1870
1871 /**
John Reck30c714c2010-12-16 17:30:34 -08001872 * Get the favicon of this tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001873 */
1874 Bitmap getFavicon() {
John Reck1cf4b792011-07-26 10:22:22 -07001875 if (mCurrentState.mFavicon != null) {
1876 return mCurrentState.mFavicon;
1877 }
1878 return getDefaultFavicon(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001879 }
1880
John Recke969cc52010-12-21 17:24:43 -08001881 public boolean isBookmarkedSite() {
1882 return mCurrentState.mIsBookmarkedSite;
1883 }
Rob Tsukf8bdfce2010-10-07 15:41:16 -07001884
Grace Kloba22ac16e2009-10-07 18:00:23 -07001885 /**
1886 * Return the tab's error console. Creates the console if createIfNEcessary
1887 * is true and we haven't already created the console.
1888 * @param createIfNecessary Flag to indicate if the console should be
1889 * created if it has not been already.
1890 * @return The tab's error console, or null if one has not been created and
1891 * createIfNecessary is false.
1892 */
1893 ErrorConsoleView getErrorConsole(boolean createIfNecessary) {
1894 if (createIfNecessary && mErrorConsole == null) {
Michael Kolb14612442011-06-24 13:06:29 -07001895 mErrorConsole = new ErrorConsoleView(mContext);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001896 mErrorConsole.setWebView(mMainView);
1897 }
1898 return mErrorConsole;
1899 }
1900
Steve Block08a6f0c2011-10-06 12:12:53 +01001901 /**
1902 * Sets the security state, clears the SSL certificate error and informs
1903 * the controller.
1904 */
Steve Block2466eff2011-10-03 15:33:09 +01001905 private void setSecurityState(SecurityState securityState) {
1906 mCurrentState.mSecurityState = securityState;
Steve Block08a6f0c2011-10-06 12:12:53 +01001907 mCurrentState.mSslCertificateError = null;
Steve Block2466eff2011-10-03 15:33:09 +01001908 mWebViewController.onUpdatedSecurityState(this);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001909 }
1910
1911 /**
Steve Block2466eff2011-10-03 15:33:09 +01001912 * @return The tab's security state.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001913 */
Steve Block2466eff2011-10-03 15:33:09 +01001914 SecurityState getSecurityState() {
1915 return mCurrentState.mSecurityState;
John Reck30c714c2010-12-16 17:30:34 -08001916 }
1917
Steve Block08a6f0c2011-10-06 12:12:53 +01001918 /**
1919 * Gets the SSL certificate error, if any, for the page's main resource.
1920 * This is only non-null when the security state is
1921 * SECURITY_STATE_BAD_CERTIFICATE.
1922 */
1923 SslError getSslCertificateError() {
1924 return mCurrentState.mSslCertificateError;
1925 }
1926
John Reck30c714c2010-12-16 17:30:34 -08001927 int getLoadProgress() {
1928 if (mInPageLoad) {
1929 return mPageLoadProgress;
1930 }
1931 return 100;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001932 }
1933
1934 /**
1935 * @return TRUE if onPageStarted is called while onPageFinished is not
1936 * called yet.
1937 */
Michael Kolb8233fac2010-10-26 16:08:53 -07001938 boolean inPageLoad() {
1939 return mInPageLoad;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001940 }
1941
1942 // force mInLoad to be false. This should only be called before closing the
1943 // tab to ensure BrowserActivity's pauseWebViewTimers() is called correctly.
Michael Kolb8233fac2010-10-26 16:08:53 -07001944 void clearInPageLoad() {
1945 mInPageLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001946 }
1947
Grace Kloba22ac16e2009-10-07 18:00:23 -07001948 /**
John Reck1cf4b792011-07-26 10:22:22 -07001949 * @return The Bundle with the tab's state if it can be saved, otherwise null
Grace Kloba22ac16e2009-10-07 18:00:23 -07001950 */
John Reck1cf4b792011-07-26 10:22:22 -07001951 public Bundle saveState() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001952 // If the WebView is null it means we ran low on memory and we already
1953 // stored the saved state in mSavedState.
1954 if (mMainView == null) {
John Reck1cf4b792011-07-26 10:22:22 -07001955 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001956 }
John Reck6c2e2f32011-08-22 13:41:23 -07001957
1958 if (TextUtils.isEmpty(mCurrentState.mUrl)) {
John Reck1cf4b792011-07-26 10:22:22 -07001959 return null;
John Reck24f18262011-06-17 14:47:20 -07001960 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001961
1962 mSavedState = new Bundle();
John Reck6c2e2f32011-08-22 13:41:23 -07001963 WebBackForwardList savedList = mMainView.saveState(mSavedState);
1964 if (savedList == null || savedList.getSize() == 0) {
1965 Log.w(LOGTAG, "Failed to save back/forward list for "
1966 + mCurrentState.mUrl);
1967 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001968
Michael Kolbc831b632011-05-11 09:30:34 -07001969 mSavedState.putLong(ID, mId);
John Reck30c714c2010-12-16 17:30:34 -08001970 mSavedState.putString(CURRURL, mCurrentState.mUrl);
1971 mSavedState.putString(CURRTITLE, mCurrentState.mTitle);
John Reck1cf4b792011-07-26 10:22:22 -07001972 mSavedState.putBoolean(INCOGNITO, mMainView.isPrivateBrowsingEnabled());
Grace Kloba22ac16e2009-10-07 18:00:23 -07001973 if (mAppId != null) {
1974 mSavedState.putString(APPID, mAppId);
1975 }
Michael Kolbe28b3472011-08-04 16:54:31 -07001976 mSavedState.putBoolean(CLOSEFLAG, mCloseOnBack);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001977 // Remember the parent tab so the relationship can be restored.
Michael Kolbc831b632011-05-11 09:30:34 -07001978 if (mParent != null) {
1979 mSavedState.putLong(PARENTTAB, mParent.mId);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001980 }
John Reckb0a86db2011-05-24 14:05:58 -07001981 mSavedState.putBoolean(USERAGENT,
1982 mSettings.hasDesktopUseragent(getWebView()));
John Reck1cf4b792011-07-26 10:22:22 -07001983 return mSavedState;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001984 }
1985
1986 /*
1987 * Restore the state of the tab.
1988 */
John Reck1cf4b792011-07-26 10:22:22 -07001989 private void restoreState(Bundle b) {
1990 mSavedState = b;
1991 if (mSavedState == null) {
1992 return;
Grace Kloba22ac16e2009-10-07 18:00:23 -07001993 }
1994 // Restore the internal state even if the WebView fails to restore.
1995 // This will maintain the app id, original url and close-on-exit values.
Michael Kolbc831b632011-05-11 09:30:34 -07001996 mId = b.getLong(ID);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001997 mAppId = b.getString(APPID);
Michael Kolbe28b3472011-08-04 16:54:31 -07001998 mCloseOnBack = b.getBoolean(CLOSEFLAG);
John Reckb0a86db2011-05-24 14:05:58 -07001999 if (b.getBoolean(USERAGENT)
2000 != mSettings.hasDesktopUseragent(getWebView())) {
2001 mSettings.toggleDesktopUseragent(getWebView());
2002 }
John Reck1cf4b792011-07-26 10:22:22 -07002003 String url = b.getString(CURRURL);
2004 String title = b.getString(CURRTITLE);
2005 boolean incognito = b.getBoolean(INCOGNITO);
2006 mCurrentState = new PageState(mContext, incognito, url, null);
2007 mCurrentState.mTitle = title;
2008 synchronized (Tab.this) {
2009 if (mCapture != null) {
John Reck4eadc342011-10-31 14:04:10 -07002010 DataController.getInstance(mContext).loadThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002011 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002012 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002013 }
Leon Scroggins III211ba542010-04-19 13:21:13 -04002014
Leon Scroggins1961ed22010-12-07 15:22:21 -05002015 public void updateBookmarkedStatus() {
John Recke969cc52010-12-21 17:24:43 -08002016 mDataController.queryBookmarkStatus(getUrl(), mIsBookmarkCallback);
Leon Scroggins1961ed22010-12-07 15:22:21 -05002017 }
2018
John Recke969cc52010-12-21 17:24:43 -08002019 private DataController.OnQueryUrlIsBookmark mIsBookmarkCallback
2020 = new DataController.OnQueryUrlIsBookmark() {
2021 @Override
2022 public void onQueryUrlIsBookmark(String url, boolean isBookmark) {
2023 if (mCurrentState.mUrl.equals(url)) {
2024 mCurrentState.mIsBookmarkedSite = isBookmark;
2025 mWebViewController.bookmarkedStatusHasChanged(Tab.this);
2026 }
Leon Scroggins1961ed22010-12-07 15:22:21 -05002027 }
John Recke969cc52010-12-21 17:24:43 -08002028 };
Michael Kolb1acef692011-03-08 14:12:06 -08002029
Michael Kolbeb95db42011-03-03 10:38:40 -08002030 public Bitmap getScreenshot() {
John Reck1cf4b792011-07-26 10:22:22 -07002031 synchronized (Tab.this) {
2032 return mCapture;
2033 }
Michael Kolbeb95db42011-03-03 10:38:40 -08002034 }
2035
John Reck541f55a2011-06-07 16:34:43 -07002036 public boolean isSnapshot() {
John Reck541f55a2011-06-07 16:34:43 -07002037 return false;
2038 }
2039
John Reckd8c74522011-06-14 08:45:00 -07002040 public ContentValues createSnapshotValues() {
2041 if (mMainView == null) return null;
John Reck9d2718e2011-10-05 17:10:17 -07002042 SnapshotByteArrayOutputStream bos = new SnapshotByteArrayOutputStream();
John Reck8cc92352011-07-06 17:41:52 -07002043 try {
2044 GZIPOutputStream stream = new GZIPOutputStream(bos);
2045 if (!mMainView.saveViewState(stream)) {
2046 return null;
2047 }
2048 stream.flush();
2049 stream.close();
2050 } catch (Exception e) {
2051 Log.w(LOGTAG, "Failed to save view state", e);
John Reck541f55a2011-06-07 16:34:43 -07002052 return null;
2053 }
John Reck8cc92352011-07-06 17:41:52 -07002054 byte[] data = bos.toByteArray();
John Reckd8c74522011-06-14 08:45:00 -07002055 ContentValues values = new ContentValues();
2056 values.put(Snapshots.TITLE, mCurrentState.mTitle);
2057 values.put(Snapshots.URL, mCurrentState.mUrl);
2058 values.put(Snapshots.VIEWSTATE, data);
2059 values.put(Snapshots.BACKGROUND, mMainView.getPageBackgroundColor());
John Reck8cc92352011-07-06 17:41:52 -07002060 values.put(Snapshots.DATE_CREATED, System.currentTimeMillis());
2061 values.put(Snapshots.FAVICON, compressBitmap(getFavicon()));
2062 Bitmap screenshot = Controller.createScreenshot(mMainView,
2063 Controller.getDesiredThumbnailWidth(mContext),
2064 Controller.getDesiredThumbnailHeight(mContext));
2065 values.put(Snapshots.THUMBNAIL, compressBitmap(screenshot));
John Reckd8c74522011-06-14 08:45:00 -07002066 return values;
John Reck541f55a2011-06-07 16:34:43 -07002067 }
2068
John Reck8cc92352011-07-06 17:41:52 -07002069 public byte[] compressBitmap(Bitmap bitmap) {
2070 if (bitmap == null) {
2071 return null;
2072 }
2073 ByteArrayOutputStream stream = new ByteArrayOutputStream();
2074 bitmap.compress(CompressFormat.PNG, 100, stream);
2075 return stream.toByteArray();
2076 }
2077
John Reck26b18322011-06-21 13:08:58 -07002078 public void loadUrl(String url, Map<String, String> headers) {
2079 if (mMainView != null) {
Michael Kolba53c9892011-10-05 13:31:40 -07002080 mPageLoadProgress = INITIAL_PROGRESS;
2081 mInPageLoad = true;
Michael Kolb14612442011-06-24 13:06:29 -07002082 mCurrentState = new PageState(mContext, false, url, null);
John Reck26b18322011-06-21 13:08:58 -07002083 mWebViewController.onPageStarted(this, mMainView, null);
2084 mMainView.loadUrl(url, headers);
2085 }
2086 }
2087
Michael Kolb9ef259a2011-07-12 15:33:08 -07002088 protected void capture() {
2089 if (mMainView == null || mCapture == null) return;
John Reck4eadc342011-10-31 14:04:10 -07002090 if (mMainView.getContentWidth() <= 0 || mMainView.getContentHeight() <= 0) {
2091 return;
2092 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002093 Canvas c = new Canvas(mCapture);
2094 final int left = mMainView.getScrollX();
2095 final int top = mMainView.getScrollY() + mMainView.getVisibleTitleHeight();
Michael Kolba3194d02011-09-07 11:23:51 -07002096 int state = c.save();
Michael Kolb9ef259a2011-07-12 15:33:08 -07002097 c.translate(-left, -top);
2098 float scale = mCaptureWidth / (float) mMainView.getWidth();
2099 c.scale(scale, scale, left, top);
John Reck8ee633f2011-08-09 16:00:35 -07002100 if (mMainView instanceof BrowserWebView) {
2101 ((BrowserWebView)mMainView).drawContent(c);
2102 } else {
2103 mMainView.draw(c);
2104 }
Michael Kolba3194d02011-09-07 11:23:51 -07002105 c.restoreToCount(state);
2106 // manually anti-alias the edges for the tilt
2107 c.drawRect(0, 0, 1, mCapture.getHeight(), sAlphaPaint);
2108 c.drawRect(mCapture.getWidth() - 1, 0, mCapture.getWidth(),
2109 mCapture.getHeight(), sAlphaPaint);
2110 c.drawRect(0, 0, mCapture.getWidth(), 1, sAlphaPaint);
2111 c.drawRect(0, mCapture.getHeight() - 1, mCapture.getWidth(),
2112 mCapture.getHeight(), sAlphaPaint);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002113 c.setBitmap(null);
John Reck8ee633f2011-08-09 16:00:35 -07002114 mHandler.removeMessages(MSG_CAPTURE);
John Reck1cf4b792011-07-26 10:22:22 -07002115 persistThumbnail();
John Reck8ee633f2011-08-09 16:00:35 -07002116 TabControl tc = mWebViewController.getTabControl();
2117 if (tc != null) {
2118 OnThumbnailUpdatedListener updateListener
2119 = tc.getOnThumbnailUpdatedListener();
2120 if (updateListener != null) {
2121 updateListener.onThumbnailUpdated(this);
2122 }
2123 }
Michael Kolb9ef259a2011-07-12 15:33:08 -07002124 }
2125
2126 @Override
2127 public void onNewPicture(WebView view, Picture picture) {
2128 //update screenshot
John Reck1cf4b792011-07-26 10:22:22 -07002129 postCapture();
2130 }
2131
2132 private void postCapture() {
Michael Kolb9ef259a2011-07-12 15:33:08 -07002133 if (!mHandler.hasMessages(MSG_CAPTURE)) {
2134 mHandler.sendEmptyMessageDelayed(MSG_CAPTURE, CAPTURE_DELAY);
2135 }
2136 }
2137
John Reckef654f12011-07-12 16:42:08 -07002138 public boolean canGoBack() {
2139 return mMainView != null ? mMainView.canGoBack() : false;
2140 }
2141
2142 public boolean canGoForward() {
2143 return mMainView != null ? mMainView.canGoForward() : false;
2144 }
2145
2146 public void goBack() {
2147 if (mMainView != null) {
2148 mMainView.goBack();
2149 }
2150 }
2151
2152 public void goForward() {
2153 if (mMainView != null) {
2154 mMainView.goForward();
2155 }
2156 }
2157
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002158 /**
2159 * Causes the tab back/forward stack to be cleared once, if the given URL is the next URL
2160 * to be added to the stack.
2161 *
2162 * This is used to ensure that preloaded URLs that are not subsequently seen by the user do
2163 * not appear in the back stack.
2164 */
Mathew Inwooda829d552011-09-02 14:16:25 +01002165 public void clearBackStackWhenItemAdded(Pattern urlPattern) {
2166 mClearHistoryUrlPattern = urlPattern;
Mathew Inwood1dd8e822011-08-03 14:34:29 +01002167 }
2168
John Reck1cf4b792011-07-26 10:22:22 -07002169 protected void persistThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002170 DataController.getInstance(mContext).saveThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002171 }
2172
2173 protected void deleteThumbnail() {
John Reck4eadc342011-10-31 14:04:10 -07002174 DataController.getInstance(mContext).deleteThumbnail(this);
John Reck1cf4b792011-07-26 10:22:22 -07002175 }
2176
John Reck4eadc342011-10-31 14:04:10 -07002177 void updateCaptureFromBlob(byte[] blob) {
John Reck1cf4b792011-07-26 10:22:22 -07002178 synchronized (Tab.this) {
2179 if (mCapture == null) {
2180 return;
2181 }
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002182 ByteBuffer buffer = ByteBuffer.wrap(blob);
Michael Kolbd837a112011-08-09 14:00:18 -07002183 try {
2184 mCapture.copyPixelsFromBuffer(buffer);
2185 } catch (RuntimeException rex) {
2186 Log.e(LOGTAG, "Load capture has mismatched sizes; buffer: "
2187 + buffer.capacity() + " blob: " + blob.length
2188 + "capture: " + mCapture.getByteCount());
2189 throw rex;
Michael Kolbbd4c00a2011-08-02 11:27:12 -07002190 }
John Reck1cf4b792011-07-26 10:22:22 -07002191 }
2192 }
2193
John Reck52be4782011-08-26 15:37:29 -07002194 @Override
2195 public String toString() {
2196 StringBuilder builder = new StringBuilder(100);
2197 builder.append(mId);
2198 builder.append(") has parent: ");
2199 if (getParent() != null) {
2200 builder.append("true[");
2201 builder.append(getParent().getId());
2202 builder.append("]");
2203 } else {
2204 builder.append("false");
2205 }
2206 builder.append(", incog: ");
2207 builder.append(isPrivateBrowsingEnabled());
2208 if (!isPrivateBrowsingEnabled()) {
2209 builder.append(", title: ");
2210 builder.append(getTitle());
2211 builder.append(", url: ");
2212 builder.append(getUrl());
2213 }
2214 return builder.toString();
2215 }
2216
Steve Block4895b012011-10-03 16:26:46 +01002217 private void handleProceededAfterSslError(SslError error) {
2218 if (error.getUrl().equals(mCurrentState.mUrl)) {
2219 // The security state should currently be SECURITY_STATE_SECURE.
2220 setSecurityState(SecurityState.SECURITY_STATE_BAD_CERTIFICATE);
Steve Block08a6f0c2011-10-06 12:12:53 +01002221 mCurrentState.mSslCertificateError = error;
Steve Block4895b012011-10-03 16:26:46 +01002222 } else if (getSecurityState() == SecurityState.SECURITY_STATE_SECURE) {
Steve Block08a6f0c2011-10-06 12:12:53 +01002223 // The page's main resource is secure and this error is for a
2224 // sub-resource.
Steve Block4895b012011-10-03 16:26:46 +01002225 setSecurityState(SecurityState.SECURITY_STATE_MIXED);
2226 }
2227 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002228}