blob: b1df847480f8442cba2a5792ab3c985b5d1dcc56 [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;
luxiaolb40014b2013-07-19 10:01:43 +080020import android.app.AlertDialog;
John Reck68234a92012-04-19 15:27:12 -070021import 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.content.ClipboardManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070025import android.content.ContentResolver;
John Reckd8c74522011-06-14 08:45:00 -070026import android.content.ContentUris;
Michael Kolb8233fac2010-10-26 16:08:53 -070027import android.content.ContentValues;
28import android.content.Context;
John Reck68234a92012-04-19 15:27:12 -070029import android.content.DialogInterface;
30import android.content.DialogInterface.OnCancelListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.content.Intent;
32import android.content.pm.PackageManager;
33import android.content.pm.ResolveInfo;
34import android.content.res.Configuration;
John Reck30b065e2011-07-19 10:58:05 -070035import android.content.res.TypedArray;
Leon Scroggins1961ed22010-12-07 15:22:21 -050036import android.database.ContentObserver;
Michael Kolb8233fac2010-10-26 16:08:53 -070037import android.database.Cursor;
38import android.database.sqlite.SQLiteDatabase;
Mattias Nilsson561d1952011-10-04 10:18:50 +020039import android.database.sqlite.SQLiteException;
Michael Kolb8233fac2010-10-26 16:08:53 -070040import android.graphics.Bitmap;
kaiyiz6e5b3e02013-08-19 20:02:01 +080041import android.graphics.BitmapFactory;
Michael Kolb8233fac2010-10-26 16:08:53 -070042import android.graphics.Canvas;
kaiyiza016da12013-08-26 17:50:22 +080043import android.net.ConnectivityManager;
44import android.net.NetworkInfo;
Michael Kolb8233fac2010-10-26 16:08:53 -070045import android.net.Uri;
46import android.net.http.SslError;
kaiyiz6e5b3e02013-08-19 20:02:01 +080047import android.net.WebAddress;
kaiyiza016da12013-08-26 17:50:22 +080048import android.net.wifi.WifiManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.os.AsyncTask;
50import android.os.Bundle;
George Mount387d45d2011-10-07 15:57:53 -070051import android.os.Environment;
Michael Kolb8233fac2010-10-26 16:08:53 -070052import android.os.Handler;
53import android.os.Message;
54import android.os.PowerManager;
55import android.os.PowerManager.WakeLock;
kaiyiza8b6dbb2013-07-29 18:11:22 +080056import android.os.SystemProperties;
Ben Murdoch8029a772010-11-16 11:58:21 +000057import android.preference.PreferenceActivity;
Michael Kolb8233fac2010-10-26 16:08:53 -070058import android.provider.Browser;
59import android.provider.BrowserContract;
Michael Kolb8233fac2010-10-26 16:08:53 -070060import android.provider.BrowserContract.Images;
61import android.provider.ContactsContract;
62import android.provider.ContactsContract.Intents.Insert;
kaiyiza016da12013-08-26 17:50:22 +080063import android.provider.Settings;
Michael Kolb0b129122012-06-04 16:31:58 -070064import android.speech.RecognizerIntent;
Michael Kolb8233fac2010-10-26 16:08:53 -070065import android.text.TextUtils;
66import android.util.Log;
John Recka00cbbd2010-12-16 12:38:19 -080067import android.util.Patterns;
Michael Kolb8233fac2010-10-26 16:08:53 -070068import android.view.ActionMode;
69import android.view.ContextMenu;
70import android.view.ContextMenu.ContextMenuInfo;
71import android.view.Gravity;
72import android.view.KeyEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070073import android.view.Menu;
74import android.view.MenuInflater;
75import android.view.MenuItem;
76import android.view.MenuItem.OnMenuItemClickListener;
Michael Kolbc3af0672011-08-09 10:24:41 -070077import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070078import android.view.View;
79import android.webkit.CookieManager;
80import android.webkit.CookieSyncManager;
81import android.webkit.HttpAuthHandler;
George Mount387d45d2011-10-07 15:57:53 -070082import android.webkit.MimeTypeMap;
Michael Kolb8233fac2010-10-26 16:08:53 -070083import android.webkit.SslErrorHandler;
84import android.webkit.ValueCallback;
85import android.webkit.WebChromeClient;
86import android.webkit.WebIconDatabase;
87import android.webkit.WebSettings;
88import android.webkit.WebView;
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +000089import android.webkit.WebViewClassic;
Leon Scrogginsac993842011-02-02 12:54:07 -050090import android.widget.Toast;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb4bd767d2011-05-27 11:33:55 -070092import com.android.browser.IntentHandler.UrlData;
John Reck2bc80422011-06-30 15:11:49 -070093import com.android.browser.UI.ComboViews;
John Reck1cf4b792011-07-26 10:22:22 -070094import com.android.browser.provider.BrowserProvider2.Thumbnails;
John Reck8cc92352011-07-06 17:41:52 -070095import com.android.browser.provider.SnapshotProvider.Snapshots;
kaiyiz6e5b3e02013-08-19 20:02:01 +080096import com.android.browser.mynavigation.AddMyNavigationPage;
97import com.android.browser.mynavigation.MyNavigationUtil;
Michael Kolb4bd767d2011-05-27 11:33:55 -070098
Michael Kolb8233fac2010-10-26 16:08:53 -070099import java.io.ByteArrayOutputStream;
George Mount387d45d2011-10-07 15:57:53 -0700100import java.io.File;
101import java.io.FileOutputStream;
102import java.io.IOException;
Michael Kolb8233fac2010-10-26 16:08:53 -0700103import java.net.URLEncoder;
George Mount387d45d2011-10-07 15:57:53 -0700104import java.text.DateFormat;
105import java.text.SimpleDateFormat;
John Reck1cf4b792011-07-26 10:22:22 -0700106import java.util.ArrayList;
Michael Kolb8233fac2010-10-26 16:08:53 -0700107import java.util.Calendar;
George Mount387d45d2011-10-07 15:57:53 -0700108import java.util.Date;
Michael Kolb8233fac2010-10-26 16:08:53 -0700109import java.util.HashMap;
Michael Kolb1bf23132010-11-19 12:55:12 -0800110import java.util.List;
Johan Redestigaa676182012-10-03 13:33:01 +0200111import java.util.Locale;
John Reck26b18322011-06-21 13:08:58 -0700112import java.util.Map;
Michael Kolb8233fac2010-10-26 16:08:53 -0700113
114/**
115 * Controller for browser
116 */
117public class Controller
John Reck9c35b9c2012-05-30 10:08:50 -0700118 implements WebViewController, UiController, ActivityController {
Michael Kolb8233fac2010-10-26 16:08:53 -0700119
120 private static final String LOGTAG = "Controller";
Michael Kolbcfa3af52010-12-14 10:36:11 -0800121 private static final String SEND_APP_ID_EXTRA =
122 "android.speech.extras.SEND_APPLICATION_ID_EXTRA";
Michael Kolba4261fd2011-05-05 11:27:37 -0700123 private static final String INCOGNITO_URI = "browser:incognito";
kaiyiza016da12013-08-26 17:50:22 +0800124 private static final String PROP_NETSWITCH = "persist.env.browser.netswitch";
125 private static final String INTENT_WIFI_SELECTION_DATA_CONNECTION =
126 "android.net.wifi.cmcc.WIFI_SELECTION_DATA_CONNECTION";
kaiyiz6e5b3e02013-08-19 20:02:01 +0800127 private static final String OFFLINE_PAGE =
128 "content://com.android.browser.mynavigation/websites";
Michael Kolb8233fac2010-10-26 16:08:53 -0700129
130 // public message ids
131 public final static int LOAD_URL = 1001;
132 public final static int STOP_LOAD = 1002;
133
134 // Message Ids
135 private static final int FOCUS_NODE_HREF = 102;
136 private static final int RELEASE_WAKELOCK = 107;
137
138 static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
139
140 private static final int OPEN_BOOKMARKS = 201;
kaiyiz591110b2013-08-06 17:11:06 +0800141 private static final int OPEN_MENU = 202;
Michael Kolb8233fac2010-10-26 16:08:53 -0700142
143 private static final int EMPTY_MENU = -1;
144
Michael Kolb8233fac2010-10-26 16:08:53 -0700145 // activity requestCode
John Reckd3e4d5b2011-07-13 15:48:43 -0700146 final static int COMBO_VIEW = 1;
Michael Kolb8233fac2010-10-26 16:08:53 -0700147 final static int PREFERENCES_PAGE = 3;
148 final static int FILE_SELECTED = 4;
Ben Murdoch8029a772010-11-16 11:58:21 +0000149 final static int AUTOFILL_SETUP = 5;
Michael Kolb0b129122012-06-04 16:31:58 -0700150 final static int VOICE_RESULT = 6;
kaiyiz6e5b3e02013-08-19 20:02:01 +0800151 final static int MY_NAVIGATION = 7;
Ben Murdoch8029a772010-11-16 11:58:21 +0000152
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes
154
155 // As the ids are dynamically created, we can't guarantee that they will
156 // be in sequence, so this static array maps ids to a window number.
157 final static private int[] WINDOW_SHORTCUT_ID_ARRAY =
158 { R.id.window_one_menu_id, R.id.window_two_menu_id,
159 R.id.window_three_menu_id, R.id.window_four_menu_id,
160 R.id.window_five_menu_id, R.id.window_six_menu_id,
161 R.id.window_seven_menu_id, R.id.window_eight_menu_id };
162
163 // "source" parameter for Google search through search key
164 final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key";
165 // "source" parameter for Google search through simplily type
166 final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type";
167
George Mount387d45d2011-10-07 15:57:53 -0700168 // "no-crash-recovery" parameter in intent to suppress crash recovery
Guang Zhu9e78f512011-05-04 11:45:11 -0700169 final static String NO_CRASH_RECOVERY = "no-crash-recovery";
170
John Reckd7dd9b22011-08-30 09:18:29 -0700171 // A bitmap that is re-used in createScreenshot as scratch space
172 private static Bitmap sThumbnailBitmap;
173
Michael Kolb8233fac2010-10-26 16:08:53 -0700174 private Activity mActivity;
175 private UI mUi;
176 private TabControl mTabControl;
177 private BrowserSettings mSettings;
178 private WebViewFactory mFactory;
179
180 private WakeLock mWakeLock;
181
182 private UrlHandler mUrlHandler;
183 private UploadHandler mUploadHandler;
184 private IntentHandler mIntentHandler;
Michael Kolb8233fac2010-10-26 16:08:53 -0700185 private PageDialogsHandler mPageDialogsHandler;
186 private NetworkStateHandler mNetworkHandler;
187
Ben Murdoch8029a772010-11-16 11:58:21 +0000188 private Message mAutoFillSetupMessage;
189
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 private boolean mShouldShowErrorConsole;
kaiyiza016da12013-08-26 17:50:22 +0800191 private boolean mNetworkShouldNotify = true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700192
193 private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins;
194
195 // FIXME, temp address onPrepareMenu performance problem.
196 // When we move everything out of view, we should rewrite this.
197 private int mCurrentMenuState = 0;
198 private int mMenuState = R.id.MAIN_MENU;
199 private int mOldMenuState = EMPTY_MENU;
200 private Menu mCachedMenu;
201
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 private boolean mMenuIsDown;
203
204 // For select and find, we keep track of the ActionMode so that
205 // finish() can be called as desired.
206 private ActionMode mActionMode;
207
208 /**
209 * Only meaningful when mOptionsMenuOpen is true. This variable keeps track
210 * of whether the configuration has changed. The first onMenuOpened call
211 * after a configuration change is simply a reopening of the same menu
212 * (i.e. mIconView did not change).
213 */
214 private boolean mConfigChanged;
215
216 /**
217 * Keeps track of whether the options menu is open. This is important in
218 * determining whether to show or hide the title bar overlay
219 */
220 private boolean mOptionsMenuOpen;
221
222 /**
223 * Whether or not the options menu is in its bigger, popup menu form. When
224 * true, we want the title bar overlay to be gone. When false, we do not.
225 * Only meaningful if mOptionsMenuOpen is true.
226 */
227 private boolean mExtendedMenuOpen;
228
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 private boolean mActivityPaused = true;
230 private boolean mLoadStopped;
231
232 private Handler mHandler;
Leon Scroggins1961ed22010-12-07 15:22:21 -0500233 // Checks to see when the bookmarks database has changed, and updates the
234 // Tabs' notion of whether they represent bookmarked sites.
235 private ContentObserver mBookmarksObserver;
John Reck847b5322011-04-14 17:02:18 -0700236 private CrashRecoveryHandler mCrashRecoveryHandler;
Michael Kolb8233fac2010-10-26 16:08:53 -0700237
Michael Kolbc3af0672011-08-09 10:24:41 -0700238 private boolean mBlockEvents;
239
Michael Kolb0b129122012-06-04 16:31:58 -0700240 private String mVoiceResult;
kaiyiz6e5b3e02013-08-19 20:02:01 +0800241 private boolean mUpdateMyNavThumbnail;
242 private String mUpdateMyNavThumbnailUrl;
Michael Kolb0b129122012-06-04 16:31:58 -0700243
George Mount3636d0a2011-11-21 09:08:21 -0800244 public Controller(Activity browser) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700245 mActivity = browser;
246 mSettings = BrowserSettings.getInstance();
247 mTabControl = new TabControl(this);
248 mSettings.setController(this);
John Reck378a4102011-06-09 16:23:01 -0700249 mCrashRecoveryHandler = CrashRecoveryHandler.initialize(this);
George Mount3636d0a2011-11-21 09:08:21 -0800250 mCrashRecoveryHandler.preloadCrashState();
Michael Kolb14612442011-06-24 13:06:29 -0700251 mFactory = new BrowserWebViewFactory(browser);
Michael Kolb8233fac2010-10-26 16:08:53 -0700252
253 mUrlHandler = new UrlHandler(this);
254 mIntentHandler = new IntentHandler(mActivity, this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 mPageDialogsHandler = new PageDialogsHandler(mActivity, this);
256
Michael Kolb8233fac2010-10-26 16:08:53 -0700257 startHandler();
Leon Scroggins1961ed22010-12-07 15:22:21 -0500258 mBookmarksObserver = new ContentObserver(mHandler) {
259 @Override
260 public void onChange(boolean selfChange) {
261 int size = mTabControl.getTabCount();
262 for (int i = 0; i < size; i++) {
263 mTabControl.getTab(i).updateBookmarkedStatus();
264 }
265 }
266
267 };
268 browser.getContentResolver().registerContentObserver(
269 BrowserContract.Bookmarks.CONTENT_URI, true, mBookmarksObserver);
Michael Kolb8233fac2010-10-26 16:08:53 -0700270
271 mNetworkHandler = new NetworkStateHandler(mActivity, this);
272 // Start watching the default geolocation permissions
273 mSystemAllowGeolocationOrigins =
274 new SystemAllowGeolocationOrigins(mActivity.getApplicationContext());
275 mSystemAllowGeolocationOrigins.start();
276
John Reckaf262e72011-07-25 13:55:44 -0700277 openIconDatabase();
Michael Kolb8233fac2010-10-26 16:08:53 -0700278 }
279
John Reck9c35b9c2012-05-30 10:08:50 -0700280 @Override
281 public void start(final Intent intent) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800282 if (BrowserWebView.isClassic()) WebViewClassic.setShouldMonitorWebCoreThread();
George Mount3636d0a2011-11-21 09:08:21 -0800283 // mCrashRecoverHandler has any previously saved state.
284 mCrashRecoveryHandler.startRecovery(intent);
John Reck847b5322011-04-14 17:02:18 -0700285 }
286
George Mount3636d0a2011-11-21 09:08:21 -0800287 void doStart(final Bundle icicle, final Intent intent) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700288 // Unless the last browser usage was within 24 hours, destroy any
289 // remaining incognito tabs.
290
291 Calendar lastActiveDate = icicle != null ?
292 (Calendar) icicle.getSerializable("lastActiveDate") : null;
293 Calendar today = Calendar.getInstance();
294 Calendar yesterday = Calendar.getInstance();
295 yesterday.add(Calendar.DATE, -1);
296
Patrick Scott7d50a932011-02-04 09:27:26 -0500297 final boolean restoreIncognitoTabs = !(lastActiveDate == null
Michael Kolb8233fac2010-10-26 16:08:53 -0700298 || lastActiveDate.before(yesterday)
Michael Kolb1bf23132010-11-19 12:55:12 -0800299 || lastActiveDate.after(today));
Michael Kolb8233fac2010-10-26 16:08:53 -0700300
Patrick Scott7d50a932011-02-04 09:27:26 -0500301 // Find out if we will restore any state and remember the tab.
Michael Kolbc831b632011-05-11 09:30:34 -0700302 final long currentTabId =
Patrick Scott7d50a932011-02-04 09:27:26 -0500303 mTabControl.canRestoreState(icicle, restoreIncognitoTabs);
Kristian Monsen2cd97012010-12-07 11:11:40 +0000304
Michael Kolbc831b632011-05-11 09:30:34 -0700305 if (currentTabId == -1) {
Patrick Scott7d50a932011-02-04 09:27:26 -0500306 // Not able to restore so we go ahead and clear session cookies. We
307 // must do this before trying to login the user as we don't want to
308 // clear any session cookies set during login.
309 CookieManager.getInstance().removeSessionCookie();
310 }
311
Patrick Scottd43e75a2011-03-14 14:47:23 -0400312 GoogleAccountLogin.startLoginIfNeeded(mActivity,
Patrick Scott7d50a932011-02-04 09:27:26 -0500313 new Runnable() {
314 @Override public void run() {
George Mount3636d0a2011-11-21 09:08:21 -0800315 onPreloginFinished(icicle, intent, currentTabId,
316 restoreIncognitoTabs);
Patrick Scott7d50a932011-02-04 09:27:26 -0500317 }
318 });
319 }
320
Michael Kolbc831b632011-05-11 09:30:34 -0700321 private void onPreloginFinished(Bundle icicle, Intent intent, long currentTabId,
George Mount3636d0a2011-11-21 09:08:21 -0800322 boolean restoreIncognitoTabs) {
Michael Kolbc831b632011-05-11 09:30:34 -0700323 if (currentTabId == -1) {
John Reck1cf4b792011-07-26 10:22:22 -0700324 BackgroundHandler.execute(new PruneThumbnails(mActivity, null));
George Mount3636d0a2011-11-21 09:08:21 -0800325 if (intent == null) {
326 // This won't happen under common scenarios. The icicle is
327 // not null, but there aren't any tabs to restore.
328 openTabToHomePage();
Michael Kolb7bcafde2011-05-09 13:55:59 -0700329 } else {
George Mount3636d0a2011-11-21 09:08:21 -0800330 final Bundle extra = intent.getExtras();
331 // Create an initial tab.
332 // If the intent is ACTION_VIEW and data is not null, the Browser is
333 // invoked to view the content by another application. In this case,
334 // the tab will be close when exit.
kaiyiz6e5b3e02013-08-19 20:02:01 +0800335 UrlData urlData = null;
336 if (intent.getData() != null
337 && Intent.ACTION_VIEW.equals(intent.getAction())
338 && intent.getData().toString().startsWith("content://")) {
339 urlData = new UrlData(intent.getData().toString());
340 } else {
341 urlData = IntentHandler.getUrlDataFromIntent(intent);
342 }
343
George Mount3636d0a2011-11-21 09:08:21 -0800344 Tab t = null;
345 if (urlData.isEmpty()) {
kaiyiz6e5b3e02013-08-19 20:02:01 +0800346 if (SystemProperties.get("persist.env.c.browser.resource", "default").equals(
347 "cmcc")) {
348 t = openTab(OFFLINE_PAGE, false, true, true);
349 } else {
350 t = openTabToHomePage();
351 }
George Mount3636d0a2011-11-21 09:08:21 -0800352 } else {
353 t = openTab(urlData);
354 }
355 if (t != null) {
356 t.setAppId(intent.getStringExtra(Browser.EXTRA_APPLICATION_ID));
357 }
358 WebView webView = t.getWebView();
359 if (extra != null) {
360 int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0);
361 if (scale > 0 && scale <= 1000) {
362 webView.setInitialScale(scale);
363 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700364 }
365 }
John Reckd8c74522011-06-14 08:45:00 -0700366 mUi.updateTabs(mTabControl.getTabs());
Michael Kolb8233fac2010-10-26 16:08:53 -0700367 } else {
Michael Kolbc831b632011-05-11 09:30:34 -0700368 mTabControl.restoreState(icicle, currentTabId, restoreIncognitoTabs,
Patrick Scott7d50a932011-02-04 09:27:26 -0500369 mUi.needsRestoreAllTabs());
John Reck1cf4b792011-07-26 10:22:22 -0700370 List<Tab> tabs = mTabControl.getTabs();
371 ArrayList<Long> restoredTabs = new ArrayList<Long>(tabs.size());
372 for (Tab t : tabs) {
373 restoredTabs.add(t.getId());
374 }
375 BackgroundHandler.execute(new PruneThumbnails(mActivity, restoredTabs));
John Reck52be4782011-08-26 15:37:29 -0700376 if (tabs.size() == 0) {
377 openTabToHomePage();
378 }
John Reck1cf4b792011-07-26 10:22:22 -0700379 mUi.updateTabs(tabs);
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 // TabControl.restoreState() will create a new tab even if
381 // restoring the state fails.
382 setActiveTab(mTabControl.getCurrentTab());
George Mount3636d0a2011-11-21 09:08:21 -0800383 // Intent is non-null when framework thinks the browser should be
384 // launching with a new intent (icicle is null).
385 if (intent != null) {
John Reck9dd4a412011-10-05 14:55:30 -0700386 mIntentHandler.onNewIntent(intent);
387 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700388 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 // Read JavaScript flags if it exists.
John Reck35e9dd62011-04-25 09:01:54 -0700390 String jsFlags = getSettings().getJsEngineFlags();
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800391 if (jsFlags.trim().length() != 0 && BrowserWebView.isClassic()) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +0000392 WebViewClassic.fromWebView(getCurrentWebView()).setJsFlags(jsFlags);
Michael Kolb8233fac2010-10-26 16:08:53 -0700393 }
George Mount3636d0a2011-11-21 09:08:21 -0800394 if (intent != null
395 && BrowserActivity.ACTION_SHOW_BOOKMARKS.equals(intent.getAction())) {
Michael Kolb315d5022011-10-13 12:47:11 -0700396 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
John Reck439c9a52010-12-14 10:04:39 -0800397 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700398 }
399
John Reck1cf4b792011-07-26 10:22:22 -0700400 private static class PruneThumbnails implements Runnable {
401 private Context mContext;
402 private List<Long> mIds;
403
404 PruneThumbnails(Context context, List<Long> preserveIds) {
405 mContext = context.getApplicationContext();
406 mIds = preserveIds;
407 }
408
409 @Override
410 public void run() {
411 ContentResolver cr = mContext.getContentResolver();
412 if (mIds == null || mIds.size() == 0) {
413 cr.delete(Thumbnails.CONTENT_URI, null, null);
414 } else {
415 int length = mIds.size();
416 StringBuilder where = new StringBuilder();
417 where.append(Thumbnails._ID);
418 where.append(" not in (");
419 for (int i = 0; i < length; i++) {
420 where.append(mIds.get(i));
421 if (i < (length - 1)) {
422 where.append(",");
423 }
424 }
425 where.append(")");
426 cr.delete(Thumbnails.CONTENT_URI, where.toString(), null);
427 }
428 }
429
430 }
431
Michael Kolb1514bb72010-11-22 09:11:48 -0800432 @Override
433 public WebViewFactory getWebViewFactory() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700434 return mFactory;
435 }
436
437 @Override
Michael Kolba713ec82010-11-29 17:27:06 -0800438 public void onSetWebView(Tab tab, WebView view) {
439 mUi.onSetWebView(tab, view);
440 }
441
442 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800443 public void createSubWindow(Tab tab) {
444 endActionMode();
445 WebView mainView = tab.getWebView();
446 WebView subView = mFactory.createWebView((mainView == null)
447 ? false
448 : mainView.isPrivateBrowsingEnabled());
449 mUi.createSubWindow(tab, subView);
450 }
451
452 @Override
Michael Kolb14612442011-06-24 13:06:29 -0700453 public Context getContext() {
454 return mActivity;
455 }
456
457 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700458 public Activity getActivity() {
459 return mActivity;
460 }
461
462 void setUi(UI ui) {
463 mUi = ui;
464 }
465
Michael Kolbaf63dba2012-05-16 12:58:05 -0700466 @Override
467 public BrowserSettings getSettings() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700468 return mSettings;
469 }
470
471 IntentHandler getIntentHandler() {
472 return mIntentHandler;
473 }
474
475 @Override
476 public UI getUi() {
477 return mUi;
478 }
479
480 int getMaxTabs() {
481 return mActivity.getResources().getInteger(R.integer.max_tabs);
482 }
483
484 @Override
485 public TabControl getTabControl() {
486 return mTabControl;
487 }
488
Michael Kolb1bf23132010-11-19 12:55:12 -0800489 @Override
490 public List<Tab> getTabs() {
491 return mTabControl.getTabs();
492 }
493
John Reckaf262e72011-07-25 13:55:44 -0700494 // Open the icon database.
495 private void openIconDatabase() {
496 // We have to call getInstance on the UI thread
497 final WebIconDatabase instance = WebIconDatabase.getInstance();
498 BackgroundHandler.execute(new Runnable() {
Ben Murdoch9446b932010-11-25 16:20:14 +0000499
John Reckaf262e72011-07-25 13:55:44 -0700500 @Override
501 public void run() {
502 instance.open(mActivity.getDir("icons", 0).getPath());
Michael Kolb8233fac2010-10-26 16:08:53 -0700503 }
John Reckaf262e72011-07-25 13:55:44 -0700504 });
Michael Kolb8233fac2010-10-26 16:08:53 -0700505 }
506
507 private void startHandler() {
508 mHandler = new Handler() {
509
510 @Override
511 public void handleMessage(Message msg) {
512 switch (msg.what) {
513 case OPEN_BOOKMARKS:
Michael Kolb315d5022011-10-13 12:47:11 -0700514 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
Michael Kolb8233fac2010-10-26 16:08:53 -0700515 break;
516 case FOCUS_NODE_HREF:
517 {
518 String url = (String) msg.getData().get("url");
519 String title = (String) msg.getData().get("title");
Cary Clark043c2d62010-12-15 11:19:39 -0500520 String src = (String) msg.getData().get("src");
521 if (url == "") url = src; // use image if no anchor
Michael Kolb8233fac2010-10-26 16:08:53 -0700522 if (TextUtils.isEmpty(url)) {
523 break;
524 }
525 HashMap focusNodeMap = (HashMap) msg.obj;
526 WebView view = (WebView) focusNodeMap.get("webview");
527 // Only apply the action if the top window did not change.
528 if (getCurrentTopWebView() != view) {
529 break;
530 }
531 switch (msg.arg1) {
532 case R.id.open_context_menu_id:
John Reck26b18322011-06-21 13:08:58 -0700533 loadUrlFromContext(url);
Michael Kolb8233fac2010-10-26 16:08:53 -0700534 break;
Cary Clark043c2d62010-12-15 11:19:39 -0500535 case R.id.view_image_context_menu_id:
John Reck26b18322011-06-21 13:08:58 -0700536 loadUrlFromContext(src);
Cary Clark043c2d62010-12-15 11:19:39 -0500537 break;
Leon Scroggins026f2542010-11-22 13:26:12 -0500538 case R.id.open_newtab_context_menu_id:
539 final Tab parent = mTabControl.getCurrentTab();
John Reck5949c662011-05-27 09:52:29 -0700540 openTab(url, parent,
541 !mSettings.openInBackground(), true);
Leon Scroggins026f2542010-11-22 13:26:12 -0500542 break;
Michael Kolb8233fac2010-10-26 16:08:53 -0700543 case R.id.copy_link_context_menu_id:
544 copy(url);
545 break;
546 case R.id.save_link_context_menu_id:
547 case R.id.download_context_menu_id:
Leon Scroggins63c02662010-11-18 15:16:27 -0500548 DownloadHandler.onDownloadStartNoStream(
Andreas Sandblad8e4ce662012-06-11 11:02:49 +0200549 mActivity, url, view.getSettings().getUserAgentString(),
luxiaol62677b02013-07-22 07:54:49 +0800550 null, null, null, view.isPrivateBrowsingEnabled(), 0);
Michael Kolb8233fac2010-10-26 16:08:53 -0700551 break;
552 }
553 break;
554 }
555
556 case LOAD_URL:
John Reck26b18322011-06-21 13:08:58 -0700557 loadUrlFromContext((String) msg.obj);
Michael Kolb8233fac2010-10-26 16:08:53 -0700558 break;
559
560 case STOP_LOAD:
561 stopLoading();
562 break;
563
564 case RELEASE_WAKELOCK:
John Reckf57c0292011-07-21 18:15:39 -0700565 if (mWakeLock != null && mWakeLock.isHeld()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700566 mWakeLock.release();
567 // if we reach here, Browser should be still in the
568 // background loading after WAKELOCK_TIMEOUT (5-min).
569 // To avoid burning the battery, stop loading.
570 mTabControl.stopAllLoading();
571 }
572 break;
573
574 case UPDATE_BOOKMARK_THUMBNAIL:
John Reck34ef2672011-02-10 11:30:55 -0800575 Tab tab = (Tab) msg.obj;
576 if (tab != null) {
577 updateScreenshot(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700578 }
579 break;
kaiyiz591110b2013-08-06 17:11:06 +0800580
581 case OPEN_MENU:
582 if (!mOptionsMenuOpen && mActivity != null ) {
583 mActivity.openOptionsMenu();
584 }
585 break;
Michael Kolb8233fac2010-10-26 16:08:53 -0700586 }
587 }
588 };
589
590 }
591
John Reckef654f12011-07-12 16:42:08 -0700592 @Override
Martijn Coenenb2f93552011-06-14 10:48:35 +0200593 public Tab getCurrentTab() {
594 return mTabControl.getCurrentTab();
595 }
596
Michael Kolbba99c5d2010-11-29 14:57:41 -0800597 @Override
598 public void shareCurrentPage() {
599 shareCurrentPage(mTabControl.getCurrentTab());
600 }
601
602 private void shareCurrentPage(Tab tab) {
603 if (tab != null) {
Michael Kolbba99c5d2010-11-29 14:57:41 -0800604 sharePage(mActivity, tab.getTitle(),
605 tab.getUrl(), tab.getFavicon(),
606 createScreenshot(tab.getWebView(),
607 getDesiredThumbnailWidth(mActivity),
608 getDesiredThumbnailHeight(mActivity)));
609 }
610 }
611
Michael Kolb8233fac2010-10-26 16:08:53 -0700612 /**
613 * Share a page, providing the title, url, favicon, and a screenshot. Uses
614 * an {@link Intent} to launch the Activity chooser.
615 * @param c Context used to launch a new Activity.
616 * @param title Title of the page. Stored in the Intent with
617 * {@link Intent#EXTRA_SUBJECT}
618 * @param url URL of the page. Stored in the Intent with
619 * {@link Intent#EXTRA_TEXT}
620 * @param favicon Bitmap of the favicon for the page. Stored in the Intent
621 * with {@link Browser#EXTRA_SHARE_FAVICON}
622 * @param screenshot Bitmap of a screenshot of the page. Stored in the
623 * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT}
624 */
625 static final void sharePage(Context c, String title, String url,
626 Bitmap favicon, Bitmap screenshot) {
627 Intent send = new Intent(Intent.ACTION_SEND);
628 send.setType("text/plain");
629 send.putExtra(Intent.EXTRA_TEXT, url);
630 send.putExtra(Intent.EXTRA_SUBJECT, title);
631 send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon);
632 send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot);
633 try {
634 c.startActivity(Intent.createChooser(send, c.getString(
635 R.string.choosertitle_sharevia)));
636 } catch(android.content.ActivityNotFoundException ex) {
637 // if no app handles it, do nothing
638 }
639 }
640
641 private void copy(CharSequence text) {
642 ClipboardManager cm = (ClipboardManager) mActivity
643 .getSystemService(Context.CLIPBOARD_SERVICE);
644 cm.setText(text);
645 }
646
647 // lifecycle
648
John Reck9c35b9c2012-05-30 10:08:50 -0700649 @Override
650 public void onConfgurationChanged(Configuration config) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700651 mConfigChanged = true;
Michael Kolb18f252f2012-03-06 13:36:20 -0800652 // update the menu in case of a locale change
653 mActivity.invalidateOptionsMenu();
kaiyiz591110b2013-08-06 17:11:06 +0800654 if (mOptionsMenuOpen) {
655 mActivity.closeOptionsMenu();
656 mHandler.sendMessageDelayed(mHandler.obtainMessage(OPEN_MENU), 100);
657 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 if (mPageDialogsHandler != null) {
659 mPageDialogsHandler.onConfigurationChanged(config);
660 }
661 mUi.onConfigurationChanged(config);
662 }
663
664 @Override
665 public void handleNewIntent(Intent intent) {
Michael Kolb59e232c2011-08-18 17:19:53 -0700666 if (!mUi.isWebShowing()) {
667 mUi.showWeb(false);
668 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700669 mIntentHandler.onNewIntent(intent);
670 }
671
John Reck9c35b9c2012-05-30 10:08:50 -0700672 @Override
673 public void onPause() {
Michael Kolb11fe02d2011-02-02 09:52:16 -0800674 if (mUi.isCustomViewShowing()) {
675 hideCustomView();
676 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 if (mActivityPaused) {
678 Log.e(LOGTAG, "BrowserActivity is already paused.");
679 return;
680 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700681 mActivityPaused = true;
Michael Kolb70976932010-11-30 11:34:01 -0800682 Tab tab = mTabControl.getCurrentTab();
683 if (tab != null) {
684 tab.pause();
685 if (!pauseWebViewTimers(tab)) {
John Reckf57c0292011-07-21 18:15:39 -0700686 if (mWakeLock == null) {
687 PowerManager pm = (PowerManager) mActivity
688 .getSystemService(Context.POWER_SERVICE);
689 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser");
690 }
Michael Kolb70976932010-11-30 11:34:01 -0800691 mWakeLock.acquire();
692 mHandler.sendMessageDelayed(mHandler
693 .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT);
694 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700695 }
696 mUi.onPause();
697 mNetworkHandler.onPause();
698
699 WebView.disablePlatformNotifications();
Ben Murdoch015e1e32011-09-01 23:45:31 +0100700 NfcHandler.unregister(mActivity);
John Reckd7dd9b22011-08-30 09:18:29 -0700701 if (sThumbnailBitmap != null) {
702 sThumbnailBitmap.recycle();
703 sThumbnailBitmap = null;
704 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700705 }
706
John Reck9c35b9c2012-05-30 10:08:50 -0700707 @Override
708 public void onSaveInstanceState(Bundle outState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700709 // Save all the tabs
George Mount3636d0a2011-11-21 09:08:21 -0800710 Bundle saveState = createSaveState();
711
712 // crash recovery manages all save & restore state
713 mCrashRecoveryHandler.writeState(saveState);
714 mSettings.setLastRunPaused(true);
715 }
716
717 /**
718 * Save the current state to outState. Does not write the state to
719 * disk.
720 * @return Bundle containing the current state of all tabs.
721 */
722 /* package */ Bundle createSaveState() {
723 Bundle saveState = new Bundle();
724 mTabControl.saveState(saveState);
725 if (!saveState.isEmpty()) {
John Reck24f18262011-06-17 14:47:20 -0700726 // Save time so that we know how old incognito tabs (if any) are.
George Mount3636d0a2011-11-21 09:08:21 -0800727 saveState.putSerializable("lastActiveDate", Calendar.getInstance());
John Reck24f18262011-06-17 14:47:20 -0700728 }
George Mount3636d0a2011-11-21 09:08:21 -0800729 return saveState;
Michael Kolb8233fac2010-10-26 16:08:53 -0700730 }
731
John Reck9c35b9c2012-05-30 10:08:50 -0700732 @Override
733 public void onResume() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700734 if (!mActivityPaused) {
735 Log.e(LOGTAG, "BrowserActivity is already resumed.");
736 return;
737 }
George Mount3636d0a2011-11-21 09:08:21 -0800738 mSettings.setLastRunPaused(false);
Michael Kolb8233fac2010-10-26 16:08:53 -0700739 mActivityPaused = false;
Michael Kolb70976932010-11-30 11:34:01 -0800740 Tab current = mTabControl.getCurrentTab();
741 if (current != null) {
742 current.resume();
743 resumeWebViewTimers(current);
744 }
John Reckf57c0292011-07-21 18:15:39 -0700745 releaseWakeLock();
Martijn Coenenb2f93552011-06-14 10:48:35 +0200746
Michael Kolb8233fac2010-10-26 16:08:53 -0700747 mUi.onResume();
748 mNetworkHandler.onResume();
749 WebView.enablePlatformNotifications();
Ben Murdoch015e1e32011-09-01 23:45:31 +0100750 NfcHandler.register(mActivity, this);
Michael Kolb0b129122012-06-04 16:31:58 -0700751 if (mVoiceResult != null) {
752 mUi.onVoiceResult(mVoiceResult);
753 mVoiceResult = null;
754 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700755 }
756
John Reckf57c0292011-07-21 18:15:39 -0700757 private void releaseWakeLock() {
758 if (mWakeLock != null && mWakeLock.isHeld()) {
759 mHandler.removeMessages(RELEASE_WAKELOCK);
760 mWakeLock.release();
761 }
762 }
763
Michael Kolb70976932010-11-30 11:34:01 -0800764 /**
Michael Kolbba99c5d2010-11-29 14:57:41 -0800765 * resume all WebView timers using the WebView instance of the given tab
Michael Kolb70976932010-11-30 11:34:01 -0800766 * @param tab guaranteed non-null
767 */
768 private void resumeWebViewTimers(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700769 boolean inLoad = tab.inPageLoad();
770 if ((!mActivityPaused && !inLoad) || (mActivityPaused && inLoad)) {
771 CookieSyncManager.getInstance().startSync();
772 WebView w = tab.getWebView();
Mathew Inwoode1dbb952011-07-08 17:27:38 +0100773 WebViewTimersControl.getInstance().onBrowserActivityResume(w);
Michael Kolb8233fac2010-10-26 16:08:53 -0700774 }
775 }
776
Michael Kolb70976932010-11-30 11:34:01 -0800777 /**
778 * Pause all WebView timers using the WebView of the given tab
779 * @param tab
780 * @return true if the timers are paused or tab is null
781 */
782 private boolean pauseWebViewTimers(Tab tab) {
783 if (tab == null) {
784 return true;
785 } else if (!tab.inPageLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700786 CookieSyncManager.getInstance().stopSync();
Mathew Inwoode1dbb952011-07-08 17:27:38 +0100787 WebViewTimersControl.getInstance().onBrowserActivityPause(getCurrentWebView());
Michael Kolb8233fac2010-10-26 16:08:53 -0700788 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700789 }
Michael Kolb70976932010-11-30 11:34:01 -0800790 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700791 }
792
John Reck9c35b9c2012-05-30 10:08:50 -0700793 @Override
794 public void onDestroy() {
John Reck38b4bf52011-02-22 14:39:34 -0800795 if (mUploadHandler != null && !mUploadHandler.handled()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700796 mUploadHandler.onResult(Activity.RESULT_CANCELED, null);
797 mUploadHandler = null;
798 }
799 if (mTabControl == null) return;
800 mUi.onDestroy();
801 // Remove the current tab and sub window
802 Tab t = mTabControl.getCurrentTab();
803 if (t != null) {
804 dismissSubWindow(t);
805 removeTab(t);
806 }
Leon Scroggins1961ed22010-12-07 15:22:21 -0500807 mActivity.getContentResolver().unregisterContentObserver(mBookmarksObserver);
Michael Kolb8233fac2010-10-26 16:08:53 -0700808 // Destroy all the tabs
809 mTabControl.destroy();
810 WebIconDatabase.getInstance().close();
811 // Stop watching the default geolocation permissions
812 mSystemAllowGeolocationOrigins.stop();
813 mSystemAllowGeolocationOrigins = null;
814 }
815
816 protected boolean isActivityPaused() {
817 return mActivityPaused;
818 }
819
John Reck9c35b9c2012-05-30 10:08:50 -0700820 @Override
821 public void onLowMemory() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700822 mTabControl.freeMemory();
823 }
824
825 @Override
826 public boolean shouldShowErrorConsole() {
827 return mShouldShowErrorConsole;
828 }
829
830 protected void setShouldShowErrorConsole(boolean show) {
831 if (show == mShouldShowErrorConsole) {
832 // Nothing to do.
833 return;
834 }
835 mShouldShowErrorConsole = show;
836 Tab t = mTabControl.getCurrentTab();
837 if (t == null) {
838 // There is no current tab so we cannot toggle the error console
839 return;
840 }
841 mUi.setShouldShowErrorConsole(t, show);
842 }
843
844 @Override
845 public void stopLoading() {
846 mLoadStopped = true;
847 Tab tab = mTabControl.getCurrentTab();
Michael Kolb8233fac2010-10-26 16:08:53 -0700848 WebView w = getCurrentTopWebView();
Michael Kolb778a4882012-04-12 15:27:28 -0700849 if (w != null) {
850 w.stopLoading();
851 mUi.onPageStopped(tab);
852 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700853 }
854
855 boolean didUserStopLoading() {
856 return mLoadStopped;
857 }
858
kaiyiza016da12013-08-26 17:50:22 +0800859 private void handleNetworkNotify(WebView view) {
860 ConnectivityManager conMgr = (ConnectivityManager) this.getContext().getSystemService(
861 Context.CONNECTIVITY_SERVICE);
862 WifiManager wifiMgr = (WifiManager) this.getContext()
863 .getSystemService(Context.WIFI_SERVICE);
864 int networkSwitchTypeOK = this.getContext().getResources()
865 .getInteger(R.integer.netswitch_type_remind);
866
867 if (wifiMgr.isWifiEnabled()) {
868 NetworkInfo mNetworkInfo = conMgr.getActiveNetworkInfo();
869 if (mNetworkInfo == null
870 || (mNetworkInfo != null && (mNetworkInfo.getType() !=
871 ConnectivityManager.TYPE_WIFI))) {
872 int isReminder = Settings.System.getInt(
873 mActivity.getContentResolver(),
874 this.getContext().getResources()
875 .getString(R.string.network_switch_remind_type),
876 networkSwitchTypeOK);
877
878 if (isReminder == networkSwitchTypeOK) {
879 Intent intent = new Intent(
880 INTENT_WIFI_SELECTION_DATA_CONNECTION);
881 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
882 this.getContext().startActivity(intent);
883 }
884 mNetworkShouldNotify = false;
885 }
886 } else {
887 if (!mNetworkHandler.isNetworkUp()) {
888 view.setNetworkAvailable(false);
889 Log.v(LOGTAG, "handleNetworkNotify() Wlan is not enabled.");
890 }
891 }
892 }
893
Michael Kolb8233fac2010-10-26 16:08:53 -0700894 // WebViewController
895
896 @Override
John Reck324d4402011-01-11 16:56:42 -0800897 public void onPageStarted(Tab tab, WebView view, Bitmap favicon) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700898
899 // We've started to load a new page. If there was a pending message
900 // to save a screenshot then we will now take the new page and save
901 // an incorrect screenshot. Therefore, remove any pending thumbnail
902 // messages from the queue.
903 mHandler.removeMessages(Controller.UPDATE_BOOKMARK_THUMBNAIL,
John Reck34ef2672011-02-10 11:30:55 -0800904 tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700905
906 // reset sync timer to avoid sync starts during loading a page
907 CookieSyncManager.getInstance().resetSync();
908
kaiyiza016da12013-08-26 17:50:22 +0800909 if (SystemProperties.getBoolean(PROP_NETSWITCH, false)) {
910 if (!mNetworkHandler.isNetworkUp()) {
911 Log.d(LOGTAG, "onPageStarted() network unavailable");
912 if (mNetworkShouldNotify) {
913 handleNetworkNotify(view);
914 } else {
915 view.setNetworkAvailable(false);
916 }
917 mNetworkShouldNotify = false;
918 } else {
919 Log.d(LOGTAG, "onPageStarted() network available");
920 if (mNetworkShouldNotify) {
921 handleNetworkNotify(view);
922 }
923 mNetworkShouldNotify = false;
924 }
925 } else {
926 if (!mNetworkHandler.isNetworkUp()) {
927 view.setNetworkAvailable(false);
928 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700929 }
930
931 // when BrowserActivity just starts, onPageStarted may be called before
932 // onResume as it is triggered from onCreate. Call resumeWebViewTimers
933 // to start the timer. As we won't switch tabs while an activity is in
934 // pause state, we can ensure calling resume and pause in pair.
935 if (mActivityPaused) {
Michael Kolb70976932010-11-30 11:34:01 -0800936 resumeWebViewTimers(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700937 }
938 mLoadStopped = false;
Michael Kolb8233fac2010-10-26 16:08:53 -0700939 endActionMode();
940
John Reck30c714c2010-12-16 17:30:34 -0800941 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700942
John Reck324d4402011-01-11 16:56:42 -0800943 String url = tab.getUrl();
Michael Kolb8233fac2010-10-26 16:08:53 -0700944 // update the bookmark database for favicon
945 maybeUpdateFavicon(tab, null, url, favicon);
946
947 Performance.tracePageStart(url);
948
949 // Performance probe
950 if (false) {
951 Performance.onPageStarted();
952 }
953
954 }
955
956 @Override
John Reck324d4402011-01-11 16:56:42 -0800957 public void onPageFinished(Tab tab) {
Michael Kolb72864272012-05-03 15:42:15 -0700958 mCrashRecoveryHandler.backupState();
John Reck30c714c2010-12-16 17:30:34 -0800959 mUi.onTabDataChanged(tab);
Martijn Coenenb2f93552011-06-14 10:48:35 +0200960
Michael Kolb8233fac2010-10-26 16:08:53 -0700961 // Performance probe
962 if (false) {
John Reck324d4402011-01-11 16:56:42 -0800963 Performance.onPageFinished(tab.getUrl());
Michael Kolb8233fac2010-10-26 16:08:53 -0700964 }
965
966 Performance.tracePageFinished();
967 }
968
969 @Override
John Reck30c714c2010-12-16 17:30:34 -0800970 public void onProgressChanged(Tab tab) {
971 int newProgress = tab.getLoadProgress();
Michael Kolb8233fac2010-10-26 16:08:53 -0700972
973 if (newProgress == 100) {
974 CookieSyncManager.getInstance().sync();
975 // onProgressChanged() may continue to be called after the main
976 // frame has finished loading, as any remaining sub frames continue
977 // to load. We'll only get called once though with newProgress as
978 // 100 when everything is loaded. (onPageFinished is called once
979 // when the main frame completes loading regardless of the state of
980 // any sub frames so calls to onProgressChanges may continue after
981 // onPageFinished has executed)
Michael Kolbb1fb70c2011-11-21 12:38:14 -0800982 if (tab.inPageLoad()) {
983 updateInLoadMenuItems(mCachedMenu, tab);
Mattias Falk9cc2d032012-05-25 09:40:31 +0200984 } else if (mActivityPaused && pauseWebViewTimers(tab)) {
985 // pause the WebView timer and release the wake lock if it is
986 // finished while BrowserActivity is in pause state.
987 releaseWakeLock();
Michael Kolb8233fac2010-10-26 16:08:53 -0700988 }
John Reckd9862372012-02-21 15:04:50 -0800989 if (!tab.isPrivateBrowsingEnabled()
990 && !TextUtils.isEmpty(tab.getUrl())
991 && !tab.isSnapshot()) {
992 // Only update the bookmark screenshot if the user did not
993 // cancel the load early and there is not already
994 // a pending update for the tab.
Michael Kolb72864272012-05-03 15:42:15 -0700995 if (tab.shouldUpdateThumbnail() &&
996 (tab.inForeground() && !didUserStopLoading()
997 || !tab.inForeground())) {
John Reckd9862372012-02-21 15:04:50 -0800998 if (!mHandler.hasMessages(UPDATE_BOOKMARK_THUMBNAIL, tab)) {
999 mHandler.sendMessageDelayed(mHandler.obtainMessage(
1000 UPDATE_BOOKMARK_THUMBNAIL, 0, 0, tab),
1001 500);
1002 }
1003 }
1004 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001005 } else {
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001006 if (!tab.inPageLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001007 // onPageFinished may have already been called but a subframe is
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001008 // still loading
1009 // updating the progress and
Michael Kolb8233fac2010-10-26 16:08:53 -07001010 // update the menu items.
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001011 updateInLoadMenuItems(mCachedMenu, tab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001012 }
1013 }
John Reck30c714c2010-12-16 17:30:34 -08001014 mUi.onProgressChanged(tab);
1015 }
1016
1017 @Override
Steve Block2466eff2011-10-03 15:33:09 +01001018 public void onUpdatedSecurityState(Tab tab) {
John Reck30c714c2010-12-16 17:30:34 -08001019 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001020 }
1021
1022 @Override
1023 public void onReceivedTitle(Tab tab, final String title) {
John Reck30c714c2010-12-16 17:30:34 -08001024 mUi.onTabDataChanged(tab);
John Reck49a603c2011-03-03 09:33:05 -08001025 final String pageUrl = tab.getOriginalUrl();
John Reck324d4402011-01-11 16:56:42 -08001026 if (TextUtils.isEmpty(pageUrl) || pageUrl.length()
Michael Kolb8233fac2010-10-26 16:08:53 -07001027 >= SQLiteDatabase.SQLITE_MAX_LIKE_PATTERN_LENGTH) {
1028 return;
1029 }
1030 // Update the title in the history database if not in private browsing mode
1031 if (!tab.isPrivateBrowsingEnabled()) {
John Reckf57c0292011-07-21 18:15:39 -07001032 DataController.getInstance(mActivity).updateHistoryTitle(pageUrl, title);
Michael Kolb8233fac2010-10-26 16:08:53 -07001033 }
1034 }
1035
1036 @Override
1037 public void onFavicon(Tab tab, WebView view, Bitmap icon) {
John Reck30c714c2010-12-16 17:30:34 -08001038 mUi.onTabDataChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001039 maybeUpdateFavicon(tab, view.getOriginalUrl(), view.getUrl(), icon);
1040 }
1041
1042 @Override
Michael Kolb18eb3772010-12-10 14:29:51 -08001043 public boolean shouldOverrideUrlLoading(Tab tab, WebView view, String url) {
1044 return mUrlHandler.shouldOverrideUrlLoading(tab, view, url);
Michael Kolb8233fac2010-10-26 16:08:53 -07001045 }
1046
1047 @Override
1048 public boolean shouldOverrideKeyEvent(KeyEvent event) {
1049 if (mMenuIsDown) {
1050 // only check shortcut key when MENU is held
1051 return mActivity.getWindow().isShortcutKey(event.getKeyCode(),
1052 event);
1053 } else {
1054 return false;
1055 }
1056 }
1057
1058 @Override
John Reck997b1b72012-04-19 18:08:25 -07001059 public boolean onUnhandledKeyEvent(KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001060 if (!isActivityPaused()) {
1061 if (event.getAction() == KeyEvent.ACTION_DOWN) {
John Reck997b1b72012-04-19 18:08:25 -07001062 return mActivity.onKeyDown(event.getKeyCode(), event);
Michael Kolb8233fac2010-10-26 16:08:53 -07001063 } else {
John Reck997b1b72012-04-19 18:08:25 -07001064 return mActivity.onKeyUp(event.getKeyCode(), event);
Michael Kolb8233fac2010-10-26 16:08:53 -07001065 }
1066 }
John Reck997b1b72012-04-19 18:08:25 -07001067 return false;
Michael Kolb8233fac2010-10-26 16:08:53 -07001068 }
1069
1070 @Override
John Reck324d4402011-01-11 16:56:42 -08001071 public void doUpdateVisitedHistory(Tab tab, boolean isReload) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001072 // Don't save anything in private browsing mode
1073 if (tab.isPrivateBrowsingEnabled()) return;
John Reck49a603c2011-03-03 09:33:05 -08001074 String url = tab.getOriginalUrl();
Michael Kolb8233fac2010-10-26 16:08:53 -07001075
John Reck324d4402011-01-11 16:56:42 -08001076 if (TextUtils.isEmpty(url)
1077 || url.regionMatches(true, 0, "about:", 0, 6)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001078 return;
1079 }
John Reckf57c0292011-07-21 18:15:39 -07001080 DataController.getInstance(mActivity).updateVisitedHistory(url);
John Reck6c2e2f32011-08-22 13:41:23 -07001081 mCrashRecoveryHandler.backupState();
Michael Kolb8233fac2010-10-26 16:08:53 -07001082 }
1083
1084 @Override
1085 public void getVisitedHistory(final ValueCallback<String[]> callback) {
1086 AsyncTask<Void, Void, String[]> task =
1087 new AsyncTask<Void, Void, String[]>() {
1088 @Override
1089 public String[] doInBackground(Void... unused) {
1090 return Browser.getVisitedHistory(mActivity.getContentResolver());
1091 }
1092 @Override
1093 public void onPostExecute(String[] result) {
1094 callback.onReceiveValue(result);
1095 }
1096 };
1097 task.execute();
1098 }
1099
1100 @Override
1101 public void onReceivedHttpAuthRequest(Tab tab, WebView view,
1102 final HttpAuthHandler handler, final String host,
1103 final String realm) {
1104 String username = null;
1105 String password = null;
1106
1107 boolean reuseHttpAuthUsernamePassword
1108 = handler.useHttpAuthUsernamePassword();
1109
1110 if (reuseHttpAuthUsernamePassword && view != null) {
1111 String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
1112 if (credentials != null && credentials.length == 2) {
1113 username = credentials[0];
1114 password = credentials[1];
1115 }
1116 }
1117
1118 if (username != null && password != null) {
1119 handler.proceed(username, password);
1120 } else {
Ben Murdochfdd37112011-08-05 15:48:14 +01001121 if (tab.inForeground() && !handler.suppressDialog()) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001122 mPageDialogsHandler.showHttpAuthentication(tab, handler, host, realm);
1123 } else {
1124 handler.cancel();
1125 }
1126 }
1127 }
1128
1129 @Override
1130 public void onDownloadStart(Tab tab, String url, String userAgent,
Selim Gurun0b3d66f2012-08-29 13:08:13 -07001131 String contentDisposition, String mimetype, String referer,
1132 long contentLength) {
Kristian Monsenbc5cc752011-03-02 13:14:03 +00001133 WebView w = tab.getWebView();
qqzhoua95a2e22013-04-18 17:28:31 +08001134 boolean ret = DownloadHandler.onDownloadStart(mActivity, url, userAgent,
luxiaol62677b02013-07-22 07:54:49 +08001135 contentDisposition, mimetype, referer, w.isPrivateBrowsingEnabled(), contentLength);
qqzhoua95a2e22013-04-18 17:28:31 +08001136 if (ret == false && w.copyBackForwardList().getSize() == 0) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001137 // This Tab was opened for the sole purpose of downloading a
1138 // file. Remove it.
1139 if (tab == mTabControl.getCurrentTab()) {
1140 // In this case, the Tab is still on top.
1141 goBackOnePageOrQuit();
1142 } else {
1143 // In this case, it is not.
1144 closeTab(tab);
1145 }
1146 }
1147 }
1148
1149 @Override
1150 public Bitmap getDefaultVideoPoster() {
1151 return mUi.getDefaultVideoPoster();
1152 }
1153
1154 @Override
1155 public View getVideoLoadingProgressView() {
1156 return mUi.getVideoLoadingProgressView();
1157 }
1158
1159 @Override
1160 public void showSslCertificateOnError(WebView view, SslErrorHandler handler,
1161 SslError error) {
1162 mPageDialogsHandler.showSSLCertificateOnError(view, handler, error);
1163 }
1164
Patrick Scott92066772011-03-10 08:46:27 -05001165 @Override
1166 public void showAutoLogin(Tab tab) {
1167 assert tab.inForeground();
1168 // Update the title bar to show the auto-login request.
1169 mUi.showAutoLogin(tab);
1170 }
1171
1172 @Override
1173 public void hideAutoLogin(Tab tab) {
1174 assert tab.inForeground();
1175 mUi.hideAutoLogin(tab);
1176 }
1177
Michael Kolb8233fac2010-10-26 16:08:53 -07001178 // helper method
1179
1180 /*
1181 * Update the favorites icon if the private browsing isn't enabled and the
1182 * icon is valid.
1183 */
1184 private void maybeUpdateFavicon(Tab tab, final String originalUrl,
1185 final String url, Bitmap favicon) {
1186 if (favicon == null) {
1187 return;
1188 }
1189 if (!tab.isPrivateBrowsingEnabled()) {
1190 Bookmarks.updateFavicon(mActivity
1191 .getContentResolver(), originalUrl, url, favicon);
1192 }
1193 }
1194
Leon Scroggins4cd97792010-12-03 15:31:56 -05001195 @Override
1196 public void bookmarkedStatusHasChanged(Tab tab) {
John Recke969cc52010-12-21 17:24:43 -08001197 // TODO: Switch to using onTabDataChanged after b/3262950 is fixed
Leon Scroggins4cd97792010-12-03 15:31:56 -05001198 mUi.bookmarkedStatusHasChanged(tab);
1199 }
1200
Michael Kolb8233fac2010-10-26 16:08:53 -07001201 // end WebViewController
1202
1203 protected void pageUp() {
1204 getCurrentTopWebView().pageUp(false);
1205 }
1206
1207 protected void pageDown() {
1208 getCurrentTopWebView().pageDown(false);
1209 }
1210
1211 // callback from phone title bar
John Reck9c35b9c2012-05-30 10:08:50 -07001212 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07001213 public void editUrl() {
1214 if (mOptionsMenuOpen) mActivity.closeOptionsMenu();
Michael Kolb1f9b3562012-04-24 14:38:34 -07001215 mUi.editUrl(false, true);
Michael Kolb8233fac2010-10-26 16:08:53 -07001216 }
1217
John Reck9c35b9c2012-05-30 10:08:50 -07001218 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001219 public void showCustomView(Tab tab, View view, int requestedOrientation,
Michael Kolb8233fac2010-10-26 16:08:53 -07001220 WebChromeClient.CustomViewCallback callback) {
1221 if (tab.inForeground()) {
1222 if (mUi.isCustomViewShowing()) {
1223 callback.onCustomViewHidden();
1224 return;
1225 }
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -04001226 mUi.showCustomView(view, requestedOrientation, callback);
Michael Kolb8233fac2010-10-26 16:08:53 -07001227 // Save the menu state and set it to empty while the custom
1228 // view is showing.
1229 mOldMenuState = mMenuState;
1230 mMenuState = EMPTY_MENU;
John Reckd73c5a22010-12-22 10:22:50 -08001231 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -07001232 }
1233 }
1234
1235 @Override
1236 public void hideCustomView() {
1237 if (mUi.isCustomViewShowing()) {
1238 mUi.onHideCustomView();
1239 // Reset the old menu state.
1240 mMenuState = mOldMenuState;
1241 mOldMenuState = EMPTY_MENU;
John Reckd73c5a22010-12-22 10:22:50 -08001242 mActivity.invalidateOptionsMenu();
Michael Kolb8233fac2010-10-26 16:08:53 -07001243 }
1244 }
1245
John Reck9c35b9c2012-05-30 10:08:50 -07001246 @Override
1247 public void onActivityResult(int requestCode, int resultCode,
Michael Kolb8233fac2010-10-26 16:08:53 -07001248 Intent intent) {
1249 if (getCurrentTopWebView() == null) return;
1250 switch (requestCode) {
1251 case PREFERENCES_PAGE:
1252 if (resultCode == Activity.RESULT_OK && intent != null) {
1253 String action = intent.getStringExtra(Intent.EXTRA_TEXT);
John Reck35e9dd62011-04-25 09:01:54 -07001254 if (PreferenceKeys.PREF_PRIVACY_CLEAR_HISTORY.equals(action)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001255 mTabControl.removeParentChildRelationShips();
1256 }
1257 }
1258 break;
1259 case FILE_SELECTED:
Ben Murdoch51f6a2f2011-02-21 12:27:07 +00001260 // Chose a file from the file picker.
John Reck9dfcdb12011-02-22 16:40:46 -08001261 if (null == mUploadHandler) break;
Michael Kolb8233fac2010-10-26 16:08:53 -07001262 mUploadHandler.onResult(resultCode, intent);
Michael Kolb8233fac2010-10-26 16:08:53 -07001263 break;
Ben Murdoch8029a772010-11-16 11:58:21 +00001264 case AUTOFILL_SETUP:
1265 // Determine whether a profile was actually set up or not
1266 // and if so, send the message back to the WebTextView to
1267 // fill the form with the new profile.
1268 if (getSettings().getAutoFillProfile() != null) {
1269 mAutoFillSetupMessage.sendToTarget();
1270 mAutoFillSetupMessage = null;
1271 }
1272 break;
John Reckd3e4d5b2011-07-13 15:48:43 -07001273 case COMBO_VIEW:
1274 if (intent == null || resultCode != Activity.RESULT_OK) {
1275 break;
1276 }
John Reck3ba45532011-08-11 16:26:53 -07001277 mUi.showWeb(false);
John Reckd3e4d5b2011-07-13 15:48:43 -07001278 if (Intent.ACTION_VIEW.equals(intent.getAction())) {
1279 Tab t = getCurrentTab();
1280 Uri uri = intent.getData();
kaiyiz6e5b3e02013-08-19 20:02:01 +08001281 mUpdateMyNavThumbnail = true;
1282 mUpdateMyNavThumbnailUrl = uri.toString();
John Reckd3e4d5b2011-07-13 15:48:43 -07001283 loadUrl(t, uri.toString());
1284 } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_ALL)) {
1285 String[] urls = intent.getStringArrayExtra(
1286 ComboViewActivity.EXTRA_OPEN_ALL);
1287 Tab parent = getCurrentTab();
1288 for (String url : urls) {
kaiyiz47097d62013-08-09 09:30:28 +08001289 if (url != null) {
1290 parent = openTab(url, parent,
1291 !mSettings.openInBackground(), true);
1292 }
John Reckd3e4d5b2011-07-13 15:48:43 -07001293 }
1294 } else if (intent.hasExtra(ComboViewActivity.EXTRA_OPEN_SNAPSHOT)) {
1295 long id = intent.getLongExtra(
1296 ComboViewActivity.EXTRA_OPEN_SNAPSHOT, -1);
1297 if (id >= 0) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -08001298 if (BrowserWebView.isClassic()) {
1299 createNewSnapshotTab(id, true);
1300 } else {
1301 Toast.makeText(mActivity, "Snapshot Tab requires WebViewClassic",
1302 Toast.LENGTH_LONG).show();
1303 }
John Reckd3e4d5b2011-07-13 15:48:43 -07001304 }
1305 }
1306 break;
Michael Kolb0b129122012-06-04 16:31:58 -07001307 case VOICE_RESULT:
1308 if (resultCode == Activity.RESULT_OK && intent != null) {
1309 ArrayList<String> results = intent.getStringArrayListExtra(
1310 RecognizerIntent.EXTRA_RESULTS);
1311 if (results.size() >= 1) {
1312 mVoiceResult = results.get(0);
1313 }
1314 }
1315 break;
kaiyiz6e5b3e02013-08-19 20:02:01 +08001316
1317 case MY_NAVIGATION:
1318 if (intent == null || resultCode != Activity.RESULT_OK) {
1319 break;
1320 }
1321
1322 if (intent.getBooleanExtra("need_refresh", false) &&
1323 getCurrentTopWebView() != null) {
1324 getCurrentTopWebView().reload();
1325 }
1326 break;
1327
Michael Kolb8233fac2010-10-26 16:08:53 -07001328 default:
1329 break;
1330 }
1331 getCurrentTopWebView().requestFocus();
1332 }
1333
1334 /**
1335 * Open the Go page.
1336 * @param startWithHistory If true, open starting on the history tab.
1337 * Otherwise, start with the bookmarks tab.
1338 */
1339 @Override
Michael Kolb315d5022011-10-13 12:47:11 -07001340 public void bookmarksOrHistoryPicker(ComboViews startView) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001341 if (mTabControl.getCurrentWebView() == null) {
1342 return;
1343 }
Michael Kolbbd3dd942011-01-12 11:09:38 -08001344 // clear action mode
1345 if (isInCustomActionMode()) {
1346 endActionMode();
1347 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001348 Bundle extras = new Bundle();
1349 // Disable opening in a new window if we have maxed out the windows
1350 extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW,
1351 !mTabControl.canCreateNewTab());
Michael Kolb315d5022011-10-13 12:47:11 -07001352 mUi.showComboView(startView, extras);
Michael Kolb8233fac2010-10-26 16:08:53 -07001353 }
1354
1355 // combo view callbacks
1356
Michael Kolb8233fac2010-10-26 16:08:53 -07001357 // key handling
1358 protected void onBackKey() {
1359 if (!mUi.onBackKey()) {
1360 WebView subwindow = mTabControl.getCurrentSubWindow();
1361 if (subwindow != null) {
1362 if (subwindow.canGoBack()) {
1363 subwindow.goBack();
1364 } else {
1365 dismissSubWindow(mTabControl.getCurrentTab());
1366 }
1367 } else {
1368 goBackOnePageOrQuit();
1369 }
1370 }
1371 }
1372
Michael Kolb4bd767d2011-05-27 11:33:55 -07001373 protected boolean onMenuKey() {
1374 return mUi.onMenuKey();
Michael Kolb2814a362011-05-19 15:49:41 -07001375 }
1376
Michael Kolb8233fac2010-10-26 16:08:53 -07001377 // menu handling and state
1378 // TODO: maybe put into separate handler
1379
John Reck9c35b9c2012-05-30 10:08:50 -07001380 @Override
1381 public boolean onCreateOptionsMenu(Menu menu) {
John Reckd73c5a22010-12-22 10:22:50 -08001382 if (mMenuState == EMPTY_MENU) {
1383 return false;
1384 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001385 MenuInflater inflater = mActivity.getMenuInflater();
1386 inflater.inflate(R.menu.browser, menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001387 return true;
1388 }
1389
John Reck9c35b9c2012-05-30 10:08:50 -07001390 @Override
1391 public void onCreateContextMenu(ContextMenu menu, View v,
Michael Kolb8233fac2010-10-26 16:08:53 -07001392 ContextMenuInfo menuInfo) {
John Reck0f602f32011-07-07 15:38:43 -07001393 if (v instanceof TitleBar) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001394 return;
1395 }
1396 if (!(v instanceof WebView)) {
1397 return;
1398 }
Leon Scroggins026f2542010-11-22 13:26:12 -05001399 final WebView webview = (WebView) v;
Michael Kolb8233fac2010-10-26 16:08:53 -07001400 WebView.HitTestResult result = webview.getHitTestResult();
1401 if (result == null) {
1402 return;
1403 }
1404
1405 int type = result.getType();
1406 if (type == WebView.HitTestResult.UNKNOWN_TYPE) {
1407 Log.w(LOGTAG,
1408 "We should not show context menu when nothing is touched");
1409 return;
1410 }
1411 if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
1412 // let TextView handles context menu
1413 return;
1414 }
1415
1416 // Note, http://b/issue?id=1106666 is requesting that
1417 // an inflated menu can be used again. This is not available
1418 // yet, so inflate each time (yuk!)
1419 MenuInflater inflater = mActivity.getMenuInflater();
1420 inflater.inflate(R.menu.browsercontext, menu);
1421
1422 // Show the correct menu group
1423 final String extra = result.getExtra();
kaiyiz6e5b3e02013-08-19 20:02:01 +08001424 final String navigationUrl = MyNavigationUtil.getMyNavigationUrl(extra);
Michael Kolbc159c1a2011-12-15 16:06:38 -08001425 if (extra == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -07001426 menu.setGroupVisible(R.id.PHONE_MENU,
1427 type == WebView.HitTestResult.PHONE_TYPE);
1428 menu.setGroupVisible(R.id.EMAIL_MENU,
1429 type == WebView.HitTestResult.EMAIL_TYPE);
1430 menu.setGroupVisible(R.id.GEO_MENU,
1431 type == WebView.HitTestResult.GEO_TYPE);
kaiyiz6e5b3e02013-08-19 20:02:01 +08001432
1433 String itemUrl = null;
1434 String url = webview.getOriginalUrl();
1435 if (url != null && url.equalsIgnoreCase(MyNavigationUtil.MY_NAVIGATION)) {
1436 itemUrl = Uri.decode(navigationUrl);
1437 if (itemUrl != null && !MyNavigationUtil.isDefaultMyNavigation(itemUrl)) {
1438 menu.setGroupVisible(R.id.MY_NAVIGATION_MENU,
1439 type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1440 } else {
1441 menu.setGroupVisible(R.id.MY_NAVIGATION_MENU, false);
1442 }
1443 menu.setGroupVisible(R.id.IMAGE_MENU, false);
1444 menu.setGroupVisible(R.id.ANCHOR_MENU, false);
1445 } else {
1446 menu.setGroupVisible(R.id.MY_NAVIGATION_MENU, false);
1447
1448 menu.setGroupVisible(R.id.IMAGE_MENU,
1449 type == WebView.HitTestResult.IMAGE_TYPE
1450 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1451 menu.setGroupVisible(R.id.ANCHOR_MENU,
1452 type == WebView.HitTestResult.SRC_ANCHOR_TYPE
1453 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1454 }
1455
Cary Clark8974d282010-11-22 10:46:05 -05001456 boolean hitText = type == WebView.HitTestResult.SRC_ANCHOR_TYPE
1457 || type == WebView.HitTestResult.PHONE_TYPE
1458 || type == WebView.HitTestResult.EMAIL_TYPE
1459 || type == WebView.HitTestResult.GEO_TYPE;
1460 menu.setGroupVisible(R.id.SELECT_TEXT_MENU, hitText);
1461 if (hitText) {
1462 menu.findItem(R.id.select_text_menu_id)
1463 .setOnMenuItemClickListener(new SelectText(webview));
1464 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001465 // Setup custom handling depending on the type
1466 switch (type) {
1467 case WebView.HitTestResult.PHONE_TYPE:
1468 menu.setHeaderTitle(Uri.decode(extra));
1469 menu.findItem(R.id.dial_context_menu_id).setIntent(
1470 new Intent(Intent.ACTION_VIEW, Uri
1471 .parse(WebView.SCHEME_TEL + extra)));
1472 Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1473 addIntent.putExtra(Insert.PHONE, Uri.decode(extra));
1474 addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
1475 menu.findItem(R.id.add_contact_context_menu_id).setIntent(
1476 addIntent);
1477 menu.findItem(R.id.copy_phone_context_menu_id)
1478 .setOnMenuItemClickListener(
1479 new Copy(extra));
1480 break;
1481
1482 case WebView.HitTestResult.EMAIL_TYPE:
1483 menu.setHeaderTitle(extra);
1484 menu.findItem(R.id.email_context_menu_id).setIntent(
1485 new Intent(Intent.ACTION_VIEW, Uri
1486 .parse(WebView.SCHEME_MAILTO + extra)));
1487 menu.findItem(R.id.copy_mail_context_menu_id)
1488 .setOnMenuItemClickListener(
1489 new Copy(extra));
1490 break;
1491
1492 case WebView.HitTestResult.GEO_TYPE:
1493 menu.setHeaderTitle(extra);
1494 menu.findItem(R.id.map_context_menu_id).setIntent(
1495 new Intent(Intent.ACTION_VIEW, Uri
1496 .parse(WebView.SCHEME_GEO
1497 + URLEncoder.encode(extra))));
1498 menu.findItem(R.id.copy_geo_context_menu_id)
1499 .setOnMenuItemClickListener(
1500 new Copy(extra));
1501 break;
1502
1503 case WebView.HitTestResult.SRC_ANCHOR_TYPE:
1504 case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
Michael Kolb4c537ce2011-01-13 15:19:33 -08001505 menu.setHeaderTitle(extra);
Michael Kolb8233fac2010-10-26 16:08:53 -07001506 // decide whether to show the open link in new tab option
1507 boolean showNewTab = mTabControl.canCreateNewTab();
1508 MenuItem newTabItem
1509 = menu.findItem(R.id.open_newtab_context_menu_id);
John Reck35e9dd62011-04-25 09:01:54 -07001510 newTabItem.setTitle(getSettings().openInBackground()
Michael Kolb2dd65c82011-01-14 11:07:38 -08001511 ? R.string.contextmenu_openlink_newwindow_background
1512 : R.string.contextmenu_openlink_newwindow);
Michael Kolb8233fac2010-10-26 16:08:53 -07001513 newTabItem.setVisible(showNewTab);
1514 if (showNewTab) {
Leon Scroggins026f2542010-11-22 13:26:12 -05001515 if (WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE == type) {
1516 newTabItem.setOnMenuItemClickListener(
1517 new MenuItem.OnMenuItemClickListener() {
1518 @Override
1519 public boolean onMenuItemClick(MenuItem item) {
1520 final HashMap<String, WebView> hrefMap =
1521 new HashMap<String, WebView>();
1522 hrefMap.put("webview", webview);
1523 final Message msg = mHandler.obtainMessage(
1524 FOCUS_NODE_HREF,
1525 R.id.open_newtab_context_menu_id,
1526 0, hrefMap);
1527 webview.requestFocusNodeHref(msg);
1528 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -07001529 }
Leon Scroggins026f2542010-11-22 13:26:12 -05001530 });
1531 } else {
1532 newTabItem.setOnMenuItemClickListener(
1533 new MenuItem.OnMenuItemClickListener() {
1534 @Override
1535 public boolean onMenuItemClick(MenuItem item) {
1536 final Tab parent = mTabControl.getCurrentTab();
John Reck5949c662011-05-27 09:52:29 -07001537 openTab(extra, parent,
1538 !mSettings.openInBackground(),
1539 true);
Leon Scroggins026f2542010-11-22 13:26:12 -05001540 return true;
1541 }
1542 });
1543 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001544 }
kaiyiz6e5b3e02013-08-19 20:02:01 +08001545 if (url != null && url.equalsIgnoreCase(MyNavigationUtil.MY_NAVIGATION)) {
1546 menu.setHeaderTitle(navigationUrl);
1547 menu.findItem(R.id.open_newtab_context_menu_id).setVisible(false);
1548
1549 if (itemUrl != null) {
1550 if (!MyNavigationUtil.isDefaultMyNavigation(itemUrl)) {
1551 menu.findItem(R.id.edit_my_navigation_context_menu_id)
1552 .setOnMenuItemClickListener(new OnMenuItemClickListener() {
1553 @Override
1554 public boolean onMenuItemClick(MenuItem item) {
1555 final Intent intent = new Intent(Controller.this
1556 .getContext(),
1557 AddMyNavigationPage.class);
1558 Bundle bundle = new Bundle();
1559 String url = Uri.decode(navigationUrl);
1560 bundle.putBoolean("isAdding", false);
1561 bundle.putString("url", url);
1562 bundle.putString("name", getNameFromUrl(url));
1563 intent.putExtra("websites", bundle);
1564 mActivity.startActivityForResult(intent, MY_NAVIGATION);
1565 return false;
1566 }
1567 });
1568 menu.findItem(R.id.delete_my_navigation_context_menu_id)
1569 .setOnMenuItemClickListener(new OnMenuItemClickListener() {
1570 @Override
1571 public boolean onMenuItemClick(MenuItem item) {
1572 showMyNavigationDeleteDialog(Uri.decode(navigationUrl));
1573 return false;
1574 }
1575 });
1576 }
1577 } else {
1578 Log.e(LOGTAG, "mynavigation onCreateContextMenu itemUrl is null!");
1579 }
1580 }
1581
Michael Kolb8233fac2010-10-26 16:08:53 -07001582 if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
1583 break;
1584 }
1585 // otherwise fall through to handle image part
1586 case WebView.HitTestResult.IMAGE_TYPE:
Victoria Lease5987b802012-03-12 13:05:23 -07001587 MenuItem shareItem = menu.findItem(R.id.share_link_context_menu_id);
1588 shareItem.setVisible(type == WebView.HitTestResult.IMAGE_TYPE);
Michael Kolb8233fac2010-10-26 16:08:53 -07001589 if (type == WebView.HitTestResult.IMAGE_TYPE) {
1590 menu.setHeaderTitle(extra);
Victoria Lease5987b802012-03-12 13:05:23 -07001591 shareItem.setOnMenuItemClickListener(
1592 new MenuItem.OnMenuItemClickListener() {
1593 @Override
1594 public boolean onMenuItemClick(MenuItem item) {
1595 sharePage(mActivity, null, extra, null,
1596 null);
1597 return true;
1598 }
1599 }
1600 );
Michael Kolb8233fac2010-10-26 16:08:53 -07001601 }
Michael Kolb3639c4c2011-09-28 15:36:40 -07001602 menu.findItem(R.id.view_image_context_menu_id)
1603 .setOnMenuItemClickListener(new OnMenuItemClickListener() {
1604 @Override
1605 public boolean onMenuItemClick(MenuItem item) {
1606 openTab(extra, mTabControl.getCurrentTab(), true, true);
1607 return false;
1608 }
1609 });
Andreas Sandblad8e4ce662012-06-11 11:02:49 +02001610 menu.findItem(R.id.download_context_menu_id).setOnMenuItemClickListener(
1611 new Download(mActivity, extra, webview.isPrivateBrowsingEnabled(),
1612 webview.getSettings().getUserAgentString()));
John Reck3527dd12011-02-22 10:35:29 -08001613 menu.findItem(R.id.set_wallpaper_context_menu_id).
1614 setOnMenuItemClickListener(new WallpaperHandler(mActivity,
1615 extra));
Michael Kolb8233fac2010-10-26 16:08:53 -07001616 break;
1617
1618 default:
1619 Log.w(LOGTAG, "We should not get here.");
1620 break;
1621 }
1622 //update the ui
1623 mUi.onContextMenuCreated(menu);
1624 }
1625
kaiyiz6e5b3e02013-08-19 20:02:01 +08001626 public void startAddMyNavigation(String url) {
1627 final Intent intent = new Intent(Controller.this.getContext(), AddMyNavigationPage.class);
1628 Bundle bundle = new Bundle();
1629 bundle.putBoolean("isAdding", true);
1630 bundle.putString("url", url);
1631 bundle.putString("name", getNameFromUrl(url));
1632 intent.putExtra("websites", bundle);
1633 mActivity.startActivityForResult(intent, MY_NAVIGATION);
1634 }
1635
1636 private void showMyNavigationDeleteDialog(final String itemUrl) {
1637 new AlertDialog.Builder(this.getContext())
1638 .setTitle(R.string.my_navigation_delete_label)
1639 .setIcon(android.R.drawable.ic_dialog_alert)
1640 .setMessage(R.string.my_navigation_delete_msg)
1641 .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
1642 @Override
1643 public void onClick(DialogInterface dialog, int whichButton) {
1644 deleteMyNavigationItem(itemUrl);
1645 }
1646 })
1647 .setNegativeButton(R.string.cancel, null)
1648 .show();
1649 }
1650
1651 private void deleteMyNavigationItem(final String itemUrl) {
1652 ContentResolver cr = this.getContext().getContentResolver();
1653 Cursor cursor = null;
1654
1655 try {
1656 cursor = cr.query(MyNavigationUtil.MY_NAVIGATION_URI,
1657 new String[] {
1658 MyNavigationUtil.ID
1659 }, "url = ?", new String[] {
1660 itemUrl
1661 }, null);
1662 if (null != cursor && cursor.moveToFirst()) {
1663 Uri uri = ContentUris.withAppendedId(MyNavigationUtil.MY_NAVIGATION_URI,
1664 cursor.getLong(0));
1665
1666 ContentValues values = new ContentValues();
1667 values.put(MyNavigationUtil.TITLE, "");
1668 values.put(MyNavigationUtil.URL, "ae://" + cursor.getLong(0) + "add-fav");
1669 values.put(MyNavigationUtil.WEBSITE, 0 + "");
1670 ByteArrayOutputStream os = new ByteArrayOutputStream();
1671 Bitmap bm = BitmapFactory.decodeResource(this.getContext().getResources(),
1672 R.raw.my_navigation_add);
1673 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
1674 values.put(MyNavigationUtil.THUMBNAIL, os.toByteArray());
1675 Log.d(LOGTAG, "deleteMyNavigationItem uri is : " + uri);
1676 cr.update(uri, values, null, null);
1677 } else {
1678 Log.e(LOGTAG, "deleteMyNavigationItem the item does not exist!");
1679 }
1680 } catch (IllegalStateException e) {
1681 Log.e(LOGTAG, "deleteMyNavigationItem", e);
1682 } finally {
1683 if (null != cursor) {
1684 cursor.close();
1685 }
1686 }
1687
1688 if (getCurrentTopWebView() != null) {
1689 getCurrentTopWebView().reload();
1690 }
1691 }
1692
1693 private String getNameFromUrl(String itemUrl) {
1694 ContentResolver cr = this.getContext().getContentResolver();
1695 Cursor cursor = null;
1696 String name = null;
1697
1698 try {
1699 cursor = cr.query(MyNavigationUtil.MY_NAVIGATION_URI,
1700 new String[] {
1701 MyNavigationUtil.TITLE
1702 }, "url = ?", new String[] {
1703 itemUrl
1704 }, null);
1705 if (null != cursor && cursor.moveToFirst()) {
1706 name = cursor.getString(0);
1707 } else {
1708 Log.e(LOGTAG, "this item does not exist!");
1709 }
1710 } catch (IllegalStateException e) {
1711 Log.e(LOGTAG, "getNameFromUrl", e);
1712 } finally {
1713 if (null != cursor) {
1714 cursor.close();
1715 }
1716 }
1717 return name;
1718 }
1719
1720 private void updateMyNavigationThumbnail(final String itemUrl, WebView webView) {
1721 int width = mActivity.getResources().getDimensionPixelOffset(
1722 R.dimen.myNavigationThumbnailWidth);
1723 int height = mActivity.getResources().getDimensionPixelOffset(
1724 R.dimen.myNavigationThumbnailHeight);
1725
1726 final Bitmap bm = createScreenshot(webView, width, height);
1727
1728 if (bm == null) {
1729 Log.e(LOGTAG, "updateMyNavigationThumbnail bm is null!");
1730 return;
1731 }
1732
1733 final ContentResolver cr = mActivity.getContentResolver();
1734 new AsyncTask<Void, Void, Void>() {
1735 @Override
1736 protected Void doInBackground(Void... unused) {
1737 ContentResolver cr = mActivity.getContentResolver();
1738 Cursor cursor = null;
1739 try {
1740 cursor = cr.query(MyNavigationUtil.MY_NAVIGATION_URI,
1741 new String[] {
1742 MyNavigationUtil.ID
1743 }, "url = ?", new String[] {
1744 itemUrl
1745 }, null);
1746 if (null != cursor && cursor.moveToFirst()) {
1747 final ByteArrayOutputStream os = new ByteArrayOutputStream();
1748 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
1749
1750 ContentValues values = new ContentValues();
1751 values.put(MyNavigationUtil.THUMBNAIL, os.toByteArray());
1752 Uri uri = ContentUris.withAppendedId(MyNavigationUtil.MY_NAVIGATION_URI,
1753 cursor.getLong(0));
1754 Log.d(LOGTAG, "updateMyNavigationThumbnail uri is " + uri);
1755 cr.update(uri, values, null, null);
1756 os.close();
1757 }
1758 } catch (IllegalStateException e) {
1759 Log.e(LOGTAG, "updateMyNavigationThumbnail", e);
1760 } catch (IOException e) {
1761 Log.e(LOGTAG, "updateMyNavigationThumbnail", e);
1762 } finally {
1763 if (null != cursor) {
1764 cursor.close();
1765 }
1766 }
1767 return null;
1768 }
1769 }.execute();
1770 }
1771
Michael Kolb8233fac2010-10-26 16:08:53 -07001772 /**
1773 * As the menu can be open when loading state changes
1774 * we must manually update the state of the stop/reload menu
1775 * item
1776 */
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001777 private void updateInLoadMenuItems(Menu menu, Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001778 if (menu == null) {
1779 return;
1780 }
1781 MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
Michael Kolbb8337132011-11-28 15:07:39 -08001782 MenuItem src = ((tab != null) && tab.inPageLoad()) ?
Michael Kolb8233fac2010-10-26 16:08:53 -07001783 menu.findItem(R.id.stop_menu_id):
1784 menu.findItem(R.id.reload_menu_id);
1785 if (src != null) {
1786 dest.setIcon(src.getIcon());
1787 dest.setTitle(src.getTitle());
1788 }
1789 }
1790
John Reck9c35b9c2012-05-30 10:08:50 -07001791 @Override
1792 public boolean onPrepareOptionsMenu(Menu menu) {
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001793 updateInLoadMenuItems(menu, getCurrentTab());
John Recke1a03a32011-09-14 17:04:16 -07001794 // hold on to the menu reference here; it is used by the page callbacks
1795 // to update the menu based on loading state
1796 mCachedMenu = menu;
Michael Kolb8233fac2010-10-26 16:08:53 -07001797 // Note: setVisible will decide whether an item is visible; while
1798 // setEnabled() will decide whether an item is enabled, which also means
1799 // whether the matching shortcut key will function.
1800 switch (mMenuState) {
1801 case EMPTY_MENU:
1802 if (mCurrentMenuState != mMenuState) {
1803 menu.setGroupVisible(R.id.MAIN_MENU, false);
1804 menu.setGroupEnabled(R.id.MAIN_MENU, false);
1805 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false);
1806 }
1807 break;
1808 default:
1809 if (mCurrentMenuState != mMenuState) {
1810 menu.setGroupVisible(R.id.MAIN_MENU, true);
1811 menu.setGroupEnabled(R.id.MAIN_MENU, true);
1812 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true);
1813 }
Michael Kolb4bf79712011-07-14 14:18:12 -07001814 updateMenuState(getCurrentTab(), menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001815 break;
1816 }
1817 mCurrentMenuState = mMenuState;
Michael Kolb1acef692011-03-08 14:12:06 -08001818 return mUi.onPrepareOptionsMenu(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -07001819 }
1820
Michael Kolb4bf79712011-07-14 14:18:12 -07001821 @Override
1822 public void updateMenuState(Tab tab, Menu menu) {
1823 boolean canGoBack = false;
1824 boolean canGoForward = false;
John Reck42229bc2011-08-19 13:26:43 -07001825 boolean isDesktopUa = false;
John Recke1a03a32011-09-14 17:04:16 -07001826 boolean isLive = false;
Michael Kolb4bf79712011-07-14 14:18:12 -07001827 if (tab != null) {
1828 canGoBack = tab.canGoBack();
1829 canGoForward = tab.canGoForward();
John Reck42229bc2011-08-19 13:26:43 -07001830 isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView());
John Recke1a03a32011-09-14 17:04:16 -07001831 isLive = !tab.isSnapshot();
Michael Kolb4bf79712011-07-14 14:18:12 -07001832 }
1833 final MenuItem back = menu.findItem(R.id.back_menu_id);
1834 back.setEnabled(canGoBack);
1835
1836 final MenuItem home = menu.findItem(R.id.homepage_menu_id);
Michael Kolb4bf79712011-07-14 14:18:12 -07001837
1838 final MenuItem forward = menu.findItem(R.id.forward_menu_id);
1839 forward.setEnabled(canGoForward);
1840
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001841 final MenuItem source = menu.findItem(isInLoad() ? R.id.stop_menu_id
1842 : R.id.reload_menu_id);
Michael Kolb4bf79712011-07-14 14:18:12 -07001843 final MenuItem dest = menu.findItem(R.id.stop_reload_menu_id);
Michael Kolb7ab75ee2011-07-14 16:36:38 -07001844 if (source != null && dest != null) {
1845 dest.setTitle(source.getTitle());
1846 dest.setIcon(source.getIcon());
1847 }
John Recke1a03a32011-09-14 17:04:16 -07001848 menu.setGroupVisible(R.id.NAV_MENU, isLive);
Michael Kolb4bf79712011-07-14 14:18:12 -07001849
1850 // decide whether to show the share link option
1851 PackageManager pm = mActivity.getPackageManager();
1852 Intent send = new Intent(Intent.ACTION_SEND);
1853 send.setType("text/plain");
1854 ResolveInfo ri = pm.resolveActivity(send,
1855 PackageManager.MATCH_DEFAULT_ONLY);
1856 menu.findItem(R.id.share_page_menu_id).setVisible(ri != null);
1857
1858 boolean isNavDump = mSettings.enableNavDump();
1859 final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id);
1860 nav.setVisible(isNavDump);
1861 nav.setEnabled(isNavDump);
1862
1863 boolean showDebugSettings = mSettings.isDebugEnabled();
John Reck42229bc2011-08-19 13:26:43 -07001864 final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id);
1865 uaSwitcher.setChecked(isDesktopUa);
John Recke1a03a32011-09-14 17:04:16 -07001866 menu.setGroupVisible(R.id.LIVE_MENU, isLive);
1867 menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive);
kaiyiza8b6dbb2013-07-29 18:11:22 +08001868
1869 // history and snapshots item are the members of COMBO menu group,
1870 // so if show history item, only make snapshots item invisible.
1871 menu.findItem(R.id.snapshots_menu_id).setVisible(false);
Michael Kolb4bf79712011-07-14 14:18:12 -07001872
Michael Kolb7bdee0b2011-08-01 11:55:38 -07001873 mUi.updateMenuState(tab, menu);
Michael Kolb4bf79712011-07-14 14:18:12 -07001874 }
1875
John Reck9c35b9c2012-05-30 10:08:50 -07001876 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07001877 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001878 if (null == getCurrentTopWebView()) {
1879 return false;
1880 }
1881 if (mMenuIsDown) {
1882 // The shortcut action consumes the MENU. Even if it is still down,
1883 // it won't trigger the next shortcut action. In the case of the
1884 // shortcut action triggering a new activity, like Bookmarks, we
1885 // won't get onKeyUp for MENU. So it is important to reset it here.
1886 mMenuIsDown = false;
1887 }
Michael Kolb3ca12752011-07-20 13:52:25 -07001888 if (mUi.onOptionsItemSelected(item)) {
1889 // ui callback handled it
1890 return true;
1891 }
Michael Kolb8233fac2010-10-26 16:08:53 -07001892 switch (item.getItemId()) {
1893 // -- Main menu
1894 case R.id.new_tab_menu_id:
1895 openTabToHomePage();
1896 break;
1897
1898 case R.id.incognito_menu_id:
Michael Kolb519d2282011-05-09 17:03:19 -07001899 openIncognitoTab();
Michael Kolb8233fac2010-10-26 16:08:53 -07001900 break;
1901
Afzal Najamd4e33312012-04-26 01:54:01 -04001902 case R.id.close_other_tabs_id:
1903 closeOtherTabs();
1904 break;
1905
Michael Kolb8233fac2010-10-26 16:08:53 -07001906 case R.id.goto_menu_id:
1907 editUrl();
1908 break;
1909
1910 case R.id.bookmarks_menu_id:
Michael Kolb315d5022011-10-13 12:47:11 -07001911 bookmarksOrHistoryPicker(ComboViews.Bookmarks);
1912 break;
1913
1914 case R.id.history_menu_id:
1915 bookmarksOrHistoryPicker(ComboViews.History);
1916 break;
1917
1918 case R.id.snapshots_menu_id:
1919 bookmarksOrHistoryPicker(ComboViews.Snapshots);
Michael Kolb8233fac2010-10-26 16:08:53 -07001920 break;
1921
Michael Kolb8233fac2010-10-26 16:08:53 -07001922 case R.id.add_bookmark_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07001923 bookmarkCurrentPage();
Michael Kolb8233fac2010-10-26 16:08:53 -07001924 break;
1925
1926 case R.id.stop_reload_menu_id:
Michael Kolbb1fb70c2011-11-21 12:38:14 -08001927 if (isInLoad()) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001928 stopLoading();
1929 } else {
1930 getCurrentTopWebView().reload();
1931 }
1932 break;
1933
1934 case R.id.back_menu_id:
John Reckef654f12011-07-12 16:42:08 -07001935 getCurrentTab().goBack();
Michael Kolb8233fac2010-10-26 16:08:53 -07001936 break;
1937
1938 case R.id.forward_menu_id:
John Reckef654f12011-07-12 16:42:08 -07001939 getCurrentTab().goForward();
Michael Kolb8233fac2010-10-26 16:08:53 -07001940 break;
1941
1942 case R.id.close_menu_id:
1943 // Close the subwindow if it exists.
1944 if (mTabControl.getCurrentSubWindow() != null) {
1945 dismissSubWindow(mTabControl.getCurrentTab());
1946 break;
1947 }
1948 closeCurrentTab();
1949 break;
1950
kaiyiza8b6dbb2013-07-29 18:11:22 +08001951 case R.id.exit_menu_id:
1952 String ret = SystemProperties.get("persist.debug.browsermonkeytest");
1953 if (ret != null && ret.equals("enable"))
1954 break;
luxiaolb40014b2013-07-19 10:01:43 +08001955 showExitDialog(mActivity);
1956 return true;
kaiyiza8b6dbb2013-07-29 18:11:22 +08001957
Michael Kolb8233fac2010-10-26 16:08:53 -07001958 case R.id.homepage_menu_id:
1959 Tab current = mTabControl.getCurrentTab();
John Reck26b18322011-06-21 13:08:58 -07001960 loadUrl(current, mSettings.getHomePage());
Michael Kolb8233fac2010-10-26 16:08:53 -07001961 break;
1962
1963 case R.id.preferences_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07001964 openPreferences();
Michael Kolb8233fac2010-10-26 16:08:53 -07001965 break;
1966
1967 case R.id.find_menu_id:
Michael Kolbe11b9212012-04-13 13:39:54 -07001968 findOnPage();
Michael Kolb8233fac2010-10-26 16:08:53 -07001969 break;
1970
John Reck2bc80422011-06-30 15:11:49 -07001971 case R.id.save_snapshot_menu_id:
1972 final Tab source = getTabControl().getCurrentTab();
John Reckf33b1632011-06-04 20:00:23 -07001973 if (source == null) break;
John Reck68234a92012-04-19 15:27:12 -07001974 new SaveSnapshotTask(source).execute();
Leon Scrogginsac993842011-02-02 12:54:07 -05001975 break;
1976
Michael Kolb8233fac2010-10-26 16:08:53 -07001977 case R.id.page_info_menu_id:
Michael Kolb315d5022011-10-13 12:47:11 -07001978 showPageInfo();
Michael Kolb8233fac2010-10-26 16:08:53 -07001979 break;
1980
John Recke1a03a32011-09-14 17:04:16 -07001981 case R.id.snapshot_go_live:
1982 goLive();
1983 return true;
1984
Michael Kolb8233fac2010-10-26 16:08:53 -07001985 case R.id.share_page_menu_id:
1986 Tab currentTab = mTabControl.getCurrentTab();
1987 if (null == currentTab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07001988 return false;
1989 }
Michael Kolbba99c5d2010-11-29 14:57:41 -08001990 shareCurrentPage(currentTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07001991 break;
1992
1993 case R.id.dump_nav_menu_id:
1994 getCurrentTopWebView().debugDump();
1995 break;
1996
Michael Kolb8233fac2010-10-26 16:08:53 -07001997 case R.id.zoom_in_menu_id:
1998 getCurrentTopWebView().zoomIn();
1999 break;
2000
2001 case R.id.zoom_out_menu_id:
2002 getCurrentTopWebView().zoomOut();
2003 break;
2004
2005 case R.id.view_downloads_menu_id:
2006 viewDownloads();
2007 break;
2008
John Reck42229bc2011-08-19 13:26:43 -07002009 case R.id.ua_desktop_menu_id:
Michael Kolb80f75082012-04-10 10:50:06 -07002010 toggleUserAgent();
John Reck42229bc2011-08-19 13:26:43 -07002011 break;
2012
Michael Kolb8233fac2010-10-26 16:08:53 -07002013 case R.id.window_one_menu_id:
2014 case R.id.window_two_menu_id:
2015 case R.id.window_three_menu_id:
2016 case R.id.window_four_menu_id:
2017 case R.id.window_five_menu_id:
2018 case R.id.window_six_menu_id:
2019 case R.id.window_seven_menu_id:
2020 case R.id.window_eight_menu_id:
2021 {
2022 int menuid = item.getItemId();
2023 for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) {
2024 if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) {
2025 Tab desiredTab = mTabControl.getTab(id);
2026 if (desiredTab != null &&
2027 desiredTab != mTabControl.getCurrentTab()) {
Michael Kolbc831b632011-05-11 09:30:34 -07002028 switchToTab(desiredTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07002029 }
2030 break;
2031 }
2032 }
2033 }
2034 break;
2035
2036 default:
2037 return false;
2038 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002039 return true;
2040 }
2041
John Reck68234a92012-04-19 15:27:12 -07002042 private class SaveSnapshotTask extends AsyncTask<Void, Void, Long>
2043 implements OnCancelListener {
2044
2045 private Tab mTab;
2046 private Dialog mProgressDialog;
2047 private ContentValues mValues;
2048
2049 private SaveSnapshotTask(Tab tab) {
2050 mTab = tab;
2051 }
2052
2053 @Override
2054 protected void onPreExecute() {
2055 CharSequence message = mActivity.getText(R.string.saving_snapshot);
2056 mProgressDialog = ProgressDialog.show(mActivity, null, message,
2057 true, true, this);
2058 mValues = mTab.createSnapshotValues();
2059 }
2060
2061 @Override
2062 protected Long doInBackground(Void... params) {
2063 if (!mTab.saveViewState(mValues)) {
2064 return null;
2065 }
2066 if (isCancelled()) {
2067 String path = mValues.getAsString(Snapshots.VIEWSTATE_PATH);
2068 File file = mActivity.getFileStreamPath(path);
2069 if (!file.delete()) {
2070 file.deleteOnExit();
2071 }
2072 return null;
2073 }
2074 final ContentResolver cr = mActivity.getContentResolver();
2075 Uri result = cr.insert(Snapshots.CONTENT_URI, mValues);
2076 if (result == null) {
2077 return null;
2078 }
2079 long id = ContentUris.parseId(result);
2080 return id;
2081 }
2082
2083 @Override
2084 protected void onPostExecute(Long id) {
2085 if (isCancelled()) {
2086 return;
2087 }
2088 mProgressDialog.dismiss();
2089 if (id == null) {
2090 Toast.makeText(mActivity, R.string.snapshot_failed,
2091 Toast.LENGTH_SHORT).show();
2092 return;
2093 }
2094 Bundle b = new Bundle();
2095 b.putLong(BrowserSnapshotPage.EXTRA_ANIMATE_ID, id);
2096 mUi.showComboView(ComboViews.Snapshots, b);
2097 }
2098
2099 @Override
2100 public void onCancel(DialogInterface dialog) {
2101 cancel(true);
2102 }
2103 }
2104
Michael Kolb80f75082012-04-10 10:50:06 -07002105 @Override
2106 public void toggleUserAgent() {
2107 WebView web = getCurrentWebView();
2108 mSettings.toggleDesktopUseragent(web);
2109 web.loadUrl(web.getOriginalUrl());
2110 }
2111
2112 @Override
2113 public void findOnPage() {
2114 getCurrentTopWebView().showFindDialog(null, true);
2115 }
2116
2117 @Override
2118 public void openPreferences() {
2119 Intent intent = new Intent(mActivity, BrowserPreferencesPage.class);
2120 intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE,
2121 getCurrentTopWebView().getUrl());
2122 mActivity.startActivityForResult(intent, PREFERENCES_PAGE);
2123 }
2124
2125 @Override
2126 public void bookmarkCurrentPage() {
2127 Intent bookmarkIntent = createBookmarkCurrentPageIntent(false);
2128 if (bookmarkIntent != null) {
2129 mActivity.startActivity(bookmarkIntent);
2130 }
2131 }
2132
John Recke1a03a32011-09-14 17:04:16 -07002133 private void goLive() {
2134 Tab t = getCurrentTab();
2135 t.loadUrl(t.getUrl(), null);
2136 }
2137
luxiaolb40014b2013-07-19 10:01:43 +08002138 private void showExitDialog(final Activity activity) {
2139 new AlertDialog.Builder(activity)
2140 .setTitle(R.string.exit_browser_title)
2141 .setIcon(android.R.drawable.ic_dialog_alert)
2142 .setMessage(R.string.exit_browser_msg)
2143 .setNegativeButton(R.string.exit_minimize, new DialogInterface.OnClickListener() {
2144 public void onClick(DialogInterface dialog, int which) {
2145 activity.moveTaskToBack(true);
2146 dialog.dismiss();
2147 }
2148 })
2149 .setPositiveButton(R.string.exit_quit, new DialogInterface.OnClickListener() {
2150 public void onClick(DialogInterface dialog, int which) {
2151 activity.finish();
2152 mHandler.postDelayed(new Runnable() {
2153 @Override
2154 public void run() {
2155 // TODO Auto-generated method stub
2156 mCrashRecoveryHandler.clearState(true);
2157 int pid = android.os.Process.myPid();
2158 android.os.Process.killProcess(pid);
2159 }
2160 }, 300);
2161 dialog.dismiss();
2162 }
2163 })
2164 .show();
2165 }
2166
Michael Kolb315d5022011-10-13 12:47:11 -07002167 @Override
2168 public void showPageInfo() {
2169 mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null);
2170 }
2171
John Reck9c35b9c2012-05-30 10:08:50 -07002172 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002173 public boolean onContextItemSelected(MenuItem item) {
John Reckdbf57df2010-11-09 16:34:03 -08002174 // Let the History and Bookmark fragments handle menus they created.
2175 if (item.getGroupId() == R.id.CONTEXT_MENU) {
2176 return false;
2177 }
2178
Michael Kolb8233fac2010-10-26 16:08:53 -07002179 int id = item.getItemId();
2180 boolean result = true;
2181 switch (id) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002182 // -- Browser context menu
2183 case R.id.open_context_menu_id:
Michael Kolb8233fac2010-10-26 16:08:53 -07002184 case R.id.save_link_context_menu_id:
Michael Kolb8233fac2010-10-26 16:08:53 -07002185 case R.id.copy_link_context_menu_id:
2186 final WebView webView = getCurrentTopWebView();
2187 if (null == webView) {
2188 result = false;
2189 break;
2190 }
2191 final HashMap<String, WebView> hrefMap =
2192 new HashMap<String, WebView>();
2193 hrefMap.put("webview", webView);
2194 final Message msg = mHandler.obtainMessage(
2195 FOCUS_NODE_HREF, id, 0, hrefMap);
2196 webView.requestFocusNodeHref(msg);
2197 break;
2198
2199 default:
2200 // For other context menus
2201 result = onOptionsItemSelected(item);
2202 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002203 return result;
2204 }
2205
2206 /**
2207 * support programmatically opening the context menu
2208 */
2209 public void openContextMenu(View view) {
2210 mActivity.openContextMenu(view);
2211 }
2212
2213 /**
2214 * programmatically open the options menu
2215 */
2216 public void openOptionsMenu() {
2217 mActivity.openOptionsMenu();
2218 }
2219
John Reck9c35b9c2012-05-30 10:08:50 -07002220 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002221 public boolean onMenuOpened(int featureId, Menu menu) {
2222 if (mOptionsMenuOpen) {
2223 if (mConfigChanged) {
2224 // We do not need to make any changes to the state of the
2225 // title bar, since the only thing that happened was a
2226 // change in orientation
2227 mConfigChanged = false;
2228 } else {
2229 if (!mExtendedMenuOpen) {
2230 mExtendedMenuOpen = true;
2231 mUi.onExtendedMenuOpened();
2232 } else {
2233 // Switching the menu back to icon view, so show the
2234 // title bar once again.
2235 mExtendedMenuOpen = false;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08002236 mUi.onExtendedMenuClosed(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07002237 }
2238 }
2239 } else {
2240 // The options menu is closed, so open it, and show the title
2241 mOptionsMenuOpen = true;
2242 mConfigChanged = false;
2243 mExtendedMenuOpen = false;
2244 mUi.onOptionsMenuOpened();
2245 }
2246 return true;
2247 }
2248
John Reck9c35b9c2012-05-30 10:08:50 -07002249 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002250 public void onOptionsMenuClosed(Menu menu) {
2251 mOptionsMenuOpen = false;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08002252 mUi.onOptionsMenuClosed(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07002253 }
2254
John Reck9c35b9c2012-05-30 10:08:50 -07002255 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002256 public void onContextMenuClosed(Menu menu) {
Michael Kolbb1fb70c2011-11-21 12:38:14 -08002257 mUi.onContextMenuClosed(menu, isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07002258 }
2259
2260 // Helper method for getting the top window.
2261 @Override
2262 public WebView getCurrentTopWebView() {
2263 return mTabControl.getCurrentTopWebView();
2264 }
2265
2266 @Override
2267 public WebView getCurrentWebView() {
2268 return mTabControl.getCurrentWebView();
2269 }
2270
2271 /*
2272 * This method is called as a result of the user selecting the options
2273 * menu to see the download window. It shows the download window on top of
2274 * the current window.
2275 */
2276 void viewDownloads() {
2277 Intent intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
2278 mActivity.startActivity(intent);
2279 }
2280
John Reck30b065e2011-07-19 10:58:05 -07002281 int getActionModeHeight() {
2282 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
2283 new int[] { android.R.attr.actionBarSize });
2284 int size = (int) actionBarSizeTypedArray.getDimension(0, 0f);
2285 actionBarSizeTypedArray.recycle();
2286 return size;
2287 }
2288
Michael Kolb8233fac2010-10-26 16:08:53 -07002289 // action mode
2290
John Reck9c35b9c2012-05-30 10:08:50 -07002291 @Override
2292 public void onActionModeStarted(ActionMode mode) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002293 mUi.onActionModeStarted(mode);
2294 mActionMode = mode;
2295 }
2296
2297 /*
2298 * True if a custom ActionMode (i.e. find or select) is in use.
2299 */
2300 @Override
2301 public boolean isInCustomActionMode() {
2302 return mActionMode != null;
2303 }
2304
2305 /*
2306 * End the current ActionMode.
2307 */
2308 @Override
2309 public void endActionMode() {
2310 if (mActionMode != null) {
2311 mActionMode.finish();
2312 }
2313 }
2314
2315 /*
2316 * Called by find and select when they are finished. Replace title bars
2317 * as necessary.
2318 */
John Reck9c35b9c2012-05-30 10:08:50 -07002319 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002320 public void onActionModeFinished(ActionMode mode) {
2321 if (!isInCustomActionMode()) return;
Michael Kolbb1fb70c2011-11-21 12:38:14 -08002322 mUi.onActionModeFinished(isInLoad());
Michael Kolb8233fac2010-10-26 16:08:53 -07002323 mActionMode = null;
2324 }
2325
2326 boolean isInLoad() {
Michael Kolbc5b0b2d2011-11-29 16:13:35 -08002327 final Tab tab = getCurrentTab();
2328 return (tab != null) && tab.inPageLoad();
Michael Kolb8233fac2010-10-26 16:08:53 -07002329 }
2330
2331 // bookmark handling
2332
2333 /**
2334 * add the current page as a bookmark to the given folder id
2335 * @param folderId use -1 for the default folder
John Reckd3e4d5b2011-07-13 15:48:43 -07002336 * @param editExisting If true, check to see whether the site is already
Leon Scrogginsbdff8a72011-02-11 15:49:04 -05002337 * bookmarked, and if it is, edit that bookmark. If false, and
2338 * the site is already bookmarked, do not attempt to edit the
2339 * existing bookmark.
Michael Kolb8233fac2010-10-26 16:08:53 -07002340 */
2341 @Override
John Reckd3e4d5b2011-07-13 15:48:43 -07002342 public Intent createBookmarkCurrentPageIntent(boolean editExisting) {
John Recka60fffa2011-09-06 16:30:29 -07002343 WebView w = getCurrentTopWebView();
2344 if (w == null) {
2345 return null;
2346 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002347 Intent i = new Intent(mActivity,
2348 AddBookmarkPage.class);
Michael Kolb8233fac2010-10-26 16:08:53 -07002349 i.putExtra(BrowserContract.Bookmarks.URL, w.getUrl());
2350 i.putExtra(BrowserContract.Bookmarks.TITLE, w.getTitle());
2351 String touchIconUrl = w.getTouchIconUrl();
2352 if (touchIconUrl != null) {
2353 i.putExtra(AddBookmarkPage.TOUCH_ICON_URL, touchIconUrl);
2354 WebSettings settings = w.getSettings();
2355 if (settings != null) {
2356 i.putExtra(AddBookmarkPage.USER_AGENT,
2357 settings.getUserAgentString());
2358 }
2359 }
2360 i.putExtra(BrowserContract.Bookmarks.THUMBNAIL,
2361 createScreenshot(w, getDesiredThumbnailWidth(mActivity),
2362 getDesiredThumbnailHeight(mActivity)));
2363 i.putExtra(BrowserContract.Bookmarks.FAVICON, w.getFavicon());
John Reckd3e4d5b2011-07-13 15:48:43 -07002364 if (editExisting) {
Leon Scrogginsbdff8a72011-02-11 15:49:04 -05002365 i.putExtra(AddBookmarkPage.CHECK_FOR_DUPE, true);
2366 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002367 // Put the dialog at the upper right of the screen, covering the
2368 // star on the title bar.
2369 i.putExtra("gravity", Gravity.RIGHT | Gravity.TOP);
John Reckd3e4d5b2011-07-13 15:48:43 -07002370 return i;
Michael Kolb8233fac2010-10-26 16:08:53 -07002371 }
2372
2373 // file chooser
John Reck9c35b9c2012-05-30 10:08:50 -07002374 @Override
Ben Murdoch8cad4132012-01-11 10:56:43 +00002375 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002376 mUploadHandler = new UploadHandler(this);
Ben Murdoch8cad4132012-01-11 10:56:43 +00002377 mUploadHandler.openFileChooser(uploadMsg, acceptType, capture);
Michael Kolb8233fac2010-10-26 16:08:53 -07002378 }
2379
2380 // thumbnails
2381
2382 /**
2383 * Return the desired width for thumbnail screenshots, which are stored in
2384 * the database, and used on the bookmarks screen.
2385 * @param context Context for finding out the density of the screen.
2386 * @return desired width for thumbnail screenshot.
2387 */
2388 static int getDesiredThumbnailWidth(Context context) {
2389 return context.getResources().getDimensionPixelOffset(
2390 R.dimen.bookmarkThumbnailWidth);
2391 }
2392
2393 /**
2394 * Return the desired height for thumbnail screenshots, which are stored in
2395 * the database, and used on the bookmarks screen.
2396 * @param context Context for finding out the density of the screen.
2397 * @return desired height for thumbnail screenshot.
2398 */
2399 static int getDesiredThumbnailHeight(Context context) {
2400 return context.getResources().getDimensionPixelOffset(
2401 R.dimen.bookmarkThumbnailHeight);
2402 }
2403
John Reck8cc92352011-07-06 17:41:52 -07002404 static Bitmap createScreenshot(WebView view, int width, int height) {
John Reckd7dd9b22011-08-30 09:18:29 -07002405 if (view == null || view.getContentHeight() == 0
2406 || view.getContentWidth() == 0) {
2407 return null;
2408 }
John Reck5c6ac2f2011-01-05 10:18:03 -08002409 // We render to a bitmap 2x the desired size so that we can then
2410 // re-scale it with filtering since canvas.scale doesn't filter
2411 // This helps reduce aliasing at the cost of being slightly blurry
2412 final int filter_scale = 2;
John Reckd7dd9b22011-08-30 09:18:29 -07002413 int scaledWidth = width * filter_scale;
2414 int scaledHeight = height * filter_scale;
2415 if (sThumbnailBitmap == null || sThumbnailBitmap.getWidth() != scaledWidth
2416 || sThumbnailBitmap.getHeight() != scaledHeight) {
2417 if (sThumbnailBitmap != null) {
2418 sThumbnailBitmap.recycle();
2419 sThumbnailBitmap = null;
2420 }
2421 sThumbnailBitmap =
2422 Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.RGB_565);
Michael Kolb8233fac2010-10-26 16:08:53 -07002423 }
John Reckd7dd9b22011-08-30 09:18:29 -07002424 Canvas canvas = new Canvas(sThumbnailBitmap);
2425 int contentWidth = view.getContentWidth();
2426 float overviewScale = scaledWidth / (view.getScale() * contentWidth);
2427 if (view instanceof BrowserWebView) {
2428 int dy = -((BrowserWebView)view).getTitleHeight();
2429 canvas.translate(0, dy * overviewScale);
2430 }
2431
2432 canvas.scale(overviewScale, overviewScale);
2433
2434 if (view instanceof BrowserWebView) {
2435 ((BrowserWebView)view).drawContent(canvas);
Michael Kolb8233fac2010-10-26 16:08:53 -07002436 } else {
John Reckd7dd9b22011-08-30 09:18:29 -07002437 view.draw(canvas);
Michael Kolb8233fac2010-10-26 16:08:53 -07002438 }
John Reckd7dd9b22011-08-30 09:18:29 -07002439 Bitmap ret = Bitmap.createScaledBitmap(sThumbnailBitmap,
2440 width, height, true);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -07002441 canvas.setBitmap(null);
John Reck5c6ac2f2011-01-05 10:18:03 -08002442 return ret;
Michael Kolb8233fac2010-10-26 16:08:53 -07002443 }
2444
John Reck34ef2672011-02-10 11:30:55 -08002445 private void updateScreenshot(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002446 // If this is a bookmarked site, add a screenshot to the database.
Michael Kolb8233fac2010-10-26 16:08:53 -07002447 // FIXME: Would like to make sure there is actually something to
2448 // draw, but the API for that (WebViewCore.pictureReady()) is not
2449 // currently accessible here.
2450
John Reck34ef2672011-02-10 11:30:55 -08002451 WebView view = tab.getWebView();
John Reck7a591202011-02-16 15:44:01 -08002452 if (view == null) {
2453 // Tab was destroyed
2454 return;
2455 }
John Reck34ef2672011-02-10 11:30:55 -08002456 final String url = tab.getUrl();
2457 final String originalUrl = view.getOriginalUrl();
kaiyiz6e5b3e02013-08-19 20:02:01 +08002458 final String thumbnailUrl = mUpdateMyNavThumbnailUrl;
John Reck34ef2672011-02-10 11:30:55 -08002459 if (TextUtils.isEmpty(url)) {
2460 return;
2461 }
2462
kaiyiz6e5b3e02013-08-19 20:02:01 +08002463 //update My Navigation Thumbnails
2464 boolean isMyNavigationUrl = MyNavigationUtil.isMyNavigationUrl(mActivity, url);
2465 if (isMyNavigationUrl) {
2466 updateMyNavigationThumbnail(url, view);
2467 }
John Reck34ef2672011-02-10 11:30:55 -08002468 // Only update thumbnails for web urls (http(s)://), not for
2469 // about:, javascript:, data:, etc...
2470 // Unless it is a bookmarked site, then always update
2471 if (!Patterns.WEB_URL.matcher(url).matches() && !tab.isBookmarkedSite()) {
2472 return;
2473 }
2474
kaiyiz6e5b3e02013-08-19 20:02:01 +08002475 if (url != null && mUpdateMyNavThumbnailUrl != null
2476 && Patterns.WEB_URL.matcher(url).matches()
2477 && Patterns.WEB_URL.matcher(mUpdateMyNavThumbnailUrl).matches()) {
2478 String urlHost = (new WebAddress(url)).getHost();
2479 String bookmarkHost = (new WebAddress(mUpdateMyNavThumbnailUrl)).getHost();
2480 if (urlHost == null || urlHost.length() == 0 || bookmarkHost == null
2481 || bookmarkHost.length() == 0) {
2482 return;
2483 }
2484 String urlDomain = urlHost.substring(urlHost.indexOf('.'), urlHost.length());
2485 String bookmarkDomain = bookmarkHost.substring(bookmarkHost.indexOf('.'),
2486 bookmarkHost.length());
2487 Log.d(LOGTAG, "addressUrl domain is " + urlDomain);
2488 Log.d(LOGTAG, "bookmarkUrl domain is " + bookmarkDomain);
2489 if (!bookmarkDomain.equals(urlDomain)) {
2490 return;
2491 }
2492 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002493 final Bitmap bm = createScreenshot(view, getDesiredThumbnailWidth(mActivity),
2494 getDesiredThumbnailHeight(mActivity));
2495 if (bm == null) {
2496 return;
2497 }
2498
2499 final ContentResolver cr = mActivity.getContentResolver();
John Reck34ef2672011-02-10 11:30:55 -08002500 new AsyncTask<Void, Void, Void>() {
2501 @Override
2502 protected Void doInBackground(Void... unused) {
2503 Cursor cursor = null;
2504 try {
2505 // TODO: Clean this up
kaiyiz6e5b3e02013-08-19 20:02:01 +08002506 cursor = Bookmarks.queryCombinedForUrl(cr, originalUrl,
2507 mUpdateMyNavThumbnail ? ((thumbnailUrl != null) ? thumbnailUrl : url)
2508 : url);
2509 if (mUpdateMyNavThumbnail) {
2510 mUpdateMyNavThumbnail = false;
2511 mUpdateMyNavThumbnailUrl = null;
2512 }
John Reck34ef2672011-02-10 11:30:55 -08002513 if (cursor != null && cursor.moveToFirst()) {
2514 final ByteArrayOutputStream os =
2515 new ByteArrayOutputStream();
2516 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
Michael Kolb8233fac2010-10-26 16:08:53 -07002517
John Reck34ef2672011-02-10 11:30:55 -08002518 ContentValues values = new ContentValues();
2519 values.put(Images.THUMBNAIL, os.toByteArray());
Michael Kolb8233fac2010-10-26 16:08:53 -07002520
John Reck34ef2672011-02-10 11:30:55 -08002521 do {
John Reck617fd832011-02-16 14:35:59 -08002522 values.put(Images.URL, cursor.getString(0));
John Reck34ef2672011-02-10 11:30:55 -08002523 cr.update(Images.CONTENT_URI, values, null, null);
2524 } while (cursor.moveToNext());
Michael Kolb8233fac2010-10-26 16:08:53 -07002525 }
John Reck34ef2672011-02-10 11:30:55 -08002526 } catch (IllegalStateException e) {
2527 // Ignore
Mattias Nilsson561d1952011-10-04 10:18:50 +02002528 } catch (SQLiteException s) {
2529 // Added for possible error when user tries to remove the same bookmark
2530 // that is being updated with a screen shot
2531 Log.w(LOGTAG, "Error when running updateScreenshot ", s);
John Reck34ef2672011-02-10 11:30:55 -08002532 } finally {
2533 if (cursor != null) cursor.close();
Michael Kolb8233fac2010-10-26 16:08:53 -07002534 }
John Reck34ef2672011-02-10 11:30:55 -08002535 return null;
2536 }
2537 }.execute();
Michael Kolb8233fac2010-10-26 16:08:53 -07002538 }
2539
2540 private class Copy implements OnMenuItemClickListener {
2541 private CharSequence mText;
2542
John Reck9c35b9c2012-05-30 10:08:50 -07002543 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002544 public boolean onMenuItemClick(MenuItem item) {
2545 copy(mText);
2546 return true;
2547 }
2548
2549 public Copy(CharSequence toCopy) {
2550 mText = toCopy;
2551 }
2552 }
2553
Leon Scroggins63c02662010-11-18 15:16:27 -05002554 private static class Download implements OnMenuItemClickListener {
2555 private Activity mActivity;
Michael Kolb8233fac2010-10-26 16:08:53 -07002556 private String mText;
Kristian Monsenbc5cc752011-03-02 13:14:03 +00002557 private boolean mPrivateBrowsing;
Andreas Sandblad8e4ce662012-06-11 11:02:49 +02002558 private String mUserAgent;
George Mount387d45d2011-10-07 15:57:53 -07002559 private static final String FALLBACK_EXTENSION = "dat";
2560 private static final String IMAGE_BASE_FORMAT = "yyyy-MM-dd-HH-mm-ss-";
Michael Kolb8233fac2010-10-26 16:08:53 -07002561
John Reck9c35b9c2012-05-30 10:08:50 -07002562 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002563 public boolean onMenuItemClick(MenuItem item) {
George Mount387d45d2011-10-07 15:57:53 -07002564 if (DataUri.isDataUri(mText)) {
2565 saveDataUri();
2566 } else {
Andreas Sandblad8e4ce662012-06-11 11:02:49 +02002567 DownloadHandler.onDownloadStartNoStream(mActivity, mText, mUserAgent,
luxiaol62677b02013-07-22 07:54:49 +08002568 null, null, null, mPrivateBrowsing, 0);
George Mount387d45d2011-10-07 15:57:53 -07002569 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002570 return true;
2571 }
2572
Andreas Sandblad8e4ce662012-06-11 11:02:49 +02002573 public Download(Activity activity, String toDownload, boolean privateBrowsing,
2574 String userAgent) {
Leon Scroggins63c02662010-11-18 15:16:27 -05002575 mActivity = activity;
Michael Kolb8233fac2010-10-26 16:08:53 -07002576 mText = toDownload;
Kristian Monsenbc5cc752011-03-02 13:14:03 +00002577 mPrivateBrowsing = privateBrowsing;
Andreas Sandblad8e4ce662012-06-11 11:02:49 +02002578 mUserAgent = userAgent;
Michael Kolb8233fac2010-10-26 16:08:53 -07002579 }
George Mount387d45d2011-10-07 15:57:53 -07002580
2581 /**
2582 * Treats mText as a data URI and writes its contents to a file
2583 * based on the current time.
2584 */
2585 private void saveDataUri() {
2586 FileOutputStream outputStream = null;
2587 try {
2588 DataUri uri = new DataUri(mText);
2589 File target = getTarget(uri);
2590 outputStream = new FileOutputStream(target);
2591 outputStream.write(uri.getData());
2592 final DownloadManager manager =
2593 (DownloadManager) mActivity.getSystemService(Context.DOWNLOAD_SERVICE);
2594 manager.addCompletedDownload(target.getName(),
2595 mActivity.getTitle().toString(), false,
2596 uri.getMimeType(), target.getAbsolutePath(),
John Reck9c35b9c2012-05-30 10:08:50 -07002597 uri.getData().length, true);
George Mount387d45d2011-10-07 15:57:53 -07002598 } catch (IOException e) {
2599 Log.e(LOGTAG, "Could not save data URL");
2600 } finally {
2601 if (outputStream != null) {
2602 try {
2603 outputStream.close();
2604 } catch (IOException e) {
2605 // ignore close errors
2606 }
2607 }
2608 }
2609 }
2610
2611 /**
2612 * Creates a File based on the current time stamp and uses
2613 * the mime type of the DataUri to get the extension.
2614 */
2615 private File getTarget(DataUri uri) throws IOException {
2616 File dir = mActivity.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
Johan Redestigaa676182012-10-03 13:33:01 +02002617 DateFormat format = new SimpleDateFormat(IMAGE_BASE_FORMAT, Locale.US);
George Mount387d45d2011-10-07 15:57:53 -07002618 String nameBase = format.format(new Date());
2619 String mimeType = uri.getMimeType();
2620 MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
2621 String extension = mimeTypeMap.getExtensionFromMimeType(mimeType);
2622 if (extension == null) {
2623 Log.w(LOGTAG, "Unknown mime type in data URI" + mimeType);
2624 extension = FALLBACK_EXTENSION;
2625 }
2626 extension = "." + extension; // createTempFile needs the '.'
2627 File targetFile = File.createTempFile(nameBase, extension, dir);
2628 return targetFile;
2629 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002630 }
2631
Cary Clark8974d282010-11-22 10:46:05 -05002632 private static class SelectText implements OnMenuItemClickListener {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002633 private WebViewClassic mWebView;
Cary Clark8974d282010-11-22 10:46:05 -05002634
John Reck9c35b9c2012-05-30 10:08:50 -07002635 @Override
Cary Clark8974d282010-11-22 10:46:05 -05002636 public boolean onMenuItemClick(MenuItem item) {
2637 if (mWebView != null) {
2638 return mWebView.selectText();
2639 }
2640 return false;
2641 }
2642
2643 public SelectText(WebView webView) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -08002644 if (BrowserWebView.isClassic()) {
2645 mWebView = WebViewClassic.fromWebView(webView);
2646 }
Cary Clark8974d282010-11-22 10:46:05 -05002647 }
2648
2649 }
2650
Michael Kolb8233fac2010-10-26 16:08:53 -07002651 /********************** TODO: UI stuff *****************************/
2652
2653 // these methods have been copied, they still need to be cleaned up
2654
2655 /****************** tabs ***************************************************/
2656
2657 // basic tab interactions:
2658
2659 // it is assumed that tabcontrol already knows about the tab
2660 protected void addTab(Tab tab) {
2661 mUi.addTab(tab);
2662 }
2663
2664 protected void removeTab(Tab tab) {
2665 mUi.removeTab(tab);
2666 mTabControl.removeTab(tab);
John Reck378a4102011-06-09 16:23:01 -07002667 mCrashRecoveryHandler.backupState();
Michael Kolb8233fac2010-10-26 16:08:53 -07002668 }
2669
Michael Kolbf2055602011-04-09 17:20:03 -07002670 @Override
2671 public void setActiveTab(Tab tab) {
Michael Kolbcd424e92011-02-24 10:26:26 -08002672 // monkey protection against delayed start
2673 if (tab != null) {
2674 mTabControl.setCurrentTab(tab);
2675 // the tab is guaranteed to have a webview after setCurrentTab
2676 mUi.setActiveTab(tab);
2677 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002678 }
2679
John Reck8bcafc12011-08-29 16:43:02 -07002680 protected void closeEmptyTab() {
Michael Kolb8233fac2010-10-26 16:08:53 -07002681 Tab current = mTabControl.getCurrentTab();
2682 if (current != null
2683 && current.getWebView().copyBackForwardList().getSize() == 0) {
John Reck8bcafc12011-08-29 16:43:02 -07002684 closeCurrentTab();
Michael Kolb8233fac2010-10-26 16:08:53 -07002685 }
2686 }
2687
John Reck26b18322011-06-21 13:08:58 -07002688 protected void reuseTab(Tab appTab, UrlData urlData) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002689 // Dismiss the subwindow if applicable.
2690 dismissSubWindow(appTab);
2691 // Since we might kill the WebView, remove it from the
2692 // content view first.
2693 mUi.detachTab(appTab);
2694 // Recreate the main WebView after destroying the old one.
John Reck30c714c2010-12-16 17:30:34 -08002695 mTabControl.recreateWebView(appTab);
Michael Kolb8233fac2010-10-26 16:08:53 -07002696 // TODO: analyze why the remove and add are necessary
2697 mUi.attachTab(appTab);
2698 if (mTabControl.getCurrentTab() != appTab) {
Michael Kolbc831b632011-05-11 09:30:34 -07002699 switchToTab(appTab);
John Reck30c714c2010-12-16 17:30:34 -08002700 loadUrlDataIn(appTab, urlData);
Michael Kolb8233fac2010-10-26 16:08:53 -07002701 } else {
2702 // If the tab was the current tab, we have to attach
2703 // it to the view system again.
2704 setActiveTab(appTab);
John Reck30c714c2010-12-16 17:30:34 -08002705 loadUrlDataIn(appTab, urlData);
Michael Kolb8233fac2010-10-26 16:08:53 -07002706 }
2707 }
2708
2709 // Remove the sub window if it exists. Also called by TabControl when the
2710 // user clicks the 'X' to dismiss a sub window.
John Reck9c35b9c2012-05-30 10:08:50 -07002711 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002712 public void dismissSubWindow(Tab tab) {
2713 removeSubWindow(tab);
2714 // dismiss the subwindow. This will destroy the WebView.
2715 tab.dismissSubWindow();
Michael Kolbe8c97572011-11-21 14:03:56 -08002716 WebView wv = getCurrentTopWebView();
2717 if (wv != null) {
2718 wv.requestFocus();
2719 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002720 }
2721
2722 @Override
2723 public void removeSubWindow(Tab t) {
2724 if (t.getSubWebView() != null) {
2725 mUi.removeSubWindow(t.getSubViewContainer());
2726 }
2727 }
2728
2729 @Override
2730 public void attachSubWindow(Tab tab) {
2731 if (tab.getSubWebView() != null) {
2732 mUi.attachSubWindow(tab.getSubViewContainer());
2733 getCurrentTopWebView().requestFocus();
2734 }
2735 }
2736
Mathew Inwood29721c22011-06-29 17:55:24 +01002737 private Tab showPreloadedTab(final UrlData urlData) {
2738 if (!urlData.isPreloaded()) {
2739 return null;
2740 }
2741 final PreloadedTabControl tabControl = urlData.getPreloadedTab();
2742 final String sbQuery = urlData.getSearchBoxQueryToSubmit();
2743 if (sbQuery != null) {
Mathew Inwood9ad1eac2011-09-15 11:29:50 +01002744 if (!tabControl.searchBoxSubmit(sbQuery, urlData.mUrl, urlData.mHeaders)) {
Mathew Inwood29721c22011-06-29 17:55:24 +01002745 // Could not submit query. Fallback to regular tab creation
2746 tabControl.destroy();
2747 return null;
2748 }
2749 }
Michael Kolbff6a7482011-07-26 16:37:15 -07002750 // check tab count and make room for new tab
2751 if (!mTabControl.canCreateNewTab()) {
2752 Tab leastUsed = mTabControl.getLeastUsedTab(getCurrentTab());
2753 if (leastUsed != null) {
2754 closeTab(leastUsed);
2755 }
2756 }
Mathew Inwood29721c22011-06-29 17:55:24 +01002757 Tab t = tabControl.getTab();
Mathew Inwoode09305e2011-09-02 12:03:26 +01002758 t.refreshIdAfterPreload();
Mathew Inwood29721c22011-06-29 17:55:24 +01002759 mTabControl.addPreloadedTab(t);
2760 addTab(t);
2761 setActiveTab(t);
2762 return t;
2763 }
2764
Michael Kolb7bcafde2011-05-09 13:55:59 -07002765 // open a non inconito tab with the given url data
2766 // and set as active tab
2767 public Tab openTab(UrlData urlData) {
Mathew Inwood29721c22011-06-29 17:55:24 +01002768 Tab tab = showPreloadedTab(urlData);
2769 if (tab == null) {
2770 tab = createNewTab(false, true, true);
Michael Kolb14612442011-06-24 13:06:29 -07002771 if ((tab != null) && !urlData.isEmpty()) {
2772 loadUrlDataIn(tab, urlData);
2773 }
Michael Kolb7bcafde2011-05-09 13:55:59 -07002774 }
Mathew Inwood29721c22011-06-29 17:55:24 +01002775 return tab;
Michael Kolb7bcafde2011-05-09 13:55:59 -07002776 }
2777
Michael Kolb843510f2010-12-09 10:51:49 -08002778 @Override
2779 public Tab openTabToHomePage() {
Michael Kolb7bcafde2011-05-09 13:55:59 -07002780 return openTab(mSettings.getHomePage(), false, true, false);
Michael Kolb8233fac2010-10-26 16:08:53 -07002781 }
2782
Michael Kolb8233fac2010-10-26 16:08:53 -07002783 @Override
Michael Kolb519d2282011-05-09 17:03:19 -07002784 public Tab openIncognitoTab() {
2785 return openTab(INCOGNITO_URI, true, true, false);
2786 }
2787
2788 @Override
Michael Kolb7bcafde2011-05-09 13:55:59 -07002789 public Tab openTab(String url, boolean incognito, boolean setActive,
2790 boolean useCurrent) {
John Reck5949c662011-05-27 09:52:29 -07002791 return openTab(url, incognito, setActive, useCurrent, null);
2792 }
2793
2794 @Override
2795 public Tab openTab(String url, Tab parent, boolean setActive,
2796 boolean useCurrent) {
2797 return openTab(url, (parent != null) && parent.isPrivateBrowsingEnabled(),
2798 setActive, useCurrent, parent);
2799 }
2800
2801 public Tab openTab(String url, boolean incognito, boolean setActive,
2802 boolean useCurrent, Tab parent) {
Michael Kolb7bcafde2011-05-09 13:55:59 -07002803 Tab tab = createNewTab(incognito, setActive, useCurrent);
2804 if (tab != null) {
John Reck5949c662011-05-27 09:52:29 -07002805 if (parent != null && parent != tab) {
2806 parent.addChildTab(tab);
2807 }
Michael Kolb519d2282011-05-09 17:03:19 -07002808 if (url != null) {
John Reck26b18322011-06-21 13:08:58 -07002809 loadUrl(tab, url);
Michael Kolb519d2282011-05-09 17:03:19 -07002810 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002811 }
Michael Kolb7bcafde2011-05-09 13:55:59 -07002812 return tab;
2813 }
2814
2815 // this method will attempt to create a new tab
2816 // incognito: private browsing tab
2817 // setActive: ste tab as current tab
2818 // useCurrent: if no new tab can be created, return current tab
2819 private Tab createNewTab(boolean incognito, boolean setActive,
2820 boolean useCurrent) {
2821 Tab tab = null;
2822 if (mTabControl.canCreateNewTab()) {
2823 tab = mTabControl.createNewTab(incognito);
2824 addTab(tab);
2825 if (setActive) {
2826 setActiveTab(tab);
2827 }
2828 } else {
2829 if (useCurrent) {
2830 tab = mTabControl.getCurrentTab();
John Reck26b18322011-06-21 13:08:58 -07002831 reuseTab(tab, null);
Michael Kolb7bcafde2011-05-09 13:55:59 -07002832 } else {
2833 mUi.showMaxTabsWarning();
2834 }
2835 }
2836 return tab;
Michael Kolb8233fac2010-10-26 16:08:53 -07002837 }
2838
John Reck2bc80422011-06-30 15:11:49 -07002839 @Override
2840 public SnapshotTab createNewSnapshotTab(long snapshotId, boolean setActive) {
2841 SnapshotTab tab = null;
2842 if (mTabControl.canCreateNewTab()) {
2843 tab = mTabControl.createSnapshotTab(snapshotId);
2844 addTab(tab);
2845 if (setActive) {
2846 setActiveTab(tab);
2847 }
2848 } else {
2849 mUi.showMaxTabsWarning();
John Reckd8c74522011-06-14 08:45:00 -07002850 }
2851 return tab;
2852 }
2853
Michael Kolb8233fac2010-10-26 16:08:53 -07002854 /**
Michael Kolbc831b632011-05-11 09:30:34 -07002855 * @param tab the tab to switch to
Michael Kolb8233fac2010-10-26 16:08:53 -07002856 * @return boolean True if we successfully switched to a different tab. If
2857 * the indexth tab is null, or if that tab is the same as
2858 * the current one, return false.
2859 */
2860 @Override
Michael Kolbc831b632011-05-11 09:30:34 -07002861 public boolean switchToTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002862 Tab currentTab = mTabControl.getCurrentTab();
2863 if (tab == null || tab == currentTab) {
2864 return false;
2865 }
2866 setActiveTab(tab);
2867 return true;
2868 }
2869
2870 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -07002871 public void closeCurrentTab() {
Michael Kolb2ae6ef72011-08-22 14:49:34 -07002872 closeCurrentTab(false);
2873 }
2874
2875 protected void closeCurrentTab(boolean andQuit) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002876 if (mTabControl.getTabCount() == 1) {
John Reckbc490d22011-07-22 15:04:59 -07002877 mCrashRecoveryHandler.clearState();
Michael Kolbc1eeb122011-08-01 09:56:26 -07002878 mTabControl.removeTab(getCurrentTab());
John Reck958b2422010-12-03 17:56:17 -08002879 mActivity.finish();
Michael Kolb8233fac2010-10-26 16:08:53 -07002880 return;
2881 }
Michael Kolbc831b632011-05-11 09:30:34 -07002882 final Tab current = mTabControl.getCurrentTab();
2883 final int pos = mTabControl.getCurrentPosition();
2884 Tab newTab = current.getParent();
2885 if (newTab == null) {
2886 newTab = mTabControl.getTab(pos + 1);
2887 if (newTab == null) {
2888 newTab = mTabControl.getTab(pos - 1);
Michael Kolb8233fac2010-10-26 16:08:53 -07002889 }
2890 }
Michael Kolb2ae6ef72011-08-22 14:49:34 -07002891 if (andQuit) {
2892 mTabControl.setCurrentTab(newTab);
2893 closeTab(current);
2894 } else if (switchToTab(newTab)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002895 // Close window
2896 closeTab(current);
2897 }
2898 }
2899
2900 /**
2901 * Close the tab, remove its associated title bar, and adjust mTabControl's
2902 * current tab to a valid value.
2903 */
2904 @Override
2905 public void closeTab(Tab tab) {
John Reck28263772011-10-11 17:13:42 -07002906 if (tab == mTabControl.getCurrentTab()) {
2907 closeCurrentTab();
2908 } else {
2909 removeTab(tab);
2910 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002911 }
2912
Afzal Najamd4e33312012-04-26 01:54:01 -04002913 /**
2914 * Close all tabs except the current one
2915 */
2916 @Override
2917 public void closeOtherTabs() {
2918 int inactiveTabs = mTabControl.getTabCount() - 1;
2919 for (int i = inactiveTabs; i >= 0; i--) {
2920 Tab tab = mTabControl.getTab(i);
2921 if (tab != mTabControl.getCurrentTab()) {
2922 removeTab(tab);
2923 }
2924 }
2925 }
2926
Michael Kolb8233fac2010-10-26 16:08:53 -07002927 // Called when loading from context menu or LOAD_URL message
John Reck26b18322011-06-21 13:08:58 -07002928 protected void loadUrlFromContext(String url) {
2929 Tab tab = getCurrentTab();
2930 WebView view = tab != null ? tab.getWebView() : null;
Michael Kolb8233fac2010-10-26 16:08:53 -07002931 // In case the user enters nothing.
John Reck26b18322011-06-21 13:08:58 -07002932 if (url != null && url.length() != 0 && tab != null && view != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -07002933 url = UrlUtils.smartUrlFilter(url);
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -08002934 if (!((BrowserWebView) view).getWebViewClient().
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00002935 shouldOverrideUrlLoading(view, url)) {
John Reck26b18322011-06-21 13:08:58 -07002936 loadUrl(tab, url);
Michael Kolb8233fac2010-10-26 16:08:53 -07002937 }
2938 }
2939 }
2940
2941 /**
2942 * Load the URL into the given WebView and update the title bar
2943 * to reflect the new load. Call this instead of WebView.loadUrl
2944 * directly.
2945 * @param view The WebView used to load url.
2946 * @param url The URL to load.
2947 */
John Reck71e51422011-07-01 16:49:28 -07002948 @Override
2949 public void loadUrl(Tab tab, String url) {
John Reck26b18322011-06-21 13:08:58 -07002950 loadUrl(tab, url, null);
2951 }
2952
2953 protected void loadUrl(Tab tab, String url, Map<String, String> headers) {
2954 if (tab != null) {
2955 dismissSubWindow(tab);
2956 tab.loadUrl(url, headers);
Michael Kolba53c9892011-10-05 13:31:40 -07002957 mUi.onProgressChanged(tab);
John Reck26b18322011-06-21 13:08:58 -07002958 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002959 }
2960
2961 /**
2962 * Load UrlData into a Tab and update the title bar to reflect the new
2963 * load. Call this instead of UrlData.loadIn directly.
2964 * @param t The Tab used to load.
2965 * @param data The UrlData being loaded.
2966 */
2967 protected void loadUrlDataIn(Tab t, UrlData data) {
John Reck26b18322011-06-21 13:08:58 -07002968 if (data != null) {
Michael Kolb5ff5c8b2012-05-03 11:37:58 -07002969 if (data.isPreloaded()) {
Michael Kolb14612442011-06-24 13:06:29 -07002970 // this isn't called for preloaded tabs
John Reck26b18322011-06-21 13:08:58 -07002971 } else {
John Reck38b39652012-06-05 09:22:59 -07002972 if (t != null && data.mDisableUrlOverride) {
2973 t.disableUrlOverridingForLoad();
2974 }
John Reck26b18322011-06-21 13:08:58 -07002975 loadUrl(t, data.mUrl, data.mHeaders);
2976 }
2977 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002978 }
2979
John Reck30c714c2010-12-16 17:30:34 -08002980 @Override
2981 public void onUserCanceledSsl(Tab tab) {
John Reck30c714c2010-12-16 17:30:34 -08002982 // TODO: Figure out the "right" behavior
John Reckef654f12011-07-12 16:42:08 -07002983 if (tab.canGoBack()) {
2984 tab.goBack();
John Reck30c714c2010-12-16 17:30:34 -08002985 } else {
John Reckef654f12011-07-12 16:42:08 -07002986 tab.loadUrl(mSettings.getHomePage(), null);
John Reck30c714c2010-12-16 17:30:34 -08002987 }
Michael Kolb8233fac2010-10-26 16:08:53 -07002988 }
2989
2990 void goBackOnePageOrQuit() {
2991 Tab current = mTabControl.getCurrentTab();
2992 if (current == null) {
2993 /*
2994 * Instead of finishing the activity, simply push this to the back
2995 * of the stack and let ActivityManager to choose the foreground
2996 * activity. As BrowserActivity is singleTask, it will be always the
2997 * root of the task. So we can use either true or false for
2998 * moveTaskToBack().
2999 */
luxiaolb40014b2013-07-19 10:01:43 +08003000 showExitDialog(mActivity);
Michael Kolb8233fac2010-10-26 16:08:53 -07003001 return;
3002 }
John Reckef654f12011-07-12 16:42:08 -07003003 if (current.canGoBack()) {
3004 current.goBack();
Michael Kolb8233fac2010-10-26 16:08:53 -07003005 } else {
3006 // Check to see if we are closing a window that was created by
3007 // another window. If so, we switch back to that window.
Michael Kolbc831b632011-05-11 09:30:34 -07003008 Tab parent = current.getParent();
Michael Kolb8233fac2010-10-26 16:08:53 -07003009 if (parent != null) {
Michael Kolbc831b632011-05-11 09:30:34 -07003010 switchToTab(parent);
Michael Kolb8233fac2010-10-26 16:08:53 -07003011 // Now we close the other tab
3012 closeTab(current);
3013 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -07003014 /*
3015 * Instead of finishing the activity, simply push this to the back
3016 * of the stack and let ActivityManager to choose the foreground
3017 * activity. As BrowserActivity is singleTask, it will be always the
3018 * root of the task. So we can use either true or false for
3019 * moveTaskToBack().
3020 */
luxiaolb40014b2013-07-19 10:01:43 +08003021 showExitDialog(mActivity);
Michael Kolb8233fac2010-10-26 16:08:53 -07003022 }
3023 }
3024 }
3025
3026 /**
Michael Kolb0035fad2011-03-14 13:25:28 -07003027 * helper method for key handler
3028 * returns the current tab if it can't advance
3029 */
Michael Kolbc831b632011-05-11 09:30:34 -07003030 private Tab getNextTab() {
Michael Kolbf5261da2011-12-15 15:07:35 -08003031 int pos = mTabControl.getCurrentPosition() + 1;
3032 if (pos >= mTabControl.getTabCount()) {
3033 pos = 0;
3034 }
3035 return mTabControl.getTab(pos);
Michael Kolb0035fad2011-03-14 13:25:28 -07003036 }
3037
3038 /**
3039 * helper method for key handler
3040 * returns the current tab if it can't advance
3041 */
Michael Kolbc831b632011-05-11 09:30:34 -07003042 private Tab getPrevTab() {
Michael Kolbf5261da2011-12-15 15:07:35 -08003043 int pos = mTabControl.getCurrentPosition() - 1;
3044 if ( pos < 0) {
3045 pos = mTabControl.getTabCount() - 1;
3046 }
3047 return mTabControl.getTab(pos);
Michael Kolb0035fad2011-03-14 13:25:28 -07003048 }
3049
John Reckbcef87f2012-02-03 14:58:34 -08003050 boolean isMenuOrCtrlKey(int keyCode) {
3051 return (KeyEvent.KEYCODE_MENU == keyCode)
3052 || (KeyEvent.KEYCODE_CTRL_LEFT == keyCode)
3053 || (KeyEvent.KEYCODE_CTRL_RIGHT == keyCode);
3054 }
3055
Michael Kolb0035fad2011-03-14 13:25:28 -07003056 /**
Michael Kolb8233fac2010-10-26 16:08:53 -07003057 * handle key events in browser
3058 *
3059 * @param keyCode
3060 * @param event
3061 * @return true if handled, false to pass to super
3062 */
John Reck9c35b9c2012-05-30 10:08:50 -07003063 @Override
3064 public boolean onKeyDown(int keyCode, KeyEvent event) {
Cary Clark160bbb92011-01-10 11:17:07 -05003065 boolean noModifiers = event.hasNoModifiers();
Michael Kolb8233fac2010-10-26 16:08:53 -07003066 // Even if MENU is already held down, we need to call to super to open
3067 // the IME on long press.
John Reckbcef87f2012-02-03 14:58:34 -08003068 if (!noModifiers && isMenuOrCtrlKey(keyCode)) {
Michael Kolb8233fac2010-10-26 16:08:53 -07003069 mMenuIsDown = true;
3070 return false;
3071 }
Michael Kolb8233fac2010-10-26 16:08:53 -07003072
Cary Clark8ff8c662010-12-29 15:03:05 -05003073 WebView webView = getCurrentTopWebView();
John Reckef654f12011-07-12 16:42:08 -07003074 Tab tab = getCurrentTab();
3075 if (webView == null || tab == null) return false;
Cary Clark8ff8c662010-12-29 15:03:05 -05003076
Cary Clark160bbb92011-01-10 11:17:07 -05003077 boolean ctrl = event.hasModifiers(KeyEvent.META_CTRL_ON);
3078 boolean shift = event.hasModifiers(KeyEvent.META_SHIFT_ON);
Cary Clark8ff8c662010-12-29 15:03:05 -05003079
Michael Kolb8233fac2010-10-26 16:08:53 -07003080 switch(keyCode) {
Michael Kolb0035fad2011-03-14 13:25:28 -07003081 case KeyEvent.KEYCODE_TAB:
3082 if (event.isCtrlPressed()) {
3083 if (event.isShiftPressed()) {
3084 // prev tab
Michael Kolbc831b632011-05-11 09:30:34 -07003085 switchToTab(getPrevTab());
Michael Kolb0035fad2011-03-14 13:25:28 -07003086 } else {
3087 // next tab
Michael Kolbc831b632011-05-11 09:30:34 -07003088 switchToTab(getNextTab());
Michael Kolb0035fad2011-03-14 13:25:28 -07003089 }
3090 return true;
3091 }
3092 break;
Michael Kolb8233fac2010-10-26 16:08:53 -07003093 case KeyEvent.KEYCODE_SPACE:
3094 // WebView/WebTextView handle the keys in the KeyDown. As
3095 // the Activity's shortcut keys are only handled when WebView
3096 // doesn't, have to do it in onKeyDown instead of onKeyUp.
Cary Clark160bbb92011-01-10 11:17:07 -05003097 if (shift) {
Michael Kolb8233fac2010-10-26 16:08:53 -07003098 pageUp();
Cary Clark160bbb92011-01-10 11:17:07 -05003099 } else if (noModifiers) {
Michael Kolb8233fac2010-10-26 16:08:53 -07003100 pageDown();
3101 }
3102 return true;
3103 case KeyEvent.KEYCODE_BACK:
Cary Clark160bbb92011-01-10 11:17:07 -05003104 if (!noModifiers) break;
John Recke6bf4ab2011-02-24 15:48:05 -08003105 event.startTracking();
3106 return true;
Michael Kolbe9e1d4a2011-07-14 15:02:17 -07003107 case KeyEvent.KEYCODE_FORWARD:
3108 if (!noModifiers) break;
3109 tab.goForward();
3110 return true;
Cary Clark8ff8c662010-12-29 15:03:05 -05003111 case KeyEvent.KEYCODE_DPAD_LEFT:
3112 if (ctrl) {
John Reckef654f12011-07-12 16:42:08 -07003113 tab.goBack();
Cary Clark8ff8c662010-12-29 15:03:05 -05003114 return true;
3115 }
3116 break;
3117 case KeyEvent.KEYCODE_DPAD_RIGHT:
3118 if (ctrl) {
John Reckef654f12011-07-12 16:42:08 -07003119 tab.goForward();
Cary Clark8ff8c662010-12-29 15:03:05 -05003120 return true;
3121 }
3122 break;
3123 case KeyEvent.KEYCODE_A:
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -08003124 if (ctrl && BrowserWebView.isClassic()) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00003125 WebViewClassic.fromWebView(webView).selectAll();
Cary Clark8ff8c662010-12-29 15:03:05 -05003126 return true;
3127 }
3128 break;
Michael Kolba4183062011-01-16 10:43:21 -08003129// case KeyEvent.KEYCODE_B: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003130 case KeyEvent.KEYCODE_C:
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -08003131 if (ctrl && BrowserWebView.isClassic()) {
Jonathan Dixon4d2fcab2012-02-24 00:13:06 +00003132 WebViewClassic.fromWebView(webView).copySelection();
Cary Clark8ff8c662010-12-29 15:03:05 -05003133 return true;
3134 }
3135 break;
Michael Kolba4183062011-01-16 10:43:21 -08003136// case KeyEvent.KEYCODE_D: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003137// case KeyEvent.KEYCODE_E: // in Chrome: puts '?' in URL bar
Michael Kolba4183062011-01-16 10:43:21 -08003138// case KeyEvent.KEYCODE_F: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003139// case KeyEvent.KEYCODE_G: // in Chrome: finds next match
Michael Kolba4183062011-01-16 10:43:21 -08003140// case KeyEvent.KEYCODE_H: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003141// case KeyEvent.KEYCODE_I: // unused
Michael Kolba4183062011-01-16 10:43:21 -08003142// case KeyEvent.KEYCODE_J: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003143// case KeyEvent.KEYCODE_K: // in Chrome: puts '?' in URL bar
Michael Kolba4183062011-01-16 10:43:21 -08003144// case KeyEvent.KEYCODE_L: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003145// case KeyEvent.KEYCODE_M: // unused
3146// case KeyEvent.KEYCODE_N: // in Chrome: new window
3147// case KeyEvent.KEYCODE_O: // in Chrome: open file
3148// case KeyEvent.KEYCODE_P: // in Chrome: print page
3149// case KeyEvent.KEYCODE_Q: // unused
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08003150// case KeyEvent.KEYCODE_R:
Cary Clark8ff8c662010-12-29 15:03:05 -05003151// case KeyEvent.KEYCODE_S: // in Chrome: saves page
3152 case KeyEvent.KEYCODE_T:
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08003153 // we can't use the ctrl/shift flags, they check for
3154 // exclusive use of a modifier
3155 if (event.isCtrlPressed()) {
Cary Clark8ff8c662010-12-29 15:03:05 -05003156 if (event.isShiftPressed()) {
Michael Kolb519d2282011-05-09 17:03:19 -07003157 openIncognitoTab();
Cary Clark8ff8c662010-12-29 15:03:05 -05003158 } else {
3159 openTabToHomePage();
3160 }
3161 return true;
3162 }
3163 break;
3164// case KeyEvent.KEYCODE_U: // in Chrome: opens source of page
3165// case KeyEvent.KEYCODE_V: // text view intercepts to paste
Michael Kolb5ae15bd2011-08-16 17:09:27 -07003166// case KeyEvent.KEYCODE_W: // menu
Cary Clark8ff8c662010-12-29 15:03:05 -05003167// case KeyEvent.KEYCODE_X: // text view intercepts to cut
3168// case KeyEvent.KEYCODE_Y: // unused
3169// case KeyEvent.KEYCODE_Z: // unused
Michael Kolb8233fac2010-10-26 16:08:53 -07003170 }
Michael Kolbdc2ee1b2011-02-14 14:34:40 -08003171 // it is a regular key and webview is not null
3172 return mUi.dispatchKey(keyCode, event);
Michael Kolb8233fac2010-10-26 16:08:53 -07003173 }
3174
John Reck9c35b9c2012-05-30 10:08:50 -07003175 @Override
3176 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
John Recke6bf4ab2011-02-24 15:48:05 -08003177 switch(keyCode) {
3178 case KeyEvent.KEYCODE_BACK:
John Reck3ba45532011-08-11 16:26:53 -07003179 if (mUi.isWebShowing()) {
Michael Kolb315d5022011-10-13 12:47:11 -07003180 bookmarksOrHistoryPicker(ComboViews.History);
John Recke6bf4ab2011-02-24 15:48:05 -08003181 return true;
3182 }
3183 break;
3184 }
3185 return false;
3186 }
3187
John Reck9c35b9c2012-05-30 10:08:50 -07003188 @Override
3189 public boolean onKeyUp(int keyCode, KeyEvent event) {
John Reckbcef87f2012-02-03 14:58:34 -08003190 if (isMenuOrCtrlKey(keyCode)) {
Michael Kolb2814a362011-05-19 15:49:41 -07003191 mMenuIsDown = false;
John Reckbcef87f2012-02-03 14:58:34 -08003192 if (KeyEvent.KEYCODE_MENU == keyCode
3193 && event.isTracking() && !event.isCanceled()) {
Michael Kolb4bd767d2011-05-27 11:33:55 -07003194 return onMenuKey();
Michael Kolb2814a362011-05-19 15:49:41 -07003195 }
3196 }
Cary Clark160bbb92011-01-10 11:17:07 -05003197 if (!event.hasNoModifiers()) return false;
Michael Kolb8233fac2010-10-26 16:08:53 -07003198 switch(keyCode) {
Michael Kolb8233fac2010-10-26 16:08:53 -07003199 case KeyEvent.KEYCODE_BACK:
3200 if (event.isTracking() && !event.isCanceled()) {
3201 onBackKey();
3202 return true;
3203 }
3204 break;
3205 }
3206 return false;
3207 }
3208
3209 public boolean isMenuDown() {
3210 return mMenuIsDown;
3211 }
3212
John Reck9c35b9c2012-05-30 10:08:50 -07003213 @Override
Ben Murdoch8029a772010-11-16 11:58:21 +00003214 public void setupAutoFill(Message message) {
3215 // Open the settings activity at the AutoFill profile fragment so that
3216 // the user can create a new profile. When they return, we will dispatch
3217 // the message so that we can autofill the form using their new profile.
3218 Intent intent = new Intent(mActivity, BrowserPreferencesPage.class);
3219 intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
3220 AutoFillSettingsFragment.class.getName());
3221 mAutoFillSetupMessage = message;
3222 mActivity.startActivityForResult(intent, AUTOFILL_SETUP);
3223 }
John Reckb3417f02011-01-14 11:01:05 -08003224
John Reck9c35b9c2012-05-30 10:08:50 -07003225 @Override
Michael Kolbfbc579a2011-07-07 15:59:33 -07003226 public boolean onSearchRequested() {
Michael Kolb1f9b3562012-04-24 14:38:34 -07003227 mUi.editUrl(false, true);
Michael Kolbfbc579a2011-07-07 15:59:33 -07003228 return true;
3229 }
3230
John Reck1cf4b792011-07-26 10:22:22 -07003231 @Override
3232 public boolean shouldCaptureThumbnails() {
3233 return mUi.shouldCaptureThumbnails();
3234 }
3235
Michael Kolbc3af0672011-08-09 10:24:41 -07003236 @Override
Michael Kolb0b129122012-06-04 16:31:58 -07003237 public boolean supportsVoice() {
3238 PackageManager pm = mActivity.getPackageManager();
3239 List activities = pm.queryIntentActivities(new Intent(
3240 RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
3241 return activities.size() != 0;
3242 }
3243
3244 @Override
3245 public void startVoiceRecognizer() {
3246 Intent voice = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
3247 voice.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
3248 RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
3249 voice.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
3250 mActivity.startActivityForResult(voice, VOICE_RESULT);
3251 }
3252
3253 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003254 public void setBlockEvents(boolean block) {
3255 mBlockEvents = block;
3256 }
3257
John Reck9c35b9c2012-05-30 10:08:50 -07003258 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003259 public boolean dispatchKeyEvent(KeyEvent event) {
Michael Kolb87357642011-08-24 14:19:18 -07003260 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07003261 }
3262
John Reck9c35b9c2012-05-30 10:08:50 -07003263 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003264 public boolean dispatchKeyShortcutEvent(KeyEvent event) {
Michael Kolb87357642011-08-24 14:19:18 -07003265 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07003266 }
3267
John Reck9c35b9c2012-05-30 10:08:50 -07003268 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003269 public boolean dispatchTouchEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07003270 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07003271 }
3272
John Reck9c35b9c2012-05-30 10:08:50 -07003273 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003274 public boolean dispatchTrackballEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07003275 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07003276 }
3277
John Reck9c35b9c2012-05-30 10:08:50 -07003278 @Override
Michael Kolbc3af0672011-08-09 10:24:41 -07003279 public boolean dispatchGenericMotionEvent(MotionEvent ev) {
Michael Kolb87357642011-08-24 14:19:18 -07003280 return mBlockEvents;
Michael Kolbc3af0672011-08-09 10:24:41 -07003281 }
3282
Michael Kolb8233fac2010-10-26 16:08:53 -07003283}