blob: 0c86988d561e7388d3776e0214739bba30d47476 [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
2 * Copyright (C) 2010 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;
John Reck68234a92012-04-19 15:27:12 -070020import android.app.AlertDialog;
21import android.app.Dialog;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.app.DownloadManager;
John Reck68234a92012-04-19 15:27:12 -070023import android.app.ProgressDialog;
Michael Kolb8233fac2010-10-26 16:08:53 -070024import android.app.SearchManager;
25import android.content.ClipboardManager;
26import android.content.ContentProvider;
27import android.content.ContentProviderClient;
28import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070029import android.content.ContentUris;
Michael Kolb8233fac2010-10-26 16:08:53 -070030import android.content.ContentValues;
31import android.content.Context;
John Reck68234a92012-04-19 15:27:12 -070032import android.content.DialogInterface;
33import android.content.DialogInterface.OnCancelListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.content.Intent;
35import android.content.pm.PackageManager;
36import android.content.pm.ResolveInfo;
37import android.content.res.Configuration;
John Reck30b065e2011-07-19 10:58:05 -070038import android.content.res.TypedArray;
Leon Scroggins1961ed22010-12-07 15:22:21 -050039import android.database.ContentObserver;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.database.Cursor;
41import android.database.sqlite.SQLiteDatabase;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.graphics.Bitmap;
43import android.graphics.Canvas;
Michael Kolb8233fac2010-10-26 16:08:53 -070044import android.net.Uri;
45import android.net.http.SslError;
46import android.os.AsyncTask;
47import android.os.Bundle;
George Mount387d45d2011-10-07 15:57:53 -070048import android.os.Environment;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.os.Handler;
50import android.os.Message;
51import android.os.PowerManager;
52import android.os.PowerManager.WakeLock;
Ben Murdoch8029a772010-11-16 11:58:21 +000053import android.preference.PreferenceActivity;
Michael Kolb8233fac2010-10-26 16:08:53 -070054import android.provider.Browser;
55import android.provider.BrowserContract;
Michael Kolb8233fac2010-10-26 16:08:53 -070056import android.provider.BrowserContract.Images;
57import android.provider.ContactsContract;
58import android.provider.ContactsContract.Intents.Insert;
Michael Kolbcfa3af52010-12-14 10:36:11 -080059import android.speech.RecognizerIntent;
Michael Kolb8233fac2010-10-26 16:08:53 -070060import android.text.TextUtils;
61import android.util.Log;
John Recka00cbbd2010-12-16 12:38:19 -080062import android.util.Patterns;
Michael Kolb8233fac2010-10-26 16:08:53 -070063import android.view.ActionMode;
64import android.view.ContextMenu;
65import android.view.ContextMenu.ContextMenuInfo;
66import android.view.Gravity;
67import android.view.KeyEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070068import android.view.Menu;
69import android.view.MenuInflater;
70import android.view.MenuItem;
71import android.view.MenuItem.OnMenuItemClickListener;
Michael Kolbc3af0672011-08-09 10:24:41 -070072import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070073import android.view.View;
74import android.webkit.CookieManager;
75import android.webkit.CookieSyncManager;
76import android.webkit.HttpAuthHandler;
George Mount387d45d2011-10-07 15:57:53 -070077import android.webkit.MimeTypeMap;
Michael Kolb8233fac2010-10-26 16:08:53 -070078import android.webkit.SslErrorHandler;
79import android.webkit.ValueCallback;
80import android.webkit.WebChromeClient;
81import android.webkit.WebIconDatabase;
82import android.webkit.WebSettings;
83import android.webkit.WebView;
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +000084import android.webkit.WebViewClassic;
Leon Scrogginsac993842011-02-02 12:54:07 -050085import android.widget.Toast;
Michael Kolb8233fac2010-10-26 16:08:53 -070086
Michael Kolb4bd767d2011-05-27 11:33:55 -070087import com.android.browser.IntentHandler.UrlData;
John Reck2bc80422011-06-30 15:11:49 -070088import com.android.browser.UI.ComboViews;
Michael Kolb4bd767d2011-05-27 11:33:55 -070089import com.android.browser.provider.BrowserProvider;
John Reck1cf4b792011-07-26 10:22:22 -070090import com.android.browser.provider.BrowserProvider2.Thumbnails;
John Reck8cc92352011-07-06 17:41:52 -070091import com.android.browser.provider.SnapshotProvider.Snapshots;
Michael Kolb4bd767d2011-05-27 11:33:55 -070092import com.android.browser.search.SearchEngine;
93import com.android.common.Search;
94
Michael Kolb8233fac2010-10-26 16:08:53 -070095import java.io.ByteArrayOutputStream;
George Mount387d45d2011-10-07 15:57:53 -070096import java.io.File;
97import java.io.FileOutputStream;
98import java.io.IOException;
Michael Kolb8233fac2010-10-26 16:08:53 -070099import java.net.URLEncoder;
George Mount387d45d2011-10-07 15:57:53 -0700100import java.text.DateFormat;
101import java.text.SimpleDateFormat;
John Reck1cf4b792011-07-26 10:22:22 -0700102import java.util.ArrayList;
Michael Kolb8233fac2010-10-26 16:08:53 -0700103import java.util.Calendar;
George Mount387d45d2011-10-07 15:57:53 -0700104import java.util.Date;
Michael Kolb8233fac2010-10-26 16:08:53 -0700105import java.util.HashMap;
Michael Kolb1bf23132010-11-19 12:55:12 -0800106import java.util.List;
John Reck26b18322011-06-21 13:08:58 -0700107import java.util.Map;
Michael Kolb8233fac2010-10-26 16:08:53 -0700108
109/**
110 * Controller for browser
111 */
112public class Controller
113 implements WebViewController, UiController {
114
115 private static final String LOGTAG = "Controller";
Michael Kolbcfa3af52010-12-14 10:36:11 -0800116 private static final String SEND_APP_ID_EXTRA =
117 "android.speech.extras.SEND_APPLICATION_ID_EXTRA";
Michael Kolba4261fd2011-05-05 11:27:37 -0700118 private static final String INCOGNITO_URI = "browser:incognito";
Michael Kolbcfa3af52010-12-14 10:36:11 -0800119
Michael Kolb8233fac2010-10-26 16:08:53 -0700120
121 // public message ids
122 public final static int LOAD_URL = 1001;
123 public final static int STOP_LOAD = 1002;
124
125 // Message Ids
126 private static final int FOCUS_NODE_HREF = 102;
127 private static final int RELEASE_WAKELOCK = 107;
128
129 static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
130
131 private static final int OPEN_BOOKMARKS = 201;
132
133 private static final int EMPTY_MENU = -1;
134
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 // activity requestCode
John Reckd3e4d5b2011-07-13 15:48:43 -0700136 final static int COMBO_VIEW = 1;
Michael Kolb8233fac2010-10-26 16:08:53 -0700137 final static int PREFERENCES_PAGE = 3;
138 final static int FILE_SELECTED = 4;
Ben Murdoch8029a772010-11-16 11:58:21 +0000139 final static int AUTOFILL_SETUP = 5;
140
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes
142
143 // As the ids are dynamically created, we can't guarantee that they will
144 // be in sequence, so this static array maps ids to a window number.
145 final static private int[] WINDOW_SHORTCUT_ID_ARRAY =
146 { R.id.window_one_menu_id, R.id.window_two_menu_id,
147 R.id.window_three_menu_id, R.id.window_four_menu_id,
148 R.id.window_five_menu_id, R.id.window_six_menu_id,
149 R.id.window_seven_menu_id, R.id.window_eight_menu_id };
150
151 // "source" parameter for Google search through search key
152 final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key";
153 // "source" parameter for Google search through simplily type
154 final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type";
155
George Mount387d45d2011-10-07 15:57:53 -0700156 // "no-crash-recovery" parameter in intent to suppress crash recovery
Guang Zhu9e78f512011-05-04 11:45:11 -0700157 final static String NO_CRASH_RECOVERY = "no-crash-recovery";
158
John Reckd7dd9b22011-08-30 09:18:29 -0700159 // A bitmap that is re-used in createScreenshot as scratch space
160 private static Bitmap sThumbnailBitmap;
161
Michael Kolb8233fac2010-10-26 16:08:53 -0700162 private Activity mActivity;
163 private UI mUi;
164 private TabControl mTabControl;
165 private BrowserSettings mSettings;
166 private WebViewFactory mFactory;
167
168 private WakeLock mWakeLock;
169
170 private UrlHandler mUrlHandler;
171 private UploadHandler mUploadHandler;
172 private IntentHandler mIntentHandler;
Michael Kolb8233fac2010-10-26 16:08:53 -0700173 private PageDialogsHandler mPageDialogsHandler;
174 private NetworkStateHandler mNetworkHandler;
175
Ben Murdoch8029a772010-11-16 11:58:21 +0000176 private Message mAutoFillSetupMessage;
177
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 private boolean mShouldShowErrorConsole;
179
180 private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins;
181
182 // FIXME, temp address onPrepareMenu performance problem.
183 // When we move everything out of view, we should rewrite this.
184 private int mCurrentMenuState = 0;
185 private int mMenuState = R.id.MAIN_MENU;
186 private int mOldMenuState = EMPTY_MENU;
187 private Menu mCachedMenu;
188
Michael Kolb8233fac2010-10-26 16:08:53 -0700189 private boolean mMenuIsDown;
190
191 // For select and find, we keep track of the ActionMode so that
192 // finish() can be called as desired.
193 private ActionMode mActionMode;
194
195 /**
196 * Only meaningful when mOptionsMenuOpen is true. This variable keeps track
197 * of whether the configuration has changed. The first onMenuOpened call
198 * after a configuration change is simply a reopening of the same menu
199 * (i.e. mIconView did not change).
200 */
201 private boolean mConfigChanged;
202
203 /**
204 * Keeps track of whether the options menu is open. This is important in
205 * determining whether to show or hide the title bar overlay
206 */
207 private boolean mOptionsMenuOpen;
208
209 /**
210 * Whether or not the options menu is in its bigger, popup menu form. When
211 * true, we want the title bar overlay to be gone. When false, we do not.
212 * Only meaningful if mOptionsMenuOpen is true.
213 */
214 private boolean mExtendedMenuOpen;
215
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 private boolean mActivityPaused = true;
217 private boolean mLoadStopped;
218
219 private Handler mHandler;
Leon Scroggins1961ed22010-12-07 15:22:21 -0500220 // Checks to see when the bookmarks database has changed, and updates the
221 // Tabs' notion of whether they represent bookmarked sites.
222 private ContentObserver mBookmarksObserver;
John Reck847b5322011-04-14 17:02:18 -0700223 private CrashRecoveryHandler mCrashRecoveryHandler;
Michael Kolb8233fac2010-10-26 16:08:53 -0700224
Michael Kolbc3af0672011-08-09 10:24:41 -0700225 private boolean mBlockEvents;
226
George Mount3636d0a2011-11-21 09:08:21 -0800227 public Controller(Activity browser) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 mActivity = browser;
229 mSettings = BrowserSettings.getInstance();
230 mTabControl = new TabControl(this);
231 mSettings.setController(this);
John Reck378a4102011-06-09 16:23:01 -0700232 mCrashRecoveryHandler = CrashRecoveryHandler.initialize(this);
George Mount3636d0a2011-11-21 09:08:21 -0800233 mCrashRecoveryHandler.preloadCrashState();
Michael Kolb14612442011-06-24 13:06:29 -0700234 mFactory = new BrowserWebViewFactory(browser);
Michael Kolb8233fac2010-10-26 16:08:53 -0700235
236 mUrlHandler = new UrlHandler(this);
237 mIntentHandler = new IntentHandler(mActivity, this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700238 mPageDialogsHandler = new PageDialogsHandler(mActivity, this);
239
Michael Kolb8233fac2010-10-26 16:08:53 -0700240 startHandler();
Leon Scroggins1961ed22010-12-07 15:22:21 -0500241 mBookmarksObserver = new ContentObserver(mHandler) {
242 @Override
243 public void onChange(boolean selfChange) {
244 int size = mTabControl.getTabCount();
245 for (int i = 0; i < size; i++) {
246 mTabControl.getTab(i).updateBookmarkedStatus();
247 }
248 }
249
250 };
251 browser.getContentResolver().registerContentObserver(
252 BrowserContract.Bookmarks.CONTENT_URI, true, mBookmarksObserver);
Michael Kolb8233fac2010-10-26 16:08:53 -0700253
254 mNetworkHandler = new NetworkStateHandler(mActivity, this);
255 // Start watching the default geolocation permissions
256 mSystemAllowGeolocationOrigins =
257 new SystemAllowGeolocationOrigins(mActivity.getApplicationContext());
258 mSystemAllowGeolocationOrigins.start();
259
John Reckaf262e72011-07-25 13:55:44 -0700260 openIconDatabase();
Michael Kolb8233fac2010-10-26 16:08:53 -0700261 }
262
George Mount3636d0a2011-11-21 09:08:21 -0800263 void start(final Intent intent) {
264 // mCrashRecoverHandler has any previously saved state.
265 mCrashRecoveryHandler.startRecovery(intent);
John Reck847b5322011-04-14 17:02:18 -0700266 }
267
George Mount3636d0a2011-11-21 09:08:21 -0800268 void doStart(final Bundle icicle, final Intent intent) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700269 // Unless the last browser usage was within 24 hours, destroy any
270 // remaining incognito tabs.
271
272 Calendar lastActiveDate = icicle != null ?
273 (Calendar) icicle.getSerializable("lastActiveDate") : null;
274 Calendar today = Calendar.getInstance();
275 Calendar yesterday = Calendar.getInstance();
276 yesterday.add(Calendar.DATE, -1);
277
Patrick Scott7d50a932011-02-04 09:27:26 -0500278 final boolean restoreIncognitoTabs = !(lastActiveDate == null
Michael Kolb8233fac2010-10-26 16:08:53 -0700279 || lastActiveDate.before(yesterday)
Michael Kolb1bf23132010-11-19 12:55:12 -0800280 || lastActiveDate.after(today));
Michael Kolb8233fac2010-10-26 16:08:53 -0700281
Patrick Scott7d50a932011-02-04 09:27:26 -0500282 // Find out if we will restore any state and remember the tab.
Michael Kolbc831b632011-05-11 09:30:34 -0700283 final long currentTabId =
Patrick Scott7d50a932011-02-04 09:27:26 -0500284 mTabControl.canRestoreState(icicle, restoreIncognitoTabs);
Kristian Monsen2cd97012010-12-07 11:11:40 +0000285
Michael Kolbc831b632011-05-11 09:30:34 -0700286 if (currentTabId == -1) {
Patrick Scott7d50a932011-02-04 09:27:26 -0500287 // Not able to restore so we go ahead and clear session cookies. We
288 // must do this before trying to login the user as we don't want to
289 // clear any session cookies set during login.
290 CookieManager.getInstance().removeSessionCookie();
291 }
292
Patrick Scottd43e75a2011-03-14 14:47:23 -0400293 GoogleAccountLogin.startLoginIfNeeded(mActivity,
Patrick Scott7d50a932011-02-04 09:27:26 -0500294 new Runnable() {
295 @Override public void run() {
George Mount3636d0a2011-11-21 09:08:21 -0800296 onPreloginFinished(icicle, intent, currentTabId,
297 restoreIncognitoTabs);
Patrick Scott7d50a932011-02-04 09:27:26 -0500298 }
299 });
300 }
301
Michael Kolbc831b632011-05-11 09:30:34 -0700302 private void onPreloginFinished(Bundle icicle, Intent intent, long currentTabId,
George Mount3636d0a2011-11-21 09:08:21 -0800303 boolean restoreIncognitoTabs) {
Michael Kolbc831b632011-05-11 09:30:34 -0700304 if (currentTabId == -1) {
John Reck1cf4b792011-07-26 10:22:22 -0700305 BackgroundHandler.execute(new PruneThumbnails(mActivity, null));
George Mount3636d0a2011-11-21 09:08:21 -0800306 if (intent == null) {
307 // This won't happen under common scenarios. The icicle is
308 // not null, but there aren't any tabs to restore.
309 openTabToHomePage();
Michael Kolb7bcafde2011-05-09 13:55:59 -0700310 } else {
George Mount3636d0a2011-11-21 09:08:21 -0800311 final Bundle extra = intent.getExtras();
312 // Create an initial tab.
313 // If the intent is ACTION_VIEW and data is not null, the Browser is
314 // invoked to view the content by another application. In this case,
315 // the tab will be close when exit.
316 UrlData urlData = IntentHandler.getUrlDataFromIntent(intent);
317 Tab t = null;
318 if (urlData.isEmpty()) {
319 t = openTabToHomePage();
320 } else {
321 t = openTab(urlData);
322 }
323 if (t != null) {
324 t.setAppId(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID));
325 }
326 WebView webView = t.getWebView();
327 if (extra != null) {
328 int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0);
329 if (scale > 0 && scale <= 1000) {
330 webView.setInitialScale(scale);
331 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700332 }
333 }
John Reckd8c74522011-06-14 08:45:00 -0700334 mUi.updateTabs(mTabControl.getTabs());
Michael Kolb8233fac2010-10-26 16:08:53 -0700335 } else {
Michael Kolbc831b632011-05-11 09:30:34 -0700336 mTabControl.restoreState(icicle, currentTabId, restoreIncognitoTabs,
Patrick Scott7d50a932011-02-04 09:27:26 -0500337 mUi.needsRestoreAllTabs());
John Reck1cf4b792011-07-26 10:22:22 -0700338 List<Tab> tabs = mTabControl.getTabs();
339 ArrayList<Long> restoredTabs = new ArrayList<Long>(tabs.size());
340 for (Tab t : tabs) {
341 restoredTabs.add(t.getId());
342 }
343 BackgroundHandler.execute(new PruneThumbnails(mActivity, restoredTabs));
John Reck52be4782011-08-26 15:37:29 -0700344 if (tabs.size() == 0) {
345 openTabToHomePage();
346 }
John Reck1cf4b792011-07-26 10:22:22 -0700347 mUi.updateTabs(tabs);
Michael Kolb8233fac2010-10-26 16:08:53 -0700348 // TabControl.restoreState() will create a new tab even if
349 // restoring the state fails.
350 setActiveTab(mTabControl.getCurrentTab());
George Mount3636d0a2011-11-21 09:08:21 -0800351 // Intent is non-null when framework thinks the browser should be
352 // launching with a new intent (icicle is null).
353 if (intent != null) {
John Reck9dd4a412011-10-05 14:55:30 -0700354 mIntentHandler.onNewIntent(intent);
355 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700356 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700357 // Read JavaScript flags if it exists.
John Reck35e9dd62011-04-25 09:01:54 -0700358 String jsFlags = getSettings().getJsEngineFlags();
Michael Kolb8233fac2010-10-26 16:08:53 -0700359 if (jsFlags.trim().length() != 0) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000360 WebViewClassic.fromWebView(getCurrentWebView()).setJsFlags(jsFlags);
Michael Kolb8233fac2010-10-26 16:08:53 -0700361 }
George Mount3636d0a2011-11-21 09:08:21 -0800362 if (intent != null
363 && BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) {
Michael Kolb315d5022011-10-13 12:47:11 -0700364 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
John Reck439c9a52010-12-14 10:04:39 -0800365 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700366 }
367
John Reck1cf4b792011-07-26 10:22:22 -0700368 private static class PruneThumbnails implements Runnable {
369 private Context mContext;
370 private List<Long> mIds;
371
372 PruneThumbnails(Context context, List<Long> preserveIds) {
373 mContext = context.getApplicationContext();
374 mIds = preserveIds;
375 }
376
377 @Override
378 public void run() {
379 ContentResolver cr = mContext.getContentResolver();
380 if (mIds == null || mIds.size() == 0) {
381 cr.delete(Thumbnails.CONTENT_URI, null, null);
382 } else {
383 int length = mIds.size();
384 StringBuilder where = new StringBuilder();
385 where.append(Thumbnails._ID);
386 where.append(" not in (");
387 for (int i = 0; i < length; i++) {
388 where.append(mIds.get(i));
389 if (i < (length - 1)) {
390 where.append(",");
391 }
392 }
393 where.append(")");
394 cr.delete(Thumbnails.CONTENT_URI, where.toString(), null);
395 }
396 }
397
398 }
399
Michael Kolb1514bb72010-11-22 09:11:48 -0800400 @Override
401 public WebViewFactory getWebViewFactory() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700402 return mFactory;
403 }
404
405 @Override
Michael Kolba713ec82010-11-29 17:27:06 -0800406 public void onSetWebView(Tab tab, WebView view) {
407 mUi.onSetWebView(tab, view);
408 }
409
410 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800411 public void createSubWindow(Tab tab) {
412 endActionMode();
413 WebView mainView = tab.getWebView();
414 WebView subView = mFactory.createWebView((mainView == null)
415 ? false
416 : mainView.isPrivateBrowsingEnabled());
417 mUi.createSubWindow(tab, subView);
418 }
419
420 @Override
Michael Kolb14612442011-06-24 13:06:29 -0700421 public Context getContext() {
422 return mActivity;
423 }
424
425 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 public Activity getActivity() {
427 return mActivity;
428 }
429
430 void setUi(UI ui) {
431 mUi = ui;
432 }
433
434 BrowserSettings getSettings() {
435 return mSettings;
436 }
437
438 IntentHandler getIntentHandler() {
439 return mIntentHandler;
440 }
441
442 @Override
443 public UI getUi() {
444 return mUi;
445 }
446
447 int getMaxTabs() {
448 return mActivity.getResources().getInteger(R.integer.max_tabs);
449 }
450
451 @Override
452 public TabControl getTabControl() {
453 return mTabControl;
454 }
455
Michael Kolb1bf23132010-11-19 12:55:12 -0800456 @Override
457 public List<Tab> getTabs() {
458 return mTabControl.getTabs();
459 }
460
John Reckaf262e72011-07-25 13:55:44 -0700461 // Open the icon database.
462 private void openIconDatabase() {
463 // We have to call getInstance on the UI thread
464 final WebIconDatabase instance = WebIconDatabase.getInstance();
465 BackgroundHandler.execute(new Runnable() {
Ben Murdoch9446b932010-11-25 16:20:14 +0000466
John Reckaf262e72011-07-25 13:55:44 -0700467 @Override
468 public void run() {
469 instance.open(mActivity.getDir("icons", 0).getPath());
Michael Kolb8233fac2010-10-26 16:08:53 -0700470 }
John Reckaf262e72011-07-25 13:55:44 -0700471 });
Michael Kolb8233fac2010-10-26 16:08:53 -0700472 }
473
474 private void startHandler() {
475 mHandler = new Handler() {
476
477 @Override
478 public void handleMessage(Message msg) {
479 switch (msg.what) {
480 case OPEN_BOOKMARKS:
Michael Kolb315d5022011-10-13 12:47:11 -0700481 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
Michael Kolb8233fac2010-10-26 16:08:53 -0700482 break;
483 case FOCUS_NODE_HREF:
484 {
485 String url = (String) msg.getData().get("url");
486 String title = (String) msg.getData().get("title");
Cary Clark043c2d62010-12-15 11:19:39 -0500487 String src = (String) msg.getData().get("src");
488 if (url == "") url = src; // use image if no anchor
Michael Kolb8233fac2010-10-26 16:08:53 -0700489 if (TextUtils.isEmpty(url)) {
490 break;
491 }
492 HashMap focusNodeMap = (HashMap) msg.obj;
493 WebView view = (WebView) focusNodeMap.get("webview");
494 // Only apply the action if the top window did not change.
495 if (getCurrentTopWebView() != view) {
496 break;
497 }
498 switch (msg.arg1) {
499 case R.id.open_context_menu_id:
John Reck26b18322011-06-21 13:08:58 -0700500 loadUrlFromContext(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700501 break;
Cary Clark043c2d62010-12-15 11:19:39 -0500502 case R.id.view_image_context_menu_id:
John Reck26b18322011-06-21 13:08:58 -0700503 loadUrlFromContext(src);
Cary Clark043c2d62010-12-15 11:19:39 -0500504 break;
Leon Scroggins026f2542010-11-22 13:26:12 -0500505 case R.id.open_newtab_context_menu_id:
506 final Tab parent = mTabControl.getCurrentTab();
John Reck5949c662011-05-27 09:52:29 -0700507 openTab(url, parent,
508 !mSettings.openInBackground(), true);
Leon Scroggins026f2542010-11-22 13:26:12 -0500509 break;
Michael Kolb8233fac2010-10-26 16:08:53 -0700510 case R.id.copy_link_context_menu_id:
511 copy(url);
512 break;
513 case R.id.save_link_context_menu_id:
514 case R.id.download_context_menu_id:
Leon Scroggins63c02662010-11-18 15:16:27 -0500515 DownloadHandler.onDownloadStartNoStream(
Kristian Monsenbc5cc752011-03-02 13:14:03 +0000516 mActivity, url, null, null, null,
517 view.isPrivateBrowsingEnabled());
Michael Kolb8233fac2010-10-26 16:08:53 -0700518 break;
519 }
520 break;
521 }
522
523 case LOAD_URL:
John Reck26b18322011-06-21 13:08:58 -0700524 loadUrlFromContext((String) msg.obj);
Michael Kolb8233fac2010-10-26 16:08:53 -0700525 break;
526
527 case STOP_LOAD:
528 stopLoading();
529 break;
530
531 case RELEASE_WAKELOCK:
John Reckf57c0292011-07-21 18:15:39 -0700532 if (mWakeLock != null && mWakeLock.isHeld()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700533 mWakeLock.release();
534 // if we reach here, Browser should be still in the
535 // background loading after WAKELOCK_TIMEOUT (5-min).
536 // To avoid burning the battery, stop loading.
537 mTabControl.stopAllLoading();
538 }
539 break;
540
541 case UPDATE_BOOKMARK_THUMBNAIL:
John Reck34ef2672011-02-10 11:30:55 -0800542 Tab tab = (Tab) msg.obj;
543 if (tab != null) {
544 updateScreenshot(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700545 }
546 break;
547 }
548 }
549 };
550
551 }
552
John Reckef654f12011-07-12 16:42:08 -0700553 @Override
Martijn Coenenb2f93552011-06-14 10:48:35 +0200554 public Tab getCurrentTab() {
555 return mTabControl.getCurrentTab();
556 }
557
Michael Kolbba99c5d2010-11-29 14:57:41 -0800558 @Override
559 public void shareCurrentPage() {
560 shareCurrentPage(mTabControl.getCurrentTab());
561 }
562
563 private void shareCurrentPage(Tab tab) {
564 if (tab != null) {
Michael Kolbba99c5d2010-11-29 14:57:41 -0800565 sharePage(mActivity, tab.getTitle(),
566 tab.getUrl(), tab.getFavicon(),
567 createScreenshot(tab.getWebView(),
568 getDesiredThumbnailWidth(mActivity),
569 getDesiredThumbnailHeight(mActivity)));
570 }
571 }
572
Michael Kolb8233fac2010-10-26 16:08:53 -0700573 /**
574 * Share a page, providing the title, url, favicon, and a screenshot. Uses
575 * an {@link Intent} to launch the Activity chooser.
576 * @param c Context used to launch a new Activity.
577 * @param title Title of the page. Stored in the Intent with
578 * {@link Intent#EXTRA_SUBJECT}
579 * @param url URL of the page. Stored in the Intent with
580 * {@link Intent#EXTRA_TEXT}
581 * @param favicon Bitmap of the favicon for the page. Stored in the Intent
582 * with {@link Browser#EXTRA_SHARE_FAVICON}
583 * @param screenshot Bitmap of a screenshot of the page. Stored in the
584 * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT}
585 */
586 static final void sharePage(Context c, String title, String url,
587 Bitmap favicon, Bitmap screenshot) {
588 Intent send = new Intent(Intent.ACTION_SEND);
589 send.setType("text/plain");
590 send.putExtra(Intent.EXTRA_TEXT, url);
591 send.putExtra(Intent.EXTRA_SUBJECT, title);
592 send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon);
593 send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot);
594 try {
595 c.startActivity(Intent.createChooser(send, c.getString(
596 R.string.choosertitle_sharevia)));
597 } catch(android.content.ActivityNotFoundException ex) {
598 // if no app handles it, do nothing
599 }
600 }
601
602 private void copy(CharSequence text) {
603 ClipboardManager cm = (ClipboardManager) mActivity
604 .getSystemService(Context.CLIPBOARD_SERVICE);
605 cm.setText(text);
606 }
607
608 // lifecycle
609
610 protected void onConfgurationChanged(Configuration config) {
611 mConfigChanged = true;
Michael Kolb18f252f2012-03-06 13:36:20 -0800612 // update the menu in case of a locale change
613 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -0700614 if (mPageDialogsHandler != null) {
615 mPageDialogsHandler.onConfigurationChanged(config);
616 }
617 mUi.onConfigurationChanged(config);
618 }
619
620 @Override
621 public void handleNewIntent(Intent intent) {
Michael Kolb59e232c2011-08-18 17:19:53 -0700622 if (!mUi.isWebShowing()) {
623 mUi.showWeb(false);
624 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700625 mIntentHandler.onNewIntent(intent);
626 }
627
628 protected void onPause() {
Michael Kolb11fe02d2011-02-02 09:52:16 -0800629 if (mUi.isCustomViewShowing()) {
630 hideCustomView();
631 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700632 if (mActivityPaused) {
633 Log.e(LOGTAG, "BrowserActivity is already paused.");
634 return;
635 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700636 mActivityPaused = true;
Michael Kolb70976932010-11-30 11:34:01 -0800637 Tab tab = mTabControl.getCurrentTab();
638 if (tab != null) {
639 tab.pause();
640 if (!pauseWebViewTimers(tab)) {
John Reckf57c0292011-07-21 18:15:39 -0700641 if (mWakeLock == null) {
642 PowerManager pm = (PowerManager) mActivity
643 .getSystemService(Context.POWER_SERVICE);
644 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser");
645 }
Michael Kolb70976932010-11-30 11:34:01 -0800646 mWakeLock.acquire();
647 mHandler.sendMessageDelayed(mHandler
648 .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT);
649 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700650 }
651 mUi.onPause();
652 mNetworkHandler.onPause();
653
654 WebView.disablePlatformNotifications();
Ben Murdoch015e1e32011-09-01 23:45:31 +0100655 NfcHandler.unregister(mActivity);
John Reckd7dd9b22011-08-30 09:18:29 -0700656 if (sThumbnailBitmap != null) {
657 sThumbnailBitmap.recycle();
658 sThumbnailBitmap = null;
659 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700660 }
661
John Reck1cf4b792011-07-26 10:22:22 -0700662 void onSaveInstanceState(Bundle outState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700663 // Save all the tabs
George Mount3636d0a2011-11-21 09:08:21 -0800664 Bundle saveState = createSaveState();
665
666 // crash recovery manages all save & restore state
667 mCrashRecoveryHandler.writeState(saveState);
668 mSettings.setLastRunPaused(true);
669 }
670
671 /**
672 * Save the current state to outState. Does not write the state to
673 * disk.
674 * @return Bundle containing the current state of all tabs.
675 */
676 /* package */ Bundle createSaveState() {
677 Bundle saveState = new Bundle();
678 mTabControl.saveState(saveState);
679 if (!saveState.isEmpty()) {
John Reck24f18262011-06-17 14:47:20 -0700680 // Save time so that we know how old incognito tabs (if any) are.
George Mount3636d0a2011-11-21 09:08:21 -0800681 saveState.putSerializable("lastActiveDate", Calendar.getInstance());
John Reck24f18262011-06-17 14:47:20 -0700682 }
George Mount3636d0a2011-11-21 09:08:21 -0800683 return saveState;
Michael Kolb8233fac2010-10-26 16:08:53 -0700684 }
685
686 void onResume() {
687 if (!mActivityPaused) {
688 Log.e(LOGTAG, "BrowserActivity is already resumed.");
689 return;
690 }
George Mount3636d0a2011-11-21 09:08:21 -0800691 mSettings.setLastRunPaused(false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700692 mActivityPaused = false;
Michael Kolb70976932010-11-30 11:34:01 -0800693 Tab current = mTabControl.getCurrentTab();
694 if (current != null) {
695 current.resume();
696 resumeWebViewTimers(current);
697 }
John Reckf57c0292011-07-21 18:15:39 -0700698 releaseWakeLock();
Martijn Coenenb2f93552011-06-14 10:48:35 +0200699
Michael Kolb8233fac2010-10-26 16:08:53 -0700700 mUi.onResume();
701 mNetworkHandler.onResume();
702 WebView.enablePlatformNotifications();
Ben Murdoch015e1e32011-09-01 23:45:31 +0100703 NfcHandler.register(mActivity, this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700704 }
705
John Reckf57c0292011-07-21 18:15:39 -0700706 private void releaseWakeLock() {
707 if (mWakeLock != null && mWakeLock.isHeld()) {
708 mHandler.removeMessages(RELEASE_WAKELOCK);
709 mWakeLock.release();
710 }
711 }
712
Michael Kolb70976932010-11-30 11:34:01 -0800713 /**
Michael Kolbba99c5d2010-11-29 14:57:41 -0800714 * resume all WebView timers using the WebView instance of the given tab
Michael Kolb70976932010-11-30 11:34:01 -0800715 * @param tab guaranteed non-null
716 */
717 private void resumeWebViewTimers(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700718 boolean inLoad = tab.inPageLoad();
719 if ((!mActivityPaused && !inLoad) || (mActivityPaused && inLoad)) {
720 CookieSyncManager.getInstance().startSync();
721 WebView w = tab.getWebView();
Mathew Inwoode1dbb952011-07-08 17:27:38 +0100722 WebViewTimersControl.getInstance().onBrowserActivityResume(w);
Michael Kolb8233fac2010-10-26 16:08:53 -0700723 }
724 }
725
Michael Kolb70976932010-11-30 11:34:01 -0800726 /**
727 * Pause all WebView timers using the WebView of the given tab
728 * @param tab
729 * @return true if the timers are paused or tab is null
730 */
731 private boolean pauseWebViewTimers(Tab tab) {
732 if (tab == null) {
733 return true;
734 } else if (!tab.inPageLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 CookieSyncManager.getInstance().stopSync();
Mathew Inwoode1dbb952011-07-08 17:27:38 +0100736 WebViewTimersControl.getInstance().onBrowserActivityPause(getCurrentWebView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700737 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700738 }
Michael Kolb70976932010-11-30 11:34:01 -0800739 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700740 }
741
742 void onDestroy() {
John Reck38b4bf52011-02-22 14:39:34 -0800743 if (mUploadHandler != null && !mUploadHandler.handled()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700744 mUploadHandler.onResult(Activity.RESULT_CANCELED, null);
745 mUploadHandler = null;
746 }
747 if (mTabControl == null) return;
748 mUi.onDestroy();
749 // Remove the current tab and sub window
750 Tab t = mTabControl.getCurrentTab();
751 if (t != null) {
752 dismissSubWindow(t);
753 removeTab(t);
754 }
Leon Scroggins1961ed22010-12-07 15:22:21 -0500755 mActivity.getContentResolver().unregisterContentObserver(mBookmarksObserver);
Michael Kolb8233fac2010-10-26 16:08:53 -0700756 // Destroy all the tabs
757 mTabControl.destroy();
758 WebIconDatabase.getInstance().close();
759 // Stop watching the default geolocation permissions
760 mSystemAllowGeolocationOrigins.stop();
761 mSystemAllowGeolocationOrigins = null;
762 }
763
764 protected boolean isActivityPaused() {
765 return mActivityPaused;
766 }
767
768 protected void onLowMemory() {
769 mTabControl.freeMemory();
770 }
771
772 @Override
773 public boolean shouldShowErrorConsole() {
774 return mShouldShowErrorConsole;
775 }
776
777 protected void setShouldShowErrorConsole(boolean show) {
778 if (show == mShouldShowErrorConsole) {
779 // Nothing to do.
780 return;
781 }
782 mShouldShowErrorConsole = show;
783 Tab t = mTabControl.getCurrentTab();
784 if (t == null) {
785 // There is no current tab so we cannot toggle the error console
786 return;
787 }
788 mUi.setShouldShowErrorConsole(t, show);
789 }
790
791 @Override
792 public void stopLoading() {
793 mLoadStopped = true;
794 Tab tab = mTabControl.getCurrentTab();
Michael Kolb8233fac2010-10-26 16:08:53 -0700795 WebView w = getCurrentTopWebView();
Michael Kolb778a4882012-04-12 15:27:28 -0700796 if (w != null) {
797 w.stopLoading();
798 mUi.onPageStopped(tab);
799 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700800 }
801
802 boolean didUserStopLoading() {
803 return mLoadStopped;
804 }
805
806 // WebViewController
807
808 @Override
John Reck324d4402011-01-11 16:56:42 -0800809 public void onPageStarted(Tab tab, WebView view, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700810
811 // We've started to load a new page. If there was a pending message
812 // to save a screenshot then we will now take the new page and save
813 // an incorrect screenshot. Therefore, remove any pending thumbnail
814 // messages from the queue.
815 mHandler.removeMessages(Controller.UPDATE_BOOKMARK_THUMBNAIL,
John Reck34ef2672011-02-10 11:30:55 -0800816 tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700817
818 // reset sync timer to avoid sync starts during loading a page
819 CookieSyncManager.getInstance().resetSync();
820
821 if (!mNetworkHandler.isNetworkUp()) {
822 view.setNetworkAvailable(false);
823 }
824
825 // when BrowserActivity just starts, onPageStarted may be called before
826 // onResume as it is triggered from onCreate. Call resumeWebViewTimers
827 // to start the timer. As we won't switch tabs while an activity is in
828 // pause state, we can ensure calling resume and pause in pair.
829 if (mActivityPaused) {
Michael Kolb70976932010-11-30 11:34:01 -0800830 resumeWebViewTimers(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700831 }
832 mLoadStopped = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700833 endActionMode();
834
John Reck30c714c2010-12-16 17:30:34 -0800835 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700836
John Reck324d4402011-01-11 16:56:42 -0800837 String url = tab.getUrl();
Michael Kolb8233fac2010-10-26 16:08:53 -0700838 // update the bookmark database for favicon
839 maybeUpdateFavicon(tab, null, url, favicon);
840
841 Performance.tracePageStart(url);
842
843 // Performance probe
844 if (false) {
845 Performance.onPageStarted();
846 }
847
848 }
849
850 @Override
John Reck324d4402011-01-11 16:56:42 -0800851 public void onPageFinished(Tab tab) {
John Reck30c714c2010-12-16 17:30:34 -0800852 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700853 // pause the WebView timer and release the wake lock if it is finished
854 // while BrowserActivity is in pause state.
Michael Kolb70976932010-11-30 11:34:01 -0800855 if (mActivityPaused && pauseWebViewTimers(tab)) {
John Reckf57c0292011-07-21 18:15:39 -0700856 releaseWakeLock();
Michael Kolb8233fac2010-10-26 16:08:53 -0700857 }
Martijn Coenenb2f93552011-06-14 10:48:35 +0200858
Michael Kolb8233fac2010-10-26 16:08:53 -0700859 // Performance probe
860 if (false) {
John Reck324d4402011-01-11 16:56:42 -0800861 Performance.onPageFinished(tab.getUrl());
Michael Kolb8233fac2010-10-26 16:08:53 -0700862 }
863
864 Performance.tracePageFinished();
865 }
866
867 @Override
John Reck30c714c2010-12-16 17:30:34 -0800868 public void onProgressChanged(Tab tab) {
John Reck6c2e2f32011-08-22 13:41:23 -0700869 mCrashRecoveryHandler.backupState();
John Reck30c714c2010-12-16 17:30:34 -0800870 int newProgress = tab.getLoadProgress();
Michael Kolb8233fac2010-10-26 16:08:53 -0700871
872 if (newProgress == 100) {
873 CookieSyncManager.getInstance().sync();
874 // onProgressChanged() may continue to be called after the main
875 // frame has finished loading, as any remaining sub frames continue
876 // to load. We'll only get called once though with newProgress as
877 // 100 when everything is loaded. (onPageFinished is called once
878 // when the main frame completes loading regardless of the state of
879 // any sub frames so calls to onProgressChanges may continue after
880 // onPageFinished has executed)
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800881 if (tab.inPageLoad()) {
882 updateInLoadMenuItems(mCachedMenu, tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700883 }
John Reckd9862372012-02-21 15:04:50 -0800884 if (!tab.isPrivateBrowsingEnabled()
885 && !TextUtils.isEmpty(tab.getUrl())
886 && !tab.isSnapshot()) {
887 // Only update the bookmark screenshot if the user did not
888 // cancel the load early and there is not already
889 // a pending update for the tab.
890 if (tab.inForeground() && !didUserStopLoading()
891 || !tab.inForeground()) {
892 if (!mHandler.hasMessages(UPDATE_BOOKMARK_THUMBNAIL, tab)) {
893 mHandler.sendMessageDelayed(mHandler.obtainMessage(
894 UPDATE_BOOKMARK_THUMBNAIL, 0, 0, tab),
895 500);
896 }
897 }
898 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700899 } else {
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800900 if (!tab.inPageLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700901 // onPageFinished may have already been called but a subframe is
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800902 // still loading
903 // updating the progress and
Michael Kolb8233fac2010-10-26 16:08:53 -0700904 // update the menu items.
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800905 updateInLoadMenuItems(mCachedMenu, tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700906 }
907 }
John Reck30c714c2010-12-16 17:30:34 -0800908 mUi.onProgressChanged(tab);
909 }
910
911 @Override
Steve Block2466eff2011-10-03 15:33:09 +0100912 public void onUpdatedSecurityState(Tab tab) {
John Reck30c714c2010-12-16 17:30:34 -0800913 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700914 }
915
916 @Override
917 public void onReceivedTitle(Tab tab, final String title) {
John Reck30c714c2010-12-16 17:30:34 -0800918 mUi.onTabDataChanged(tab);
John Reck49a603c2011-03-03 09:33:05 -0800919 final String pageUrl = tab.getOriginalUrl();
John Reck324d4402011-01-11 16:56:42 -0800920 if (TextUtils.isEmpty(pageUrl) || pageUrl.length()
Michael Kolb8233fac2010-10-26 16:08:53 -0700921 >= SQLiteDatabase.SQLITE_MAX_LIKE_PATTERN_LENGTH) {
922 return;
923 }
924 // Update the title in the history database if not in private browsing mode
925 if (!tab.isPrivateBrowsingEnabled()) {
John Reckf57c0292011-07-21 18:15:39 -0700926 DataController.getInstance(mActivity).updateHistoryTitle(pageUrl, title);
Michael Kolb8233fac2010-10-26 16:08:53 -0700927 }
928 }
929
930 @Override
931 public void onFavicon(Tab tab, WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -0800932 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700933 maybeUpdateFavicon(tab, view.getOriginalUrl(), view.getUrl(), icon);
934 }
935
936 @Override
Michael Kolb18eb3772010-12-10 14:29:51 -0800937 public boolean shouldOverrideUrlLoading(Tab tab, WebView view, String url) {
938 return mUrlHandler.shouldOverrideUrlLoading(tab, view, url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700939 }
940
941 @Override
942 public boolean shouldOverrideKeyEvent(KeyEvent event) {
943 if (mMenuIsDown) {
944 // only check shortcut key when MENU is held
945 return mActivity.getWindow().isShortcutKey(event.getKeyCode(),
946 event);
947 } else {
948 return false;
949 }
950 }
951
952 @Override
John Reck997b1b72012-04-19 18:08:25 -0700953 public boolean onUnhandledKeyEvent(KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700954 if (!isActivityPaused()) {
955 if (event.getAction() == KeyEvent.ACTION_DOWN) {
John Reck997b1b72012-04-19 18:08:25 -0700956 return mActivity.onKeyDown(event.getKeyCode(), event);
Michael Kolb8233fac2010-10-26 16:08:53 -0700957 } else {
John Reck997b1b72012-04-19 18:08:25 -0700958 return mActivity.onKeyUp(event.getKeyCode(), event);
Michael Kolb8233fac2010-10-26 16:08:53 -0700959 }
960 }
John Reck997b1b72012-04-19 18:08:25 -0700961 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700962 }
963
964 @Override
John Reck324d4402011-01-11 16:56:42 -0800965 public void doUpdateVisitedHistory(Tab tab, boolean isReload) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700966 // Don't save anything in private browsing mode
967 if (tab.isPrivateBrowsingEnabled()) return;
John Reck49a603c2011-03-03 09:33:05 -0800968 String url = tab.getOriginalUrl();
Michael Kolb8233fac2010-10-26 16:08:53 -0700969
John Reck324d4402011-01-11 16:56:42 -0800970 if (TextUtils.isEmpty(url)
971 || url.regionMatches(true, 0, "about:", 0, 6)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700972 return;
973 }
John Reckf57c0292011-07-21 18:15:39 -0700974 DataController.getInstance(mActivity).updateVisitedHistory(url);
John Reck6c2e2f32011-08-22 13:41:23 -0700975 mCrashRecoveryHandler.backupState();
Michael Kolb8233fac2010-10-26 16:08:53 -0700976 }
977
978 @Override
979 public void getVisitedHistory(final ValueCallback<String[]> callback) {
980 AsyncTask<Void, Void, String[]> task =
981 new AsyncTask<Void, Void, String[]>() {
982 @Override
983 public String[] doInBackground(Void... unused) {
984 return Browser.getVisitedHistory(mActivity.getContentResolver());
985 }
986 @Override
987 public void onPostExecute(String[] result) {
988 callback.onReceiveValue(result);
989 }
990 };
991 task.execute();
992 }
993
994 @Override
995 public void onReceivedHttpAuthRequest(Tab tab, WebView view,
996 final HttpAuthHandler handler, final String host,
997 final String realm) {
998 String username = null;
999 String password = null;
1000
1001 boolean reuseHttpAuthUsernamePassword
1002 = handler.useHttpAuthUsernamePassword();
1003
1004 if (reuseHttpAuthUsernamePassword && view != null) {
1005 String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
1006 if (credentials != null && credentials.length == 2) {
1007 username = credentials[0];
1008 password = credentials[1];
1009 }
1010 }
1011
1012 if (username != null && password != null) {
1013 handler.proceed(username, password);
1014 } else {
Ben Murdochfdd37112011-08-05 15:48:14 +01001015 if (tab.inForeground() && !handler.suppressDialog()) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001016 mPageDialogsHandler.showHttpAuthentication(tab, handler, host, realm);
1017 } else {
1018 handler.cancel();
1019 }
1020 }
1021 }
1022
1023 @Override
1024 public void onDownloadStart(Tab tab, String url, String userAgent,
1025 String contentDisposition, String mimetype, long contentLength) {
Kristian Monsenbc5cc752011-03-02 13:14:03 +00001026 WebView w = tab.getWebView();
Leon Scroggins63c02662010-11-18 15:16:27 -05001027 DownloadHandler.onDownloadStart(mActivity, url, userAgent,
Kristian Monsenbc5cc752011-03-02 13:14:03 +00001028 contentDisposition, mimetype, w.isPrivateBrowsingEnabled());
1029 if (w.copyBackForwardList().getSize() == 0) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001030 // This Tab was opened for the sole purpose of downloading a
1031 // file. Remove it.
1032 if (tab == mTabControl.getCurrentTab()) {
1033 // In this case, the Tab is still on top.
1034 goBackOnePageOrQuit();
1035 } else {
1036 // In this case, it is not.
1037 closeTab(tab);
1038 }
1039 }
1040 }
1041
1042 @Override
1043 public Bitmap getDefaultVideoPoster() {
1044 return mUi.getDefaultVideoPoster();
1045 }
1046
1047 @Override
1048 public View getVideoLoadingProgressView() {
1049 return mUi.getVideoLoadingProgressView();
1050 }
1051
1052 @Override
1053 public void showSslCertificateOnError(WebView view, SslErrorHandler handler,
1054 SslError error) {
1055 mPageDialogsHandler.showSSLCertificateOnError(view, handler, error);
1056 }
1057
Patrick Scott92066772011-03-10 08:46:27 -05001058 @Override
1059 public void showAutoLogin(Tab tab) {
1060 assert tab.inForeground();
1061 // Update the title bar to show the auto-login request.
1062 mUi.showAutoLogin(tab);
1063 }
1064
1065 @Override
1066 public void hideAutoLogin(Tab tab) {
1067 assert tab.inForeground();
1068 mUi.hideAutoLogin(tab);
1069 }
1070
Michael Kolb8233fac2010-10-26 16:08:53 -07001071 // helper method
1072
1073 /*
1074 * Update the favorites icon if the private browsing isn't enabled and the
1075 * icon is valid.
1076 */
1077 private void maybeUpdateFavicon(Tab tab, final String originalUrl,
1078 final String url, Bitmap favicon) {
1079 if (favicon == null) {
1080 return;
1081 }
1082 if (!tab.isPrivateBrowsingEnabled()) {
1083 Bookmarks.updateFavicon(mActivity
1084 .getContentResolver(), originalUrl, url, favicon);
1085 }
1086 }
1087
Leon Scroggins4cd97792010-12-03 15:31:56 -05001088 @Override
1089 public void bookmarkedStatusHasChanged(Tab tab) {
John Recke969cc52010-12-21 17:24:43 -08001090 // TODO: Switch to using onTabDataChanged after b/3262950 is fixed
Leon Scroggins4cd97792010-12-03 15:31:56 -05001091 mUi.bookmarkedStatusHasChanged(tab);
1092 }
1093
Michael Kolb8233fac2010-10-26 16:08:53 -07001094 // end WebViewController
1095
1096 protected void pageUp() {
1097 getCurrentTopWebView().pageUp(false);
1098 }
1099
1100 protected void pageDown() {
1101 getCurrentTopWebView().pageDown(false);
1102 }
1103
1104 // callback from phone title bar
1105 public void editUrl() {
1106 if (mOptionsMenuOpen) mActivity.closeOptionsMenu();
Michael Kolb1f9b3562012-04-24 14:38:34 -07001107 mUi.editUrl(false, true);
Michael Kolb8233fac2010-10-26 16:08:53 -07001108 }
1109
Michael Kolbcfa3af52010-12-14 10:36:11 -08001110 public void startVoiceSearch() {
1111 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
1112 intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
1113 RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
1114 intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
1115 mActivity.getComponentName().flattenToString());
1116 intent.putExtra(SEND_APP_ID_EXTRA, false);
Michael Kolb17c4eba2011-01-10 13:10:07 -08001117 intent.putExtra(RecognizerIntent.EXTRA_WEB_SEARCH_ONLY, true);
Michael Kolbcfa3af52010-12-14 10:36:11 -08001118 mActivity.startActivity(intent);
1119 }
1120
Michael Kolb11d19782011-03-20 10:17:40 -07001121 @Override
1122 public void activateVoiceSearchMode(String title, List<String> results) {
1123 mUi.showVoiceTitleBar(title, results);
Michael Kolb8233fac2010-10-26 16:08:53 -07001124 }
1125
1126 public void revertVoiceSearchMode(Tab tab) {
1127 mUi.revertVoiceTitleBar(tab);
1128 }
1129
Michael Kolb736990c2011-03-20 10:01:20 -07001130 public boolean supportsVoiceSearch() {
John Reck35e9dd62011-04-25 09:01:54 -07001131 SearchEngine searchEngine = getSettings().getSearchEngine();
Michael Kolb736990c2011-03-20 10:01:20 -07001132 return (searchEngine != null && searchEngine.supportsVoiceSearch());
1133 }
1134
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001135 public void showCustomView(Tab tab, View view, int requestedOrientation,
Michael Kolb8233fac2010-10-26 16:08:53 -07001136 WebChromeClient.CustomViewCallback callback) {
1137 if (tab.inForeground()) {
1138 if (mUi.isCustomViewShowing()) {
1139 callback.onCustomViewHidden();
1140 return;
1141 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001142 mUi.showCustomView(view, requestedOrientation, callback);
Michael Kolb8233fac2010-10-26 16:08:53 -07001143 // Save the menu state and set it to empty while the custom
1144 // view is showing.
1145 mOldMenuState = mMenuState;
1146 mMenuState = EMPTY_MENU;
John Reckd73c5a22010-12-22 10:22:50 -08001147 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -07001148 }
1149 }
1150
1151 @Override
1152 public void hideCustomView() {
1153 if (mUi.isCustomViewShowing()) {
1154 mUi.onHideCustomView();
1155 // Reset the old menu state.
1156 mMenuState = mOldMenuState;
1157 mOldMenuState = EMPTY_MENU;
John Reckd73c5a22010-12-22 10:22:50 -08001158 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -07001159 }
1160 }
1161
1162 protected void onActivityResult(int requestCode, int resultCode,
1163 Intent intent) {
1164 if (getCurrentTopWebView() == null) return;
1165 switch (requestCode) {
1166 case PREFERENCES_PAGE:
1167 if (resultCode == Activity.RESULT_OK && intent != null) {
1168 String action = intent.getStringExtra(Intent.EXTRA_TEXT);
John Reck35e9dd62011-04-25 09:01:54 -07001169 if (PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY.equals(action)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001170 mTabControl.removeParentChildRelationShips();
1171 }
1172 }
1173 break;
1174 case FILE_SELECTED:
Ben Murdoch51f6a2f2011-02-21 12:27:07 +00001175 // Chose a file from the file picker.
John Reck9dfcdb12011-02-22 16:40:46 -08001176 if (null == mUploadHandler) break;
Michael Kolb8233fac2010-10-26 16:08:53 -07001177 mUploadHandler.onResult(resultCode, intent);
Michael Kolb8233fac2010-10-26 16:08:53 -07001178 break;
Ben Murdoch8029a772010-11-16 11:58:21 +00001179 case AUTOFILL_SETUP:
1180 // Determine whether a profile was actually set up or not
1181 // and if so, send the message back to the WebTextView to
1182 // fill the form with the new profile.
1183 if (getSettings().getAutoFillProfile() != null) {
1184 mAutoFillSetupMessage.sendToTarget();
1185 mAutoFillSetupMessage = null;
1186 }
1187 break;
John Reckd3e4d5b2011-07-13 15:48:43 -07001188 case COMBO_VIEW:
1189 if (intent == null || resultCode != Activity.RESULT_OK) {
1190 break;
1191 }
John Reck3ba45532011-08-11 16:26:53 -07001192 mUi.showWeb(false);
John Reckd3e4d5b2011-07-13 15:48:43 -07001193 if (Intent.ACTION_VIEW.equals(intent.getAction())) {
1194 Tab t = getCurrentTab();
1195 Uri uri = intent.getData();
1196 loadUrl(t, uri.toString());
1197 } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_ALL)) {
1198 String[] urls = intent.getStringArrayExtra(
1199 ComboViewActivity.EXTRA_OPEN_ALL);
1200 Tab parent = getCurrentTab();
1201 for (String url : urls) {
1202 parent = openTab(url, parent,
1203 !mSettings.openInBackground(), true);
1204 }
1205 } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_SNAPSHOT)) {
1206 long id = intent.getLongExtra(
1207 ComboViewActivity.EXTRA_OPEN_SNAPSHOT, -1);
1208 if (id >= 0) {
1209 createNewSnapshotTab(id, true);
1210 }
1211 }
1212 break;
Michael Kolb8233fac2010-10-26 16:08:53 -07001213 default:
1214 break;
1215 }
1216 getCurrentTopWebView().requestFocus();
1217 }
1218
1219 /**
1220 * Open the Go page.
1221 * @param startWithHistory If true, open starting on the history tab.
1222 * Otherwise, start with the bookmarks tab.
1223 */
1224 @Override
Michael Kolb315d5022011-10-13 12:47:11 -07001225 public void bookmarksOrHistoryPicker(ComboViews startView) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001226 if (mTabControl.getCurrentWebView() == null) {
1227 return;
1228 }
Michael Kolbbd3dd942011-01-12 11:09:38 -08001229 // clear action mode
1230 if (isInCustomActionMode()) {
1231 endActionMode();
1232 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001233 Bundle extras = new Bundle();
1234 // Disable opening in a new window if we have maxed out the windows
1235 extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW,
1236 !mTabControl.canCreateNewTab());
Michael Kolb315d5022011-10-13 12:47:11 -07001237 mUi.showComboView(startView, extras);
Michael Kolb8233fac2010-10-26 16:08:53 -07001238 }
1239
1240 // combo view callbacks
1241
Michael Kolb8233fac2010-10-26 16:08:53 -07001242 // key handling
1243 protected void onBackKey() {
1244 if (!mUi.onBackKey()) {
1245 WebView subwindow = mTabControl.getCurrentSubWindow();
1246 if (subwindow != null) {
1247 if (subwindow.canGoBack()) {
1248 subwindow.goBack();
1249 } else {
1250 dismissSubWindow(mTabControl.getCurrentTab());
1251 }
1252 } else {
1253 goBackOnePageOrQuit();
1254 }
1255 }
1256 }
1257
Michael Kolb4bd767d2011-05-27 11:33:55 -07001258 protected boolean onMenuKey() {
1259 return mUi.onMenuKey();
Michael Kolb2814a362011-05-19 15:49:41 -07001260 }
1261
Michael Kolb8233fac2010-10-26 16:08:53 -07001262 // menu handling and state
1263 // TODO: maybe put into separate handler
1264
1265 protected boolean onCreateOptionsMenu(Menu menu) {
John Reckd73c5a22010-12-22 10:22:50 -08001266 if (mMenuState == EMPTY_MENU) {
1267 return false;
1268 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001269 MenuInflater inflater = mActivity.getMenuInflater();
1270 inflater.inflate(R.menu.browser, menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001271 return true;
1272 }
1273
1274 protected void onCreateContextMenu(ContextMenu menu, View v,
1275 ContextMenuInfo menuInfo) {
John Reck0f602f32011-07-07 15:38:43 -07001276 if (v instanceof TitleBar) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001277 return;
1278 }
1279 if (!(v instanceof WebView)) {
1280 return;
1281 }
Leon Scroggins026f2542010-11-22 13:26:12 -05001282 final WebView webview = (WebView) v;
Michael Kolb8233fac2010-10-26 16:08:53 -07001283 WebView.HitTestResult result = webview.getHitTestResult();
1284 if (result == null) {
1285 return;
1286 }
1287
1288 int type = result.getType();
1289 if (type == WebView.HitTestResult.UNKNOWN_TYPE) {
1290 Log.w(LOGTAG,
1291 "We should not show context menu when nothing is touched");
1292 return;
1293 }
1294 if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
1295 // let TextView handles context menu
1296 return;
1297 }
1298
1299 // Note, http://b/issue?id=1106666 is requesting that
1300 // an inflated menu can be used again. This is not available
1301 // yet, so inflate each time (yuk!)
1302 MenuInflater inflater = mActivity.getMenuInflater();
1303 inflater.inflate(R.menu.browsercontext, menu);
1304
1305 // Show the correct menu group
1306 final String extra = result.getExtra();
Michael Kolbc159c1a2011-12-15 16:06:38 -08001307 if (extra == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -07001308 menu.setGroupVisible(R.id.PHONE_MENU,
1309 type == WebView.HitTestResult.PHONE_TYPE);
1310 menu.setGroupVisible(R.id.EMAIL_MENU,
1311 type == WebView.HitTestResult.EMAIL_TYPE);
1312 menu.setGroupVisible(R.id.GEO_MENU,
1313 type == WebView.HitTestResult.GEO_TYPE);
1314 menu.setGroupVisible(R.id.IMAGE_MENU,
1315 type == WebView.HitTestResult.IMAGE_TYPE
1316 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1317 menu.setGroupVisible(R.id.ANCHOR_MENU,
1318 type == WebView.HitTestResult.SRC_ANCHOR_TYPE
1319 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
Cary Clark8974d282010-11-22 10:46:05 -05001320 boolean hitText = type == WebView.HitTestResult.SRC_ANCHOR_TYPE
1321 || type == WebView.HitTestResult.PHONE_TYPE
1322 || type == WebView.HitTestResult.EMAIL_TYPE
1323 || type == WebView.HitTestResult.GEO_TYPE;
1324 menu.setGroupVisible(R.id.SELECT_TEXT_MENU, hitText);
1325 if (hitText) {
1326 menu.findItem(R.id.select_text_menu_id)
1327 .setOnMenuItemClickListener(new SelectText(webview));
1328 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001329 // Setup custom handling depending on the type
1330 switch (type) {
1331 case WebView.HitTestResult.PHONE_TYPE:
1332 menu.setHeaderTitle(Uri.decode(extra));
1333 menu.findItem(R.id.dial_context_menu_id).setIntent(
1334 new Intent(Intent.ACTION_VIEW, Uri
1335 .parse(WebView.SCHEME_TEL + extra)));
1336 Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1337 addIntent.putExtra(Insert.PHONE, Uri.decode(extra));
1338 addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
1339 menu.findItem(R.id.add_contact_context_menu_id).setIntent(
1340 addIntent);
1341 menu.findItem(R.id.copy_phone_context_menu_id)
1342 .setOnMenuItemClickListener(
1343 new Copy(extra));
1344 break;
1345
1346 case WebView.HitTestResult.EMAIL_TYPE:
1347 menu.setHeaderTitle(extra);
1348 menu.findItem(R.id.email_context_menu_id).setIntent(
1349 new Intent(Intent.ACTION_VIEW, Uri
1350 .parse(WebView.SCHEME_MAILTO + extra)));
1351 menu.findItem(R.id.copy_mail_context_menu_id)
1352 .setOnMenuItemClickListener(
1353 new Copy(extra));
1354 break;
1355
1356 case WebView.HitTestResult.GEO_TYPE:
1357 menu.setHeaderTitle(extra);
1358 menu.findItem(R.id.map_context_menu_id).setIntent(
1359 new Intent(Intent.ACTION_VIEW, Uri
1360 .parse(WebView.SCHEME_GEO
1361 + URLEncoder.encode(extra))));
1362 menu.findItem(R.id.copy_geo_context_menu_id)
1363 .setOnMenuItemClickListener(
1364 new Copy(extra));
1365 break;
1366
1367 case WebView.HitTestResult.SRC_ANCHOR_TYPE:
1368 case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
Michael Kolb4c537ce2011-01-13 15:19:33 -08001369 menu.setHeaderTitle(extra);
Michael Kolb8233fac2010-10-26 16:08:53 -07001370 // decide whether to show the open link in new tab option
1371 boolean showNewTab = mTabControl.canCreateNewTab();
1372 MenuItem newTabItem
1373 = menu.findItem(R.id.open_newtab_context_menu_id);
John Reck35e9dd62011-04-25 09:01:54 -07001374 newTabItem.setTitle(getSettings().openInBackground()
Michael Kolb2dd65c82011-01-14 11:07:38 -08001375 ? R.string.contextmenu_openlink_newwindow_background
1376 : R.string.contextmenu_openlink_newwindow);
Michael Kolb8233fac2010-10-26 16:08:53 -07001377 newTabItem.setVisible(showNewTab);
1378 if (showNewTab) {
Leon Scroggins026f2542010-11-22 13:26:12 -05001379 if (WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE == type) {
1380 newTabItem.setOnMenuItemClickListener(
1381 new MenuItem.OnMenuItemClickListener() {
1382 @Override
1383 public boolean onMenuItemClick(MenuItem item) {
1384 final HashMap<String, WebView> hrefMap =
1385 new HashMap<String, WebView>();
1386 hrefMap.put("webview", webview);
1387 final Message msg = mHandler.obtainMessage(
1388 FOCUS_NODE_HREF,
1389 R.id.open_newtab_context_menu_id,
1390 0, hrefMap);
1391 webview.requestFocusNodeHref(msg);
1392 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -07001393 }
Leon Scroggins026f2542010-11-22 13:26:12 -05001394 });
1395 } else {
1396 newTabItem.setOnMenuItemClickListener(
1397 new MenuItem.OnMenuItemClickListener() {
1398 @Override
1399 public boolean onMenuItemClick(MenuItem item) {
1400 final Tab parent = mTabControl.getCurrentTab();
John Reck5949c662011-05-27 09:52:29 -07001401 openTab(extra, parent,
1402 !mSettings.openInBackground(),
1403 true);
Leon Scroggins026f2542010-11-22 13:26:12 -05001404 return true;
1405 }
1406 });
1407 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001408 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001409 if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
1410 break;
1411 }
1412 // otherwise fall through to handle image part
1413 case WebView.HitTestResult.IMAGE_TYPE:
Victoria Lease5987b802012-03-12 13:05:23 -07001414 MenuItem shareItem = menu.findItem(R.id.share_link_context_menu_id);
1415 shareItem.setVisible(type == WebView.HitTestResult.IMAGE_TYPE);
Michael Kolb8233fac2010-10-26 16:08:53 -07001416 if (type == WebView.HitTestResult.IMAGE_TYPE) {
1417 menu.setHeaderTitle(extra);
Victoria Lease5987b802012-03-12 13:05:23 -07001418 shareItem.setOnMenuItemClickListener(
1419 new MenuItem.OnMenuItemClickListener() {
1420 @Override
1421 public boolean onMenuItemClick(MenuItem item) {
1422 sharePage(mActivity, null, extra, null,
1423 null);
1424 return true;
1425 }
1426 }
1427 );
Michael Kolb8233fac2010-10-26 16:08:53 -07001428 }
Michael Kolb3639c4c2011-09-28 15:36:40 -07001429 menu.findItem(R.id.view_image_context_menu_id)
1430 .setOnMenuItemClickListener(new OnMenuItemClickListener() {
1431 @Override
1432 public boolean onMenuItemClick(MenuItem item) {
1433 openTab(extra, mTabControl.getCurrentTab(), true, true);
1434 return false;
1435 }
1436 });
Michael Kolb8233fac2010-10-26 16:08:53 -07001437 menu.findItem(R.id.download_context_menu_id).
Kristian Monsenbc5cc752011-03-02 13:14:03 +00001438 setOnMenuItemClickListener(
1439 new Download(mActivity, extra, webview.isPrivateBrowsingEnabled()));
John Reck3527dd12011-02-22 10:35:29 -08001440 menu.findItem(R.id.set_wallpaper_context_menu_id).
1441 setOnMenuItemClickListener(new WallpaperHandler(mActivity,
1442 extra));
Michael Kolb8233fac2010-10-26 16:08:53 -07001443 break;
1444
1445 default:
1446 Log.w(LOGTAG, "We should not get here.");
1447 break;
1448 }
1449 //update the ui
1450 mUi.onContextMenuCreated(menu);
1451 }
1452
1453 /**
1454 * As the menu can be open when loading state changes
1455 * we must manually update the state of the stop/reload menu
1456 * item
1457 */
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001458 private void updateInLoadMenuItems(Menu menu, Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001459 if (menu == null) {
1460 return;
1461 }
1462 MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
Michael Kolbb8337132011-11-28 15:07:39 -08001463 MenuItem src = ((tab != null) && tab.inPageLoad()) ?
Michael Kolb8233fac2010-10-26 16:08:53 -07001464 menu.findItem(R.id.stop_menu_id):
1465 menu.findItem(R.id.reload_menu_id);
1466 if (src != null) {
1467 dest.setIcon(src.getIcon());
1468 dest.setTitle(src.getTitle());
1469 }
1470 }
1471
John Reckb3417f02011-01-14 11:01:05 -08001472 boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001473 updateInLoadMenuItems(menu, getCurrentTab());
John Recke1a03a32011-09-14 17:04:16 -07001474 // hold on to the menu reference here; it is used by the page callbacks
1475 // to update the menu based on loading state
1476 mCachedMenu = menu;
Michael Kolb8233fac2010-10-26 16:08:53 -07001477 // Note: setVisible will decide whether an item is visible; while
1478 // setEnabled() will decide whether an item is enabled, which also means
1479 // whether the matching shortcut key will function.
1480 switch (mMenuState) {
1481 case EMPTY_MENU:
1482 if (mCurrentMenuState != mMenuState) {
1483 menu.setGroupVisible(R.id.MAIN_MENU, false);
1484 menu.setGroupEnabled(R.id.MAIN_MENU, false);
1485 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false);
1486 }
1487 break;
1488 default:
1489 if (mCurrentMenuState != mMenuState) {
1490 menu.setGroupVisible(R.id.MAIN_MENU, true);
1491 menu.setGroupEnabled(R.id.MAIN_MENU, true);
1492 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true);
1493 }
Michael Kolb4bf79712011-07-14 14:18:12 -07001494 updateMenuState(getCurrentTab(), menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001495 break;
1496 }
1497 mCurrentMenuState = mMenuState;
Michael Kolb1acef692011-03-08 14:12:06 -08001498 return mUi.onPrepareOptionsMenu(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001499 }
1500
Michael Kolb4bf79712011-07-14 14:18:12 -07001501 @Override
1502 public void updateMenuState(Tab tab, Menu menu) {
1503 boolean canGoBack = false;
1504 boolean canGoForward = false;
1505 boolean isHome = false;
John Reck42229bc2011-08-19 13:26:43 -07001506 boolean isDesktopUa = false;
John Recke1a03a32011-09-14 17:04:16 -07001507 boolean isLive = false;
Michael Kolb4bf79712011-07-14 14:18:12 -07001508 if (tab != null) {
1509 canGoBack = tab.canGoBack();
1510 canGoForward = tab.canGoForward();
1511 isHome = mSettings.getHomePage().equals(tab.getUrl());
John Reck42229bc2011-08-19 13:26:43 -07001512 isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView());
John Recke1a03a32011-09-14 17:04:16 -07001513 isLive = !tab.isSnapshot();
Michael Kolb4bf79712011-07-14 14:18:12 -07001514 }
1515 final MenuItem back = menu.findItem(R.id.back_menu_id);
1516 back.setEnabled(canGoBack);
1517
1518 final MenuItem home = menu.findItem(R.id.homepage_menu_id);
1519 home.setEnabled(!isHome);
1520
1521 final MenuItem forward = menu.findItem(R.id.forward_menu_id);
1522 forward.setEnabled(canGoForward);
1523
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001524 final MenuItem source = menu.findItem(isInLoad() ? R.id.stop_menu_id
1525 : R.id.reload_menu_id);
Michael Kolb4bf79712011-07-14 14:18:12 -07001526 final MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
Michael Kolb7ab75ee2011-07-14 16:36:38 -07001527 if (source != null && dest != null) {
1528 dest.setTitle(source.getTitle());
1529 dest.setIcon(source.getIcon());
1530 }
John Recke1a03a32011-09-14 17:04:16 -07001531 menu.setGroupVisible(R.id.NAV_MENU, isLive);
Michael Kolb4bf79712011-07-14 14:18:12 -07001532
1533 // decide whether to show the share link option
1534 PackageManager pm = mActivity.getPackageManager();
1535 Intent send = new Intent(Intent.ACTION_SEND);
1536 send.setType("text/plain");
1537 ResolveInfo ri = pm.resolveActivity(send,
1538 PackageManager.MATCH_DEFAULT_ONLY);
1539 menu.findItem(R.id.share_page_menu_id).setVisible(ri != null);
1540
1541 boolean isNavDump = mSettings.enableNavDump();
1542 final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id);
1543 nav.setVisible(isNavDump);
1544 nav.setEnabled(isNavDump);
1545
1546 boolean showDebugSettings = mSettings.isDebugEnabled();
John Reck42229bc2011-08-19 13:26:43 -07001547 final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id);
1548 uaSwitcher.setChecked(isDesktopUa);
John Recke1a03a32011-09-14 17:04:16 -07001549 menu.setGroupVisible(R.id.LIVE_MENU, isLive);
1550 menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive);
Michael Kolb315d5022011-10-13 12:47:11 -07001551 menu.setGroupVisible(R.id.COMBO_MENU, false);
Michael Kolb4bf79712011-07-14 14:18:12 -07001552
Michael Kolb7bdee0b2011-08-01 11:55:38 -07001553 mUi.updateMenuState(tab, menu);
Michael Kolb4bf79712011-07-14 14:18:12 -07001554 }
1555
Michael Kolb8233fac2010-10-26 16:08:53 -07001556 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001557 if (null == getCurrentTopWebView()) {
1558 return false;
1559 }
1560 if (mMenuIsDown) {
1561 // The shortcut action consumes the MENU. Even if it is still down,
1562 // it won't trigger the next shortcut action. In the case of the
1563 // shortcut action triggering a new activity, like Bookmarks, we
1564 // won't get onKeyUp for MENU. So it is important to reset it here.
1565 mMenuIsDown = false;
1566 }
Michael Kolb3ca12752011-07-20 13:52:25 -07001567 if (mUi.onOptionsItemSelected(item)) {
1568 // ui callback handled it
1569 return true;
1570 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001571 switch (item.getItemId()) {
1572 // -- Main menu
1573 case R.id.new_tab_menu_id:
1574 openTabToHomePage();
1575 break;
1576
1577 case R.id.incognito_menu_id:
Michael Kolb519d2282011-05-09 17:03:19 -07001578 openIncognitoTab();
Michael Kolb8233fac2010-10-26 16:08:53 -07001579 break;
1580
1581 case R.id.goto_menu_id:
1582 editUrl();
1583 break;
1584
1585 case R.id.bookmarks_menu_id:
Michael Kolb315d5022011-10-13 12:47:11 -07001586 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
1587 break;
1588
1589 case R.id.history_menu_id:
1590 bookmarksOrHistoryPicker(ComboViews.History);
1591 break;
1592
1593 case R.id.snapshots_menu_id:
1594 bookmarksOrHistoryPicker(ComboViews.Snapshots);
Michael Kolb8233fac2010-10-26 16:08:53 -07001595 break;
1596
Michael Kolb8233fac2010-10-26 16:08:53 -07001597 case R.id.add_bookmark_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07001598 bookmarkCurrentPage();
Michael Kolb8233fac2010-10-26 16:08:53 -07001599 break;
1600
1601 case R.id.stop_reload_menu_id:
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001602 if (isInLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001603 stopLoading();
1604 } else {
1605 getCurrentTopWebView().reload();
1606 }
1607 break;
1608
1609 case R.id.back_menu_id:
John Reckef654f12011-07-12 16:42:08 -07001610 getCurrentTab().goBack();
Michael Kolb8233fac2010-10-26 16:08:53 -07001611 break;
1612
1613 case R.id.forward_menu_id:
John Reckef654f12011-07-12 16:42:08 -07001614 getCurrentTab().goForward();
Michael Kolb8233fac2010-10-26 16:08:53 -07001615 break;
1616
1617 case R.id.close_menu_id:
1618 // Close the subwindow if it exists.
1619 if (mTabControl.getCurrentSubWindow() != null) {
1620 dismissSubWindow(mTabControl.getCurrentTab());
1621 break;
1622 }
1623 closeCurrentTab();
1624 break;
1625
1626 case R.id.homepage_menu_id:
1627 Tab current = mTabControl.getCurrentTab();
John Reck26b18322011-06-21 13:08:58 -07001628 loadUrl(current, mSettings.getHomePage());
Michael Kolb8233fac2010-10-26 16:08:53 -07001629 break;
1630
1631 case R.id.preferences_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07001632 openPreferences();
Michael Kolb8233fac2010-10-26 16:08:53 -07001633 break;
1634
1635 case R.id.find_menu_id:
Michael Kolbe11b9212012-04-13 13:39:54 -07001636 findOnPage();
Michael Kolb8233fac2010-10-26 16:08:53 -07001637 break;
1638
John Reck2bc80422011-06-30 15:11:49 -07001639 case R.id.save_snapshot_menu_id:
1640 final Tab source = getTabControl().getCurrentTab();
John Reckf33b1632011-06-04 20:00:23 -07001641 if (source == null) break;
John Reck68234a92012-04-19 15:27:12 -07001642 new SaveSnapshotTask(source).execute();
Leon Scrogginsac993842011-02-02 12:54:07 -05001643 break;
1644
Michael Kolb8233fac2010-10-26 16:08:53 -07001645 case R.id.page_info_menu_id:
Michael Kolb315d5022011-10-13 12:47:11 -07001646 showPageInfo();
Michael Kolb8233fac2010-10-26 16:08:53 -07001647 break;
1648
John Recke1a03a32011-09-14 17:04:16 -07001649 case R.id.snapshot_go_live:
1650 goLive();
1651 return true;
1652
Michael Kolb8233fac2010-10-26 16:08:53 -07001653 case R.id.share_page_menu_id:
1654 Tab currentTab = mTabControl.getCurrentTab();
1655 if (null == currentTab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001656 return false;
1657 }
Michael Kolbba99c5d2010-11-29 14:57:41 -08001658 shareCurrentPage(currentTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001659 break;
1660
1661 case R.id.dump_nav_menu_id:
1662 getCurrentTopWebView().debugDump();
1663 break;
1664
Michael Kolb8233fac2010-10-26 16:08:53 -07001665 case R.id.zoom_in_menu_id:
1666 getCurrentTopWebView().zoomIn();
1667 break;
1668
1669 case R.id.zoom_out_menu_id:
1670 getCurrentTopWebView().zoomOut();
1671 break;
1672
1673 case R.id.view_downloads_menu_id:
1674 viewDownloads();
1675 break;
1676
John Reck42229bc2011-08-19 13:26:43 -07001677 case R.id.ua_desktop_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07001678 toggleUserAgent();
John Reck42229bc2011-08-19 13:26:43 -07001679 break;
1680
Michael Kolb8233fac2010-10-26 16:08:53 -07001681 case R.id.window_one_menu_id:
1682 case R.id.window_two_menu_id:
1683 case R.id.window_three_menu_id:
1684 case R.id.window_four_menu_id:
1685 case R.id.window_five_menu_id:
1686 case R.id.window_six_menu_id:
1687 case R.id.window_seven_menu_id:
1688 case R.id.window_eight_menu_id:
1689 {
1690 int menuid = item.getItemId();
1691 for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) {
1692 if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) {
1693 Tab desiredTab = mTabControl.getTab(id);
1694 if (desiredTab != null &&
1695 desiredTab != mTabControl.getCurrentTab()) {
Michael Kolbc831b632011-05-11 09:30:34 -07001696 switchToTab(desiredTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001697 }
1698 break;
1699 }
1700 }
1701 }
1702 break;
1703
1704 default:
1705 return false;
1706 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001707 return true;
1708 }
1709
John Reck68234a92012-04-19 15:27:12 -07001710 private class SaveSnapshotTask extends AsyncTask<Void, Void, Long>
1711 implements OnCancelListener {
1712
1713 private Tab mTab;
1714 private Dialog mProgressDialog;
1715 private ContentValues mValues;
1716
1717 private SaveSnapshotTask(Tab tab) {
1718 mTab = tab;
1719 }
1720
1721 @Override
1722 protected void onPreExecute() {
1723 CharSequence message = mActivity.getText(R.string.saving_snapshot);
1724 mProgressDialog = ProgressDialog.show(mActivity, null, message,
1725 true, true, this);
1726 mValues = mTab.createSnapshotValues();
1727 }
1728
1729 @Override
1730 protected Long doInBackground(Void... params) {
1731 if (!mTab.saveViewState(mValues)) {
1732 return null;
1733 }
1734 if (isCancelled()) {
1735 String path = mValues.getAsString(Snapshots.VIEWSTATE_PATH);
1736 File file = mActivity.getFileStreamPath(path);
1737 if (!file.delete()) {
1738 file.deleteOnExit();
1739 }
1740 return null;
1741 }
1742 final ContentResolver cr = mActivity.getContentResolver();
1743 Uri result = cr.insert(Snapshots.CONTENT_URI, mValues);
1744 if (result == null) {
1745 return null;
1746 }
1747 long id = ContentUris.parseId(result);
1748 return id;
1749 }
1750
1751 @Override
1752 protected void onPostExecute(Long id) {
1753 if (isCancelled()) {
1754 return;
1755 }
1756 mProgressDialog.dismiss();
1757 if (id == null) {
1758 Toast.makeText(mActivity, R.string.snapshot_failed,
1759 Toast.LENGTH_SHORT).show();
1760 return;
1761 }
1762 Bundle b = new Bundle();
1763 b.putLong(BrowserSnapshotPage.EXTRA_ANIMATE_ID, id);
1764 mUi.showComboView(ComboViews.Snapshots, b);
1765 }
1766
1767 @Override
1768 public void onCancel(DialogInterface dialog) {
1769 cancel(true);
1770 }
1771 }
1772
Michael Kolb80f75082012-04-10 10:50:06 -07001773 @Override
1774 public void toggleUserAgent() {
1775 WebView web = getCurrentWebView();
1776 mSettings.toggleDesktopUseragent(web);
1777 web.loadUrl(web.getOriginalUrl());
1778 }
1779
1780 @Override
1781 public void findOnPage() {
1782 getCurrentTopWebView().showFindDialog(null, true);
1783 }
1784
1785 @Override
1786 public void openPreferences() {
1787 Intent intent = new Intent(mActivity, BrowserPreferencesPage.class);
1788 intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE,
1789 getCurrentTopWebView().getUrl());
1790 mActivity.startActivityForResult(intent, PREFERENCES_PAGE);
1791 }
1792
1793 @Override
1794 public void bookmarkCurrentPage() {
1795 Intent bookmarkIntent = createBookmarkCurrentPageIntent(false);
1796 if (bookmarkIntent != null) {
1797 mActivity.startActivity(bookmarkIntent);
1798 }
1799 }
1800
John Recke1a03a32011-09-14 17:04:16 -07001801 private void goLive() {
1802 Tab t = getCurrentTab();
1803 t.loadUrl(t.getUrl(), null);
1804 }
1805
Michael Kolb315d5022011-10-13 12:47:11 -07001806 @Override
1807 public void showPageInfo() {
1808 mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null);
1809 }
1810
Michael Kolb8233fac2010-10-26 16:08:53 -07001811 public boolean onContextItemSelected(MenuItem item) {
John Reckdbf57df2010-11-09 16:34:03 -08001812 // Let the History and Bookmark fragments handle menus they created.
1813 if (item.getGroupId() == R.id.CONTEXT_MENU) {
1814 return false;
1815 }
1816
Michael Kolb8233fac2010-10-26 16:08:53 -07001817 int id = item.getItemId();
1818 boolean result = true;
1819 switch (id) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001820 // -- Browser context menu
1821 case R.id.open_context_menu_id:
Michael Kolb8233fac2010-10-26 16:08:53 -07001822 case R.id.save_link_context_menu_id:
Michael Kolb8233fac2010-10-26 16:08:53 -07001823 case R.id.copy_link_context_menu_id:
1824 final WebView webView = getCurrentTopWebView();
1825 if (null == webView) {
1826 result = false;
1827 break;
1828 }
1829 final HashMap<String, WebView> hrefMap =
1830 new HashMap<String, WebView>();
1831 hrefMap.put("webview", webView);
1832 final Message msg = mHandler.obtainMessage(
1833 FOCUS_NODE_HREF, id, 0, hrefMap);
1834 webView.requestFocusNodeHref(msg);
1835 break;
1836
1837 default:
1838 // For other context menus
1839 result = onOptionsItemSelected(item);
1840 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001841 return result;
1842 }
1843
1844 /**
1845 * support programmatically opening the context menu
1846 */
1847 public void openContextMenu(View view) {
1848 mActivity.openContextMenu(view);
1849 }
1850
1851 /**
1852 * programmatically open the options menu
1853 */
1854 public void openOptionsMenu() {
1855 mActivity.openOptionsMenu();
1856 }
1857
1858 public boolean onMenuOpened(int featureId, Menu menu) {
1859 if (mOptionsMenuOpen) {
1860 if (mConfigChanged) {
1861 // We do not need to make any changes to the state of the
1862 // title bar, since the only thing that happened was a
1863 // change in orientation
1864 mConfigChanged = false;
1865 } else {
1866 if (!mExtendedMenuOpen) {
1867 mExtendedMenuOpen = true;
1868 mUi.onExtendedMenuOpened();
1869 } else {
1870 // Switching the menu back to icon view, so show the
1871 // title bar once again.
1872 mExtendedMenuOpen = false;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001873 mUi.onExtendedMenuClosed(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07001874 }
1875 }
1876 } else {
1877 // The options menu is closed, so open it, and show the title
1878 mOptionsMenuOpen = true;
1879 mConfigChanged = false;
1880 mExtendedMenuOpen = false;
1881 mUi.onOptionsMenuOpened();
1882 }
1883 return true;
1884 }
1885
1886 public void onOptionsMenuClosed(Menu menu) {
1887 mOptionsMenuOpen = false;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001888 mUi.onOptionsMenuClosed(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07001889 }
1890
1891 public void onContextMenuClosed(Menu menu) {
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001892 mUi.onContextMenuClosed(menu, isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07001893 }
1894
1895 // Helper method for getting the top window.
1896 @Override
1897 public WebView getCurrentTopWebView() {
1898 return mTabControl.getCurrentTopWebView();
1899 }
1900
1901 @Override
1902 public WebView getCurrentWebView() {
1903 return mTabControl.getCurrentWebView();
1904 }
1905
1906 /*
1907 * This method is called as a result of the user selecting the options
1908 * menu to see the download window. It shows the download window on top of
1909 * the current window.
1910 */
1911 void viewDownloads() {
1912 Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
1913 mActivity.startActivity(intent);
1914 }
1915
John Reck30b065e2011-07-19 10:58:05 -07001916 int getActionModeHeight() {
1917 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
1918 new int[] { android.R.attr.actionBarSize });
1919 int size = (int) actionBarSizeTypedArray.getDimension(0, 0f);
1920 actionBarSizeTypedArray.recycle();
1921 return size;
1922 }
1923
Michael Kolb8233fac2010-10-26 16:08:53 -07001924 // action mode
1925
1926 void onActionModeStarted(ActionMode mode) {
1927 mUi.onActionModeStarted(mode);
1928 mActionMode = mode;
1929 }
1930
1931 /*
1932 * True if a custom ActionMode (i.e. find or select) is in use.
1933 */
1934 @Override
1935 public boolean isInCustomActionMode() {
1936 return mActionMode != null;
1937 }
1938
1939 /*
1940 * End the current ActionMode.
1941 */
1942 @Override
1943 public void endActionMode() {
1944 if (mActionMode != null) {
1945 mActionMode.finish();
1946 }
1947 }
1948
1949 /*
1950 * Called by find and select when they are finished. Replace title bars
1951 * as necessary.
1952 */
1953 public void onActionModeFinished(ActionMode mode) {
1954 if (!isInCustomActionMode()) return;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001955 mUi.onActionModeFinished(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07001956 mActionMode = null;
1957 }
1958
1959 boolean isInLoad() {
Michael Kolbc5b0b2d2011-11-29 16:13:35 -08001960 final Tab tab = getCurrentTab();
1961 return (tab != null) && tab.inPageLoad();
Michael Kolb8233fac2010-10-26 16:08:53 -07001962 }
1963
1964 // bookmark handling
1965
1966 /**
1967 * add the current page as a bookmark to the given folder id
1968 * @param folderId use -1 for the default folder
John Reckd3e4d5b2011-07-13 15:48:43 -07001969 * @param editExisting If true, check to see whether the site is already
Leon Scrogginsbdff8a72011-02-11 15:49:04 -05001970 * bookmarked, and if it is, edit that bookmark. If false, and
1971 * the site is already bookmarked, do not attempt to edit the
1972 * existing bookmark.
Michael Kolb8233fac2010-10-26 16:08:53 -07001973 */
1974 @Override
John Reckd3e4d5b2011-07-13 15:48:43 -07001975 public Intent createBookmarkCurrentPageIntent(boolean editExisting) {
John Recka60fffa2011-09-06 16:30:29 -07001976 WebView w = getCurrentTopWebView();
1977 if (w == null) {
1978 return null;
1979 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001980 Intent i = new Intent(mActivity,
1981 AddBookmarkPage.class);
Michael Kolb8233fac2010-10-26 16:08:53 -07001982 i.putExtra(BrowserContract.Bookmarks.URL, w.getUrl());
1983 i.putExtra(BrowserContract.Bookmarks.TITLE, w.getTitle());
1984 String touchIconUrl = w.getTouchIconUrl();
1985 if (touchIconUrl != null) {
1986 i.putExtra(AddBookmarkPage.TOUCH_ICON_URL, touchIconUrl);
1987 WebSettings settings = w.getSettings();
1988 if (settings != null) {
1989 i.putExtra(AddBookmarkPage.USER_AGENT,
1990 settings.getUserAgentString());
1991 }
1992 }
1993 i.putExtra(BrowserContract.Bookmarks.THUMBNAIL,
1994 createScreenshot(w, getDesiredThumbnailWidth(mActivity),
1995 getDesiredThumbnailHeight(mActivity)));
1996 i.putExtra(BrowserContract.Bookmarks.FAVICON, w.getFavicon());
John Reckd3e4d5b2011-07-13 15:48:43 -07001997 if (editExisting) {
Leon Scrogginsbdff8a72011-02-11 15:49:04 -05001998 i.putExtra(AddBookmarkPage.CHECK_FOR_DUPE, true);
1999 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002000 // Put the dialog at the upper right of the screen, covering the
2001 // star on the title bar.
2002 i.putExtra("gravity", Gravity.RIGHT | Gravity.TOP);
John Reckd3e4d5b2011-07-13 15:48:43 -07002003 return i;
Michael Kolb8233fac2010-10-26 16:08:53 -07002004 }
2005
2006 // file chooser
Ben Murdoch8cad4132012-01-11 10:56:43 +00002007 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002008 mUploadHandler = new UploadHandler(this);
Ben Murdoch8cad4132012-01-11 10:56:43 +00002009 mUploadHandler.openFileChooser(uploadMsg, acceptType, capture);
Michael Kolb8233fac2010-10-26 16:08:53 -07002010 }
2011
2012 // thumbnails
2013
2014 /**
2015 * Return the desired width for thumbnail screenshots, which are stored in
2016 * the database, and used on the bookmarks screen.
2017 * @param context Context for finding out the density of the screen.
2018 * @return desired width for thumbnail screenshot.
2019 */
2020 static int getDesiredThumbnailWidth(Context context) {
2021 return context.getResources().getDimensionPixelOffset(
2022 R.dimen.bookmarkThumbnailWidth);
2023 }
2024
2025 /**
2026 * Return the desired height for thumbnail screenshots, which are stored in
2027 * the database, and used on the bookmarks screen.
2028 * @param context Context for finding out the density of the screen.
2029 * @return desired height for thumbnail screenshot.
2030 */
2031 static int getDesiredThumbnailHeight(Context context) {
2032 return context.getResources().getDimensionPixelOffset(
2033 R.dimen.bookmarkThumbnailHeight);
2034 }
2035
John Reck8cc92352011-07-06 17:41:52 -07002036 static Bitmap createScreenshot(WebView view, int width, int height) {
John Reckd7dd9b22011-08-30 09:18:29 -07002037 if (view == null || view.getContentHeight() == 0
2038 || view.getContentWidth() == 0) {
2039 return null;
2040 }
John Reck5c6ac2f2011-01-05 10:18:03 -08002041 // We render to a bitmap 2x the desired size so that we can then
2042 // re-scale it with filtering since canvas.scale doesn't filter
2043 // This helps reduce aliasing at the cost of being slightly blurry
2044 final int filter_scale = 2;
John Reckd7dd9b22011-08-30 09:18:29 -07002045 int scaledWidth = width * filter_scale;
2046 int scaledHeight = height * filter_scale;
2047 if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != scaledWidth
2048 || sThumbnailBitmap.getHeight() != scaledHeight) {
2049 if (sThumbnailBitmap != null) {
2050 sThumbnailBitmap.recycle();
2051 sThumbnailBitmap = null;
2052 }
2053 sThumbnailBitmap =
2054 Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.RGB_565);
Michael Kolb8233fac2010-10-26 16:08:53 -07002055 }
John Reckd7dd9b22011-08-30 09:18:29 -07002056 Canvas canvas = new Canvas(sThumbnailBitmap);
2057 int contentWidth = view.getContentWidth();
2058 float overviewScale = scaledWidth / (view.getScale() * contentWidth);
2059 if (view instanceof BrowserWebView) {
2060 int dy = -((BrowserWebView)view).getTitleHeight();
2061 canvas.translate(0, dy * overviewScale);
2062 }
2063
2064 canvas.scale(overviewScale, overviewScale);
2065
2066 if (view instanceof BrowserWebView) {
2067 ((BrowserWebView)view).drawContent(canvas);
Michael Kolb8233fac2010-10-26 16:08:53 -07002068 } else {
John Reckd7dd9b22011-08-30 09:18:29 -07002069 view.draw(canvas);
Michael Kolb8233fac2010-10-26 16:08:53 -07002070 }
John Reckd7dd9b22011-08-30 09:18:29 -07002071 Bitmap ret = Bitmap.createScaledBitmap(sThumbnailBitmap,
2072 width, height, true);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002073 canvas.setBitmap(null);
John Reck5c6ac2f2011-01-05 10:18:03 -08002074 return ret;
Michael Kolb8233fac2010-10-26 16:08:53 -07002075 }
2076
John Reck34ef2672011-02-10 11:30:55 -08002077 private void updateScreenshot(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002078 // If this is a bookmarked site, add a screenshot to the database.
Michael Kolb8233fac2010-10-26 16:08:53 -07002079 // FIXME: Would like to make sure there is actually something to
2080 // draw, but the API for that (WebViewCore.pictureReady()) is not
2081 // currently accessible here.
2082
John Reck34ef2672011-02-10 11:30:55 -08002083 WebView view = tab.getWebView();
John Reck7a591202011-02-16 15:44:01 -08002084 if (view == null) {
2085 // Tab was destroyed
2086 return;
2087 }
John Reck34ef2672011-02-10 11:30:55 -08002088 final String url = tab.getUrl();
2089 final String originalUrl = view.getOriginalUrl();
John Reck34ef2672011-02-10 11:30:55 -08002090 if (TextUtils.isEmpty(url)) {
2091 return;
2092 }
2093
2094 // Only update thumbnails for web urls (http(s)://), not for
2095 // about:, javascript:, data:, etc...
2096 // Unless it is a bookmarked site, then always update
2097 if (!Patterns.WEB_URL.matcher(url).matches() && !tab.isBookmarkedSite()) {
2098 return;
2099 }
2100
Michael Kolb8233fac2010-10-26 16:08:53 -07002101 final Bitmap bm = createScreenshot(view, getDesiredThumbnailWidth(mActivity),
2102 getDesiredThumbnailHeight(mActivity));
2103 if (bm == null) {
2104 return;
2105 }
2106
2107 final ContentResolver cr = mActivity.getContentResolver();
John Reck34ef2672011-02-10 11:30:55 -08002108 new AsyncTask<Void, Void, Void>() {
2109 @Override
2110 protected Void doInBackground(Void... unused) {
2111 Cursor cursor = null;
2112 try {
2113 // TODO: Clean this up
2114 cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl, url);
2115 if (cursor != null && cursor.moveToFirst()) {
2116 final ByteArrayOutputStream os =
2117 new ByteArrayOutputStream();
2118 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
Michael Kolb8233fac2010-10-26 16:08:53 -07002119
John Reck34ef2672011-02-10 11:30:55 -08002120 ContentValues values = new ContentValues();
2121 values.put(Images.THUMBNAIL, os.toByteArray());
Michael Kolb8233fac2010-10-26 16:08:53 -07002122
John Reck34ef2672011-02-10 11:30:55 -08002123 do {
John Reck617fd832011-02-16 14:35:59 -08002124 values.put(Images.URL, cursor.getString(0));
John Reck34ef2672011-02-10 11:30:55 -08002125 cr.update(Images.CONTENT_URI, values, null, null);
2126 } while (cursor.moveToNext());
Michael Kolb8233fac2010-10-26 16:08:53 -07002127 }
John Reck34ef2672011-02-10 11:30:55 -08002128 } catch (IllegalStateException e) {
2129 // Ignore
2130 } finally {
2131 if (cursor != null) cursor.close();
Michael Kolb8233fac2010-10-26 16:08:53 -07002132 }
John Reck34ef2672011-02-10 11:30:55 -08002133 return null;
2134 }
2135 }.execute();
Michael Kolb8233fac2010-10-26 16:08:53 -07002136 }
2137
2138 private class Copy implements OnMenuItemClickListener {
2139 private CharSequence mText;
2140
2141 public boolean onMenuItemClick(MenuItem item) {
2142 copy(mText);
2143 return true;
2144 }
2145
2146 public Copy(CharSequence toCopy) {
2147 mText = toCopy;
2148 }
2149 }
2150
Leon Scroggins63c02662010-11-18 15:16:27 -05002151 private static class Download implements OnMenuItemClickListener {
2152 private Activity mActivity;
Michael Kolb8233fac2010-10-26 16:08:53 -07002153 private String mText;
Kristian Monsenbc5cc752011-03-02 13:14:03 +00002154 private boolean mPrivateBrowsing;
George Mount387d45d2011-10-07 15:57:53 -07002155 private static final String FALLBACK_EXTENSION = "dat";
2156 private static final String IMAGE_BASE_FORMAT = "yyyy-MM-dd-HH-mm-ss-";
Michael Kolb8233fac2010-10-26 16:08:53 -07002157
2158 public boolean onMenuItemClick(MenuItem item) {
George Mount387d45d2011-10-07 15:57:53 -07002159 if (DataUri.isDataUri(mText)) {
2160 saveDataUri();
2161 } else {
2162 DownloadHandler.onDownloadStartNoStream(mActivity, mText, null,
2163 null, null, mPrivateBrowsing);
2164 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002165 return true;
2166 }
2167
Kristian Monsenbc5cc752011-03-02 13:14:03 +00002168 public Download(Activity activity, String toDownload, boolean privateBrowsing) {
Leon Scroggins63c02662010-11-18 15:16:27 -05002169 mActivity = activity;
Michael Kolb8233fac2010-10-26 16:08:53 -07002170 mText = toDownload;
Kristian Monsenbc5cc752011-03-02 13:14:03 +00002171 mPrivateBrowsing = privateBrowsing;
Michael Kolb8233fac2010-10-26 16:08:53 -07002172 }
George Mount387d45d2011-10-07 15:57:53 -07002173
2174 /**
2175 * Treats mText as a data URI and writes its contents to a file
2176 * based on the current time.
2177 */
2178 private void saveDataUri() {
2179 FileOutputStream outputStream = null;
2180 try {
2181 DataUri uri = new DataUri(mText);
2182 File target = getTarget(uri);
2183 outputStream = new FileOutputStream(target);
2184 outputStream.write(uri.getData());
2185 final DownloadManager manager =
2186 (DownloadManager) mActivity.getSystemService(Context.DOWNLOAD_SERVICE);
2187 manager.addCompletedDownload(target.getName(),
2188 mActivity.getTitle().toString(), false,
2189 uri.getMimeType(), target.getAbsolutePath(),
George Mount7501bf42011-11-17 11:17:03 -08002190 (long)uri.getData().length, true);
George Mount387d45d2011-10-07 15:57:53 -07002191 } catch (IOException e) {
2192 Log.e(LOGTAG, "Could not save data URL");
2193 } finally {
2194 if (outputStream != null) {
2195 try {
2196 outputStream.close();
2197 } catch (IOException e) {
2198 // ignore close errors
2199 }
2200 }
2201 }
2202 }
2203
2204 /**
2205 * Creates a File based on the current time stamp and uses
2206 * the mime type of the DataUri to get the extension.
2207 */
2208 private File getTarget(DataUri uri) throws IOException {
2209 File dir = mActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
2210 DateFormat format = new SimpleDateFormat(IMAGE_BASE_FORMAT);
2211 String nameBase = format.format(new Date());
2212 String mimeType = uri.getMimeType();
2213 MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
2214 String extension = mimeTypeMap.getExtensionFromMimeType(mimeType);
2215 if (extension == null) {
2216 Log.w(LOGTAG, "Unknown mime type in data URI" + mimeType);
2217 extension = FALLBACK_EXTENSION;
2218 }
2219 extension = "." + extension; // createTempFile needs the '.'
2220 File targetFile = File.createTempFile(nameBase, extension, dir);
2221 return targetFile;
2222 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002223 }
2224
Cary Clark8974d282010-11-22 10:46:05 -05002225 private static class SelectText implements OnMenuItemClickListener {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002226 private WebViewClassic mWebView;
Cary Clark8974d282010-11-22 10:46:05 -05002227
2228 public boolean onMenuItemClick(MenuItem item) {
2229 if (mWebView != null) {
2230 return mWebView.selectText();
2231 }
2232 return false;
2233 }
2234
2235 public SelectText(WebView webView) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002236 mWebView = WebViewClassic.fromWebView(webView);
Cary Clark8974d282010-11-22 10:46:05 -05002237 }
2238
2239 }
2240
Michael Kolb8233fac2010-10-26 16:08:53 -07002241 /********************** TODO: UI stuff *****************************/
2242
2243 // these methods have been copied, they still need to be cleaned up
2244
2245 /****************** tabs ***************************************************/
2246
2247 // basic tab interactions:
2248
2249 // it is assumed that tabcontrol already knows about the tab
2250 protected void addTab(Tab tab) {
2251 mUi.addTab(tab);
2252 }
2253
2254 protected void removeTab(Tab tab) {
2255 mUi.removeTab(tab);
2256 mTabControl.removeTab(tab);
John Reck378a4102011-06-09 16:23:01 -07002257 mCrashRecoveryHandler.backupState();
Michael Kolb8233fac2010-10-26 16:08:53 -07002258 }
2259
Michael Kolbf2055602011-04-09 17:20:03 -07002260 @Override
2261 public void setActiveTab(Tab tab) {
Michael Kolbcd424e92011-02-24 10:26:26 -08002262 // monkey protection against delayed start
2263 if (tab != null) {
2264 mTabControl.setCurrentTab(tab);
2265 // the tab is guaranteed to have a webview after setCurrentTab
2266 mUi.setActiveTab(tab);
2267 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002268 }
2269
John Reck8bcafc12011-08-29 16:43:02 -07002270 protected void closeEmptyTab() {
Michael Kolb8233fac2010-10-26 16:08:53 -07002271 Tab current = mTabControl.getCurrentTab();
2272 if (current != null
2273 && current.getWebView().copyBackForwardList().getSize() == 0) {
John Reck8bcafc12011-08-29 16:43:02 -07002274 closeCurrentTab();
Michael Kolb8233fac2010-10-26 16:08:53 -07002275 }
2276 }
2277
John Reck26b18322011-06-21 13:08:58 -07002278 protected void reuseTab(Tab appTab, UrlData urlData) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002279 // Dismiss the subwindow if applicable.
2280 dismissSubWindow(appTab);
2281 // Since we might kill the WebView, remove it from the
2282 // content view first.
2283 mUi.detachTab(appTab);
2284 // Recreate the main WebView after destroying the old one.
John Reck30c714c2010-12-16 17:30:34 -08002285 mTabControl.recreateWebView(appTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07002286 // TODO: analyze why the remove and add are necessary
2287 mUi.attachTab(appTab);
2288 if (mTabControl.getCurrentTab() != appTab) {
Michael Kolbc831b632011-05-11 09:30:34 -07002289 switchToTab(appTab);
John Reck30c714c2010-12-16 17:30:34 -08002290 loadUrlDataIn(appTab, urlData);
Michael Kolb8233fac2010-10-26 16:08:53 -07002291 } else {
2292 // If the tab was the current tab, we have to attach
2293 // it to the view system again.
2294 setActiveTab(appTab);
John Reck30c714c2010-12-16 17:30:34 -08002295 loadUrlDataIn(appTab, urlData);
Michael Kolb8233fac2010-10-26 16:08:53 -07002296 }
2297 }
2298
2299 // Remove the sub window if it exists. Also called by TabControl when the
2300 // user clicks the 'X' to dismiss a sub window.
2301 public void dismissSubWindow(Tab tab) {
2302 removeSubWindow(tab);
2303 // dismiss the subwindow. This will destroy the WebView.
2304 tab.dismissSubWindow();
Michael Kolbe8c97572011-11-21 14:03:56 -08002305 WebView wv = getCurrentTopWebView();
2306 if (wv != null) {
2307 wv.requestFocus();
2308 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002309 }
2310
2311 @Override
2312 public void removeSubWindow(Tab t) {
2313 if (t.getSubWebView() != null) {
2314 mUi.removeSubWindow(t.getSubViewContainer());
2315 }
2316 }
2317
2318 @Override
2319 public void attachSubWindow(Tab tab) {
2320 if (tab.getSubWebView() != null) {
2321 mUi.attachSubWindow(tab.getSubViewContainer());
2322 getCurrentTopWebView().requestFocus();
2323 }
2324 }
2325
Mathew Inwood29721c22011-06-29 17:55:24 +01002326 private Tab showPreloadedTab(final UrlData urlData) {
2327 if (!urlData.isPreloaded()) {
2328 return null;
2329 }
2330 final PreloadedTabControl tabControl = urlData.getPreloadedTab();
2331 final String sbQuery = urlData.getSearchBoxQueryToSubmit();
2332 if (sbQuery != null) {
Mathew Inwood9ad1eac2011-09-15 11:29:50 +01002333 if (!tabControl.searchBoxSubmit(sbQuery, urlData.mUrl, urlData.mHeaders)) {
Mathew Inwood29721c22011-06-29 17:55:24 +01002334 // Could not submit query. Fallback to regular tab creation
2335 tabControl.destroy();
2336 return null;
2337 }
2338 }
Michael Kolbff6a7482011-07-26 16:37:15 -07002339 // check tab count and make room for new tab
2340 if (!mTabControl.canCreateNewTab()) {
2341 Tab leastUsed = mTabControl.getLeastUsedTab(getCurrentTab());
2342 if (leastUsed != null) {
2343 closeTab(leastUsed);
2344 }
2345 }
Mathew Inwood29721c22011-06-29 17:55:24 +01002346 Tab t = tabControl.getTab();
Mathew Inwoode09305e2011-09-02 12:03:26 +01002347 t.refreshIdAfterPreload();
Mathew Inwood29721c22011-06-29 17:55:24 +01002348 mTabControl.addPreloadedTab(t);
2349 addTab(t);
2350 setActiveTab(t);
2351 return t;
2352 }
2353
Michael Kolb7bcafde2011-05-09 13:55:59 -07002354 // open a non inconito tab with the given url data
2355 // and set as active tab
2356 public Tab openTab(UrlData urlData) {
Mathew Inwood29721c22011-06-29 17:55:24 +01002357 Tab tab = showPreloadedTab(urlData);
2358 if (tab == null) {
2359 tab = createNewTab(false, true, true);
Michael Kolb14612442011-06-24 13:06:29 -07002360 if ((tab != null) && !urlData.isEmpty()) {
2361 loadUrlDataIn(tab, urlData);
2362 }
Michael Kolb7bcafde2011-05-09 13:55:59 -07002363 }
Mathew Inwood29721c22011-06-29 17:55:24 +01002364 return tab;
Michael Kolb7bcafde2011-05-09 13:55:59 -07002365 }
2366
Michael Kolb843510f2010-12-09 10:51:49 -08002367 @Override
2368 public Tab openTabToHomePage() {
Michael Kolb7bcafde2011-05-09 13:55:59 -07002369 return openTab(mSettings.getHomePage(), false, true, false);
Michael Kolb8233fac2010-10-26 16:08:53 -07002370 }
2371
Michael Kolb8233fac2010-10-26 16:08:53 -07002372 @Override
Michael Kolb519d2282011-05-09 17:03:19 -07002373 public Tab openIncognitoTab() {
2374 return openTab(INCOGNITO_URI, true, true, false);
2375 }
2376
2377 @Override
Michael Kolb7bcafde2011-05-09 13:55:59 -07002378 public Tab openTab(String url, boolean incognito, boolean setActive,
2379 boolean useCurrent) {
John Reck5949c662011-05-27 09:52:29 -07002380 return openTab(url, incognito, setActive, useCurrent, null);
2381 }
2382
2383 @Override
2384 public Tab openTab(String url, Tab parent, boolean setActive,
2385 boolean useCurrent) {
2386 return openTab(url, (parent != null) && parent.isPrivateBrowsingEnabled(),
2387 setActive, useCurrent, parent);
2388 }
2389
2390 public Tab openTab(String url, boolean incognito, boolean setActive,
2391 boolean useCurrent, Tab parent) {
Michael Kolb7bcafde2011-05-09 13:55:59 -07002392 Tab tab = createNewTab(incognito, setActive, useCurrent);
2393 if (tab != null) {
John Reck5949c662011-05-27 09:52:29 -07002394 if (parent != null && parent != tab) {
2395 parent.addChildTab(tab);
2396 }
Michael Kolb519d2282011-05-09 17:03:19 -07002397 if (url != null) {
John Reck26b18322011-06-21 13:08:58 -07002398 loadUrl(tab, url);
Michael Kolb519d2282011-05-09 17:03:19 -07002399 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002400 }
Michael Kolb7bcafde2011-05-09 13:55:59 -07002401 return tab;
2402 }
2403
2404 // this method will attempt to create a new tab
2405 // incognito: private browsing tab
2406 // setActive: ste tab as current tab
2407 // useCurrent: if no new tab can be created, return current tab
2408 private Tab createNewTab(boolean incognito, boolean setActive,
2409 boolean useCurrent) {
2410 Tab tab = null;
2411 if (mTabControl.canCreateNewTab()) {
2412 tab = mTabControl.createNewTab(incognito);
2413 addTab(tab);
2414 if (setActive) {
2415 setActiveTab(tab);
2416 }
2417 } else {
2418 if (useCurrent) {
2419 tab = mTabControl.getCurrentTab();
John Reck26b18322011-06-21 13:08:58 -07002420 reuseTab(tab, null);
Michael Kolb7bcafde2011-05-09 13:55:59 -07002421 } else {
2422 mUi.showMaxTabsWarning();
2423 }
2424 }
2425 return tab;
Michael Kolb8233fac2010-10-26 16:08:53 -07002426 }
2427
John Reck2bc80422011-06-30 15:11:49 -07002428 @Override
2429 public SnapshotTab createNewSnapshotTab(long snapshotId, boolean setActive) {
2430 SnapshotTab tab = null;
2431 if (mTabControl.canCreateNewTab()) {
2432 tab = mTabControl.createSnapshotTab(snapshotId);
2433 addTab(tab);
2434 if (setActive) {
2435 setActiveTab(tab);
2436 }
2437 } else {
2438 mUi.showMaxTabsWarning();
John Reckd8c74522011-06-14 08:45:00 -07002439 }
2440 return tab;
2441 }
2442
Michael Kolb8233fac2010-10-26 16:08:53 -07002443 /**
Michael Kolbc831b632011-05-11 09:30:34 -07002444 * @param tab the tab to switch to
Michael Kolb8233fac2010-10-26 16:08:53 -07002445 * @return boolean True if we successfully switched to a different tab. If
2446 * the indexth tab is null, or if that tab is the same as
2447 * the current one, return false.
2448 */
2449 @Override
Michael Kolbc831b632011-05-11 09:30:34 -07002450 public boolean switchToTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002451 Tab currentTab = mTabControl.getCurrentTab();
2452 if (tab == null || tab == currentTab) {
2453 return false;
2454 }
2455 setActiveTab(tab);
2456 return true;
2457 }
2458
2459 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002460 public void closeCurrentTab() {
Michael Kolb2ae6ef72011-08-22 14:49:34 -07002461 closeCurrentTab(false);
2462 }
2463
2464 protected void closeCurrentTab(boolean andQuit) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002465 if (mTabControl.getTabCount() == 1) {
John Reckbc490d22011-07-22 15:04:59 -07002466 mCrashRecoveryHandler.clearState();
Michael Kolbc1eeb122011-08-01 09:56:26 -07002467 mTabControl.removeTab(getCurrentTab());
John Reck958b2422010-12-03 17:56:17 -08002468 mActivity.finish();
Michael Kolb8233fac2010-10-26 16:08:53 -07002469 return;
2470 }
Michael Kolbc831b632011-05-11 09:30:34 -07002471 final Tab current = mTabControl.getCurrentTab();
2472 final int pos = mTabControl.getCurrentPosition();
2473 Tab newTab = current.getParent();
2474 if (newTab == null) {
2475 newTab = mTabControl.getTab(pos + 1);
2476 if (newTab == null) {
2477 newTab = mTabControl.getTab(pos - 1);
Michael Kolb8233fac2010-10-26 16:08:53 -07002478 }
2479 }
Michael Kolb2ae6ef72011-08-22 14:49:34 -07002480 if (andQuit) {
2481 mTabControl.setCurrentTab(newTab);
2482 closeTab(current);
2483 } else if (switchToTab(newTab)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002484 // Close window
2485 closeTab(current);
2486 }
2487 }
2488
2489 /**
2490 * Close the tab, remove its associated title bar, and adjust mTabControl's
2491 * current tab to a valid value.
2492 */
2493 @Override
2494 public void closeTab(Tab tab) {
John Reck28263772011-10-11 17:13:42 -07002495 if (tab == mTabControl.getCurrentTab()) {
2496 closeCurrentTab();
2497 } else {
2498 removeTab(tab);
2499 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002500 }
2501
Michael Kolb8233fac2010-10-26 16:08:53 -07002502 // Called when loading from context menu or LOAD_URL message
John Reck26b18322011-06-21 13:08:58 -07002503 protected void loadUrlFromContext(String url) {
2504 Tab tab = getCurrentTab();
2505 WebView view = tab != null ? tab.getWebView() : null;
Michael Kolb8233fac2010-10-26 16:08:53 -07002506 // In case the user enters nothing.
John Reck26b18322011-06-21 13:08:58 -07002507 if (url != null && url.length() != 0 && tab != null && view != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002508 url = UrlUtils.smartUrlFilter(url);
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002509 if (!WebViewClassic.fromWebView(view).getWebViewClient().
2510 shouldOverrideUrlLoading(view, url)) {
John Reck26b18322011-06-21 13:08:58 -07002511 loadUrl(tab, url);
Michael Kolb8233fac2010-10-26 16:08:53 -07002512 }
2513 }
2514 }
2515
2516 /**
2517 * Load the URL into the given WebView and update the title bar
2518 * to reflect the new load. Call this instead of WebView.loadUrl
2519 * directly.
2520 * @param view The WebView used to load url.
2521 * @param url The URL to load.
2522 */
John Reck71e51422011-07-01 16:49:28 -07002523 @Override
2524 public void loadUrl(Tab tab, String url) {
John Reck26b18322011-06-21 13:08:58 -07002525 loadUrl(tab, url, null);
2526 }
2527
2528 protected void loadUrl(Tab tab, String url, Map<String, String> headers) {
2529 if (tab != null) {
2530 dismissSubWindow(tab);
2531 tab.loadUrl(url, headers);
Michael Kolba53c9892011-10-05 13:31:40 -07002532 mUi.onProgressChanged(tab);
John Reck26b18322011-06-21 13:08:58 -07002533 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002534 }
2535
2536 /**
2537 * Load UrlData into a Tab and update the title bar to reflect the new
2538 * load. Call this instead of UrlData.loadIn directly.
2539 * @param t The Tab used to load.
2540 * @param data The UrlData being loaded.
2541 */
2542 protected void loadUrlDataIn(Tab t, UrlData data) {
John Reck26b18322011-06-21 13:08:58 -07002543 if (data != null) {
2544 if (data.mVoiceIntent != null) {
2545 t.activateVoiceSearchMode(data.mVoiceIntent);
Michael Kolb14612442011-06-24 13:06:29 -07002546 } else if (data.isPreloaded()) {
2547 // this isn't called for preloaded tabs
John Reck26b18322011-06-21 13:08:58 -07002548 } else {
2549 loadUrl(t, data.mUrl, data.mHeaders);
2550 }
2551 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002552 }
2553
John Reck30c714c2010-12-16 17:30:34 -08002554 @Override
2555 public void onUserCanceledSsl(Tab tab) {
John Reck30c714c2010-12-16 17:30:34 -08002556 // TODO: Figure out the "right" behavior
John Reckef654f12011-07-12 16:42:08 -07002557 if (tab.canGoBack()) {
2558 tab.goBack();
John Reck30c714c2010-12-16 17:30:34 -08002559 } else {
John Reckef654f12011-07-12 16:42:08 -07002560 tab.loadUrl(mSettings.getHomePage(), null);
John Reck30c714c2010-12-16 17:30:34 -08002561 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002562 }
2563
2564 void goBackOnePageOrQuit() {
2565 Tab current = mTabControl.getCurrentTab();
2566 if (current == null) {
2567 /*
2568 * Instead of finishing the activity, simply push this to the back
2569 * of the stack and let ActivityManager to choose the foreground
2570 * activity. As BrowserActivity is singleTask, it will be always the
2571 * root of the task. So we can use either true or false for
2572 * moveTaskToBack().
2573 */
2574 mActivity.moveTaskToBack(true);
2575 return;
2576 }
John Reckef654f12011-07-12 16:42:08 -07002577 if (current.canGoBack()) {
2578 current.goBack();
Michael Kolb8233fac2010-10-26 16:08:53 -07002579 } else {
2580 // Check to see if we are closing a window that was created by
2581 // another window. If so, we switch back to that window.
Michael Kolbc831b632011-05-11 09:30:34 -07002582 Tab parent = current.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -07002583 if (parent != null) {
Michael Kolbc831b632011-05-11 09:30:34 -07002584 switchToTab(parent);
Michael Kolb8233fac2010-10-26 16:08:53 -07002585 // Now we close the other tab
2586 closeTab(current);
2587 } else {
Michael Kolbe28b3472011-08-04 16:54:31 -07002588 if ((current.getAppId() != null) || current.closeOnBack()) {
Michael Kolb2ae6ef72011-08-22 14:49:34 -07002589 closeCurrentTab(true);
Michael Kolbe28b3472011-08-04 16:54:31 -07002590 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002591 /*
2592 * Instead of finishing the activity, simply push this to the back
2593 * of the stack and let ActivityManager to choose the foreground
2594 * activity. As BrowserActivity is singleTask, it will be always the
2595 * root of the task. So we can use either true or false for
2596 * moveTaskToBack().
2597 */
2598 mActivity.moveTaskToBack(true);
2599 }
2600 }
2601 }
2602
2603 /**
2604 * Feed the previously stored results strings to the BrowserProvider so that
2605 * the SearchDialog will show them instead of the standard searches.
2606 * @param result String to show on the editable line of the SearchDialog.
2607 */
2608 @Override
2609 public void showVoiceSearchResults(String result) {
2610 ContentProviderClient client = mActivity.getContentResolver()
2611 .acquireContentProviderClient(Browser.BOOKMARKS_URI);
2612 ContentProvider prov = client.getLocalContentProvider();
2613 BrowserProvider bp = (BrowserProvider) prov;
2614 bp.setQueryResults(mTabControl.getCurrentTab().getVoiceSearchResults());
2615 client.release();
2616
2617 Bundle bundle = createGoogleSearchSourceBundle(
2618 GOOGLE_SEARCH_SOURCE_SEARCHKEY);
2619 bundle.putBoolean(SearchManager.CONTEXT_IS_VOICE, true);
2620 startSearch(result, false, bundle, false);
2621 }
2622
2623 private void startSearch(String initialQuery, boolean selectInitialQuery,
2624 Bundle appSearchData, boolean globalSearch) {
2625 if (appSearchData == null) {
2626 appSearchData = createGoogleSearchSourceBundle(
2627 GOOGLE_SEARCH_SOURCE_TYPE);
2628 }
2629
2630 SearchEngine searchEngine = mSettings.getSearchEngine();
2631 if (searchEngine != null && !searchEngine.supportsVoiceSearch()) {
2632 appSearchData.putBoolean(SearchManager.DISABLE_VOICE_SEARCH, true);
2633 }
2634 mActivity.startSearch(initialQuery, selectInitialQuery, appSearchData,
2635 globalSearch);
2636 }
2637
2638 private Bundle createGoogleSearchSourceBundle(String source) {
2639 Bundle bundle = new Bundle();
2640 bundle.putString(Search.SOURCE, source);
2641 return bundle;
2642 }
2643
2644 /**
Michael Kolb0035fad2011-03-14 13:25:28 -07002645 * helper method for key handler
2646 * returns the current tab if it can't advance
2647 */
Michael Kolbc831b632011-05-11 09:30:34 -07002648 private Tab getNextTab() {
Michael Kolbf5261da2011-12-15 15:07:35 -08002649 int pos = mTabControl.getCurrentPosition() + 1;
2650 if (pos >= mTabControl.getTabCount()) {
2651 pos = 0;
2652 }
2653 return mTabControl.getTab(pos);
Michael Kolb0035fad2011-03-14 13:25:28 -07002654 }
2655
2656 /**
2657 * helper method for key handler
2658 * returns the current tab if it can't advance
2659 */
Michael Kolbc831b632011-05-11 09:30:34 -07002660 private Tab getPrevTab() {
Michael Kolbf5261da2011-12-15 15:07:35 -08002661 int pos = mTabControl.getCurrentPosition() - 1;
2662 if ( pos < 0) {
2663 pos = mTabControl.getTabCount() - 1;
2664 }
2665 return mTabControl.getTab(pos);
Michael Kolb0035fad2011-03-14 13:25:28 -07002666 }
2667
John Reckbcef87f2012-02-03 14:58:34 -08002668 boolean isMenuOrCtrlKey(int keyCode) {
2669 return (KeyEvent.KEYCODE_MENU == keyCode)
2670 || (KeyEvent.KEYCODE_CTRL_LEFT == keyCode)
2671 || (KeyEvent.KEYCODE_CTRL_RIGHT == keyCode);
2672 }
2673
Michael Kolb0035fad2011-03-14 13:25:28 -07002674 /**
Michael Kolb8233fac2010-10-26 16:08:53 -07002675 * handle key events in browser
2676 *
2677 * @param keyCode
2678 * @param event
2679 * @return true if handled, false to pass to super
2680 */
2681 boolean onKeyDown(int keyCode, KeyEvent event) {
Cary Clark160bbb92011-01-10 11:17:07 -05002682 boolean noModifiers = event.hasNoModifiers();
Michael Kolb8233fac2010-10-26 16:08:53 -07002683 // Even if MENU is already held down, we need to call to super to open
2684 // the IME on long press.
John Reckbcef87f2012-02-03 14:58:34 -08002685 if (!noModifiers && isMenuOrCtrlKey(keyCode)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002686 mMenuIsDown = true;
2687 return false;
2688 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002689
Cary Clark8ff8c662010-12-29 15:03:05 -05002690 WebView webView = getCurrentTopWebView();
John Reckef654f12011-07-12 16:42:08 -07002691 Tab tab = getCurrentTab();
2692 if (webView == null || tab == null) return false;
Cary Clark8ff8c662010-12-29 15:03:05 -05002693
Cary Clark160bbb92011-01-10 11:17:07 -05002694 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
2695 boolean shift = event.hasModifiers(KeyEvent.META_SHIFT_ON);
Cary Clark8ff8c662010-12-29 15:03:05 -05002696
Michael Kolb8233fac2010-10-26 16:08:53 -07002697 switch(keyCode) {
Michael Kolb0035fad2011-03-14 13:25:28 -07002698 case KeyEvent.KEYCODE_TAB:
2699 if (event.isCtrlPressed()) {
2700 if (event.isShiftPressed()) {
2701 // prev tab
Michael Kolbc831b632011-05-11 09:30:34 -07002702 switchToTab(getPrevTab());
Michael Kolb0035fad2011-03-14 13:25:28 -07002703 } else {
2704 // next tab
Michael Kolbc831b632011-05-11 09:30:34 -07002705 switchToTab(getNextTab());
Michael Kolb0035fad2011-03-14 13:25:28 -07002706 }
2707 return true;
2708 }
2709 break;
Michael Kolb8233fac2010-10-26 16:08:53 -07002710 case KeyEvent.KEYCODE_SPACE:
2711 // WebView/WebTextView handle the keys in the KeyDown. As
2712 // the Activity's shortcut keys are only handled when WebView
2713 // doesn't, have to do it in onKeyDown instead of onKeyUp.
Cary Clark160bbb92011-01-10 11:17:07 -05002714 if (shift) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002715 pageUp();
Cary Clark160bbb92011-01-10 11:17:07 -05002716 } else if (noModifiers) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002717 pageDown();
2718 }
2719 return true;
2720 case KeyEvent.KEYCODE_BACK:
Cary Clark160bbb92011-01-10 11:17:07 -05002721 if (!noModifiers) break;
John Recke6bf4ab2011-02-24 15:48:05 -08002722 event.startTracking();
2723 return true;
Michael Kolbe9e1d4a2011-07-14 15:02:17 -07002724 case KeyEvent.KEYCODE_FORWARD:
2725 if (!noModifiers) break;
2726 tab.goForward();
2727 return true;
Cary Clark8ff8c662010-12-29 15:03:05 -05002728 case KeyEvent.KEYCODE_DPAD_LEFT:
2729 if (ctrl) {
John Reckef654f12011-07-12 16:42:08 -07002730 tab.goBack();
Cary Clark8ff8c662010-12-29 15:03:05 -05002731 return true;
2732 }
2733 break;
2734 case KeyEvent.KEYCODE_DPAD_RIGHT:
2735 if (ctrl) {
John Reckef654f12011-07-12 16:42:08 -07002736 tab.goForward();
Cary Clark8ff8c662010-12-29 15:03:05 -05002737 return true;
2738 }
2739 break;
2740 case KeyEvent.KEYCODE_A:
2741 if (ctrl) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002742 WebViewClassic.fromWebView(webView).selectAll();
Cary Clark8ff8c662010-12-29 15:03:05 -05002743 return true;
2744 }
2745 break;
Michael Kolba4183062011-01-16 10:43:21 -08002746// case KeyEvent.KEYCODE_B: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002747 case KeyEvent.KEYCODE_C:
2748 if (ctrl) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002749 WebViewClassic.fromWebView(webView).copySelection();
Cary Clark8ff8c662010-12-29 15:03:05 -05002750 return true;
2751 }
2752 break;
Michael Kolba4183062011-01-16 10:43:21 -08002753// case KeyEvent.KEYCODE_D: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002754// case KeyEvent.KEYCODE_E: // in Chrome: puts '?' in URL bar
Michael Kolba4183062011-01-16 10:43:21 -08002755// case KeyEvent.KEYCODE_F: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002756// case KeyEvent.KEYCODE_G: // in Chrome: finds next match
Michael Kolba4183062011-01-16 10:43:21 -08002757// case KeyEvent.KEYCODE_H: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002758// case KeyEvent.KEYCODE_I: // unused
Michael Kolba4183062011-01-16 10:43:21 -08002759// case KeyEvent.KEYCODE_J: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002760// case KeyEvent.KEYCODE_K: // in Chrome: puts '?' in URL bar
Michael Kolba4183062011-01-16 10:43:21 -08002761// case KeyEvent.KEYCODE_L: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002762// case KeyEvent.KEYCODE_M: // unused
2763// case KeyEvent.KEYCODE_N: // in Chrome: new window
2764// case KeyEvent.KEYCODE_O: // in Chrome: open file
2765// case KeyEvent.KEYCODE_P: // in Chrome: print page
2766// case KeyEvent.KEYCODE_Q: // unused
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08002767// case KeyEvent.KEYCODE_R:
Cary Clark8ff8c662010-12-29 15:03:05 -05002768// case KeyEvent.KEYCODE_S: // in Chrome: saves page
2769 case KeyEvent.KEYCODE_T:
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08002770 // we can't use the ctrl/shift flags, they check for
2771 // exclusive use of a modifier
2772 if (event.isCtrlPressed()) {
Cary Clark8ff8c662010-12-29 15:03:05 -05002773 if (event.isShiftPressed()) {
Michael Kolb519d2282011-05-09 17:03:19 -07002774 openIncognitoTab();
Cary Clark8ff8c662010-12-29 15:03:05 -05002775 } else {
2776 openTabToHomePage();
2777 }
2778 return true;
2779 }
2780 break;
2781// case KeyEvent.KEYCODE_U: // in Chrome: opens source of page
2782// case KeyEvent.KEYCODE_V: // text view intercepts to paste
Michael Kolb5ae15bd2011-08-16 17:09:27 -07002783// case KeyEvent.KEYCODE_W: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05002784// case KeyEvent.KEYCODE_X: // text view intercepts to cut
2785// case KeyEvent.KEYCODE_Y: // unused
2786// case KeyEvent.KEYCODE_Z: // unused
Michael Kolb8233fac2010-10-26 16:08:53 -07002787 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08002788 // it is a regular key and webview is not null
2789 return mUi.dispatchKey(keyCode, event);
Michael Kolb8233fac2010-10-26 16:08:53 -07002790 }
2791
John Recke6bf4ab2011-02-24 15:48:05 -08002792 boolean onKeyLongPress(int keyCode, KeyEvent event) {
2793 switch(keyCode) {
2794 case KeyEvent.KEYCODE_BACK:
John Reck3ba45532011-08-11 16:26:53 -07002795 if (mUi.isWebShowing()) {
Michael Kolb315d5022011-10-13 12:47:11 -07002796 bookmarksOrHistoryPicker(ComboViews.History);
John Recke6bf4ab2011-02-24 15:48:05 -08002797 return true;
2798 }
2799 break;
2800 }
2801 return false;
2802 }
2803
Michael Kolb8233fac2010-10-26 16:08:53 -07002804 boolean onKeyUp(int keyCode, KeyEvent event) {
John Reckbcef87f2012-02-03 14:58:34 -08002805 if (isMenuOrCtrlKey(keyCode)) {
Michael Kolb2814a362011-05-19 15:49:41 -07002806 mMenuIsDown = false;
John Reckbcef87f2012-02-03 14:58:34 -08002807 if (KeyEvent.KEYCODE_MENU == keyCode
2808 && event.isTracking() && !event.isCanceled()) {
Michael Kolb4bd767d2011-05-27 11:33:55 -07002809 return onMenuKey();
Michael Kolb2814a362011-05-19 15:49:41 -07002810 }
2811 }
Cary Clark160bbb92011-01-10 11:17:07 -05002812 if (!event.hasNoModifiers()) return false;
Michael Kolb8233fac2010-10-26 16:08:53 -07002813 switch(keyCode) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002814 case KeyEvent.KEYCODE_BACK:
2815 if (event.isTracking() && !event.isCanceled()) {
2816 onBackKey();
2817 return true;
2818 }
2819 break;
2820 }
2821 return false;
2822 }
2823
2824 public boolean isMenuDown() {
2825 return mMenuIsDown;
2826 }
2827
Ben Murdoch8029a772010-11-16 11:58:21 +00002828 public void setupAutoFill(Message message) {
2829 // Open the settings activity at the AutoFill profile fragment so that
2830 // the user can create a new profile. When they return, we will dispatch
2831 // the message so that we can autofill the form using their new profile.
2832 Intent intent = new Intent(mActivity, BrowserPreferencesPage.class);
2833 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
2834 AutoFillSettingsFragment.class.getName());
2835 mAutoFillSetupMessage = message;
2836 mActivity.startActivityForResult(intent, AUTOFILL_SETUP);
2837 }
John Reckb3417f02011-01-14 11:01:05 -08002838
Michael Kolbfbc579a2011-07-07 15:59:33 -07002839 public boolean onSearchRequested() {
Michael Kolb1f9b3562012-04-24 14:38:34 -07002840 mUi.editUrl(false, true);
Michael Kolbfbc579a2011-07-07 15:59:33 -07002841 return true;
2842 }
2843
John Reck1cf4b792011-07-26 10:22:22 -07002844 @Override
2845 public boolean shouldCaptureThumbnails() {
2846 return mUi.shouldCaptureThumbnails();
2847 }
2848
Michael Kolbc3af0672011-08-09 10:24:41 -07002849 @Override
2850 public void setBlockEvents(boolean block) {
2851 mBlockEvents = block;
2852 }
2853
2854 public boolean dispatchKeyEvent(KeyEvent event) {
Michael Kolb87357642011-08-24 14:19:18 -07002855 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07002856 }
2857
2858 public boolean dispatchKeyShortcutEvent(KeyEvent event) {
Michael Kolb87357642011-08-24 14:19:18 -07002859 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07002860 }
2861
2862 public boolean dispatchTouchEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07002863 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07002864 }
2865
2866 public boolean dispatchTrackballEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07002867 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07002868 }
2869
2870 public boolean dispatchGenericMotionEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07002871 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07002872 }
2873
Michael Kolb8233fac2010-10-26 16:08:53 -07002874}