blob: 926193ae9bb730fb204eee1251bbf435f3607d74 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2006 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
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.app.Activity;
The Android Open Source Project0c908882009-03-03 19:32:16 -080020import android.app.AlertDialog;
21import android.app.ProgressDialog;
22import android.app.SearchManager;
23import android.content.ActivityNotFoundException;
24import android.content.BroadcastReceiver;
25import android.content.ComponentName;
Leon Scroggins58d56c62010-01-28 15:12:40 -050026import android.content.ContentProvider;
27import android.content.ContentProviderClient;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.content.ContentResolver;
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -040029import android.content.ContentUris;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030import android.content.ContentValues;
31import android.content.Context;
32import android.content.DialogInterface;
33import android.content.Intent;
34import android.content.IntentFilter;
Grace Klobab4da0ad2009-05-14 14:45:40 -070035import android.content.pm.PackageInfo;
The Android Open Source Project0c908882009-03-03 19:32:16 -080036import android.content.pm.PackageManager;
37import android.content.pm.ResolveInfo;
The Android Open Source Project0c908882009-03-03 19:32:16 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
40import android.database.Cursor;
Leon Scroggins96afcb12009-12-10 12:35:56 -050041import android.database.DatabaseUtils;
The Android Open Source Project0c908882009-03-03 19:32:16 -080042import android.graphics.Bitmap;
Andrei Popescu540035d2009-09-18 18:59:20 +010043import android.graphics.BitmapFactory;
The Android Open Source Project0c908882009-03-03 19:32:16 -080044import android.graphics.Canvas;
The Android Open Source Project0c908882009-03-03 19:32:16 -080045import android.graphics.Picture;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -040046import android.graphics.PixelFormat;
47import android.graphics.Rect;
The Android Open Source Project0c908882009-03-03 19:32:16 -080048import android.graphics.drawable.Drawable;
The Android Open Source Project0c908882009-03-03 19:32:16 -080049import android.net.ConnectivityManager;
Andrei Popescu56199cc2010-01-12 22:39:16 +000050import android.net.NetworkInfo;
The Android Open Source Project0c908882009-03-03 19:32:16 -080051import android.net.Uri;
52import android.net.WebAddress;
The Android Open Source Project0c908882009-03-03 19:32:16 -080053import android.net.http.SslCertificate;
54import android.net.http.SslError;
55import android.os.AsyncTask;
56import android.os.Bundle;
57import android.os.Debug;
58import android.os.Environment;
59import android.os.Handler;
The Android Open Source Project0c908882009-03-03 19:32:16 -080060import android.os.Message;
61import android.os.PowerManager;
62import android.os.Process;
The Android Open Source Project0c908882009-03-03 19:32:16 -080063import android.os.ServiceManager;
64import android.os.SystemClock;
The Android Open Source Project0c908882009-03-03 19:32:16 -080065import android.provider.Browser;
Cary Clark5e335a32009-09-22 14:53:11 -040066import android.provider.ContactsContract;
67import android.provider.ContactsContract.Intents.Insert;
The Android Open Source Project0c908882009-03-03 19:32:16 -080068import android.provider.Downloads;
69import android.provider.MediaStore;
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -050070import android.speech.RecognizerResultsIntent;
The Android Open Source Project0c908882009-03-03 19:32:16 -080071import android.text.IClipboard;
72import android.text.TextUtils;
73import android.text.format.DateFormat;
Leon Scrogginsb94bf272009-09-25 15:22:08 -040074import android.util.AttributeSet;
The Android Open Source Project0c908882009-03-03 19:32:16 -080075import android.util.Log;
Dianne Hackborn385effd2010-02-24 20:03:04 -080076import android.util.Patterns;
The Android Open Source Project0c908882009-03-03 19:32:16 -080077import android.view.ContextMenu;
78import android.view.Gravity;
79import android.view.KeyEvent;
80import android.view.LayoutInflater;
81import android.view.Menu;
82import android.view.MenuInflater;
83import android.view.MenuItem;
84import android.view.View;
85import android.view.ViewGroup;
86import android.view.Window;
87import android.view.WindowManager;
88import android.view.ContextMenu.ContextMenuInfo;
89import android.view.MenuItem.OnMenuItemClickListener;
Svetoslav Ganov2b345992010-05-06 06:13:54 -070090import android.view.accessibility.AccessibilityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080091import android.webkit.CookieManager;
92import android.webkit.CookieSyncManager;
93import android.webkit.DownloadListener;
94import android.webkit.HttpAuthHandler;
Grace Klobab4da0ad2009-05-14 14:45:40 -070095import android.webkit.PluginManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080096import android.webkit.SslErrorHandler;
97import android.webkit.URLUtil;
Leon Clarkecb6cc862009-09-29 18:35:13 +010098import android.webkit.ValueCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -080099import android.webkit.WebChromeClient;
100import android.webkit.WebHistoryItem;
101import android.webkit.WebIconDatabase;
102import android.webkit.WebView;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800103import android.widget.EditText;
104import android.widget.FrameLayout;
105import android.widget.LinearLayout;
106import android.widget.TextView;
107import android.widget.Toast;
Fred Quintana752b6562009-12-18 10:18:26 -0800108import android.accounts.Account;
109import android.accounts.AccountManager;
110import android.accounts.AccountManagerFuture;
111import android.accounts.AuthenticatorException;
112import android.accounts.OperationCanceledException;
113import android.accounts.AccountManagerCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800114
Bjorn Bringert10d1cca2010-02-10 14:22:12 +0000115import com.android.common.Search;
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500116import com.android.common.speech.LoggingEvents;
Dan Egnor5ee906c2009-11-18 12:11:49 -0800117
Leon Scrogginsb6b7f9e2009-06-18 12:05:28 -0400118import java.io.ByteArrayOutputStream;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800119import java.io.File;
Ben Murdoch4f75ba22009-10-27 11:48:28 +0000120import java.io.IOException;
121import java.io.InputStream;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800122import java.net.MalformedURLException;
123import java.net.URI;
Dianne Hackborn99189432009-06-17 18:06:18 -0700124import java.net.URISyntaxException;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800125import java.net.URL;
126import java.net.URLEncoder;
127import java.text.ParseException;
128import java.util.Date;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129import java.util.HashMap;
Andrei Popescu30995e72010-02-09 16:59:58 +0000130import java.util.HashSet;
Grace Kloba00f54c52010-01-27 14:53:51 -0800131import java.util.Iterator;
Andrei Popescu30995e72010-02-09 16:59:58 +0000132import java.util.List;
Grace Kloba068e48b2010-01-26 18:11:27 -0800133import java.util.Map;
Andrei Popescu30995e72010-02-09 16:59:58 +0000134import java.util.Set;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135import java.util.regex.Matcher;
136import java.util.regex.Pattern;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800137
138public class BrowserActivity extends Activity
Shimeng (Simon) Wang98d5fce2010-03-16 13:23:39 -0700139 implements View.OnCreateContextMenuListener, DownloadListener {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800140
Dave Bort31a6d1c2009-04-13 15:56:49 -0700141 /* Define some aliases to make these debugging flags easier to refer to.
142 * This file imports android.provider.Browser, so we can't just refer to "Browser.DEBUG".
143 */
144 private final static boolean DEBUG = com.android.browser.Browser.DEBUG;
145 private final static boolean LOGV_ENABLED = com.android.browser.Browser.LOGV_ENABLED;
146 private final static boolean LOGD_ENABLED = com.android.browser.Browser.LOGD_ENABLED;
147
Satish Sampath565505b2009-05-29 15:37:27 +0100148 // These are single-character shortcuts for searching popular sources.
149 private static final int SHORTCUT_INVALID = 0;
150 private static final int SHORTCUT_GOOGLE_SEARCH = 1;
151 private static final int SHORTCUT_WIKIPEDIA_SEARCH = 2;
152 private static final int SHORTCUT_DICTIONARY_SEARCH = 3;
153 private static final int SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH = 4;
154
Cary Clarka9771242009-08-11 16:42:26 -0400155 private static class ClearThumbnails extends AsyncTask<File, Void, Void> {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800156 @Override
157 public Void doInBackground(File... files) {
158 if (files != null) {
159 for (File f : files) {
Cary Clarkd6be1752009-08-12 12:56:42 -0400160 if (!f.delete()) {
161 Log.e(LOGTAG, f.getPath() + " was not deleted");
162 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800163 }
164 }
165 return null;
166 }
167 }
168
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400169 /**
170 * This layout holds everything you see below the status bar, including the
171 * error console, the custom view container, and the webviews.
172 */
173 private FrameLayout mBrowserFrameLayout;
Leon Scroggins81db3662009-06-04 17:45:11 -0400174
Leon Scrogginsd746a942010-05-19 13:21:44 -0400175 private boolean mXLargeScreenSize;
176
Grace Kloba22ac16e2009-10-07 18:00:23 -0700177 @Override
178 public void onCreate(Bundle icicle) {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700179 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800180 Log.v(LOGTAG, this + " onStart");
181 }
182 super.onCreate(icicle);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800183 // test the browser in OpenGL
184 // requestWindowFeature(Window.FEATURE_OPENGL);
185
Mike Reedd334bf52010-01-26 15:21:44 -0500186 // enable this to test the browser in 32bit
187 if (false) {
188 getWindow().setFormat(PixelFormat.RGBX_8888);
189 BitmapFactory.setDefaultConfig(Bitmap.Config.ARGB_8888);
190 }
191
Svetoslav Ganov2b345992010-05-06 06:13:54 -0700192 if (AccessibilityManager.getInstance(this).isEnabled()) {
193 setDefaultKeyMode(DEFAULT_KEYS_DISABLE);
194 } else {
195 setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
196 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800197
198 mResolver = getContentResolver();
199
Grace Kloba0923d692009-09-23 21:37:25 -0700200 // If this was a web search request, pass it on to the default web
201 // search provider and finish this activity.
202 if (handleWebSearchIntent(getIntent())) {
203 finish();
204 return;
205 }
206
The Android Open Source Project0c908882009-03-03 19:32:16 -0800207 mSecLockIcon = Resources.getSystem().getDrawable(
208 android.R.drawable.ic_secure);
209 mMixLockIcon = Resources.getSystem().getDrawable(
210 android.R.drawable.ic_partial_secure);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800211
Leon Scroggins81db3662009-06-04 17:45:11 -0400212 FrameLayout frameLayout = (FrameLayout) getWindow().getDecorView()
213 .findViewById(com.android.internal.R.id.content);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400214 mBrowserFrameLayout = (FrameLayout) LayoutInflater.from(this)
215 .inflate(R.layout.custom_screen, null);
216 mContentView = (FrameLayout) mBrowserFrameLayout.findViewById(
217 R.id.main_content);
218 mErrorConsoleContainer = (LinearLayout) mBrowserFrameLayout
219 .findViewById(R.id.error_console);
220 mCustomViewContainer = (FrameLayout) mBrowserFrameLayout
221 .findViewById(R.id.fullscreen_custom_content);
222 frameLayout.addView(mBrowserFrameLayout, COVER_SCREEN_PARAMS);
Leon Scrogginsd746a942010-05-19 13:21:44 -0400223 mXLargeScreenSize = (getResources().getConfiguration().screenLayout
224 & Configuration.SCREENLAYOUT_SIZE_MASK)
225 == Configuration.SCREENLAYOUT_SIZE_XLARGE;
226 if (mXLargeScreenSize) {
Leon Scroggins571b3762010-05-26 10:25:01 -0400227 mTitleBar = new TitleBarXLarge(this);
Leon Scrogginsd746a942010-05-19 13:21:44 -0400228 LinearLayout layout = (LinearLayout) mBrowserFrameLayout.
229 findViewById(R.id.vertical_layout);
230 layout.addView(mTitleBar, 0, new LinearLayout.LayoutParams(
231 ViewGroup.LayoutParams.MATCH_PARENT,
232 ViewGroup.LayoutParams.WRAP_CONTENT));
233 } else {
Leon Scroggins571b3762010-05-26 10:25:01 -0400234 mTitleBar = new TitleBar(this);
Leon Scrogginsd746a942010-05-19 13:21:44 -0400235 // mTitleBar will be always be shown in the fully loaded mode on
236 // phone
237 mTitleBar.setProgress(100);
238 // Fake title bar is not needed in xlarge layout
239 mFakeTitleBar = new TitleBar(this);
240 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800241
242 // Create the tab control and our initial tab
243 mTabControl = new TabControl(this);
244
245 // Open the icon database and retain all the bookmark urls for favicons
246 retainIconsOnStartup();
247
248 // Keep a settings instance handy.
249 mSettings = BrowserSettings.getInstance();
250 mSettings.setTabControl(mTabControl);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800251
252 PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
253 mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Browser");
254
Patrick Scott6adacc92010-03-05 08:24:51 -0500255 // Find out if the network is currently up.
256 ConnectivityManager cm = (ConnectivityManager) getSystemService(
257 Context.CONNECTIVITY_SERVICE);
258 NetworkInfo info = cm.getActiveNetworkInfo();
259 if (info != null) {
260 mIsNetworkUp = info.isAvailable();
261 }
262
Grace Klobaa34f6862009-07-31 16:28:17 -0700263 /* enables registration for changes in network status from
264 http stack */
265 mNetworkStateChangedFilter = new IntentFilter();
266 mNetworkStateChangedFilter.addAction(
267 ConnectivityManager.CONNECTIVITY_ACTION);
268 mNetworkStateIntentReceiver = new BroadcastReceiver() {
269 @Override
270 public void onReceive(Context context, Intent intent) {
271 if (intent.getAction().equals(
272 ConnectivityManager.CONNECTIVITY_ACTION)) {
Andrei Popescue4c98462010-02-19 15:44:13 +0000273
274 NetworkInfo info = intent.getParcelableExtra(
275 ConnectivityManager.EXTRA_NETWORK_INFO);
276 String typeName = info.getTypeName();
277 String subtypeName = info.getSubtypeName();
278 sendNetworkType(typeName.toLowerCase(),
279 (subtypeName != null ? subtypeName.toLowerCase() : ""));
280
281 onNetworkToggle(info.isAvailable());
Grace Klobaa34f6862009-07-31 16:28:17 -0700282 }
283 }
284 };
285
Grace Kloba615c6c92009-08-03 10:22:44 -0700286 IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
287 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
288 filter.addDataScheme("package");
289 mPackageInstallationReceiver = new BroadcastReceiver() {
290 @Override
291 public void onReceive(Context context, Intent intent) {
292 final String action = intent.getAction();
293 final String packageName = intent.getData()
294 .getSchemeSpecificPart();
295 final boolean replacing = intent.getBooleanExtra(
296 Intent.EXTRA_REPLACING, false);
297 if (Intent.ACTION_PACKAGE_REMOVED.equals(action) && replacing) {
298 // if it is replacing, refreshPlugins() when adding
299 return;
300 }
Andrei Popescu30995e72010-02-09 16:59:58 +0000301
302 if (sGoogleApps.contains(packageName)) {
303 BrowserActivity.this.packageChanged(packageName,
304 Intent.ACTION_PACKAGE_ADDED.equals(action));
305 }
306
Grace Kloba615c6c92009-08-03 10:22:44 -0700307 PackageManager pm = BrowserActivity.this.getPackageManager();
308 PackageInfo pkgInfo = null;
309 try {
310 pkgInfo = pm.getPackageInfo(packageName,
311 PackageManager.GET_PERMISSIONS);
312 } catch (PackageManager.NameNotFoundException e) {
313 return;
314 }
315 if (pkgInfo != null) {
316 String permissions[] = pkgInfo.requestedPermissions;
317 if (permissions == null) {
318 return;
319 }
320 boolean permissionOk = false;
321 for (String permit : permissions) {
322 if (PluginManager.PLUGIN_PERMISSION.equals(permit)) {
323 permissionOk = true;
324 break;
325 }
326 }
327 if (permissionOk) {
328 PluginManager.getInstance(BrowserActivity.this)
Grace Klobae56a0f22010-05-26 17:31:02 -0700329 .refreshPlugins(true);
Grace Kloba615c6c92009-08-03 10:22:44 -0700330 }
331 }
332 }
333 };
334 registerReceiver(mPackageInstallationReceiver, filter);
335
The Android Open Source Project0c908882009-03-03 19:32:16 -0800336 if (!mTabControl.restoreState(icicle)) {
337 // clear up the thumbnail directory if we can't restore the state as
338 // none of the files in the directory are referenced any more.
339 new ClearThumbnails().execute(
340 mTabControl.getThumbnailDir().listFiles());
Grace Klobaaab3f092009-07-30 12:29:51 -0700341 // there is no quit on Android. But if we can't restore the state,
342 // we can treat it as a new Browser, remove the old session cookies.
343 CookieManager.getInstance().removeSessionCookie();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800344 final Intent intent = getIntent();
345 final Bundle extra = intent.getExtras();
346 // Create an initial tab.
347 // If the intent is ACTION_VIEW and data is not null, the Browser is
348 // invoked to view the content by another application. In this case,
349 // the tab will be close when exit.
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700350 UrlData urlData = getUrlDataFromIntent(intent);
351
Leon Scroggins58d56c62010-01-28 15:12:40 -0500352 String action = intent.getAction();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700353 final Tab t = mTabControl.createNewTab(
Leon Scroggins58d56c62010-01-28 15:12:40 -0500354 (Intent.ACTION_VIEW.equals(action) &&
355 intent.getData() != null)
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -0500356 || RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS
357 .equals(action),
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700358 intent.getStringExtra(Browser.EXTRA_APPLICATION_ID), urlData.mUrl);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800359 mTabControl.setCurrentTab(t);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800360 attachTabToContentView(t);
361 WebView webView = t.getWebView();
362 if (extra != null) {
363 int scale = extra.getInt(Browser.INITIAL_ZOOM_LEVEL, 0);
364 if (scale > 0 && scale <= 1000) {
365 webView.setInitialScale(scale);
366 }
367 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800368
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700369 if (urlData.isEmpty()) {
Shimeng (Simon) Wang98d5fce2010-03-16 13:23:39 -0700370 loadUrl(webView, mSettings.getHomePage());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800371 } else {
Patrick Scott9d53da02010-02-19 10:19:01 -0500372 loadUrlDataIn(t, urlData);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800373 }
374 } else {
375 // TabControl.restoreState() will create a new tab even if
Leon Scroggins1f005d32009-08-10 17:36:42 -0400376 // restoring the state fails.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800377 attachTabToContentView(mTabControl.getCurrentTab());
378 }
Grace Kloba615c6c92009-08-03 10:22:44 -0700379
Feng Qianb3c02da2009-06-29 15:58:08 -0700380 // Read JavaScript flags if it exists.
381 String jsFlags = mSettings.getJsFlags();
382 if (jsFlags.trim().length() != 0) {
383 mTabControl.getCurrentWebView().setJsFlags(jsFlags);
384 }
Andrei Popescu30995e72010-02-09 16:59:58 +0000385 // Work out which packages are installed on the system.
386 getInstalledPackages();
Bjorn Bringerta7611812010-03-24 11:12:02 +0000387
388 // Start watching the default geolocation permissions
389 mSystemAllowGeolocationOrigins
390 = new SystemAllowGeolocationOrigins(getApplicationContext());
391 mSystemAllowGeolocationOrigins.start();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800392 }
393
Leon Scroggins58d56c62010-01-28 15:12:40 -0500394 /**
395 * Feed the previously stored results strings to the BrowserProvider so that
396 * the SearchDialog will show them instead of the standard searches.
397 * @param result String to show on the editable line of the SearchDialog.
398 */
399 /* package */ void showVoiceSearchResults(String result) {
400 ContentProviderClient client = mResolver.acquireContentProviderClient(
401 Browser.BOOKMARKS_URI);
402 ContentProvider prov = client.getLocalContentProvider();
403 BrowserProvider bp = (BrowserProvider) prov;
404 bp.setQueryResults(mTabControl.getCurrentTab().getVoiceSearchResults());
405 client.release();
406
Leon Scrogginsfbb3f152010-03-09 17:26:56 -0500407 Bundle bundle = createGoogleSearchSourceBundle(
408 GOOGLE_SEARCH_SOURCE_SEARCHKEY);
409 bundle.putBoolean(SearchManager.CONTEXT_IS_VOICE, true);
410 startSearch(result, false, bundle, false);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500411 }
412
The Android Open Source Project0c908882009-03-03 19:32:16 -0800413 @Override
414 protected void onNewIntent(Intent intent) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700415 Tab current = mTabControl.getCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800416 // When a tab is closed on exit, the current tab index is set to -1.
417 // Reset before proceed as Browser requires the current tab to be set.
418 if (current == null) {
419 // Try to reset the tab in case the index was incorrect.
420 current = mTabControl.getTab(0);
421 if (current == null) {
422 // No tabs at all so just ignore this intent.
423 return;
424 }
425 mTabControl.setCurrentTab(current);
426 attachTabToContentView(current);
427 resetTitleAndIcon(current.getWebView());
428 }
429 final String action = intent.getAction();
430 final int flags = intent.getFlags();
431 if (Intent.ACTION_MAIN.equals(action) ||
432 (flags & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
433 // just resume the browser
434 return;
435 }
Leon Scrogginsb8a844d2010-03-18 15:06:15 -0400436 // In case the SearchDialog is open.
437 ((SearchManager) getSystemService(Context.SEARCH_SERVICE))
438 .stopSearch();
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -0500439 boolean activateVoiceSearch = RecognizerResultsIntent
440 .ACTION_VOICE_SEARCH_RESULTS.equals(action);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800441 if (Intent.ACTION_VIEW.equals(action)
442 || Intent.ACTION_SEARCH.equals(action)
443 || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)
Leon Scroggins58d56c62010-01-28 15:12:40 -0500444 || Intent.ACTION_WEB_SEARCH.equals(action)
445 || activateVoiceSearch) {
Leon Scroggins3b18ce32010-02-08 17:35:59 -0500446 if (current.isInVoiceSearchMode()) {
447 String title = current.getVoiceDisplayTitle();
448 if (title != null && title.equals(intent.getStringExtra(
449 SearchManager.QUERY))) {
450 // The user submitted the same search as the last voice
451 // search, so do nothing.
452 return;
453 }
Leon Scroggins1fe13a52010-02-09 15:31:26 -0500454 if (Intent.ACTION_SEARCH.equals(action)
455 && current.voiceSearchSourceIsGoogle()) {
456 Intent logIntent = new Intent(
457 LoggingEvents.ACTION_LOG_EVENT);
458 logIntent.putExtra(LoggingEvents.EXTRA_EVENT,
459 LoggingEvents.VoiceSearch.QUERY_UPDATED);
460 logIntent.putExtra(
461 LoggingEvents.VoiceSearch.EXTRA_QUERY_UPDATED_VALUE,
462 intent.getDataString());
463 sendBroadcast(logIntent);
464 // Note, onPageStarted will revert the voice title bar
465 // When http://b/issue?id=2379215 is fixed, we should update
466 // the title bar here.
467 }
Leon Scroggins3b18ce32010-02-08 17:35:59 -0500468 }
Satish Sampath565505b2009-05-29 15:37:27 +0100469 // If this was a search request (e.g. search query directly typed into the address bar),
470 // pass it on to the default web search provider.
471 if (handleWebSearchIntent(intent)) {
472 return;
473 }
474
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700475 UrlData urlData = getUrlDataFromIntent(intent);
476 if (urlData.isEmpty()) {
477 urlData = new UrlData(mSettings.getHomePage());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800478 }
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700479
Grace Klobacc634032009-07-28 15:58:19 -0700480 final String appId = intent
481 .getStringExtra(Browser.EXTRA_APPLICATION_ID);
Leon Scroggins47208682010-04-07 17:59:48 -0400482 if ((Intent.ACTION_VIEW.equals(action)
483 // If a voice search has no appId, it means that it came
484 // from the browser. In that case, reuse the current tab.
485 || (activateVoiceSearch && appId != null))
Grace Klobacc634032009-07-28 15:58:19 -0700486 && !getPackageName().equals(appId)
487 && (flags & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
Grace Kloba22ac16e2009-10-07 18:00:23 -0700488 Tab appTab = mTabControl.getTabFromId(appId);
The Android Open Source Projectf59ec872009-03-13 13:04:24 -0700489 if (appTab != null) {
490 Log.i(LOGTAG, "Reusing tab for " + appId);
491 // Dismiss the subwindow if applicable.
492 dismissSubWindow(appTab);
493 // Since we might kill the WebView, remove it from the
494 // content view first.
495 removeTabFromContentView(appTab);
496 // Recreate the main WebView after destroying the old one.
497 // If the WebView has the same original url and is on that
498 // page, it can be reused.
499 boolean needsLoad =
Leon Scroggins6eac63e2010-03-15 18:19:14 -0400500 mTabControl.recreateWebView(appTab, urlData);
Ben Murdochbff2d602009-07-01 20:19:05 +0100501
The Android Open Source Projectf59ec872009-03-13 13:04:24 -0700502 if (current != appTab) {
Leon Scroggins1f005d32009-08-10 17:36:42 -0400503 switchToTab(mTabControl.getTabIndex(appTab));
504 if (needsLoad) {
Patrick Scott9d53da02010-02-19 10:19:01 -0500505 loadUrlDataIn(appTab, urlData);
Leon Scroggins1f005d32009-08-10 17:36:42 -0400506 }
The Android Open Source Projectf59ec872009-03-13 13:04:24 -0700507 } else {
Leon Scroggins1f005d32009-08-10 17:36:42 -0400508 // If the tab was the current tab, we have to attach
509 // it to the view system again.
510 attachTabToContentView(appTab);
511 if (needsLoad) {
Patrick Scott9d53da02010-02-19 10:19:01 -0500512 loadUrlDataIn(appTab, urlData);
The Android Open Source Projectf59ec872009-03-13 13:04:24 -0700513 }
514 }
515 return;
Patrick Scottcd115892009-07-16 09:42:58 -0400516 } else {
517 // No matching application tab, try to find a regular tab
518 // with a matching url.
519 appTab = mTabControl.findUnusedTabWithUrl(urlData.mUrl);
Leon Scroggins25515f82009-08-19 15:31:58 -0400520 if (appTab != null) {
521 if (current != appTab) {
522 switchToTab(mTabControl.getTabIndex(appTab));
523 }
524 // Otherwise, we are already viewing the correct tab.
Patrick Scottcd115892009-07-16 09:42:58 -0400525 } else {
526 // if FLAG_ACTIVITY_BROUGHT_TO_FRONT flag is on, the url
527 // will be opened in a new tab unless we have reached
528 // MAX_TABS. Then the url will be opened in the current
529 // tab. If a new tab is created, it will have "true" for
530 // exit on close.
Leon Scroggins1f005d32009-08-10 17:36:42 -0400531 openTabAndShow(urlData, true, appId);
Patrick Scottcd115892009-07-16 09:42:58 -0400532 }
The Android Open Source Projectf59ec872009-03-13 13:04:24 -0700533 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800534 } else {
Grace Kloba638d3f42009-11-23 10:35:04 -0800535 if (!urlData.isEmpty()
536 && urlData.mUrl.startsWith("about:debug")) {
537 if ("about:debug.dom".equals(urlData.mUrl)) {
538 current.getWebView().dumpDomTree(false);
539 } else if ("about:debug.dom.file".equals(urlData.mUrl)) {
540 current.getWebView().dumpDomTree(true);
541 } else if ("about:debug.render".equals(urlData.mUrl)) {
542 current.getWebView().dumpRenderTree(false);
543 } else if ("about:debug.render.file".equals(urlData.mUrl)) {
544 current.getWebView().dumpRenderTree(true);
545 } else if ("about:debug.display".equals(urlData.mUrl)) {
546 current.getWebView().dumpDisplayTree();
Mike Reed9b78e1d2010-01-13 14:40:52 -0800547 } else if (urlData.mUrl.startsWith("about:debug.drag")) {
548 int index = urlData.mUrl.codePointAt(16) - '0';
549 if (index <= 0 || index > 9) {
550 current.getWebView().setDragTracker(null);
551 } else {
552 current.getWebView().setDragTracker(new MeshTracker(index));
553 }
Grace Kloba638d3f42009-11-23 10:35:04 -0800554 } else {
555 mSettings.toggleDebugSettings();
556 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800557 return;
558 }
Leon Scroggins1f005d32009-08-10 17:36:42 -0400559 // Get rid of the subwindow if it exists
560 dismissSubWindow(current);
Leon Scroggins8588d152010-04-15 11:01:53 -0400561 // If the current Tab is being used as an application tab,
562 // remove the association, since the new Intent means that it is
563 // no longer associated with that application.
564 current.setAppId(null);
Patrick Scott9d53da02010-02-19 10:19:01 -0500565 loadUrlDataIn(current, urlData);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800566 }
567 }
568 }
569
Satish Sampath565505b2009-05-29 15:37:27 +0100570 private int parseUrlShortcut(String url) {
571 if (url == null) return SHORTCUT_INVALID;
572
573 // FIXME: quick search, need to be customized by setting
574 if (url.length() > 2 && url.charAt(1) == ' ') {
575 switch (url.charAt(0)) {
576 case 'g': return SHORTCUT_GOOGLE_SEARCH;
577 case 'w': return SHORTCUT_WIKIPEDIA_SEARCH;
578 case 'd': return SHORTCUT_DICTIONARY_SEARCH;
579 case 'l': return SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH;
580 }
581 }
582 return SHORTCUT_INVALID;
583 }
584
585 /**
586 * Launches the default web search activity with the query parameters if the given intent's data
587 * are identified as plain search terms and not URLs/shortcuts.
588 * @return true if the intent was handled and web search activity was launched, false if not.
589 */
590 private boolean handleWebSearchIntent(Intent intent) {
591 if (intent == null) return false;
592
593 String url = null;
594 final String action = intent.getAction();
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -0500595 if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS.equals(
596 action)) {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500597 return false;
598 }
Satish Sampath565505b2009-05-29 15:37:27 +0100599 if (Intent.ACTION_VIEW.equals(action)) {
Grace Kloba1e705052009-09-29 13:13:36 -0700600 Uri data = intent.getData();
601 if (data != null) url = data.toString();
Satish Sampath565505b2009-05-29 15:37:27 +0100602 } else if (Intent.ACTION_SEARCH.equals(action)
603 || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)
604 || Intent.ACTION_WEB_SEARCH.equals(action)) {
605 url = intent.getStringExtra(SearchManager.QUERY);
606 }
Bjorn Bringert04851702009-09-22 10:36:01 +0100607 return handleWebSearchRequest(url, intent.getBundleExtra(SearchManager.APP_DATA),
608 intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
Satish Sampath565505b2009-05-29 15:37:27 +0100609 }
610
611 /**
612 * Launches the default web search activity with the query parameters if the given url string
613 * was identified as plain search terms and not URL/shortcut.
614 * @return true if the request was handled and web search activity was launched, false if not.
615 */
Bjorn Bringert04851702009-09-22 10:36:01 +0100616 private boolean handleWebSearchRequest(String inUrl, Bundle appData, String extraData) {
Satish Sampath565505b2009-05-29 15:37:27 +0100617 if (inUrl == null) return false;
618
619 // In general, we shouldn't modify URL from Intent.
620 // But currently, we get the user-typed URL from search box as well.
621 String url = fixUrl(inUrl).trim();
622
623 // URLs and site specific search shortcuts are handled by the regular flow of control, so
624 // return early.
Dan Egnor5ee906c2009-11-18 12:11:49 -0800625 if (Patterns.WEB_URL.matcher(url).matches()
Satish Sampathbc5b9f32009-06-04 18:21:40 +0100626 || ACCEPTED_URI_SCHEMA.matcher(url).matches()
Satish Sampath565505b2009-05-29 15:37:27 +0100627 || parseUrlShortcut(url) != SHORTCUT_INVALID) {
628 return false;
629 }
630
Leon Scroggins8d06e362010-03-24 14:45:57 -0400631 final ContentResolver cr = mResolver;
632 final String newUrl = url;
633 new AsyncTask<Void, Void, Void>() {
634 protected Void doInBackground(Void... unused) {
635 Browser.updateVisitedHistory(cr, newUrl, false);
636 Browser.addSearchUrl(cr, newUrl);
637 return null;
638 }
639 }.execute();
Satish Sampath565505b2009-05-29 15:37:27 +0100640
641 Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
642 intent.addCategory(Intent.CATEGORY_DEFAULT);
643 intent.putExtra(SearchManager.QUERY, url);
Satish Sampath15e9f2d2009-06-23 22:29:49 +0100644 if (appData != null) {
645 intent.putExtra(SearchManager.APP_DATA, appData);
646 }
Bjorn Bringert04851702009-09-22 10:36:01 +0100647 if (extraData != null) {
648 intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
649 }
Grace Klobacc634032009-07-28 15:58:19 -0700650 intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
Satish Sampath565505b2009-05-29 15:37:27 +0100651 startActivity(intent);
652
653 return true;
654 }
655
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700656 private UrlData getUrlDataFromIntent(Intent intent) {
Leon Scroggins58d56c62010-01-28 15:12:40 -0500657 String url = "";
Grace Kloba068e48b2010-01-26 18:11:27 -0800658 Map<String, String> headers = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800659 if (intent != null) {
660 final String action = intent.getAction();
661 if (Intent.ACTION_VIEW.equals(action)) {
662 url = smartUrlFilter(intent.getData());
663 if (url != null && url.startsWith("content:")) {
664 /* Append mimetype so webview knows how to display */
665 String mimeType = intent.resolveType(getContentResolver());
666 if (mimeType != null) {
667 url += "?" + mimeType;
668 }
669 }
Grace Kloba068e48b2010-01-26 18:11:27 -0800670 if (url != null && url.startsWith("http")) {
Grace Kloba00f54c52010-01-27 14:53:51 -0800671 final Bundle pairs = intent
672 .getBundleExtra(Browser.EXTRA_HEADERS);
Grace Kloba2d508ed2010-01-28 11:39:15 -0800673 if (pairs != null && !pairs.isEmpty()) {
Grace Kloba00f54c52010-01-27 14:53:51 -0800674 Iterator<String> iter = pairs.keySet().iterator();
Grace Kloba068e48b2010-01-26 18:11:27 -0800675 headers = new HashMap<String, String>();
Grace Kloba00f54c52010-01-27 14:53:51 -0800676 while (iter.hasNext()) {
677 String key = iter.next();
678 headers.put(key, pairs.getString(key));
Grace Kloba068e48b2010-01-26 18:11:27 -0800679 }
680 }
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -0700681 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800682 } else if (Intent.ACTION_SEARCH.equals(action)
683 || MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)
684 || Intent.ACTION_WEB_SEARCH.equals(action)) {
685 url = intent.getStringExtra(SearchManager.QUERY);
686 if (url != null) {
687 mLastEnteredUrl = url;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800688 // In general, we shouldn't modify URL from Intent.
689 // But currently, we get the user-typed URL from search box as well.
690 url = fixUrl(url);
691 url = smartUrlFilter(url);
Leon Scroggins8d06e362010-03-24 14:45:57 -0400692 final ContentResolver cr = mResolver;
693 final String newUrl = url;
694 new AsyncTask<Void, Void, Void>() {
695 protected Void doInBackground(Void... unused) {
696 Browser.updateVisitedHistory(cr, newUrl, false);
697 return null;
698 }
699 }.execute();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800700 String searchSource = "&source=android-" + GOOGLE_SEARCH_SOURCE_SUGGEST + "&";
701 if (url.contains(searchSource)) {
702 String source = null;
703 final Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
704 if (appData != null) {
Bjorn Bringert10d1cca2010-02-10 14:22:12 +0000705 source = appData.getString(Search.SOURCE);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800706 }
707 if (TextUtils.isEmpty(source)) {
708 source = GOOGLE_SEARCH_SOURCE_UNKNOWN;
709 }
710 url = url.replace(searchSource, "&source=android-"+source+"&");
711 }
712 }
713 }
714 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500715 return new UrlData(url, headers, intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800716 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500717 /* package */ void showVoiceTitleBar(String title) {
718 mTitleBar.setInVoiceMode(true);
Leon Scroggins58d56c62010-01-28 15:12:40 -0500719 mTitleBar.setDisplayTitle(title);
Leon Scrogginsd746a942010-05-19 13:21:44 -0400720
721 if (!mXLargeScreenSize) {
722 mFakeTitleBar.setInVoiceMode(true);
723 mFakeTitleBar.setDisplayTitle(title);
724 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500725 }
726 /* package */ void revertVoiceTitleBar() {
727 mTitleBar.setInVoiceMode(false);
Leon Scroggins003a5dd2010-03-10 12:13:14 -0500728 mTitleBar.setDisplayTitle(mUrl);
Leon Scrogginsd746a942010-05-19 13:21:44 -0400729
730 if (!mXLargeScreenSize) {
731 mFakeTitleBar.setInVoiceMode(false);
732 mFakeTitleBar.setDisplayTitle(mUrl);
733 }
Leon Scroggins58d56c62010-01-28 15:12:40 -0500734 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800735 /* package */ static String fixUrl(String inUrl) {
Cary Clark652ff872009-09-10 13:34:44 -0400736 // FIXME: Converting the url to lower case
737 // duplicates functionality in smartUrlFilter().
738 // However, changing all current callers of fixUrl to
739 // call smartUrlFilter in addition may have unwanted
740 // consequences, and is deferred for now.
741 int colon = inUrl.indexOf(':');
742 boolean allLower = true;
743 for (int index = 0; index < colon; index++) {
744 char ch = inUrl.charAt(index);
745 if (!Character.isLetter(ch)) {
746 break;
747 }
748 allLower &= Character.isLowerCase(ch);
749 if (index == colon - 1 && !allLower) {
750 inUrl = inUrl.substring(0, colon).toLowerCase()
751 + inUrl.substring(colon);
752 }
753 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800754 if (inUrl.startsWith("http://") || inUrl.startsWith("https://"))
755 return inUrl;
756 if (inUrl.startsWith("http:") ||
757 inUrl.startsWith("https:")) {
758 if (inUrl.startsWith("http:/") || inUrl.startsWith("https:/")) {
759 inUrl = inUrl.replaceFirst("/", "//");
760 } else inUrl = inUrl.replaceFirst(":", "://");
761 }
762 return inUrl;
763 }
764
Grace Kloba22ac16e2009-10-07 18:00:23 -0700765 @Override
766 protected void onResume() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800767 super.onResume();
Dave Bort31a6d1c2009-04-13 15:56:49 -0700768 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800769 Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this);
770 }
771
772 if (!mActivityInPause) {
773 Log.e(LOGTAG, "BrowserActivity is already resumed.");
774 return;
775 }
776
Mike Reed7bfa63b2009-05-28 11:08:32 -0400777 mTabControl.resumeCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800778 mActivityInPause = false;
Mike Reed7bfa63b2009-05-28 11:08:32 -0400779 resumeWebViewTimers();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800780
781 if (mWakeLock.isHeld()) {
782 mHandler.removeMessages(RELEASE_WAKELOCK);
783 mWakeLock.release();
784 }
785
The Android Open Source Project0c908882009-03-03 19:32:16 -0800786 registerReceiver(mNetworkStateIntentReceiver,
787 mNetworkStateChangedFilter);
788 WebView.enablePlatformNotifications();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800789 }
790
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400791 /**
792 * Since the actual title bar is embedded in the WebView, and removing it
Leon Scrogginsfe87bd32009-10-06 10:10:00 -0400793 * would change its appearance, use a different TitleBar to show overlayed
794 * at the top of the screen, when the menu is open or the page is loading.
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400795 */
796 private TitleBar mFakeTitleBar;
797
798 /**
799 * Keeps track of whether the options menu is open. This is important in
800 * determining whether to show or hide the title bar overlay.
801 */
802 private boolean mOptionsMenuOpen;
803
804 /**
805 * Only meaningful when mOptionsMenuOpen is true. This variable keeps track
806 * of whether the configuration has changed. The first onMenuOpened call
807 * after a configuration change is simply a reopening of the same menu
808 * (i.e. mIconView did not change).
809 */
810 private boolean mConfigChanged;
811
812 /**
813 * Whether or not the options menu is in its smaller, icon menu form. When
814 * true, we want the title bar overlay to be up. When false, we do not.
815 * Only meaningful if mOptionsMenuOpen is true.
816 */
817 private boolean mIconView;
818
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400819 @Override
820 public boolean onMenuOpened(int featureId, Menu menu) {
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400821 if (Window.FEATURE_OPTIONS_PANEL == featureId) {
822 if (mOptionsMenuOpen) {
823 if (mConfigChanged) {
824 // We do not need to make any changes to the state of the
825 // title bar, since the only thing that happened was a
826 // change in orientation
827 mConfigChanged = false;
828 } else {
829 if (mIconView) {
830 // Switching the menu to expanded view, so hide the
831 // title bar.
832 hideFakeTitleBar();
833 mIconView = false;
834 } else {
835 // Switching the menu back to icon view, so show the
836 // title bar once again.
837 showFakeTitleBar();
838 mIconView = true;
839 }
840 }
841 } else {
842 // The options menu is closed, so open it, and show the title
843 showFakeTitleBar();
844 mOptionsMenuOpen = true;
845 mConfigChanged = false;
846 mIconView = true;
847 }
848 }
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400849 return true;
850 }
851
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400852 private void showFakeTitleBar() {
Leon Scrogginsd746a942010-05-19 13:21:44 -0400853 if (mXLargeScreenSize) return;
Leon Scrogginsfe87bd32009-10-06 10:10:00 -0400854 if (mFakeTitleBar.getParent() == null && mActiveTabsPage == null
Grace Kloba847c25b2010-03-30 16:00:26 -0700855 && !mActivityInPause) {
856 WebView mainView = mTabControl.getCurrentWebView();
857 // if there is no current WebView, don't show the faked title bar;
Grace Kloba65190702010-04-02 23:37:26 -0700858 if (mainView == null) {
Cary Clarka0464552009-09-29 13:00:45 -0400859 return;
860 }
Leon Scroggins79e36d92010-04-29 16:01:46 +0100861 // Do not need to check for null, since the current tab will have
862 // at least a main WebView, or we would have returned above.
Cary Clark01cfcdd2010-06-04 16:36:45 -0400863 if (dialogIsUp()) {
Leon Scroggins79e36d92010-04-29 16:01:46 +0100864 // Do not show the fake title bar, which would cover up the
Cary Clark01cfcdd2010-06-04 16:36:45 -0400865 // find or select dialog.
Leon Scroggins79e36d92010-04-29 16:01:46 +0100866 return;
867 }
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400868
869 WindowManager manager
870 = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
871
872 // Add the title bar to the window manager so it can receive touches
873 // while the menu is up
874 WindowManager.LayoutParams params
875 = new WindowManager.LayoutParams(
Romain Guy15b8ec62010-01-08 15:06:43 -0800876 ViewGroup.LayoutParams.MATCH_PARENT,
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400877 ViewGroup.LayoutParams.WRAP_CONTENT,
Grace Kloba847c25b2010-03-30 16:00:26 -0700878 WindowManager.LayoutParams.TYPE_APPLICATION,
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400879 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
Leon Scroggins68549862009-09-21 16:02:01 -0400880 PixelFormat.TRANSLUCENT);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400881 params.gravity = Gravity.TOP;
Grace Kloba847c25b2010-03-30 16:00:26 -0700882 boolean atTop = mainView.getScrollY() == 0;
Leon Scroggins83932c72009-09-30 11:55:54 -0400883 params.windowAnimations = atTop ? 0 : R.style.TitleBar;
Grace Kloba13f9ace2010-03-18 21:44:14 -0700884 manager.addView(mFakeTitleBar, params);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400885 }
886 }
887
888 @Override
889 public void onOptionsMenuClosed(Menu menu) {
890 mOptionsMenuOpen = false;
Leon Scrogginsa27ff192009-09-14 12:58:04 -0400891 if (!mInLoad) {
892 hideFakeTitleBar();
893 } else if (!mIconView) {
894 // The page is currently loading, and we are in expanded mode, so
895 // we were not showing the menu. Show it once again. It will be
896 // removed when the page finishes.
897 showFakeTitleBar();
898 }
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400899 }
Grace Kloba22ac16e2009-10-07 18:00:23 -0700900
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400901 private void hideFakeTitleBar() {
Leon Scrogginsd746a942010-05-19 13:21:44 -0400902 if (mXLargeScreenSize || mFakeTitleBar.getParent() == null) return;
Leon Scroggins20329572009-09-23 17:42:41 -0400903 WindowManager.LayoutParams params = (WindowManager.LayoutParams)
Grace Kloba13f9ace2010-03-18 21:44:14 -0700904 mFakeTitleBar.getLayoutParams();
Leon Scroggins20329572009-09-23 17:42:41 -0400905 WebView mainView = mTabControl.getCurrentWebView();
906 // Although we decided whether or not to animate based on the current
907 // scroll position, the scroll position may have changed since the
908 // fake title bar was displayed. Make sure it has the appropriate
909 // animation/lack thereof before removing.
910 params.windowAnimations = mainView != null && mainView.getScrollY() == 0
Leon Scroggins83932c72009-09-30 11:55:54 -0400911 ? 0 : R.style.TitleBar;
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400912 WindowManager manager
913 = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Grace Kloba13f9ace2010-03-18 21:44:14 -0700914 manager.updateViewLayout(mFakeTitleBar, params);
915 manager.removeView(mFakeTitleBar);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400916 }
917
The Android Open Source Project0c908882009-03-03 19:32:16 -0800918 /**
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400919 * Special method for the fake title bar to call when displaying its context
920 * menu, since it is in its own Window, and its parent does not show a
921 * context menu.
922 */
923 /* package */ void showTitleBarContextMenu() {
Cary Clark65f4a3c2009-09-28 17:05:06 -0400924 if (null == mTitleBar.getParent()) {
925 return;
926 }
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400927 openContextMenu(mTitleBar);
928 }
929
Leon Scrogginsb2b19f52009-10-09 16:10:00 -0400930 @Override
931 public void onContextMenuClosed(Menu menu) {
932 super.onContextMenuClosed(menu);
933 if (mInLoad) {
934 showFakeTitleBar();
935 }
936 }
937
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400938 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -0800939 * onSaveInstanceState(Bundle map)
940 * onSaveInstanceState is called right before onStop(). The map contains
941 * the saved state.
942 */
Grace Kloba22ac16e2009-10-07 18:00:23 -0700943 @Override
944 protected void onSaveInstanceState(Bundle outState) {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700945 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800946 Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this);
947 }
948 // the default implementation requires each view to have an id. As the
949 // browser handles the state itself and it doesn't use id for the views,
950 // don't call the default implementation. Otherwise it will trigger the
951 // warning like this, "couldn't save which view has focus because the
952 // focused view XXX has no id".
953
954 // Save all the tabs
955 mTabControl.saveState(outState);
956 }
957
Grace Kloba22ac16e2009-10-07 18:00:23 -0700958 @Override
959 protected void onPause() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800960 super.onPause();
961
962 if (mActivityInPause) {
963 Log.e(LOGTAG, "BrowserActivity is already paused.");
964 return;
965 }
966
Mike Reed7bfa63b2009-05-28 11:08:32 -0400967 mTabControl.pauseCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800968 mActivityInPause = true;
Mike Reed7bfa63b2009-05-28 11:08:32 -0400969 if (mTabControl.getCurrentIndex() >= 0 && !pauseWebViewTimers()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800970 mWakeLock.acquire();
971 mHandler.sendMessageDelayed(mHandler
972 .obtainMessage(RELEASE_WAKELOCK), WAKELOCK_TIMEOUT);
973 }
974
Leon Scrogginsa2ab6a72009-09-11 11:49:52 -0400975 // FIXME: This removes the active tabs page and resets the menu to
976 // MAIN_MENU. A better solution might be to do this work in onNewIntent
977 // but then we would need to save it in onSaveInstanceState and restore
978 // it in onCreate/onRestoreInstanceState
979 if (mActiveTabsPage != null) {
980 removeActiveTabPage(true);
981 }
982
The Android Open Source Project0c908882009-03-03 19:32:16 -0800983 cancelStopToast();
984
985 // unregister network state listener
986 unregisterReceiver(mNetworkStateIntentReceiver);
987 WebView.disablePlatformNotifications();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800988 }
989
Grace Kloba22ac16e2009-10-07 18:00:23 -0700990 @Override
991 protected void onDestroy() {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700992 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800993 Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this);
994 }
995 super.onDestroy();
Grace Kloba0923d692009-09-23 21:37:25 -0700996
Leon Scroggins8d5fa432009-10-02 15:55:59 -0400997 if (mUploadMessage != null) {
998 mUploadMessage.onReceiveValue(null);
999 mUploadMessage = null;
1000 }
1001
Grace Kloba0923d692009-09-23 21:37:25 -07001002 if (mTabControl == null) return;
1003
Grace Kloba1fc98a32009-10-21 13:23:08 -07001004 // Remove the fake title bar if it is there
1005 hideFakeTitleBar();
1006
The Android Open Source Project0c908882009-03-03 19:32:16 -08001007 // Remove the current tab and sub window
Grace Kloba22ac16e2009-10-07 18:00:23 -07001008 Tab t = mTabControl.getCurrentTab();
Patrick Scottfb5e77f2009-04-08 19:17:37 -07001009 if (t != null) {
1010 dismissSubWindow(t);
1011 removeTabFromContentView(t);
1012 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001013 // Destroy all the tabs
1014 mTabControl.destroy();
1015 WebIconDatabase.getInstance().close();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001016
Grace Klobab4da0ad2009-05-14 14:45:40 -07001017 unregisterReceiver(mPackageInstallationReceiver);
Bjorn Bringerta7611812010-03-24 11:12:02 +00001018
1019 // Stop watching the default geolocation permissions
1020 mSystemAllowGeolocationOrigins.stop();
1021 mSystemAllowGeolocationOrigins = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001022 }
1023
1024 @Override
1025 public void onConfigurationChanged(Configuration newConfig) {
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -04001026 mConfigChanged = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001027 super.onConfigurationChanged(newConfig);
1028
1029 if (mPageInfoDialog != null) {
1030 mPageInfoDialog.dismiss();
1031 showPageInfo(
1032 mPageInfoView,
Leon Scrogginsc7b92f82010-01-11 18:17:31 -05001033 mPageInfoFromShowSSLCertificateOnError);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001034 }
1035 if (mSSLCertificateDialog != null) {
1036 mSSLCertificateDialog.dismiss();
1037 showSSLCertificate(
1038 mSSLCertificateView);
1039 }
1040 if (mSSLCertificateOnErrorDialog != null) {
1041 mSSLCertificateOnErrorDialog.dismiss();
1042 showSSLCertificateOnError(
1043 mSSLCertificateOnErrorView,
1044 mSSLCertificateOnErrorHandler,
1045 mSSLCertificateOnErrorError);
1046 }
1047 if (mHttpAuthenticationDialog != null) {
1048 String title = ((TextView) mHttpAuthenticationDialog
1049 .findViewById(com.android.internal.R.id.alertTitle)).getText()
1050 .toString();
1051 String name = ((TextView) mHttpAuthenticationDialog
1052 .findViewById(R.id.username_edit)).getText().toString();
1053 String password = ((TextView) mHttpAuthenticationDialog
1054 .findViewById(R.id.password_edit)).getText().toString();
1055 int focusId = mHttpAuthenticationDialog.getCurrentFocus()
1056 .getId();
1057 mHttpAuthenticationDialog.dismiss();
1058 showHttpAuthentication(mHttpAuthHandler, null, null, title,
1059 name, password, focusId);
1060 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001061 }
1062
Grace Kloba22ac16e2009-10-07 18:00:23 -07001063 @Override
1064 public void onLowMemory() {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001065 super.onLowMemory();
1066 mTabControl.freeMemory();
1067 }
1068
Cary Clarkff4d92c2010-03-25 11:17:03 -04001069 private void resumeWebViewTimers() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001070 Tab tab = mTabControl.getCurrentTab();
Cary Clarkff4d92c2010-03-25 11:17:03 -04001071 if (tab == null) return; // monkey can trigger this
Grace Kloba22ac16e2009-10-07 18:00:23 -07001072 boolean inLoad = tab.inLoad();
1073 if ((!mActivityInPause && !inLoad) || (mActivityInPause && inLoad)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001074 CookieSyncManager.getInstance().startSync();
Grace Kloba22ac16e2009-10-07 18:00:23 -07001075 WebView w = tab.getWebView();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001076 if (w != null) {
1077 w.resumeTimers();
1078 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001079 }
1080 }
1081
Mike Reed7bfa63b2009-05-28 11:08:32 -04001082 private boolean pauseWebViewTimers() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001083 Tab tab = mTabControl.getCurrentTab();
1084 boolean inLoad = tab.inLoad();
1085 if (mActivityInPause && !inLoad) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001086 CookieSyncManager.getInstance().stopSync();
1087 WebView w = mTabControl.getCurrentWebView();
1088 if (w != null) {
1089 w.pauseTimers();
1090 }
1091 return true;
1092 } else {
1093 return false;
1094 }
1095 }
1096
The Android Open Source Project0c908882009-03-03 19:32:16 -08001097 // Open the icon database and retain all the icons for visited sites.
1098 private void retainIconsOnStartup() {
1099 final WebIconDatabase db = WebIconDatabase.getInstance();
1100 db.open(getDir("icons", 0).getPath());
Leon Scroggins2c0f6112010-03-12 18:09:39 -05001101 Cursor c = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001102 try {
Leon Scroggins2c0f6112010-03-12 18:09:39 -05001103 c = Browser.getAllBookmarks(mResolver);
1104 if (c.moveToFirst()) {
1105 int urlIndex = c.getColumnIndex(Browser.BookmarkColumns.URL);
1106 do {
1107 String url = c.getString(urlIndex);
1108 db.retainIconForPageUrl(url);
1109 } while (c.moveToNext());
The Android Open Source Project0c908882009-03-03 19:32:16 -08001110 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001111 } catch (IllegalStateException e) {
1112 Log.e(LOGTAG, "retainIconsOnStartup", e);
Leon Scroggins2c0f6112010-03-12 18:09:39 -05001113 } finally {
1114 if (c!= null) c.close();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001115 }
1116 }
1117
1118 // Helper method for getting the top window.
1119 WebView getTopWindow() {
1120 return mTabControl.getCurrentTopWebView();
1121 }
1122
Grace Kloba22ac16e2009-10-07 18:00:23 -07001123 TabControl getTabControl() {
1124 return mTabControl;
1125 }
1126
The Android Open Source Project0c908882009-03-03 19:32:16 -08001127 @Override
1128 public boolean onCreateOptionsMenu(Menu menu) {
1129 super.onCreateOptionsMenu(menu);
1130
1131 MenuInflater inflater = getMenuInflater();
1132 inflater.inflate(R.menu.browser, menu);
1133 mMenu = menu;
1134 updateInLoadMenuItems();
1135 return true;
1136 }
1137
1138 /**
1139 * As the menu can be open when loading state changes
1140 * we must manually update the state of the stop/reload menu
1141 * item
1142 */
1143 private void updateInLoadMenuItems() {
1144 if (mMenu == null) {
1145 return;
1146 }
1147 MenuItem src = mInLoad ?
1148 mMenu.findItem(R.id.stop_menu_id):
1149 mMenu.findItem(R.id.reload_menu_id);
1150 MenuItem dest = mMenu.findItem(R.id.stop_reload_menu_id);
1151 dest.setIcon(src.getIcon());
1152 dest.setTitle(src.getTitle());
1153 }
1154
1155 @Override
1156 public boolean onContextItemSelected(MenuItem item) {
1157 // chording is not an issue with context menus, but we use the same
1158 // options selector, so set mCanChord to true so we can access them.
1159 mCanChord = true;
1160 int id = item.getItemId();
Leon Scroggins96afcb12009-12-10 12:35:56 -05001161 boolean result = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001162 switch (id) {
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001163 // For the context menu from the title bar
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001164 case R.id.title_bar_copy_page_url:
Leon Scroggins96afcb12009-12-10 12:35:56 -05001165 Tab currentTab = mTabControl.getCurrentTab();
1166 if (null == currentTab) {
1167 result = false;
1168 break;
1169 }
1170 WebView mainView = currentTab.getWebView();
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001171 if (null == mainView) {
Leon Scroggins96afcb12009-12-10 12:35:56 -05001172 result = false;
1173 break;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001174 }
Leon Scroggins96afcb12009-12-10 12:35:56 -05001175 copy(mainView.getUrl());
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001176 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001177 // -- Browser context menu
1178 case R.id.open_context_menu_id:
The Android Open Source Project0c908882009-03-03 19:32:16 -08001179 case R.id.bookmark_context_menu_id:
1180 case R.id.save_link_context_menu_id:
1181 case R.id.share_link_context_menu_id:
1182 case R.id.copy_link_context_menu_id:
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001183 final WebView webView = getTopWindow();
1184 if (null == webView) {
Leon Scroggins96afcb12009-12-10 12:35:56 -05001185 result = false;
1186 break;
Leon Scrogginsc6fa1102009-09-21 10:40:01 -04001187 }
1188 final HashMap hrefMap = new HashMap();
1189 hrefMap.put("webview", webView);
1190 final Message msg = mHandler.obtainMessage(
1191 FOCUS_NODE_HREF, id, 0, hrefMap);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001192 webView.requestFocusNodeHref(msg);
1193 break;
1194
1195 default:
1196 // For other context menus
Leon Scroggins96afcb12009-12-10 12:35:56 -05001197 result = onOptionsItemSelected(item);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001198 }
1199 mCanChord = false;
Leon Scroggins96afcb12009-12-10 12:35:56 -05001200 return result;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001201 }
1202
1203 private Bundle createGoogleSearchSourceBundle(String source) {
1204 Bundle bundle = new Bundle();
Bjorn Bringert10d1cca2010-02-10 14:22:12 +00001205 bundle.putString(Search.SOURCE, source);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001206 return bundle;
1207 }
1208
Leon Scroggins8ad29922010-02-16 12:33:55 -05001209 /* package */ void editUrl() {
Leon Scroggins68579392009-09-15 15:31:54 -04001210 if (mOptionsMenuOpen) closeOptionsMenu();
Leon Scroggins5bbe9802009-07-31 13:10:55 -04001211 String url = (getTopWindow() == null) ? null : getTopWindow().getUrl();
Grace Kloba83f47342009-07-20 10:44:31 -07001212 startSearch(mSettings.getHomePage().equals(url) ? null : url, true,
Leon Scroggins8ad29922010-02-16 12:33:55 -05001213 null, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001214 }
1215
Leon Scroggins8ad29922010-02-16 12:33:55 -05001216 /**
1217 * Overriding this to insert a local information bundle
1218 */
The Android Open Source Project0c908882009-03-03 19:32:16 -08001219 @Override
1220 public void startSearch(String initialQuery, boolean selectInitialQuery,
1221 Bundle appSearchData, boolean globalSearch) {
1222 if (appSearchData == null) {
1223 appSearchData = createGoogleSearchSourceBundle(GOOGLE_SEARCH_SOURCE_TYPE);
1224 }
1225 super.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
1226 }
1227
Leon Scroggins1f005d32009-08-10 17:36:42 -04001228 /**
1229 * Switch tabs. Called by the TitleBarSet when sliding the title bar
1230 * results in changing tabs.
Leon Scroggins160a7e72009-08-14 18:28:01 -04001231 * @param index Index of the tab to change to, as defined by
1232 * mTabControl.getTabIndex(Tab t).
1233 * @return boolean True if we successfully switched to a different tab. If
1234 * the indexth tab is null, or if that tab is the same as
1235 * the current one, return false.
Leon Scroggins1f005d32009-08-10 17:36:42 -04001236 */
Leon Scroggins160a7e72009-08-14 18:28:01 -04001237 /* package */ boolean switchToTab(int index) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001238 Tab tab = mTabControl.getTab(index);
1239 Tab currentTab = mTabControl.getCurrentTab();
Leon Scroggins1f005d32009-08-10 17:36:42 -04001240 if (tab == null || tab == currentTab) {
Leon Scroggins160a7e72009-08-14 18:28:01 -04001241 return false;
Leon Scroggins1f005d32009-08-10 17:36:42 -04001242 }
1243 if (currentTab != null) {
1244 // currentTab may be null if it was just removed. In that case,
1245 // we do not need to remove it
1246 removeTabFromContentView(currentTab);
1247 }
Leon Scroggins1f005d32009-08-10 17:36:42 -04001248 mTabControl.setCurrentTab(tab);
1249 attachTabToContentView(tab);
Grace Klobaeb6eef42009-09-15 17:56:32 -07001250 resetTitleIconAndProgress();
1251 updateLockIconToLatest();
Leon Scroggins160a7e72009-08-14 18:28:01 -04001252 return true;
Leon Scroggins1f005d32009-08-10 17:36:42 -04001253 }
1254
Grace Kloba22ac16e2009-10-07 18:00:23 -07001255 /* package */ Tab openTabToHomePage() {
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001256 return openTabAndShow(mSettings.getHomePage(), false, null);
1257 }
1258
Leon Scroggins1f005d32009-08-10 17:36:42 -04001259 /* package */ void closeCurrentWindow() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001260 final Tab current = mTabControl.getCurrentTab();
Leon Scroggins160a7e72009-08-14 18:28:01 -04001261 if (mTabControl.getTabCount() == 1) {
Leon Scroggins30444232009-09-04 18:36:20 -04001262 // This is the last tab. Open a new one, with the home
1263 // page and close the current one.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001264 openTabToHomePage();
Leon Scroggins160a7e72009-08-14 18:28:01 -04001265 closeTab(current);
Leon Scroggins160a7e72009-08-14 18:28:01 -04001266 return;
1267 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07001268 final Tab parent = current.getParentTab();
Leon Scroggins1f005d32009-08-10 17:36:42 -04001269 int indexToShow = -1;
1270 if (parent != null) {
1271 indexToShow = mTabControl.getTabIndex(parent);
1272 } else {
Leon Scroggins160a7e72009-08-14 18:28:01 -04001273 final int currentIndex = mTabControl.getCurrentIndex();
1274 // Try to move to the tab to the right
1275 indexToShow = currentIndex + 1;
1276 if (indexToShow > mTabControl.getTabCount() - 1) {
1277 // Try to move to the tab to the left
1278 indexToShow = currentIndex - 1;
Leon Scroggins1f005d32009-08-10 17:36:42 -04001279 }
1280 }
Leon Scroggins160a7e72009-08-14 18:28:01 -04001281 if (switchToTab(indexToShow)) {
1282 // Close window
1283 closeTab(current);
1284 }
Leon Scroggins1f005d32009-08-10 17:36:42 -04001285 }
1286
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001287 private ActiveTabsPage mActiveTabsPage;
1288
1289 /**
1290 * Remove the active tabs page.
1291 * @param needToAttach If true, the active tabs page did not attach a tab
1292 * to the content view, so we need to do that here.
1293 */
1294 /* package */ void removeActiveTabPage(boolean needToAttach) {
1295 mContentView.removeView(mActiveTabsPage);
Leon Scrogginsd746a942010-05-19 13:21:44 -04001296 mTitleBar.setVisibility(View.VISIBLE);
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001297 mActiveTabsPage = null;
1298 mMenuState = R.id.MAIN_MENU;
1299 if (needToAttach) {
1300 attachTabToContentView(mTabControl.getCurrentTab());
1301 }
1302 getTopWindow().requestFocus();
1303 }
1304
Cary Clark01cfcdd2010-06-04 16:36:45 -04001305 private WebView showDialog(WebDialog dialog) {
1306 // Need to do something special for Tablet
1307 Tab tab = mTabControl.getCurrentTab();
1308 if (tab.getSubWebView() == null) {
1309 // If the find or select is being performed on the main webview,
1310 // remove the embedded title bar.
1311 WebView mainView = tab.getWebView();
1312 if (mainView != null) {
1313 mainView.setEmbeddedTitleBar(null);
1314 }
1315 }
1316 hideFakeTitleBar();
1317 mMenuState = EMPTY_MENU;
1318 return tab.showDialog(dialog);
1319 }
1320
The Android Open Source Project0c908882009-03-03 19:32:16 -08001321 @Override
1322 public boolean onOptionsItemSelected(MenuItem item) {
1323 if (!mCanChord) {
1324 // The user has already fired a shortcut with this hold down of the
1325 // menu key.
1326 return false;
1327 }
Leon Scroggins1f005d32009-08-10 17:36:42 -04001328 if (null == getTopWindow()) {
Leon Scroggins0d7ae0e2009-06-05 11:04:45 -04001329 return false;
1330 }
Grace Kloba6ee9c492009-07-13 10:04:34 -07001331 if (mMenuIsDown) {
1332 // The shortcut action consumes the MENU. Even if it is still down,
1333 // it won't trigger the next shortcut action. In the case of the
1334 // shortcut action triggering a new activity, like Bookmarks, we
1335 // won't get onKeyUp for MENU. So it is important to reset it here.
1336 mMenuIsDown = false;
1337 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001338 switch (item.getItemId()) {
1339 // -- Main menu
Leon Scrogginsa81a7642009-08-31 17:05:41 -04001340 case R.id.new_tab_menu_id:
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001341 openTabToHomePage();
Leon Scrogginsa81a7642009-08-31 17:05:41 -04001342 break;
1343
Leon Scroggins64b80f32009-08-07 12:03:34 -04001344 case R.id.goto_menu_id:
Leon Scroggins8ad29922010-02-16 12:33:55 -05001345 editUrl();
Leon Scrogginsb3a5bed2009-09-28 11:21:56 -04001346 break;
1347
1348 case R.id.bookmarks_menu_id:
Leon Scroggins30444232009-09-04 18:36:20 -04001349 bookmarksOrHistoryPicker(false);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001350 break;
1351
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001352 case R.id.active_tabs_menu_id:
1353 mActiveTabsPage = new ActiveTabsPage(this, mTabControl);
1354 removeTabFromContentView(mTabControl.getCurrentTab());
Leon Scrogginsd746a942010-05-19 13:21:44 -04001355 mTitleBar.setVisibility(View.GONE);
Leon Scroggins43de6162009-09-14 19:59:58 -04001356 hideFakeTitleBar();
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001357 mContentView.addView(mActiveTabsPage, COVER_SCREEN_PARAMS);
1358 mActiveTabsPage.requestFocus();
1359 mMenuState = EMPTY_MENU;
1360 break;
1361
Leon Scroggins1f005d32009-08-10 17:36:42 -04001362 case R.id.add_bookmark_menu_id:
Leon Scroggins571b3762010-05-26 10:25:01 -04001363 bookmarkCurrentPage();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001364 break;
1365
1366 case R.id.stop_reload_menu_id:
1367 if (mInLoad) {
1368 stopLoading();
1369 } else {
1370 getTopWindow().reload();
1371 }
1372 break;
1373
1374 case R.id.back_menu_id:
1375 getTopWindow().goBack();
1376 break;
1377
1378 case R.id.forward_menu_id:
1379 getTopWindow().goForward();
1380 break;
1381
1382 case R.id.close_menu_id:
1383 // Close the subwindow if it exists.
1384 if (mTabControl.getCurrentSubWindow() != null) {
1385 dismissSubWindow(mTabControl.getCurrentTab());
1386 break;
1387 }
Leon Scroggins1f005d32009-08-10 17:36:42 -04001388 closeCurrentWindow();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001389 break;
1390
1391 case R.id.homepage_menu_id:
Grace Kloba22ac16e2009-10-07 18:00:23 -07001392 Tab current = mTabControl.getCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001393 if (current != null) {
1394 dismissSubWindow(current);
Leon Scroggins92472e82010-02-17 16:32:28 -05001395 loadUrl(current.getWebView(), mSettings.getHomePage());
The Android Open Source Project0c908882009-03-03 19:32:16 -08001396 }
1397 break;
1398
1399 case R.id.preferences_menu_id:
1400 Intent intent = new Intent(this,
1401 BrowserPreferencesPage.class);
Leon Scrogginsd5304942009-12-10 16:11:39 -05001402 intent.putExtra(BrowserPreferencesPage.CURRENT_PAGE,
1403 getTopWindow().getUrl());
The Android Open Source Project0c908882009-03-03 19:32:16 -08001404 startActivityForResult(intent, PREFERENCES_PAGE);
1405 break;
1406
1407 case R.id.find_menu_id:
Cary Clark01cfcdd2010-06-04 16:36:45 -04001408 showFindDialog();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001409 break;
1410
1411 case R.id.select_text_id:
Cary Clark01cfcdd2010-06-04 16:36:45 -04001412 showSelectDialog();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001413 break;
Cary Clark01cfcdd2010-06-04 16:36:45 -04001414
The Android Open Source Project0c908882009-03-03 19:32:16 -08001415 case R.id.page_info_menu_id:
1416 showPageInfo(mTabControl.getCurrentTab(), false);
1417 break;
1418
1419 case R.id.classic_history_menu_id:
Leon Scroggins30444232009-09-04 18:36:20 -04001420 bookmarksOrHistoryPicker(true);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001421 break;
1422
Leon Scroggins96afcb12009-12-10 12:35:56 -05001423 case R.id.title_bar_share_page_url:
The Android Open Source Project0c908882009-03-03 19:32:16 -08001424 case R.id.share_page_menu_id:
Leon Scroggins96afcb12009-12-10 12:35:56 -05001425 Tab currentTab = mTabControl.getCurrentTab();
1426 if (null == currentTab) {
1427 mCanChord = false;
1428 return false;
1429 }
1430 currentTab.populatePickerData();
1431 sharePage(this, currentTab.getTitle(),
1432 currentTab.getUrl(), currentTab.getFavicon(),
1433 createScreenshot(currentTab.getWebView()));
The Android Open Source Project0c908882009-03-03 19:32:16 -08001434 break;
1435
1436 case R.id.dump_nav_menu_id:
1437 getTopWindow().debugDump();
1438 break;
1439
Andrei Popescu7a8b88b2010-02-02 00:30:38 +00001440 case R.id.dump_counters_menu_id:
1441 getTopWindow().dumpV8Counters();
1442 break;
1443
The Android Open Source Project0c908882009-03-03 19:32:16 -08001444 case R.id.zoom_in_menu_id:
1445 getTopWindow().zoomIn();
1446 break;
1447
1448 case R.id.zoom_out_menu_id:
1449 getTopWindow().zoomOut();
1450 break;
1451
1452 case R.id.view_downloads_menu_id:
1453 viewDownloads(null);
1454 break;
1455
The Android Open Source Project0c908882009-03-03 19:32:16 -08001456 case R.id.window_one_menu_id:
1457 case R.id.window_two_menu_id:
1458 case R.id.window_three_menu_id:
1459 case R.id.window_four_menu_id:
1460 case R.id.window_five_menu_id:
1461 case R.id.window_six_menu_id:
1462 case R.id.window_seven_menu_id:
1463 case R.id.window_eight_menu_id:
1464 {
1465 int menuid = item.getItemId();
1466 for (int id = 0; id < WINDOW_SHORTCUT_ID_ARRAY.length; id++) {
1467 if (WINDOW_SHORTCUT_ID_ARRAY[id] == menuid) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001468 Tab desiredTab = mTabControl.getTab(id);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001469 if (desiredTab != null &&
1470 desiredTab != mTabControl.getCurrentTab()) {
Leon Scroggins1f005d32009-08-10 17:36:42 -04001471 switchToTab(id);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001472 }
1473 break;
1474 }
1475 }
1476 }
1477 break;
1478
1479 default:
1480 if (!super.onOptionsItemSelected(item)) {
1481 return false;
1482 }
1483 // Otherwise fall through.
1484 }
1485 mCanChord = false;
1486 return true;
1487 }
1488
Leon Scroggins571b3762010-05-26 10:25:01 -04001489 /* package */ void bookmarkCurrentPage() {
1490 Intent i = new Intent(BrowserActivity.this,
1491 AddBookmarkPage.class);
1492 WebView w = getTopWindow();
1493 i.putExtra("url", w.getUrl());
1494 i.putExtra("title", w.getTitle());
1495 i.putExtra("touch_icon_url", w.getTouchIconUrl());
1496 i.putExtra("thumbnail", createScreenshot(w));
1497 startActivity(i);
1498 }
1499
Cary Clark01cfcdd2010-06-04 16:36:45 -04001500 private boolean dialogIsUp() {
1501 return null != mFindDialog && mFindDialog.isVisible() ||
1502 null != mSelectDialog && mSelectDialog.isVisible();
1503 }
1504
1505 private boolean closeDialog(WebDialog dialog) {
1506 if (null == dialog || !dialog.isVisible()) return false;
Leon Scroggins79e36d92010-04-29 16:01:46 +01001507 Tab currentTab = mTabControl.getCurrentTab();
Cary Clark01cfcdd2010-06-04 16:36:45 -04001508 currentTab.closeDialog(dialog);
1509 dialog.dismiss();
1510 return true;
1511 }
1512
1513 /*
1514 * Remove the find dialog or select dialog.
1515 */
1516 public void closeDialogs() {
1517 if (!(closeDialog(mFindDialog) || closeDialog(mSelectDialog))) return;
Leon Scrogginsd746a942010-05-19 13:21:44 -04001518 if (!mXLargeScreenSize) {
1519 // If the Find was being performed in the main WebView, replace the
1520 // embedded title bar.
Cary Clark01cfcdd2010-06-04 16:36:45 -04001521 Tab currentTab = mTabControl.getCurrentTab();
Leon Scrogginsd746a942010-05-19 13:21:44 -04001522 if (currentTab.getSubWebView() == null) {
1523 WebView mainView = currentTab.getWebView();
1524 if (mainView != null) {
1525 mainView.setEmbeddedTitleBar(mTitleBar);
1526 }
Leon Scroggins79e36d92010-04-29 16:01:46 +01001527 }
1528 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001529 mMenuState = R.id.MAIN_MENU;
Leon Scroggins79e36d92010-04-29 16:01:46 +01001530 if (mInLoad) {
1531 // The title bar was hidden, because otherwise it would cover up the
Cary Clark01cfcdd2010-06-04 16:36:45 -04001532 // find or select dialog. Now that the dialog has been removed,
1533 // show the fake title bar once again.
Leon Scroggins79e36d92010-04-29 16:01:46 +01001534 showFakeTitleBar();
1535 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001536 }
1537
Cary Clark01cfcdd2010-06-04 16:36:45 -04001538 public void showFindDialog() {
1539 if (null == mFindDialog) {
1540 mFindDialog = new FindDialog(this);
1541 }
1542 showDialog(mFindDialog).setFindIsUp(true);
1543 }
1544
1545 public void setFindDialogText(String text) {
1546 mFindDialog.setText(text);
1547 }
1548
1549 public void showSelectDialog() {
1550 if (null == mSelectDialog) {
1551 mSelectDialog = new SelectDialog(this);
1552 }
1553 showDialog(mSelectDialog).setUpSelect();
1554 mSelectDialog.hideSoftInput();
1555 }
1556
Grace Kloba22ac16e2009-10-07 18:00:23 -07001557 @Override
1558 public boolean onPrepareOptionsMenu(Menu menu) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001559 // This happens when the user begins to hold down the menu key, so
1560 // allow them to chord to get a shortcut.
1561 mCanChord = true;
1562 // Note: setVisible will decide whether an item is visible; while
1563 // setEnabled() will decide whether an item is enabled, which also means
1564 // whether the matching shortcut key will function.
1565 super.onPrepareOptionsMenu(menu);
1566 switch (mMenuState) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001567 case EMPTY_MENU:
1568 if (mCurrentMenuState != mMenuState) {
1569 menu.setGroupVisible(R.id.MAIN_MENU, false);
1570 menu.setGroupEnabled(R.id.MAIN_MENU, false);
1571 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001572 }
1573 break;
1574 default:
1575 if (mCurrentMenuState != mMenuState) {
1576 menu.setGroupVisible(R.id.MAIN_MENU, true);
1577 menu.setGroupEnabled(R.id.MAIN_MENU, true);
1578 menu.setGroupEnabled(R.id.MAIN_SHORTCUT_MENU, true);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001579 }
1580 final WebView w = getTopWindow();
1581 boolean canGoBack = false;
1582 boolean canGoForward = false;
1583 boolean isHome = false;
1584 if (w != null) {
1585 canGoBack = w.canGoBack();
1586 canGoForward = w.canGoForward();
1587 isHome = mSettings.getHomePage().equals(w.getUrl());
1588 }
1589 final MenuItem back = menu.findItem(R.id.back_menu_id);
1590 back.setEnabled(canGoBack);
1591
1592 final MenuItem home = menu.findItem(R.id.homepage_menu_id);
1593 home.setEnabled(!isHome);
1594
1595 menu.findItem(R.id.forward_menu_id)
1596 .setEnabled(canGoForward);
1597
Leon Scrogginsa81a7642009-08-31 17:05:41 -04001598 menu.findItem(R.id.new_tab_menu_id).setEnabled(
Grace Kloba22ac16e2009-10-07 18:00:23 -07001599 mTabControl.canCreateNewTab());
Leon Scrogginsa81a7642009-08-31 17:05:41 -04001600
The Android Open Source Project0c908882009-03-03 19:32:16 -08001601 // decide whether to show the share link option
1602 PackageManager pm = getPackageManager();
1603 Intent send = new Intent(Intent.ACTION_SEND);
1604 send.setType("text/plain");
1605 ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY);
1606 menu.findItem(R.id.share_page_menu_id).setVisible(ri != null);
1607
The Android Open Source Project0c908882009-03-03 19:32:16 -08001608 boolean isNavDump = mSettings.isNavDump();
1609 final MenuItem nav = menu.findItem(R.id.dump_nav_menu_id);
1610 nav.setVisible(isNavDump);
1611 nav.setEnabled(isNavDump);
Andrei Popescu7a8b88b2010-02-02 00:30:38 +00001612
1613 boolean showDebugSettings = mSettings.showDebugSettings();
1614 final MenuItem counter = menu.findItem(R.id.dump_counters_menu_id);
1615 counter.setVisible(showDebugSettings);
1616 counter.setEnabled(showDebugSettings);
1617
The Android Open Source Project0c908882009-03-03 19:32:16 -08001618 break;
1619 }
1620 mCurrentMenuState = mMenuState;
1621 return true;
1622 }
1623
1624 @Override
1625 public void onCreateContextMenu(ContextMenu menu, View v,
1626 ContextMenuInfo menuInfo) {
Leon Scroggins571b3762010-05-26 10:25:01 -04001627 if (v instanceof TitleBarBase) {
Leon Scroggins4e9f89b2010-02-22 16:54:14 -05001628 return;
1629 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001630 WebView webview = (WebView) v;
1631 WebView.HitTestResult result = webview.getHitTestResult();
1632 if (result == null) {
1633 return;
1634 }
1635
1636 int type = result.getType();
1637 if (type == WebView.HitTestResult.UNKNOWN_TYPE) {
1638 Log.w(LOGTAG,
1639 "We should not show context menu when nothing is touched");
1640 return;
1641 }
1642 if (type == WebView.HitTestResult.EDIT_TEXT_TYPE) {
1643 // let TextView handles context menu
1644 return;
1645 }
1646
1647 // Note, http://b/issue?id=1106666 is requesting that
1648 // an inflated menu can be used again. This is not available
1649 // yet, so inflate each time (yuk!)
1650 MenuInflater inflater = getMenuInflater();
1651 inflater.inflate(R.menu.browsercontext, menu);
1652
1653 // Show the correct menu group
Leon Scroggins III9e997c72010-05-26 13:25:16 -04001654 final String extra = result.getExtra();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001655 menu.setGroupVisible(R.id.PHONE_MENU,
1656 type == WebView.HitTestResult.PHONE_TYPE);
1657 menu.setGroupVisible(R.id.EMAIL_MENU,
1658 type == WebView.HitTestResult.EMAIL_TYPE);
1659 menu.setGroupVisible(R.id.GEO_MENU,
1660 type == WebView.HitTestResult.GEO_TYPE);
1661 menu.setGroupVisible(R.id.IMAGE_MENU,
1662 type == WebView.HitTestResult.IMAGE_TYPE
1663 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1664 menu.setGroupVisible(R.id.ANCHOR_MENU,
1665 type == WebView.HitTestResult.SRC_ANCHOR_TYPE
1666 || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE);
1667
1668 // Setup custom handling depending on the type
1669 switch (type) {
1670 case WebView.HitTestResult.PHONE_TYPE:
1671 menu.setHeaderTitle(Uri.decode(extra));
1672 menu.findItem(R.id.dial_context_menu_id).setIntent(
1673 new Intent(Intent.ACTION_VIEW, Uri
1674 .parse(WebView.SCHEME_TEL + extra)));
1675 Intent addIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
1676 addIntent.putExtra(Insert.PHONE, Uri.decode(extra));
Cary Clark5e335a32009-09-22 14:53:11 -04001677 addIntent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001678 menu.findItem(R.id.add_contact_context_menu_id).setIntent(
1679 addIntent);
1680 menu.findItem(R.id.copy_phone_context_menu_id).setOnMenuItemClickListener(
1681 new Copy(extra));
1682 break;
1683
1684 case WebView.HitTestResult.EMAIL_TYPE:
1685 menu.setHeaderTitle(extra);
1686 menu.findItem(R.id.email_context_menu_id).setIntent(
1687 new Intent(Intent.ACTION_VIEW, Uri
1688 .parse(WebView.SCHEME_MAILTO + extra)));
1689 menu.findItem(R.id.copy_mail_context_menu_id).setOnMenuItemClickListener(
1690 new Copy(extra));
1691 break;
1692
1693 case WebView.HitTestResult.GEO_TYPE:
1694 menu.setHeaderTitle(extra);
1695 menu.findItem(R.id.map_context_menu_id).setIntent(
1696 new Intent(Intent.ACTION_VIEW, Uri
1697 .parse(WebView.SCHEME_GEO
1698 + URLEncoder.encode(extra))));
1699 menu.findItem(R.id.copy_geo_context_menu_id).setOnMenuItemClickListener(
1700 new Copy(extra));
1701 break;
1702
1703 case WebView.HitTestResult.SRC_ANCHOR_TYPE:
1704 case WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE:
1705 TextView titleView = (TextView) LayoutInflater.from(this)
1706 .inflate(android.R.layout.browser_link_context_header,
1707 null);
1708 titleView.setText(extra);
1709 menu.setHeaderView(titleView);
1710 // decide whether to show the open link in new tab option
Leon Scroggins III9e997c72010-05-26 13:25:16 -04001711 boolean showNewTab = mTabControl.canCreateNewTab();
1712 MenuItem newTabItem
1713 = menu.findItem(R.id.open_newtab_context_menu_id);
1714 newTabItem.setVisible(showNewTab);
1715 if (showNewTab) {
1716 newTabItem.setOnMenuItemClickListener(
1717 new MenuItem.OnMenuItemClickListener() {
1718 public boolean onMenuItemClick(MenuItem item) {
1719 final Tab parent = mTabControl.getCurrentTab();
1720 final Tab newTab = openTab(extra);
1721 if (newTab != parent) {
1722 parent.addChildTab(newTab);
1723 }
1724 return true;
1725 }
1726 });
1727 }
Ben Murdochde353622009-10-12 10:29:00 +01001728 menu.findItem(R.id.bookmark_context_menu_id).setVisible(
1729 Bookmarks.urlHasAcceptableScheme(extra));
The Android Open Source Project0c908882009-03-03 19:32:16 -08001730 PackageManager pm = getPackageManager();
1731 Intent send = new Intent(Intent.ACTION_SEND);
1732 send.setType("text/plain");
1733 ResolveInfo ri = pm.resolveActivity(send, PackageManager.MATCH_DEFAULT_ONLY);
1734 menu.findItem(R.id.share_link_context_menu_id).setVisible(ri != null);
1735 if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
1736 break;
1737 }
1738 // otherwise fall through to handle image part
1739 case WebView.HitTestResult.IMAGE_TYPE:
1740 if (type == WebView.HitTestResult.IMAGE_TYPE) {
1741 menu.setHeaderTitle(extra);
1742 }
1743 menu.findItem(R.id.view_image_context_menu_id).setIntent(
1744 new Intent(Intent.ACTION_VIEW, Uri.parse(extra)));
1745 menu.findItem(R.id.download_context_menu_id).
1746 setOnMenuItemClickListener(new Download(extra));
Ben Murdoch4f75ba22009-10-27 11:48:28 +00001747 menu.findItem(R.id.set_wallpaper_context_menu_id).
1748 setOnMenuItemClickListener(new SetAsWallpaper(extra));
The Android Open Source Project0c908882009-03-03 19:32:16 -08001749 break;
1750
1751 default:
1752 Log.w(LOGTAG, "We should not get here.");
1753 break;
1754 }
Leon Scrogginsb2b19f52009-10-09 16:10:00 -04001755 hideFakeTitleBar();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001756 }
1757
The Android Open Source Project0c908882009-03-03 19:32:16 -08001758 // Attach the given tab to the content view.
Grace Klobac928c302009-09-17 11:51:21 -07001759 // this should only be called for the current tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001760 private void attachTabToContentView(Tab t) {
Steve Block2bc69912009-07-30 14:45:13 +01001761 // Attach the container that contains the main WebView and any other UI
1762 // associated with the tab.
Patrick Scottd0119532009-09-17 08:00:31 -04001763 t.attachTabToContentView(mContentView);
Ben Murdochbff2d602009-07-01 20:19:05 +01001764
1765 if (mShouldShowErrorConsole) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001766 ErrorConsoleView errorConsole = t.getErrorConsole(true);
Ben Murdochbff2d602009-07-01 20:19:05 +01001767 if (errorConsole.numberOfErrors() == 0) {
1768 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
1769 } else {
1770 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
1771 }
1772
1773 mErrorConsoleContainer.addView(errorConsole,
Romain Guy15b8ec62010-01-08 15:06:43 -08001774 new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
Ben Murdochbff2d602009-07-01 20:19:05 +01001775 ViewGroup.LayoutParams.WRAP_CONTENT));
1776 }
1777
Leon Scrogginsd746a942010-05-19 13:21:44 -04001778 if (!mXLargeScreenSize){
1779 WebView view = t.getWebView();
1780 view.setEmbeddedTitleBar(mTitleBar);
1781 }
Leon Scroggins58d56c62010-01-28 15:12:40 -05001782 if (t.isInVoiceSearchMode()) {
1783 showVoiceTitleBar(t.getVoiceDisplayTitle());
1784 } else {
1785 revertVoiceTitleBar();
1786 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001787 // Request focus on the top window.
1788 t.getTopWindow().requestFocus();
1789 }
1790
1791 // Attach a sub window to the main WebView of the given tab.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001792 void attachSubWindow(Tab t) {
Patrick Scottd0119532009-09-17 08:00:31 -04001793 t.attachSubWindow(mContentView);
1794 getTopWindow().requestFocus();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001795 }
1796
1797 // Remove the given tab from the content view.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001798 private void removeTabFromContentView(Tab t) {
Steve Block2bc69912009-07-30 14:45:13 +01001799 // Remove the container that contains the main WebView.
Patrick Scottd0119532009-09-17 08:00:31 -04001800 t.removeTabFromContentView(mContentView);
Ben Murdochbff2d602009-07-01 20:19:05 +01001801
Grace Kloba22ac16e2009-10-07 18:00:23 -07001802 ErrorConsoleView errorConsole = t.getErrorConsole(false);
1803 if (errorConsole != null) {
1804 mErrorConsoleContainer.removeView(errorConsole);
Ben Murdochbff2d602009-07-01 20:19:05 +01001805 }
1806
Leon Scrogginsd746a942010-05-19 13:21:44 -04001807 if (!mXLargeScreenSize) {
1808 WebView view = t.getWebView();
1809 if (view != null) {
1810 view.setEmbeddedTitleBar(null);
1811 }
Leon Scrogginsbb85b902009-09-14 19:27:20 -04001812 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08001813 }
1814
1815 // Remove the sub window if it exists. Also called by TabControl when the
1816 // user clicks the 'X' to dismiss a sub window.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001817 /* package */ void dismissSubWindow(Tab t) {
Patrick Scottd0119532009-09-17 08:00:31 -04001818 t.removeSubWindow(mContentView);
Grace Kloba22ac16e2009-10-07 18:00:23 -07001819 // dismiss the subwindow. This will destroy the WebView.
1820 t.dismissSubWindow();
Patrick Scottd0119532009-09-17 08:00:31 -04001821 getTopWindow().requestFocus();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001822 }
1823
Leon Scroggins1f005d32009-08-10 17:36:42 -04001824 // A wrapper function of {@link #openTabAndShow(UrlData, boolean, String)}
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07001825 // that accepts url as string.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001826 private Tab openTabAndShow(String url, boolean closeOnExit, String appId) {
Leon Scroggins1f005d32009-08-10 17:36:42 -04001827 return openTabAndShow(new UrlData(url), closeOnExit, appId);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001828 }
1829
1830 // This method does a ton of stuff. It will attempt to create a new tab
1831 // if we haven't reached MAX_TABS. Otherwise it uses the current tab. If
Leon Scroggins1f005d32009-08-10 17:36:42 -04001832 // url isn't null, it will load the given url.
Grace Kloba22ac16e2009-10-07 18:00:23 -07001833 /* package */Tab openTabAndShow(UrlData urlData, boolean closeOnExit,
1834 String appId) {
1835 final Tab currentTab = mTabControl.getCurrentTab();
1836 if (mTabControl.canCreateNewTab()) {
1837 final Tab tab = mTabControl.createNewTab(closeOnExit, appId,
1838 urlData.mUrl);
Leon Scroggins1f005d32009-08-10 17:36:42 -04001839 WebView webview = tab.getWebView();
Leon Scroggins0a64ba52009-09-08 15:35:33 -04001840 // If the last tab was removed from the active tabs page, currentTab
1841 // will be null.
1842 if (currentTab != null) {
1843 removeTabFromContentView(currentTab);
1844 }
Patrick Scott8bbd69f2009-08-14 13:35:53 -04001845 // We must set the new tab as the current tab to reflect the old
1846 // animation behavior.
1847 mTabControl.setCurrentTab(tab);
Grace Klobaeb6eef42009-09-15 17:56:32 -07001848 attachTabToContentView(tab);
Leon Scroggins160a7e72009-08-14 18:28:01 -04001849 if (!urlData.isEmpty()) {
Patrick Scott9d53da02010-02-19 10:19:01 -05001850 loadUrlDataIn(tab, urlData);
Leon Scroggins1f005d32009-08-10 17:36:42 -04001851 }
1852 return tab;
1853 } else {
1854 // Get rid of the subwindow if it exists
1855 dismissSubWindow(currentTab);
1856 if (!urlData.isEmpty()) {
1857 // Load the given url.
Patrick Scott9d53da02010-02-19 10:19:01 -05001858 loadUrlDataIn(currentTab, urlData);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001859 }
Leon Scroggins58d56c62010-01-28 15:12:40 -05001860 return currentTab;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001861 }
1862 }
1863
Grace Kloba22ac16e2009-10-07 18:00:23 -07001864 private Tab openTab(String url) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08001865 if (mSettings.openInBackground()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001866 Tab t = mTabControl.createNewTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001867 if (t != null) {
Leon Scroggins1f005d32009-08-10 17:36:42 -04001868 WebView view = t.getWebView();
Leon Scroggins92472e82010-02-17 16:32:28 -05001869 loadUrl(view, url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001870 }
Grace Klobac9181842009-04-14 08:53:22 -07001871 return t;
The Android Open Source Project0c908882009-03-03 19:32:16 -08001872 } else {
Leon Scroggins1f005d32009-08-10 17:36:42 -04001873 return openTabAndShow(url, false, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08001874 }
1875 }
1876
1877 private class Copy implements OnMenuItemClickListener {
1878 private CharSequence mText;
1879
1880 public boolean onMenuItemClick(MenuItem item) {
1881 copy(mText);
1882 return true;
1883 }
1884
1885 public Copy(CharSequence toCopy) {
1886 mText = toCopy;
1887 }
1888 }
1889
1890 private class Download implements OnMenuItemClickListener {
1891 private String mText;
1892
1893 public boolean onMenuItemClick(MenuItem item) {
1894 onDownloadStartNoStream(mText, null, null, null, -1);
1895 return true;
1896 }
1897
1898 public Download(String toDownload) {
1899 mText = toDownload;
1900 }
1901 }
1902
Ben Murdoch4f75ba22009-10-27 11:48:28 +00001903 private class SetAsWallpaper extends Thread implements
1904 OnMenuItemClickListener, DialogInterface.OnCancelListener {
1905 private URL mUrl;
1906 private ProgressDialog mWallpaperProgress;
1907 private boolean mCanceled = false;
1908
1909 public SetAsWallpaper(String url) {
1910 try {
1911 mUrl = new URL(url);
1912 } catch (MalformedURLException e) {
1913 mUrl = null;
1914 }
1915 }
1916
1917 public void onCancel(DialogInterface dialog) {
1918 mCanceled = true;
1919 }
1920
1921 public boolean onMenuItemClick(MenuItem item) {
1922 if (mUrl != null) {
1923 // The user may have tried to set a image with a large file size as their
1924 // background so it may take a few moments to perform the operation. Display
1925 // a progress spinner while it is working.
1926 mWallpaperProgress = new ProgressDialog(BrowserActivity.this);
1927 mWallpaperProgress.setIndeterminate(true);
1928 mWallpaperProgress.setMessage(getText(R.string.progress_dialog_setting_wallpaper));
1929 mWallpaperProgress.setCancelable(true);
1930 mWallpaperProgress.setOnCancelListener(this);
1931 mWallpaperProgress.show();
1932 start();
1933 }
1934 return true;
1935 }
1936
1937 public void run() {
1938 Drawable oldWallpaper = BrowserActivity.this.getWallpaper();
1939 try {
1940 // TODO: This will cause the resource to be downloaded again, when we
1941 // should in most cases be able to grab it from the cache. To fix this
1942 // we should query WebCore to see if we can access a cached version and
1943 // instead open an input stream on that. This pattern could also be used
1944 // in the download manager where the same problem exists.
1945 InputStream inputstream = mUrl.openStream();
1946 if (inputstream != null) {
1947 setWallpaper(inputstream);
1948 }
1949 } catch (IOException e) {
1950 Log.e(LOGTAG, "Unable to set new wallpaper");
1951 // Act as though the user canceled the operation so we try to
1952 // restore the old wallpaper.
1953 mCanceled = true;
1954 }
1955
1956 if (mCanceled) {
1957 // Restore the old wallpaper if the user cancelled whilst we were setting
1958 // the new wallpaper.
1959 int width = oldWallpaper.getIntrinsicWidth();
1960 int height = oldWallpaper.getIntrinsicHeight();
1961 Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
1962 Canvas canvas = new Canvas(bm);
1963 oldWallpaper.setBounds(0, 0, width, height);
1964 oldWallpaper.draw(canvas);
1965 try {
1966 setWallpaper(bm);
1967 } catch (IOException e) {
1968 Log.e(LOGTAG, "Unable to restore old wallpaper.");
1969 }
1970 mCanceled = false;
1971 }
1972
1973 if (mWallpaperProgress.isShowing()) {
1974 mWallpaperProgress.dismiss();
1975 }
1976 }
1977 }
1978
The Android Open Source Project0c908882009-03-03 19:32:16 -08001979 private void copy(CharSequence text) {
1980 try {
1981 IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard"));
1982 if (clip != null) {
1983 clip.setClipboardText(text);
1984 }
1985 } catch (android.os.RemoteException e) {
1986 Log.e(LOGTAG, "Copy failed", e);
1987 }
1988 }
1989
1990 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -08001991 * Resets the browser title-view to whatever it must be
1992 * (for example, if we had a loading error)
1993 * When we have a new page, we call resetTitle, when we
1994 * have to reset the titlebar to whatever it used to be
1995 * (for example, if the user chose to stop loading), we
1996 * call resetTitleAndRevertLockIcon.
1997 */
1998 /* package */ void resetTitleAndRevertLockIcon() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07001999 mTabControl.getCurrentTab().revertLockIcon();
2000 updateLockIconToLatest();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002001 resetTitleIconAndProgress();
2002 }
2003
2004 /**
2005 * Reset the title, favicon, and progress.
2006 */
2007 private void resetTitleIconAndProgress() {
2008 WebView current = mTabControl.getCurrentWebView();
2009 if (current == null) {
2010 return;
2011 }
2012 resetTitleAndIcon(current);
2013 int progress = current.getProgress();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002014 current.getWebChromeClient().onProgressChanged(current, progress);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002015 }
2016
2017 // Reset the title and the icon based on the given item.
2018 private void resetTitleAndIcon(WebView view) {
2019 WebHistoryItem item = view.copyBackForwardList().getCurrentItem();
2020 if (item != null) {
Leon Scroggins68579392009-09-15 15:31:54 -04002021 setUrlTitle(item.getUrl(), item.getTitle());
The Android Open Source Project0c908882009-03-03 19:32:16 -08002022 setFavicon(item.getFavicon());
2023 } else {
Leon Scroggins68579392009-09-15 15:31:54 -04002024 setUrlTitle(null, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002025 setFavicon(null);
2026 }
2027 }
2028
2029 /**
2030 * Sets a title composed of the URL and the title string.
2031 * @param url The URL of the site being loaded.
2032 * @param title The title of the site being loaded.
2033 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07002034 void setUrlTitle(String url, String title) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002035 mUrl = url;
2036 mTitle = title;
2037
Leon Scroggins58d56c62010-01-28 15:12:40 -05002038 // If we are in voice search mode, the title has already been set.
2039 if (mTabControl.getCurrentTab().isInVoiceSearchMode()) return;
2040 mTitleBar.setDisplayTitle(url);
Leon Scrogginsd746a942010-05-19 13:21:44 -04002041 if (!mXLargeScreenSize) {
2042 mFakeTitleBar.setDisplayTitle(url);
2043 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002044 }
2045
2046 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -08002047 * @param url The URL to build a title version of the URL from.
2048 * @return The title version of the URL or null if fails.
2049 * The title version of the URL can be either the URL hostname,
2050 * or the hostname with an "https://" prefix (for secure URLs),
2051 * or an empty string if, for example, the URL in question is a
2052 * file:// URL with no hostname.
2053 */
Leon Scroggins32e14a62009-06-11 10:26:34 -04002054 /* package */ static String buildTitleUrl(String url) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002055 String titleUrl = null;
2056
2057 if (url != null) {
2058 try {
2059 // parse the url string
2060 URL urlObj = new URL(url);
2061 if (urlObj != null) {
2062 titleUrl = "";
2063
2064 String protocol = urlObj.getProtocol();
2065 String host = urlObj.getHost();
2066
2067 if (host != null && 0 < host.length()) {
2068 titleUrl = host;
2069 if (protocol != null) {
2070 // if a secure site, add an "https://" prefix!
2071 if (protocol.equalsIgnoreCase("https")) {
2072 titleUrl = protocol + "://" + host;
2073 }
2074 }
2075 }
2076 }
2077 } catch (MalformedURLException e) {}
2078 }
2079
2080 return titleUrl;
2081 }
2082
2083 // Set the favicon in the title bar.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002084 void setFavicon(Bitmap icon) {
Leon Scroggins68579392009-09-15 15:31:54 -04002085 mTitleBar.setFavicon(icon);
Leon Scrogginsd746a942010-05-19 13:21:44 -04002086 if (!mXLargeScreenSize) {
2087 mFakeTitleBar.setFavicon(icon);
2088 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002089 }
2090
2091 /**
Leon Scroggins0a64ba52009-09-08 15:35:33 -04002092 * Close the tab, remove its associated title bar, and adjust mTabControl's
2093 * current tab to a valid value.
Leon Scroggins1f005d32009-08-10 17:36:42 -04002094 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07002095 /* package */ void closeTab(Tab t) {
Leon Scroggins0a64ba52009-09-08 15:35:33 -04002096 int currentIndex = mTabControl.getCurrentIndex();
2097 int removeIndex = mTabControl.getTabIndex(t);
Leon Scroggins1f005d32009-08-10 17:36:42 -04002098 mTabControl.removeTab(t);
Leon Scroggins0a64ba52009-09-08 15:35:33 -04002099 if (currentIndex >= removeIndex && currentIndex != 0) {
2100 currentIndex--;
2101 }
2102 mTabControl.setCurrentTab(mTabControl.getTab(currentIndex));
Andrei Popescua5bf1de2009-09-23 16:39:23 +01002103 resetTitleIconAndProgress();
Leon Scroggins654899b2010-06-25 16:25:23 -04002104 updateLockIconToLatest();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002105 }
2106
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05002107 /* package */ void goBackOnePageOrQuit() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002108 Tab current = mTabControl.getCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002109 if (current == null) {
2110 /*
2111 * Instead of finishing the activity, simply push this to the back
2112 * of the stack and let ActivityManager to choose the foreground
2113 * activity. As BrowserActivity is singleTask, it will be always the
2114 * root of the task. So we can use either true or false for
2115 * moveTaskToBack().
2116 */
2117 moveTaskToBack(true);
Grace Kloba00d85e72009-09-23 18:50:05 -07002118 return;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002119 }
2120 WebView w = current.getWebView();
2121 if (w.canGoBack()) {
2122 w.goBack();
2123 } else {
2124 // Check to see if we are closing a window that was created by
2125 // another window. If so, we switch back to that window.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002126 Tab parent = current.getParentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002127 if (parent != null) {
Leon Scroggins1f005d32009-08-10 17:36:42 -04002128 switchToTab(mTabControl.getTabIndex(parent));
2129 // Now we close the other tab
2130 closeTab(current);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002131 } else {
2132 if (current.closeOnExit()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002133 // force the tab's inLoad() to be false as we are going to
2134 // either finish the activity or remove the tab. This will
2135 // ensure pauseWebViewTimers() taking action.
2136 mTabControl.getCurrentTab().clearInLoad();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002137 if (mTabControl.getTabCount() == 1) {
2138 finish();
2139 return;
2140 }
Mike Reed7bfa63b2009-05-28 11:08:32 -04002141 // call pauseWebViewTimers() now, we won't be able to call
2142 // it in onPause() as the WebView won't be valid.
Grace Klobaec1b5ad2009-08-18 08:42:32 -07002143 // Temporarily change mActivityInPause to be true as
2144 // pauseWebViewTimers() will do nothing if mActivityInPause
2145 // is false.
Grace Kloba918e1d72009-08-13 14:55:06 -07002146 boolean savedState = mActivityInPause;
2147 if (savedState) {
Grace Klobaec1b5ad2009-08-18 08:42:32 -07002148 Log.e(LOGTAG, "BrowserActivity is already paused "
2149 + "while handing goBackOnePageOrQuit.");
Grace Kloba918e1d72009-08-13 14:55:06 -07002150 }
2151 mActivityInPause = true;
Mike Reed7bfa63b2009-05-28 11:08:32 -04002152 pauseWebViewTimers();
Grace Kloba918e1d72009-08-13 14:55:06 -07002153 mActivityInPause = savedState;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002154 removeTabFromContentView(current);
2155 mTabControl.removeTab(current);
2156 }
2157 /*
2158 * Instead of finishing the activity, simply push this to the back
2159 * of the stack and let ActivityManager to choose the foreground
2160 * activity. As BrowserActivity is singleTask, it will be always the
2161 * root of the task. So we can use either true or false for
2162 * moveTaskToBack().
2163 */
2164 moveTaskToBack(true);
2165 }
2166 }
2167 }
2168
Grace Kloba22ac16e2009-10-07 18:00:23 -07002169 boolean isMenuDown() {
2170 return mMenuIsDown;
2171 }
2172
Grace Kloba5942df02009-09-18 11:48:29 -07002173 @Override
2174 public boolean onKeyDown(int keyCode, KeyEvent event) {
Leon Scrogginsf65b50d2009-12-08 10:44:28 -05002175 // Even if MENU is already held down, we need to call to super to open
2176 // the IME on long press.
2177 if (KeyEvent.KEYCODE_MENU == keyCode) {
2178 mMenuIsDown = true;
2179 return super.onKeyDown(keyCode, event);
2180 }
Grace Kloba5942df02009-09-18 11:48:29 -07002181 // The default key mode is DEFAULT_KEYS_SEARCH_LOCAL. As the MENU is
2182 // still down, we don't want to trigger the search. Pretend to consume
2183 // the key and do nothing.
2184 if (mMenuIsDown) return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002185
Grace Kloba5942df02009-09-18 11:48:29 -07002186 switch(keyCode) {
Grace Kloba5942df02009-09-18 11:48:29 -07002187 case KeyEvent.KEYCODE_SPACE:
Grace Klobada0fe552009-09-22 18:17:24 -07002188 // WebView/WebTextView handle the keys in the KeyDown. As
2189 // the Activity's shortcut keys are only handled when WebView
2190 // doesn't, have to do it in onKeyDown instead of onKeyUp.
2191 if (event.isShiftPressed()) {
2192 getTopWindow().pageUp(false);
2193 } else {
2194 getTopWindow().pageDown(false);
2195 }
Grace Kloba5942df02009-09-18 11:48:29 -07002196 return true;
2197 case KeyEvent.KEYCODE_BACK:
2198 if (event.getRepeatCount() == 0) {
2199 event.startTracking();
2200 return true;
2201 } else if (mCustomView == null && mActiveTabsPage == null
2202 && event.isLongPress()) {
2203 bookmarksOrHistoryPicker(true);
2204 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002205 }
Grace Kloba5942df02009-09-18 11:48:29 -07002206 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002207 }
Grace Kloba5942df02009-09-18 11:48:29 -07002208 return super.onKeyDown(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002209 }
2210
Grace Kloba5942df02009-09-18 11:48:29 -07002211 @Override
2212 public boolean onKeyUp(int keyCode, KeyEvent event) {
2213 switch(keyCode) {
2214 case KeyEvent.KEYCODE_MENU:
2215 mMenuIsDown = false;
2216 break;
Grace Kloba5942df02009-09-18 11:48:29 -07002217 case KeyEvent.KEYCODE_BACK:
2218 if (event.isTracking() && !event.isCanceled()) {
2219 if (mCustomView != null) {
2220 // if a custom view is showing, hide it
Grace Kloba22ac16e2009-10-07 18:00:23 -07002221 mTabControl.getCurrentWebView().getWebChromeClient()
2222 .onHideCustomView();
Grace Kloba5942df02009-09-18 11:48:29 -07002223 } else if (mActiveTabsPage != null) {
2224 // if tab page is showing, hide it
2225 removeActiveTabPage(true);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002226 } else {
Grace Kloba5942df02009-09-18 11:48:29 -07002227 WebView subwindow = mTabControl.getCurrentSubWindow();
2228 if (subwindow != null) {
2229 if (subwindow.canGoBack()) {
2230 subwindow.goBack();
2231 } else {
2232 dismissSubWindow(mTabControl.getCurrentTab());
2233 }
2234 } else {
2235 goBackOnePageOrQuit();
2236 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002237 }
Grace Kloba5942df02009-09-18 11:48:29 -07002238 return true;
2239 }
2240 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002241 }
Grace Kloba5942df02009-09-18 11:48:29 -07002242 return super.onKeyUp(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002243 }
2244
Leon Scroggins68579392009-09-15 15:31:54 -04002245 /* package */ void stopLoading() {
Ben Murdochb7cc8b42009-09-28 10:59:09 +01002246 mDidStopLoad = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002247 resetTitleAndRevertLockIcon();
2248 WebView w = getTopWindow();
2249 w.stopLoading();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002250 // FIXME: before refactor, it is using mWebViewClient. So I keep the
2251 // same logic here. But for subwindow case, should we call into the main
2252 // WebView's onPageFinished as we never call its onPageStarted and if
2253 // the page finishes itself, we don't call onPageFinished.
2254 mTabControl.getCurrentWebView().getWebViewClient().onPageFinished(w,
2255 w.getUrl());
The Android Open Source Project0c908882009-03-03 19:32:16 -08002256
2257 cancelStopToast();
2258 mStopToast = Toast
2259 .makeText(this, R.string.stopping, Toast.LENGTH_SHORT);
2260 mStopToast.show();
2261 }
2262
Grace Kloba22ac16e2009-10-07 18:00:23 -07002263 boolean didUserStopLoading() {
2264 return mDidStopLoad;
2265 }
2266
The Android Open Source Project0c908882009-03-03 19:32:16 -08002267 private void cancelStopToast() {
2268 if (mStopToast != null) {
2269 mStopToast.cancel();
2270 mStopToast = null;
2271 }
2272 }
2273
Grace Kloba22ac16e2009-10-07 18:00:23 -07002274 // called by a UI or non-UI thread to post the message
2275 public void postMessage(int what, int arg1, int arg2, Object obj,
2276 long delayMillis) {
2277 mHandler.sendMessageDelayed(mHandler.obtainMessage(what, arg1, arg2,
2278 obj), delayMillis);
2279 }
2280
2281 // called by a UI or non-UI thread to remove the message
2282 void removeMessages(int what, Object object) {
2283 mHandler.removeMessages(what, object);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002284 }
2285
2286 // public message ids
2287 public final static int LOAD_URL = 1001;
2288 public final static int STOP_LOAD = 1002;
2289
2290 // Message Ids
2291 private static final int FOCUS_NODE_HREF = 102;
Grace Kloba92c18a52009-07-31 23:48:32 -07002292 private static final int RELEASE_WAKELOCK = 107;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002293
Grace Kloba22ac16e2009-10-07 18:00:23 -07002294 static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
Ben Murdoch2694e232009-09-29 09:41:11 +01002295
The Android Open Source Project0c908882009-03-03 19:32:16 -08002296 // Private handler for handling javascript and saving passwords
2297 private Handler mHandler = new Handler() {
2298
2299 public void handleMessage(Message msg) {
2300 switch (msg.what) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002301 case FOCUS_NODE_HREF:
Ben Murdoch2694e232009-09-29 09:41:11 +01002302 {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002303 String url = (String) msg.getData().get("url");
Ben Murdoch90d088c2009-11-17 18:14:04 +00002304 String title = (String) msg.getData().get("title");
The Android Open Source Project0c908882009-03-03 19:32:16 -08002305 if (url == null || url.length() == 0) {
2306 break;
2307 }
2308 HashMap focusNodeMap = (HashMap) msg.obj;
2309 WebView view = (WebView) focusNodeMap.get("webview");
2310 // Only apply the action if the top window did not change.
2311 if (getTopWindow() != view) {
2312 break;
2313 }
2314 switch (msg.arg1) {
2315 case R.id.open_context_menu_id:
2316 case R.id.view_image_context_menu_id:
Leon Scroggins92472e82010-02-17 16:32:28 -05002317 loadUrlFromContext(getTopWindow(), url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002318 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002319 case R.id.bookmark_context_menu_id:
2320 Intent intent = new Intent(BrowserActivity.this,
2321 AddBookmarkPage.class);
2322 intent.putExtra("url", url);
Ben Murdoch90d088c2009-11-17 18:14:04 +00002323 intent.putExtra("title", title);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002324 startActivity(intent);
2325 break;
2326 case R.id.share_link_context_menu_id:
Leon Scroggins3e204452010-05-10 11:06:03 -04002327 sharePage(BrowserActivity.this, title, url, null,
Leon Scroggins96afcb12009-12-10 12:35:56 -05002328 null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002329 break;
2330 case R.id.copy_link_context_menu_id:
2331 copy(url);
2332 break;
2333 case R.id.save_link_context_menu_id:
2334 case R.id.download_context_menu_id:
2335 onDownloadStartNoStream(url, null, null, null, -1);
2336 break;
2337 }
2338 break;
Ben Murdoch2694e232009-09-29 09:41:11 +01002339 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002340
2341 case LOAD_URL:
Leon Scroggins92472e82010-02-17 16:32:28 -05002342 loadUrlFromContext(getTopWindow(), (String) msg.obj);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002343 break;
2344
2345 case STOP_LOAD:
2346 stopLoading();
2347 break;
2348
The Android Open Source Project0c908882009-03-03 19:32:16 -08002349 case RELEASE_WAKELOCK:
2350 if (mWakeLock.isHeld()) {
2351 mWakeLock.release();
Grace Kloba5d0e02e2009-10-05 15:15:36 -07002352 // if we reach here, Browser should be still in the
2353 // background loading after WAKELOCK_TIMEOUT (5-min).
2354 // To avoid burning the battery, stop loading.
2355 mTabControl.stopAllLoading();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002356 }
2357 break;
Ben Murdoch2694e232009-09-29 09:41:11 +01002358
2359 case UPDATE_BOOKMARK_THUMBNAIL:
2360 WebView view = (WebView) msg.obj;
2361 if (view != null) {
2362 updateScreenshot(view);
2363 }
2364 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002365 }
2366 }
2367 };
2368
Leon Scroggins96afcb12009-12-10 12:35:56 -05002369 /**
2370 * Share a page, providing the title, url, favicon, and a screenshot. Uses
2371 * an {@link Intent} to launch the Activity chooser.
2372 * @param c Context used to launch a new Activity.
2373 * @param title Title of the page. Stored in the Intent with
Paul Westbrook03e6d392010-02-12 10:33:29 -08002374 * {@link Intent#EXTRA_SUBJECT}
Leon Scroggins96afcb12009-12-10 12:35:56 -05002375 * @param url URL of the page. Stored in the Intent with
2376 * {@link Intent#EXTRA_TEXT}
2377 * @param favicon Bitmap of the favicon for the page. Stored in the Intent
2378 * with {@link Browser#EXTRA_SHARE_FAVICON}
2379 * @param screenshot Bitmap of a screenshot of the page. Stored in the
2380 * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT}
2381 */
2382 public static final void sharePage(Context c, String title, String url,
2383 Bitmap favicon, Bitmap screenshot) {
2384 Intent send = new Intent(Intent.ACTION_SEND);
2385 send.setType("text/plain");
2386 send.putExtra(Intent.EXTRA_TEXT, url);
Paul Westbrook03e6d392010-02-12 10:33:29 -08002387 send.putExtra(Intent.EXTRA_SUBJECT, title);
Leon Scroggins96afcb12009-12-10 12:35:56 -05002388 send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon);
2389 send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot);
2390 try {
2391 c.startActivity(Intent.createChooser(send, c.getString(
2392 R.string.choosertitle_sharevia)));
2393 } catch(android.content.ActivityNotFoundException ex) {
2394 // if no app handles it, do nothing
2395 }
2396 }
2397
Leon Scroggins89c6d362009-07-15 16:54:37 -04002398 private void updateScreenshot(WebView view) {
2399 // If this is a bookmarked site, add a screenshot to the database.
2400 // FIXME: When should we update? Every time?
2401 // FIXME: Would like to make sure there is actually something to
2402 // draw, but the API for that (WebViewCore.pictureReady()) is not
2403 // currently accessible here.
Ben Murdochaac7aa62009-09-17 16:57:40 +01002404
Patrick Scottcb192b52010-04-14 14:38:55 -04002405 final Bitmap bm = createScreenshot(view);
2406 if (bm == null) {
2407 return;
Leon Scroggins89c6d362009-07-15 16:54:37 -04002408 }
Patrick Scottcb192b52010-04-14 14:38:55 -04002409
2410 final ContentResolver cr = getContentResolver();
2411 final String url = view.getUrl();
2412 final String originalUrl = view.getOriginalUrl();
2413
2414 new AsyncTask<Void, Void, Void>() {
2415 @Override
2416 protected Void doInBackground(Void... unused) {
2417 Cursor c = null;
2418 try {
2419 c = BrowserBookmarksAdapter.queryBookmarksForUrl(
2420 cr, originalUrl, url, true);
2421 if (c != null) {
2422 if (c.moveToFirst()) {
2423 ContentValues values = new ContentValues();
2424 final ByteArrayOutputStream os
2425 = new ByteArrayOutputStream();
2426 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
2427 values.put(Browser.BookmarkColumns.THUMBNAIL,
2428 os.toByteArray());
2429 do {
2430 cr.update(ContentUris.withAppendedId(
2431 Browser.BOOKMARKS_URI, c.getInt(0)),
2432 values, null, null);
2433 } while (c.moveToNext());
2434 }
2435 }
2436 } catch (IllegalStateException e) {
2437 // Ignore
2438 } finally {
2439 if (c != null) c.close();
2440 }
2441 return null;
2442 }
2443 }.execute();
Leon Scroggins89c6d362009-07-15 16:54:37 -04002444 }
2445
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002446 /**
Leon Scrogginsf8551612009-09-24 16:06:02 -04002447 * Values for the size of the thumbnail created when taking a screenshot.
2448 * Lazily initialized. Instead of using these directly, use
2449 * getDesiredThumbnailWidth() or getDesiredThumbnailHeight().
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002450 */
Leon Scrogginsf8551612009-09-24 16:06:02 -04002451 private static int THUMBNAIL_WIDTH = 0;
2452 private static int THUMBNAIL_HEIGHT = 0;
2453
2454 /**
2455 * Return the desired width for thumbnail screenshots, which are stored in
2456 * the database, and used on the bookmarks screen.
2457 * @param context Context for finding out the density of the screen.
2458 * @return int desired width for thumbnail screenshot.
2459 */
2460 /* package */ static int getDesiredThumbnailWidth(Context context) {
2461 if (THUMBNAIL_WIDTH == 0) {
2462 float density = context.getResources().getDisplayMetrics().density;
2463 THUMBNAIL_WIDTH = (int) (90 * density);
2464 THUMBNAIL_HEIGHT = (int) (80 * density);
2465 }
2466 return THUMBNAIL_WIDTH;
2467 }
2468
2469 /**
2470 * Return the desired height for thumbnail screenshots, which are stored in
2471 * the database, and used on the bookmarks screen.
2472 * @param context Context for finding out the density of the screen.
2473 * @return int desired height for thumbnail screenshot.
2474 */
2475 /* package */ static int getDesiredThumbnailHeight(Context context) {
2476 // To ensure that they are both initialized.
2477 getDesiredThumbnailWidth(context);
2478 return THUMBNAIL_HEIGHT;
2479 }
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002480
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002481 private Bitmap createScreenshot(WebView view) {
2482 Picture thumbnail = view.capturePicture();
Leon Scroggins45800572009-09-29 16:38:47 -04002483 if (thumbnail == null) {
2484 return null;
2485 }
Leon Scrogginsf8551612009-09-24 16:06:02 -04002486 Bitmap bm = Bitmap.createBitmap(getDesiredThumbnailWidth(this),
Cary Clarkab168ba2010-04-08 09:11:28 -04002487 getDesiredThumbnailHeight(this), Bitmap.Config.RGB_565);
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002488 Canvas canvas = new Canvas(bm);
2489 // May need to tweak these values to determine what is the
2490 // best scale factor
Ben Murdoch2694e232009-09-29 09:41:11 +01002491 int thumbnailWidth = thumbnail.getWidth();
Ben Murdochae59c3f2009-10-20 18:30:28 +01002492 int thumbnailHeight = thumbnail.getHeight();
2493 float scaleFactorX = 1.0f;
2494 float scaleFactorY = 1.0f;
Ben Murdoch2694e232009-09-29 09:41:11 +01002495 if (thumbnailWidth > 0) {
Ben Murdochae59c3f2009-10-20 18:30:28 +01002496 scaleFactorX = (float) getDesiredThumbnailWidth(this) /
Ben Murdoch2694e232009-09-29 09:41:11 +01002497 (float)thumbnailWidth;
Ben Murdochae59c3f2009-10-20 18:30:28 +01002498 } else {
2499 return null;
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002500 }
Ben Murdochae59c3f2009-10-20 18:30:28 +01002501
2502 if (view.getWidth() > view.getHeight() &&
2503 thumbnailHeight < view.getHeight() && thumbnailHeight > 0) {
2504 // If the device is in landscape and the page is shorter
2505 // than the height of the view, stretch the thumbnail to fill the
2506 // space.
2507 scaleFactorY = (float) getDesiredThumbnailHeight(this) /
2508 (float)thumbnailHeight;
2509 } else {
2510 // In the portrait case, this looks nice.
2511 scaleFactorY = scaleFactorX;
2512 }
2513
2514 canvas.scale(scaleFactorX, scaleFactorY);
2515
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002516 thumbnail.draw(canvas);
2517 return bm;
2518 }
2519
The Android Open Source Project0c908882009-03-03 19:32:16 -08002520 // -------------------------------------------------------------------------
Grace Kloba22ac16e2009-10-07 18:00:23 -07002521 // Helper function for WebViewClient.
The Android Open Source Project0c908882009-03-03 19:32:16 -08002522 //-------------------------------------------------------------------------
2523
2524 // Use in overrideUrlLoading
2525 /* package */ final static String SCHEME_WTAI = "wtai://wp/";
2526 /* package */ final static String SCHEME_WTAI_MC = "wtai://wp/mc;";
2527 /* package */ final static String SCHEME_WTAI_SD = "wtai://wp/sd;";
2528 /* package */ final static String SCHEME_WTAI_AP = "wtai://wp/ap;";
2529
Leon Scroggins92472e82010-02-17 16:32:28 -05002530 // Keep this initial progress in sync with initialProgressValue (* 100)
2531 // in ProgressTracker.cpp
2532 private final static int INITIAL_PROGRESS = 10;
2533
Grace Kloba22ac16e2009-10-07 18:00:23 -07002534 void onPageStarted(WebView view, String url, Bitmap favicon) {
2535 // when BrowserActivity just starts, onPageStarted may be called before
2536 // onResume as it is triggered from onCreate. Call resumeWebViewTimers
2537 // to start the timer. As we won't switch tabs while an activity is in
2538 // pause state, we can ensure calling resume and pause in pair.
2539 if (mActivityInPause) resumeWebViewTimers();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002540
Grace Kloba22ac16e2009-10-07 18:00:23 -07002541 resetLockIcon(url);
2542 setUrlTitle(url, null);
2543 setFavicon(favicon);
Leon Scroggins8cf8f682009-11-04 11:13:50 -08002544 // Show some progress so that the user knows the page is beginning to
2545 // load
Leon Scroggins92472e82010-02-17 16:32:28 -05002546 onProgressChanged(view, INITIAL_PROGRESS);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002547 mDidStopLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07002548 if (!mIsNetworkUp) createAndShowNetworkDialog();
Cary Clark01cfcdd2010-06-04 16:36:45 -04002549 closeDialogs();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002550 if (mSettings.isTracing()) {
2551 String host;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002552 try {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002553 WebAddress uri = new WebAddress(url);
2554 host = uri.mHost;
2555 } catch (android.net.ParseException ex) {
2556 host = "browser";
The Android Open Source Project0c908882009-03-03 19:32:16 -08002557 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002558 host = host.replace('.', '_');
2559 host += ".trace";
2560 mInTrace = true;
2561 Debug.startMethodTracing(host, 20 * 1024 * 1024);
2562 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002563
Grace Kloba22ac16e2009-10-07 18:00:23 -07002564 // Performance probe
2565 if (false) {
2566 mStart = SystemClock.uptimeMillis();
2567 mProcessStart = Process.getElapsedCpuTime();
2568 long[] sysCpu = new long[7];
2569 if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null,
2570 sysCpu, null)) {
2571 mUserStart = sysCpu[0] + sysCpu[1];
2572 mSystemStart = sysCpu[2];
2573 mIdleStart = sysCpu[3];
2574 mIrqStart = sysCpu[4] + sysCpu[5] + sysCpu[6];
2575 }
2576 mUiStart = SystemClock.currentThreadTimeMillis();
2577 }
2578 }
2579
2580 void onPageFinished(WebView view, String url) {
2581 // Reset the title and icon in case we stopped a provisional load.
2582 resetTitleAndIcon(view);
2583 // Update the lock icon image only once we are done loading
2584 updateLockIconToLatest();
2585 // pause the WebView timer and release the wake lock if it is finished
2586 // while BrowserActivity is in pause state.
2587 if (mActivityInPause && pauseWebViewTimers()) {
2588 if (mWakeLock.isHeld()) {
2589 mHandler.removeMessages(RELEASE_WAKELOCK);
2590 mWakeLock.release();
2591 }
2592 }
2593
2594 // Performance probe
2595 if (false) {
2596 long[] sysCpu = new long[7];
2597 if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null,
2598 sysCpu, null)) {
2599 String uiInfo = "UI thread used "
2600 + (SystemClock.currentThreadTimeMillis() - mUiStart)
2601 + " ms";
2602 if (LOGD_ENABLED) {
2603 Log.d(LOGTAG, uiInfo);
2604 }
2605 //The string that gets written to the log
2606 String performanceString = "It took total "
2607 + (SystemClock.uptimeMillis() - mStart)
2608 + " ms clock time to load the page."
2609 + "\nbrowser process used "
2610 + (Process.getElapsedCpuTime() - mProcessStart)
2611 + " ms, user processes used "
2612 + (sysCpu[0] + sysCpu[1] - mUserStart) * 10
2613 + " ms, kernel used "
2614 + (sysCpu[2] - mSystemStart) * 10
2615 + " ms, idle took " + (sysCpu[3] - mIdleStart) * 10
2616 + " ms and irq took "
2617 + (sysCpu[4] + sysCpu[5] + sysCpu[6] - mIrqStart)
2618 * 10 + " ms, " + uiInfo;
2619 if (LOGD_ENABLED) {
2620 Log.d(LOGTAG, performanceString + "\nWebpage: " + url);
2621 }
2622 if (url != null) {
2623 // strip the url to maintain consistency
2624 String newUrl = new String(url);
2625 if (newUrl.startsWith("http://www.")) {
2626 newUrl = newUrl.substring(11);
2627 } else if (newUrl.startsWith("http://")) {
2628 newUrl = newUrl.substring(7);
2629 } else if (newUrl.startsWith("https://www.")) {
2630 newUrl = newUrl.substring(12);
2631 } else if (newUrl.startsWith("https://")) {
2632 newUrl = newUrl.substring(8);
2633 }
2634 if (LOGD_ENABLED) {
2635 Log.d(LOGTAG, newUrl + " loaded");
2636 }
Grace Kloba5b078b52009-06-24 20:23:41 -07002637 }
2638 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002639 }
Grace Kloba5b078b52009-06-24 20:23:41 -07002640
Grace Kloba22ac16e2009-10-07 18:00:23 -07002641 if (mInTrace) {
2642 mInTrace = false;
2643 Debug.stopMethodTracing();
2644 }
2645 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002646
Grace Kloba22ac16e2009-10-07 18:00:23 -07002647 boolean shouldOverrideUrlLoading(WebView view, String url) {
2648 if (url.startsWith(SCHEME_WTAI)) {
2649 // wtai://wp/mc;number
2650 // number=string(phone-number)
2651 if (url.startsWith(SCHEME_WTAI_MC)) {
2652 Intent intent = new Intent(Intent.ACTION_VIEW,
2653 Uri.parse(WebView.SCHEME_TEL +
2654 url.substring(SCHEME_WTAI_MC.length())));
2655 startActivity(intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002656 return true;
2657 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002658 // wtai://wp/sd;dtmf
2659 // dtmf=string(dialstring)
2660 if (url.startsWith(SCHEME_WTAI_SD)) {
2661 // TODO: only send when there is active voice connection
2662 return false;
2663 }
2664 // wtai://wp/ap;number;name
2665 // number=string(phone-number)
2666 // name=string
2667 if (url.startsWith(SCHEME_WTAI_AP)) {
2668 // TODO
2669 return false;
2670 }
2671 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002672
Grace Kloba22ac16e2009-10-07 18:00:23 -07002673 // The "about:" schemes are internal to the browser; don't want these to
2674 // be dispatched to other apps.
2675 if (url.startsWith("about:")) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002676 return false;
2677 }
2678
Grace Kloba22ac16e2009-10-07 18:00:23 -07002679 Intent intent;
2680 // perform generic parsing of the URI to turn it into an Intent.
2681 try {
2682 intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
2683 } catch (URISyntaxException ex) {
2684 Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage());
2685 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002686 }
2687
Grace Kloba22ac16e2009-10-07 18:00:23 -07002688 // check whether the intent can be resolved. If not, we will see
2689 // whether we can download it from the Market.
2690 if (getPackageManager().resolveActivity(intent, 0) == null) {
2691 String packagename = intent.getPackage();
2692 if (packagename != null) {
2693 intent = new Intent(Intent.ACTION_VIEW, Uri
2694 .parse("market://search?q=pname:" + packagename));
2695 intent.addCategory(Intent.CATEGORY_BROWSABLE);
2696 startActivity(intent);
2697 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002698 } else {
2699 return false;
2700 }
2701 }
2702
Grace Kloba22ac16e2009-10-07 18:00:23 -07002703 // sanitize the Intent, ensuring web pages can not bypass browser
2704 // security (only access to BROWSABLE activities).
2705 intent.addCategory(Intent.CATEGORY_BROWSABLE);
2706 intent.setComponent(null);
2707 try {
2708 if (startActivityIfNeeded(intent, -1)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002709 return true;
2710 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002711 } catch (ActivityNotFoundException ex) {
2712 // ignore the error. If no application can handle the URL,
2713 // eg about:blank, assume the browser can handle it.
2714 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002715
Grace Kloba22ac16e2009-10-07 18:00:23 -07002716 if (mMenuIsDown) {
2717 openTab(url);
2718 closeOptionsMenu();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002719 return true;
2720 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002721 return false;
2722 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002723
Grace Kloba22ac16e2009-10-07 18:00:23 -07002724 // -------------------------------------------------------------------------
2725 // Helper function for WebChromeClient
2726 // -------------------------------------------------------------------------
The Android Open Source Project0c908882009-03-03 19:32:16 -08002727
Grace Kloba22ac16e2009-10-07 18:00:23 -07002728 void onProgressChanged(WebView view, int newProgress) {
Leon Scrogginsd746a942010-05-19 13:21:44 -04002729 if (mXLargeScreenSize) {
2730 mTitleBar.setProgress(newProgress);
2731 } else {
2732 // On the phone, the fake title bar will always cover up the
2733 // regular title bar (or the regular one is offscreen), so only the
2734 // fake title bar needs to change its progress
2735 mFakeTitleBar.setProgress(newProgress);
2736 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002737
Grace Kloba22ac16e2009-10-07 18:00:23 -07002738 if (newProgress == 100) {
2739 // onProgressChanged() may continue to be called after the main
2740 // frame has finished loading, as any remaining sub frames continue
2741 // to load. We'll only get called once though with newProgress as
2742 // 100 when everything is loaded. (onPageFinished is called once
2743 // when the main frame completes loading regardless of the state of
2744 // any sub frames so calls to onProgressChanges may continue after
2745 // onPageFinished has executed)
2746 if (mInLoad) {
2747 mInLoad = false;
Leon Scrogginsa27ff192009-09-14 12:58:04 -04002748 updateInLoadMenuItems();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002749 // If the options menu is open, leave the title bar
2750 if (!mOptionsMenuOpen || !mIconView) {
2751 hideFakeTitleBar();
The Android Open Source Projectcb9a0bb2009-03-11 12:11:58 -07002752 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002753 }
Leon Scrogginsaa37e7f2010-03-05 11:51:20 -05002754 } else {
2755 if (!mInLoad) {
2756 // onPageFinished may have already been called but a subframe is
2757 // still loading and updating the progress. Reset mInLoad and
2758 // update the menu items.
2759 mInLoad = true;
2760 updateInLoadMenuItems();
2761 }
2762 // When the page first begins to load, the Activity may still be
2763 // paused, in which case showFakeTitleBar will do nothing. Call
2764 // again as the page continues to load so that it will be shown.
2765 // (Calling it will the fake title bar is already showing will also
2766 // do nothing.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002767 if (!mOptionsMenuOpen || mIconView) {
2768 // This page has begun to load, so show the title bar
2769 showFakeTitleBar();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002770 }
2771 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002772 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002773
Grace Kloba22ac16e2009-10-07 18:00:23 -07002774 void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
Derek Sollenberger8ff57db2009-12-08 15:39:55 -05002775 // if a view already exists then immediately terminate the new one
2776 if (mCustomView != null) {
2777 callback.onCustomViewHidden();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002778 return;
Derek Sollenberger8ff57db2009-12-08 15:39:55 -05002779 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002780
2781 // Add the custom view to its container.
2782 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
2783 mCustomView = view;
2784 mCustomViewCallback = callback;
2785 // Save the menu state and set it to empty while the custom
2786 // view is showing.
2787 mOldMenuState = mMenuState;
2788 mMenuState = EMPTY_MENU;
2789 // Hide the content view.
2790 mContentView.setVisibility(View.GONE);
2791 // Finally show the custom view container.
Andrei Popescu163ab742009-10-20 17:58:23 +01002792 setStatusBarVisibility(false);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002793 mCustomViewContainer.setVisibility(View.VISIBLE);
2794 mCustomViewContainer.bringToFront();
2795 }
2796
2797 void onHideCustomView() {
2798 if (mCustomView == null)
2799 return;
2800
2801 // Hide the custom view.
2802 mCustomView.setVisibility(View.GONE);
2803 // Remove the custom view from its container.
2804 mCustomViewContainer.removeView(mCustomView);
2805 mCustomView = null;
2806 // Reset the old menu state.
2807 mMenuState = mOldMenuState;
2808 mOldMenuState = EMPTY_MENU;
2809 mCustomViewContainer.setVisibility(View.GONE);
2810 mCustomViewCallback.onCustomViewHidden();
2811 // Show the content view.
Andrei Popescu163ab742009-10-20 17:58:23 +01002812 setStatusBarVisibility(true);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002813 mContentView.setVisibility(View.VISIBLE);
2814 }
2815
2816 Bitmap getDefaultVideoPoster() {
2817 if (mDefaultVideoPoster == null) {
2818 mDefaultVideoPoster = BitmapFactory.decodeResource(
2819 getResources(), R.drawable.default_video_poster);
Patrick Scott3918d442009-08-04 13:22:29 -04002820 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002821 return mDefaultVideoPoster;
2822 }
Patrick Scott3918d442009-08-04 13:22:29 -04002823
Grace Kloba22ac16e2009-10-07 18:00:23 -07002824 View getVideoLoadingProgressView() {
2825 if (mVideoProgressView == null) {
2826 LayoutInflater inflater = LayoutInflater.from(BrowserActivity.this);
2827 mVideoProgressView = inflater.inflate(
2828 R.layout.video_loading_progress, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002829 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002830 return mVideoProgressView;
2831 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002832
Leon Scroggins8d5fa432009-10-02 15:55:59 -04002833 /*
2834 * The Object used to inform the WebView of the file to upload.
2835 */
2836 private ValueCallback<Uri> mUploadMessage;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002837 private String mCameraFilePath;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04002838
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002839 void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
2840
2841 final String imageMimeType = "image/*";
2842 final String imageSourceKey = "source";
2843 final String imageSourceValueCamera = "camera";
2844 final String imageSourceValueGallery = "gallery";
2845
2846 // image source can be 'gallery' or 'camera'.
2847 String imageSource = "";
2848
2849 // We add the camera intent if there was no accept type (or '*/*') or 'image/*'.
2850 boolean addCameraIntent = true;
2851
Grace Kloba22ac16e2009-10-07 18:00:23 -07002852 if (mUploadMessage != null) return;
2853 mUploadMessage = uploadMsg;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002854
2855 // Parse the accept type.
2856 String params[] = acceptType.split(";");
2857 String mimeType = params[0];
2858
2859 for (String p : params) {
2860 String[] keyValue = p.split("=");
2861 if (keyValue.length == 2) {
2862 // Process key=value parameters.
2863 if (imageSourceKey.equals(keyValue[0])) {
2864 imageSource = keyValue[1];
2865 }
2866 }
2867 }
2868
2869 // This intent will display the standard OPENABLE file picker.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002870 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
2871 i.addCategory(Intent.CATEGORY_OPENABLE);
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002872
2873 // Create an intent to add to the standard file picker that will
2874 // capture an image from the camera. We'll combine this intent with
2875 // the standard OPENABLE picker unless the web developer specifically
2876 // requested the camera or gallery be opened by passing a parameter
2877 // in the accept type.
2878 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
2879 File externalDataDir = Environment.getExternalStoragePublicDirectory(
2880 Environment.DIRECTORY_DCIM);
2881 File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
2882 File.separator + "browser-photos");
2883 cameraDataDir.mkdirs();
2884 mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator +
2885 System.currentTimeMillis() + ".jpg";
2886 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath)));
2887
2888 if (mimeType.equals(imageMimeType)) {
2889 i.setType(imageMimeType);
2890 if (imageSource.equals(imageSourceValueCamera)) {
2891 // Specified 'image/*' and requested the camera, so go ahead and launch the camera
2892 // directly.
2893 BrowserActivity.this.startActivityForResult(cameraIntent, FILE_SELECTED);
2894 return;
2895 } else if (imageSource.equals(imageSourceValueGallery)) {
2896 // Specified gallery as the source, so don't want to consider the camera.
2897 addCameraIntent = false;
2898 }
2899 } else {
2900 i.setType("*/*");
2901 }
2902
2903 // Combine the chooser and the extra choices (like camera)
2904 Intent chooser = new Intent(Intent.ACTION_CHOOSER);
2905 chooser.putExtra(Intent.EXTRA_INTENT, i);
2906
2907 if (addCameraIntent) {
2908 // Add the camera Intent
2909 Intent[] choices = new Intent[1];
2910 choices[0] = cameraIntent;
2911 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, choices);
2912 }
2913
2914 chooser.putExtra(Intent.EXTRA_TITLE, getString(R.string.choose_upload));
2915 BrowserActivity.this.startActivityForResult(chooser, FILE_SELECTED);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002916 }
2917
2918 // -------------------------------------------------------------------------
2919 // Implement functions for DownloadListener
2920 // -------------------------------------------------------------------------
2921
The Android Open Source Project0c908882009-03-03 19:32:16 -08002922 /**
2923 * Notify the host application a download should be done, or that
2924 * the data should be streamed if a streaming viewer is available.
2925 * @param url The full url to the content that should be downloaded
2926 * @param contentDisposition Content-disposition http header, if
2927 * present.
2928 * @param mimetype The mimetype of the content reported by the server
2929 * @param contentLength The file size reported by the server
2930 */
2931 public void onDownloadStart(String url, String userAgent,
2932 String contentDisposition, String mimetype, long contentLength) {
2933 // if we're dealing wih A/V content that's not explicitly marked
2934 // for download, check if it's streamable.
2935 if (contentDisposition == null
Patrick Scotte1fb9662009-08-31 14:31:52 -04002936 || !contentDisposition.regionMatches(
2937 true, 0, "attachment", 0, 10)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002938 // query the package manager to see if there's a registered handler
2939 // that matches.
2940 Intent intent = new Intent(Intent.ACTION_VIEW);
2941 intent.setDataAndType(Uri.parse(url), mimetype);
Patrick Scotte1fb9662009-08-31 14:31:52 -04002942 ResolveInfo info = getPackageManager().resolveActivity(intent,
2943 PackageManager.MATCH_DEFAULT_ONLY);
2944 if (info != null) {
2945 ComponentName myName = getComponentName();
2946 // If we resolved to ourselves, we don't want to attempt to
2947 // load the url only to try and download it again.
2948 if (!myName.getPackageName().equals(
2949 info.activityInfo.packageName)
2950 || !myName.getClassName().equals(
2951 info.activityInfo.name)) {
2952 // someone (other than us) knows how to handle this mime
2953 // type with this scheme, don't download.
2954 try {
2955 startActivity(intent);
2956 return;
2957 } catch (ActivityNotFoundException ex) {
2958 if (LOGD_ENABLED) {
2959 Log.d(LOGTAG, "activity not found for " + mimetype
2960 + " over " + Uri.parse(url).getScheme(),
2961 ex);
2962 }
2963 // Best behavior is to fall back to a download in this
2964 // case
The Android Open Source Project0c908882009-03-03 19:32:16 -08002965 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002966 }
2967 }
2968 }
2969 onDownloadStartNoStream(url, userAgent, contentDisposition, mimetype, contentLength);
2970 }
2971
Kristian Monsenfa52d172010-03-25 18:29:21 +00002972 // This is to work around the fact that java.net.URI throws Exceptions
2973 // instead of just encoding URL's properly
2974 // Helper method for onDownloadStartNoStream
2975 private static String encodePath(String path) {
2976 char[] chars = path.toCharArray();
2977
2978 boolean needed = false;
2979 for (char c : chars) {
2980 if (c == '[' || c == ']') {
2981 needed = true;
2982 break;
2983 }
2984 }
2985 if (needed == false) {
2986 return path;
2987 }
2988
2989 StringBuilder sb = new StringBuilder("");
2990 for (char c : chars) {
2991 if (c == '[' || c == ']') {
2992 sb.append('%');
2993 sb.append(Integer.toHexString(c));
2994 } else {
2995 sb.append(c);
2996 }
2997 }
2998
2999 return sb.toString();
3000 }
3001
The Android Open Source Project0c908882009-03-03 19:32:16 -08003002 /**
3003 * Notify the host application a download should be done, even if there
3004 * is a streaming viewer available for thise type.
3005 * @param url The full url to the content that should be downloaded
3006 * @param contentDisposition Content-disposition http header, if
3007 * present.
3008 * @param mimetype The mimetype of the content reported by the server
3009 * @param contentLength The file size reported by the server
3010 */
3011 /*package */ void onDownloadStartNoStream(String url, String userAgent,
3012 String contentDisposition, String mimetype, long contentLength) {
3013
3014 String filename = URLUtil.guessFileName(url,
3015 contentDisposition, mimetype);
3016
3017 // Check to see if we have an SDCard
3018 String status = Environment.getExternalStorageState();
3019 if (!status.equals(Environment.MEDIA_MOUNTED)) {
3020 int title;
3021 String msg;
3022
3023 // Check to see if the SDCard is busy, same as the music app
3024 if (status.equals(Environment.MEDIA_SHARED)) {
3025 msg = getString(R.string.download_sdcard_busy_dlg_msg);
3026 title = R.string.download_sdcard_busy_dlg_title;
3027 } else {
3028 msg = getString(R.string.download_no_sdcard_dlg_msg, filename);
3029 title = R.string.download_no_sdcard_dlg_title;
3030 }
3031
3032 new AlertDialog.Builder(this)
3033 .setTitle(title)
3034 .setIcon(android.R.drawable.ic_dialog_alert)
3035 .setMessage(msg)
3036 .setPositiveButton(R.string.ok, null)
3037 .show();
3038 return;
3039 }
3040
Kristian Monsenfa52d172010-03-25 18:29:21 +00003041 // java.net.URI is a lot stricter than KURL so we have to encode some
3042 // extra characters. Fix for b 2538060 and b 1634719
3043 WebAddress webAddress;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003044 try {
Kristian Monsenfa52d172010-03-25 18:29:21 +00003045 webAddress = new WebAddress(url);
3046 webAddress.mPath = encodePath(webAddress.mPath);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003047 } catch (Exception e) {
Kristian Monsenfa52d172010-03-25 18:29:21 +00003048 // This only happens for very bad urls, we want to chatch the
3049 // exception here
3050 Log.e(LOGTAG, "Exception trying to parse url:" + url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003051 return;
3052 }
3053
3054 // XXX: Have to use the old url since the cookies were stored using the
3055 // old percent-encoded url.
3056 String cookies = CookieManager.getInstance().getCookie(url);
3057
3058 ContentValues values = new ContentValues();
Kristian Monsenfa52d172010-03-25 18:29:21 +00003059 values.put(Downloads.Impl.COLUMN_URI, webAddress.toString());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003060 values.put(Downloads.Impl.COLUMN_COOKIE_DATA, cookies);
3061 values.put(Downloads.Impl.COLUMN_USER_AGENT, userAgent);
3062 values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003063 getPackageName());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003064 values.put(Downloads.Impl.COLUMN_NOTIFICATION_CLASS,
Leon Scrogginsa563d092010-04-19 16:53:49 -04003065 OpenDownloadReceiver.class.getCanonicalName());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003066 values.put(Downloads.Impl.COLUMN_VISIBILITY,
3067 Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
3068 values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimetype);
3069 values.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename);
Kristian Monsenfa52d172010-03-25 18:29:21 +00003070 values.put(Downloads.Impl.COLUMN_DESCRIPTION, webAddress.mHost);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003071 if (contentLength > 0) {
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003072 values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, contentLength);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003073 }
3074 if (mimetype == null) {
3075 // We must have long pressed on a link or image to download it. We
3076 // are not sure of the mimetype in this case, so do a head request
3077 new FetchUrlMimeType(this).execute(values);
3078 } else {
3079 final Uri contentUri =
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003080 getContentResolver().insert(Downloads.Impl.CONTENT_URI, values);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003081 }
Leon Scroggins9191a7f2010-03-18 14:44:44 -04003082 Toast.makeText(this, R.string.download_pending, Toast.LENGTH_SHORT)
3083 .show();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003084 }
3085
Grace Kloba22ac16e2009-10-07 18:00:23 -07003086 // -------------------------------------------------------------------------
3087
The Android Open Source Project0c908882009-03-03 19:32:16 -08003088 /**
3089 * Resets the lock icon. This method is called when we start a new load and
3090 * know the url to be loaded.
3091 */
3092 private void resetLockIcon(String url) {
3093 // Save the lock-icon state (we revert to it if the load gets cancelled)
Grace Kloba22ac16e2009-10-07 18:00:23 -07003094 mTabControl.getCurrentTab().resetLockIcon(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003095 updateLockIconImage(LOCK_ICON_UNSECURE);
3096 }
3097
The Android Open Source Project0c908882009-03-03 19:32:16 -08003098 /**
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -04003099 * Update the lock icon to correspond to our latest state.
3100 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003101 private void updateLockIconToLatest() {
3102 updateLockIconImage(mTabControl.getCurrentTab().getLockIconType());
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -04003103 }
3104
3105 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -08003106 * Updates the lock-icon image in the title-bar.
3107 */
3108 private void updateLockIconImage(int lockIconType) {
3109 Drawable d = null;
3110 if (lockIconType == LOCK_ICON_SECURE) {
3111 d = mSecLockIcon;
3112 } else if (lockIconType == LOCK_ICON_MIXED) {
3113 d = mMixLockIcon;
3114 }
Leon Scroggins68579392009-09-15 15:31:54 -04003115 mTitleBar.setLock(d);
Leon Scrogginsd746a942010-05-19 13:21:44 -04003116 if (!mXLargeScreenSize) {
3117 mFakeTitleBar.setLock(d);
3118 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003119 }
3120
3121 /**
3122 * Displays a page-info dialog.
3123 * @param tab The tab to show info about
3124 * @param fromShowSSLCertificateOnError The flag that indicates whether
3125 * this dialog was opened from the SSL-certificate-on-error dialog or
3126 * not. This is important, since we need to know whether to return to
3127 * the parent dialog or simply dismiss.
3128 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003129 private void showPageInfo(final Tab tab,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003130 final boolean fromShowSSLCertificateOnError) {
3131 final LayoutInflater factory = LayoutInflater
3132 .from(this);
3133
3134 final View pageInfoView = factory.inflate(R.layout.page_info, null);
3135
3136 final WebView view = tab.getWebView();
3137
3138 String url = null;
3139 String title = null;
3140
3141 if (view == null) {
3142 url = tab.getUrl();
3143 title = tab.getTitle();
3144 } else if (view == mTabControl.getCurrentWebView()) {
3145 // Use the cached title and url if this is the current WebView
3146 url = mUrl;
3147 title = mTitle;
3148 } else {
3149 url = view.getUrl();
3150 title = view.getTitle();
3151 }
3152
3153 if (url == null) {
3154 url = "";
3155 }
3156 if (title == null) {
3157 title = "";
3158 }
3159
3160 ((TextView) pageInfoView.findViewById(R.id.address)).setText(url);
3161 ((TextView) pageInfoView.findViewById(R.id.title)).setText(title);
3162
3163 mPageInfoView = tab;
Leon Scrogginsc7b92f82010-01-11 18:17:31 -05003164 mPageInfoFromShowSSLCertificateOnError = fromShowSSLCertificateOnError;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003165
3166 AlertDialog.Builder alertDialogBuilder =
3167 new AlertDialog.Builder(this)
3168 .setTitle(R.string.page_info).setIcon(android.R.drawable.ic_dialog_info)
3169 .setView(pageInfoView)
3170 .setPositiveButton(
3171 R.string.ok,
3172 new DialogInterface.OnClickListener() {
3173 public void onClick(DialogInterface dialog,
3174 int whichButton) {
3175 mPageInfoDialog = null;
3176 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003177
3178 // if we came here from the SSL error dialog
3179 if (fromShowSSLCertificateOnError) {
3180 // go back to the SSL error dialog
3181 showSSLCertificateOnError(
3182 mSSLCertificateOnErrorView,
3183 mSSLCertificateOnErrorHandler,
3184 mSSLCertificateOnErrorError);
3185 }
3186 }
3187 })
3188 .setOnCancelListener(
3189 new DialogInterface.OnCancelListener() {
3190 public void onCancel(DialogInterface dialog) {
3191 mPageInfoDialog = null;
3192 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003193
3194 // if we came here from the SSL error dialog
3195 if (fromShowSSLCertificateOnError) {
3196 // go back to the SSL error dialog
3197 showSSLCertificateOnError(
3198 mSSLCertificateOnErrorView,
3199 mSSLCertificateOnErrorHandler,
3200 mSSLCertificateOnErrorError);
3201 }
3202 }
3203 });
3204
3205 // if we have a main top-level page SSL certificate set or a certificate
3206 // error
3207 if (fromShowSSLCertificateOnError ||
3208 (view != null && view.getCertificate() != null)) {
3209 // add a 'View Certificate' button
3210 alertDialogBuilder.setNeutralButton(
3211 R.string.view_certificate,
3212 new DialogInterface.OnClickListener() {
3213 public void onClick(DialogInterface dialog,
3214 int whichButton) {
3215 mPageInfoDialog = null;
3216 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003217
3218 // if we came here from the SSL error dialog
3219 if (fromShowSSLCertificateOnError) {
3220 // go back to the SSL error dialog
3221 showSSLCertificateOnError(
3222 mSSLCertificateOnErrorView,
3223 mSSLCertificateOnErrorHandler,
3224 mSSLCertificateOnErrorError);
3225 } else {
3226 // otherwise, display the top-most certificate from
3227 // the chain
3228 if (view.getCertificate() != null) {
3229 showSSLCertificate(tab);
3230 }
3231 }
3232 }
3233 });
3234 }
3235
3236 mPageInfoDialog = alertDialogBuilder.show();
3237 }
3238
3239 /**
3240 * Displays the main top-level page SSL certificate dialog
3241 * (accessible from the Page-Info dialog).
3242 * @param tab The tab to show certificate for.
3243 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003244 private void showSSLCertificate(final Tab tab) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003245 final View certificateView =
3246 inflateCertificateView(tab.getWebView().getCertificate());
3247 if (certificateView == null) {
3248 return;
3249 }
3250
3251 LayoutInflater factory = LayoutInflater.from(this);
3252
3253 final LinearLayout placeholder =
3254 (LinearLayout)certificateView.findViewById(R.id.placeholder);
3255
3256 LinearLayout ll = (LinearLayout) factory.inflate(
3257 R.layout.ssl_success, placeholder);
3258 ((TextView)ll.findViewById(R.id.success))
3259 .setText(R.string.ssl_certificate_is_valid);
3260
3261 mSSLCertificateView = tab;
3262 mSSLCertificateDialog =
3263 new AlertDialog.Builder(this)
3264 .setTitle(R.string.ssl_certificate).setIcon(
3265 R.drawable.ic_dialog_browser_certificate_secure)
3266 .setView(certificateView)
3267 .setPositiveButton(R.string.ok,
3268 new DialogInterface.OnClickListener() {
3269 public void onClick(DialogInterface dialog,
3270 int whichButton) {
3271 mSSLCertificateDialog = null;
3272 mSSLCertificateView = null;
3273
3274 showPageInfo(tab, false);
3275 }
3276 })
3277 .setOnCancelListener(
3278 new DialogInterface.OnCancelListener() {
3279 public void onCancel(DialogInterface dialog) {
3280 mSSLCertificateDialog = null;
3281 mSSLCertificateView = null;
3282
3283 showPageInfo(tab, false);
3284 }
3285 })
3286 .show();
3287 }
3288
3289 /**
3290 * Displays the SSL error certificate dialog.
3291 * @param view The target web-view.
3292 * @param handler The SSL error handler responsible for cancelling the
3293 * connection that resulted in an SSL error or proceeding per user request.
3294 * @param error The SSL error object.
3295 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003296 void showSSLCertificateOnError(
The Android Open Source Project0c908882009-03-03 19:32:16 -08003297 final WebView view, final SslErrorHandler handler, final SslError error) {
3298
3299 final View certificateView =
3300 inflateCertificateView(error.getCertificate());
3301 if (certificateView == null) {
3302 return;
3303 }
3304
3305 LayoutInflater factory = LayoutInflater.from(this);
3306
3307 final LinearLayout placeholder =
3308 (LinearLayout)certificateView.findViewById(R.id.placeholder);
3309
3310 if (error.hasError(SslError.SSL_UNTRUSTED)) {
3311 LinearLayout ll = (LinearLayout)factory
3312 .inflate(R.layout.ssl_warning, placeholder);
3313 ((TextView)ll.findViewById(R.id.warning))
3314 .setText(R.string.ssl_untrusted);
3315 }
3316
3317 if (error.hasError(SslError.SSL_IDMISMATCH)) {
3318 LinearLayout ll = (LinearLayout)factory
3319 .inflate(R.layout.ssl_warning, placeholder);
3320 ((TextView)ll.findViewById(R.id.warning))
3321 .setText(R.string.ssl_mismatch);
3322 }
3323
3324 if (error.hasError(SslError.SSL_EXPIRED)) {
3325 LinearLayout ll = (LinearLayout)factory
3326 .inflate(R.layout.ssl_warning, placeholder);
3327 ((TextView)ll.findViewById(R.id.warning))
3328 .setText(R.string.ssl_expired);
3329 }
3330
3331 if (error.hasError(SslError.SSL_NOTYETVALID)) {
3332 LinearLayout ll = (LinearLayout)factory
3333 .inflate(R.layout.ssl_warning, placeholder);
3334 ((TextView)ll.findViewById(R.id.warning))
3335 .setText(R.string.ssl_not_yet_valid);
3336 }
3337
3338 mSSLCertificateOnErrorHandler = handler;
3339 mSSLCertificateOnErrorView = view;
3340 mSSLCertificateOnErrorError = error;
3341 mSSLCertificateOnErrorDialog =
3342 new AlertDialog.Builder(this)
3343 .setTitle(R.string.ssl_certificate).setIcon(
3344 R.drawable.ic_dialog_browser_certificate_partially_secure)
3345 .setView(certificateView)
3346 .setPositiveButton(R.string.ok,
3347 new DialogInterface.OnClickListener() {
3348 public void onClick(DialogInterface dialog,
3349 int whichButton) {
3350 mSSLCertificateOnErrorDialog = null;
3351 mSSLCertificateOnErrorView = null;
3352 mSSLCertificateOnErrorHandler = null;
3353 mSSLCertificateOnErrorError = null;
3354
Grace Kloba22ac16e2009-10-07 18:00:23 -07003355 view.getWebViewClient().onReceivedSslError(
3356 view, handler, error);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003357 }
3358 })
3359 .setNeutralButton(R.string.page_info_view,
3360 new DialogInterface.OnClickListener() {
3361 public void onClick(DialogInterface dialog,
3362 int whichButton) {
3363 mSSLCertificateOnErrorDialog = null;
3364
3365 // do not clear the dialog state: we will
3366 // need to show the dialog again once the
3367 // user is done exploring the page-info details
3368
3369 showPageInfo(mTabControl.getTabFromView(view),
3370 true);
3371 }
3372 })
3373 .setOnCancelListener(
3374 new DialogInterface.OnCancelListener() {
3375 public void onCancel(DialogInterface dialog) {
3376 mSSLCertificateOnErrorDialog = null;
3377 mSSLCertificateOnErrorView = null;
3378 mSSLCertificateOnErrorHandler = null;
3379 mSSLCertificateOnErrorError = null;
3380
Grace Kloba22ac16e2009-10-07 18:00:23 -07003381 view.getWebViewClient().onReceivedSslError(
3382 view, handler, error);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003383 }
3384 })
3385 .show();
3386 }
3387
3388 /**
3389 * Inflates the SSL certificate view (helper method).
3390 * @param certificate The SSL certificate.
3391 * @return The resultant certificate view with issued-to, issued-by,
3392 * issued-on, expires-on, and possibly other fields set.
3393 * If the input certificate is null, returns null.
3394 */
3395 private View inflateCertificateView(SslCertificate certificate) {
3396 if (certificate == null) {
3397 return null;
3398 }
3399
3400 LayoutInflater factory = LayoutInflater.from(this);
3401
3402 View certificateView = factory.inflate(
3403 R.layout.ssl_certificate, null);
3404
3405 // issued to:
3406 SslCertificate.DName issuedTo = certificate.getIssuedTo();
3407 if (issuedTo != null) {
3408 ((TextView) certificateView.findViewById(R.id.to_common))
3409 .setText(issuedTo.getCName());
3410 ((TextView) certificateView.findViewById(R.id.to_org))
3411 .setText(issuedTo.getOName());
3412 ((TextView) certificateView.findViewById(R.id.to_org_unit))
3413 .setText(issuedTo.getUName());
3414 }
3415
3416 // issued by:
3417 SslCertificate.DName issuedBy = certificate.getIssuedBy();
3418 if (issuedBy != null) {
3419 ((TextView) certificateView.findViewById(R.id.by_common))
3420 .setText(issuedBy.getCName());
3421 ((TextView) certificateView.findViewById(R.id.by_org))
3422 .setText(issuedBy.getOName());
3423 ((TextView) certificateView.findViewById(R.id.by_org_unit))
3424 .setText(issuedBy.getUName());
3425 }
3426
3427 // issued on:
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003428 String issuedOn = formatCertificateDate(
3429 certificate.getValidNotBeforeDate());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003430 ((TextView) certificateView.findViewById(R.id.issued_on))
3431 .setText(issuedOn);
3432
3433 // expires on:
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003434 String expiresOn = formatCertificateDate(
3435 certificate.getValidNotAfterDate());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003436 ((TextView) certificateView.findViewById(R.id.expires_on))
3437 .setText(expiresOn);
3438
3439 return certificateView;
3440 }
3441
3442 /**
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003443 * Formats the certificate date to a properly localized date string.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003444 * @return Properly localized version of the certificate date string and
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003445 * the "" if it fails to localize.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003446 */
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003447 private String formatCertificateDate(Date certificateDate) {
3448 if (certificateDate == null) {
3449 return "";
The Android Open Source Project0c908882009-03-03 19:32:16 -08003450 }
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003451 String formattedDate = DateFormat.getDateFormat(this).format(certificateDate);
3452 if (formattedDate == null) {
3453 return "";
3454 }
3455 return formattedDate;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003456 }
3457
3458 /**
3459 * Displays an http-authentication dialog.
3460 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003461 void showHttpAuthentication(final HttpAuthHandler handler,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003462 final String host, final String realm, final String title,
3463 final String name, final String password, int focusId) {
3464 LayoutInflater factory = LayoutInflater.from(this);
3465 final View v = factory
3466 .inflate(R.layout.http_authentication, null);
3467 if (name != null) {
3468 ((EditText) v.findViewById(R.id.username_edit)).setText(name);
3469 }
3470 if (password != null) {
3471 ((EditText) v.findViewById(R.id.password_edit)).setText(password);
3472 }
3473
3474 String titleText = title;
3475 if (titleText == null) {
3476 titleText = getText(R.string.sign_in_to).toString().replace(
3477 "%s1", host).replace("%s2", realm);
3478 }
3479
3480 mHttpAuthHandler = handler;
3481 AlertDialog dialog = new AlertDialog.Builder(this)
3482 .setTitle(titleText)
3483 .setIcon(android.R.drawable.ic_dialog_alert)
3484 .setView(v)
3485 .setPositiveButton(R.string.action,
3486 new DialogInterface.OnClickListener() {
3487 public void onClick(DialogInterface dialog,
3488 int whichButton) {
3489 String nm = ((EditText) v
3490 .findViewById(R.id.username_edit))
3491 .getText().toString();
3492 String pw = ((EditText) v
3493 .findViewById(R.id.password_edit))
3494 .getText().toString();
3495 BrowserActivity.this.setHttpAuthUsernamePassword
3496 (host, realm, nm, pw);
3497 handler.proceed(nm, pw);
3498 mHttpAuthenticationDialog = null;
3499 mHttpAuthHandler = null;
3500 }})
3501 .setNegativeButton(R.string.cancel,
3502 new DialogInterface.OnClickListener() {
3503 public void onClick(DialogInterface dialog,
3504 int whichButton) {
3505 handler.cancel();
3506 BrowserActivity.this.resetTitleAndRevertLockIcon();
3507 mHttpAuthenticationDialog = null;
3508 mHttpAuthHandler = null;
3509 }})
3510 .setOnCancelListener(new DialogInterface.OnCancelListener() {
3511 public void onCancel(DialogInterface dialog) {
3512 handler.cancel();
3513 BrowserActivity.this.resetTitleAndRevertLockIcon();
3514 mHttpAuthenticationDialog = null;
3515 mHttpAuthHandler = null;
3516 }})
3517 .create();
3518 // Make the IME appear when the dialog is displayed if applicable.
3519 dialog.getWindow().setSoftInputMode(
3520 WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
3521 dialog.show();
3522 if (focusId != 0) {
3523 dialog.findViewById(focusId).requestFocus();
3524 } else {
3525 v.findViewById(R.id.username_edit).requestFocus();
3526 }
3527 mHttpAuthenticationDialog = dialog;
3528 }
3529
3530 public int getProgress() {
3531 WebView w = mTabControl.getCurrentWebView();
3532 if (w != null) {
3533 return w.getProgress();
3534 } else {
3535 return 100;
3536 }
3537 }
3538
3539 /**
3540 * Set HTTP authentication password.
3541 *
3542 * @param host The host for the password
3543 * @param realm The realm for the password
3544 * @param username The username for the password. If it is null, it means
3545 * password can't be saved.
3546 * @param password The password
3547 */
3548 public void setHttpAuthUsernamePassword(String host, String realm,
3549 String username,
3550 String password) {
Steve Block95a53b22010-03-25 17:24:58 +00003551 WebView w = getTopWindow();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003552 if (w != null) {
3553 w.setHttpAuthUsernamePassword(host, realm, username, password);
3554 }
3555 }
3556
3557 /**
3558 * connectivity manager says net has come or gone... inform the user
3559 * @param up true if net has come up, false if net has gone down
3560 */
3561 public void onNetworkToggle(boolean up) {
3562 if (up == mIsNetworkUp) {
3563 return;
3564 } else if (up) {
3565 mIsNetworkUp = true;
3566 if (mAlertDialog != null) {
3567 mAlertDialog.cancel();
3568 mAlertDialog = null;
3569 }
3570 } else {
3571 mIsNetworkUp = false;
Patrick Scotteb6ab2a2009-09-16 10:00:17 -04003572 if (mInLoad) {
3573 createAndShowNetworkDialog();
3574 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003575 }
3576 WebView w = mTabControl.getCurrentWebView();
3577 if (w != null) {
3578 w.setNetworkAvailable(up);
3579 }
3580 }
3581
Grace Kloba22ac16e2009-10-07 18:00:23 -07003582 boolean isNetworkUp() {
3583 return mIsNetworkUp;
3584 }
3585
Patrick Scotteb6ab2a2009-09-16 10:00:17 -04003586 // This method shows the network dialog alerting the user that the net is
3587 // down. It will only show the dialog if mAlertDialog is null.
3588 private void createAndShowNetworkDialog() {
3589 if (mAlertDialog == null) {
3590 mAlertDialog = new AlertDialog.Builder(this)
3591 .setTitle(R.string.loadSuspendedTitle)
3592 .setMessage(R.string.loadSuspended)
3593 .setPositiveButton(R.string.ok, null)
3594 .show();
3595 }
3596 }
3597
The Android Open Source Project0c908882009-03-03 19:32:16 -08003598 @Override
3599 protected void onActivityResult(int requestCode, int resultCode,
3600 Intent intent) {
Grace Klobabb394f32009-11-19 10:26:37 -08003601 if (getTopWindow() == null) return;
3602
The Android Open Source Project0c908882009-03-03 19:32:16 -08003603 switch (requestCode) {
3604 case COMBO_PAGE:
3605 if (resultCode == RESULT_OK && intent != null) {
3606 String data = intent.getAction();
3607 Bundle extras = intent.getExtras();
3608 if (extras != null && extras.getBoolean("new_window", false)) {
Leon Scroggins25d35472009-09-15 11:37:27 -04003609 openTab(data);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003610 } else {
Grace Kloba22ac16e2009-10-07 18:00:23 -07003611 final Tab currentTab =
The Android Open Source Project0c908882009-03-03 19:32:16 -08003612 mTabControl.getCurrentTab();
Leon Scroggins1f005d32009-08-10 17:36:42 -04003613 dismissSubWindow(currentTab);
3614 if (data != null && data.length() != 0) {
Leon Scroggins92472e82010-02-17 16:32:28 -05003615 loadUrl(getTopWindow(), data);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003616 }
3617 }
3618 }
Leon Scrogginsfde97462010-01-11 13:06:21 -05003619 // Deliberately fall through to PREFERENCES_PAGE, since the
3620 // same extra may be attached to the COMBO_PAGE
3621 case PREFERENCES_PAGE:
3622 if (resultCode == RESULT_OK && intent != null) {
3623 String action = intent.getStringExtra(Intent.EXTRA_TEXT);
3624 if (BrowserSettings.PREF_CLEAR_HISTORY.equals(action)) {
3625 mTabControl.removeParentChildRelationShips();
3626 }
3627 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003628 break;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003629 // Choose a file from the file picker.
3630 case FILE_SELECTED:
3631 if (null == mUploadMessage) break;
3632 Uri result = intent == null || resultCode != RESULT_OK ? null
3633 : intent.getData();
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003634
3635 // As we ask the camera to save the result of the user taking
3636 // a picture, the camera application does not return anything other
3637 // than RESULT_OK. So we need to check whether the file we expected
3638 // was written to disk in the in the case that we
3639 // did not get an intent returned but did get a RESULT_OK. If it was,
3640 // we assume that this result has came back from the camera.
3641 if (result == null && intent == null && resultCode == RESULT_OK) {
3642 File cameraFile = new File(mCameraFilePath);
3643 if (cameraFile.exists()) {
3644 result = Uri.fromFile(cameraFile);
Ben Murdoch07d34732010-05-27 18:34:46 +01003645 // Broadcast to the media scanner that we have a new photo
3646 // so it will be added into the gallery for the user.
3647 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003648 }
3649 }
3650
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003651 mUploadMessage.onReceiveValue(result);
3652 mUploadMessage = null;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003653 mCameraFilePath = null;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003654 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003655 default:
3656 break;
3657 }
Leon Scroggins30444232009-09-04 18:36:20 -04003658 getTopWindow().requestFocus();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003659 }
3660
3661 /*
3662 * This method is called as a result of the user selecting the options
Leon Scrogginsf08809b2010-01-21 09:27:46 -05003663 * menu to see the download window. It shows the download window on top of
3664 * the current window.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003665 */
Leon Scrogginsf08809b2010-01-21 09:27:46 -05003666 private void viewDownloads(Uri downloadRecord) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003667 Intent intent = new Intent(this,
3668 BrowserDownloadPage.class);
3669 intent.setData(downloadRecord);
Grace Kloba22ac16e2009-10-07 18:00:23 -07003670 startActivityForResult(intent, BrowserActivity.DOWNLOAD_PAGE);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003671
3672 }
3673
Leon Scroggins160a7e72009-08-14 18:28:01 -04003674 /**
3675 * Open the Go page.
3676 * @param startWithHistory If true, open starting on the history tab.
3677 * Otherwise, start with the bookmarks tab.
Leon Scroggins160a7e72009-08-14 18:28:01 -04003678 */
Leon Scroggins30444232009-09-04 18:36:20 -04003679 /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003680 WebView current = mTabControl.getCurrentWebView();
3681 if (current == null) {
3682 return;
3683 }
3684 Intent intent = new Intent(this,
3685 CombinedBookmarkHistoryActivity.class);
3686 String title = current.getTitle();
3687 String url = current.getUrl();
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01003688 Bitmap thumbnail = createScreenshot(current);
3689
The Android Open Source Project0c908882009-03-03 19:32:16 -08003690 // Just in case the user opens bookmarks before a page finishes loading
3691 // so the current history item, and therefore the page, is null.
3692 if (null == url) {
3693 url = mLastEnteredUrl;
3694 // This can happen.
3695 if (null == url) {
3696 url = mSettings.getHomePage();
3697 }
3698 }
3699 // In case the web page has not yet received its associated title.
3700 if (title == null) {
3701 title = url;
3702 }
3703 intent.putExtra("title", title);
3704 intent.putExtra("url", url);
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01003705 intent.putExtra("thumbnail", thumbnail);
Leon Scroggins30444232009-09-04 18:36:20 -04003706 // Disable opening in a new window if we have maxed out the windows
Grace Kloba22ac16e2009-10-07 18:00:23 -07003707 intent.putExtra("disable_new_window", !mTabControl.canCreateNewTab());
Patrick Scott3918d442009-08-04 13:22:29 -04003708 intent.putExtra("touch_icon_url", current.getTouchIconUrl());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003709 if (startWithHistory) {
3710 intent.putExtra(CombinedBookmarkHistoryActivity.STARTING_TAB,
3711 CombinedBookmarkHistoryActivity.HISTORY_TAB);
3712 }
3713 startActivityForResult(intent, COMBO_PAGE);
3714 }
3715
3716 // Called when loading from context menu or LOAD_URL message
Leon Scroggins92472e82010-02-17 16:32:28 -05003717 private void loadUrlFromContext(WebView view, String url) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003718 // In case the user enters nothing.
3719 if (url != null && url.length() != 0 && view != null) {
3720 url = smartUrlFilter(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -07003721 if (!view.getWebViewClient().shouldOverrideUrlLoading(view, url)) {
Leon Scroggins92472e82010-02-17 16:32:28 -05003722 loadUrl(view, url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003723 }
3724 }
3725 }
3726
Leon Scroggins92472e82010-02-17 16:32:28 -05003727 /**
3728 * Load the URL into the given WebView and update the title bar
3729 * to reflect the new load. Call this instead of WebView.loadUrl
3730 * directly.
3731 * @param view The WebView used to load url.
3732 * @param url The URL to load.
3733 */
3734 private void loadUrl(WebView view, String url) {
3735 updateTitleBarForNewLoad(view, url);
3736 view.loadUrl(url);
3737 }
3738
3739 /**
3740 * Load UrlData into a Tab and update the title bar to reflect the new
3741 * load. Call this instead of UrlData.loadIn directly.
3742 * @param t The Tab used to load.
3743 * @param data The UrlData being loaded.
3744 */
3745 private void loadUrlDataIn(Tab t, UrlData data) {
3746 updateTitleBarForNewLoad(t.getWebView(), data.mUrl);
3747 data.loadIn(t);
3748 }
3749
3750 /**
3751 * If the WebView is the top window, update the title bar to reflect
3752 * loading the new URL. i.e. set its text, clear the favicon (which
3753 * will be set once the page begins loading), and set the progress to
3754 * INITIAL_PROGRESS to show that the page has begun to load. Called
3755 * by loadUrl and loadUrlDataIn.
3756 * @param view The WebView that is starting a load.
3757 * @param url The URL that is being loaded.
3758 */
3759 private void updateTitleBarForNewLoad(WebView view, String url) {
3760 if (view == getTopWindow()) {
3761 setUrlTitle(url, null);
3762 setFavicon(null);
3763 onProgressChanged(view, INITIAL_PROGRESS);
3764 }
3765 }
3766
The Android Open Source Project0c908882009-03-03 19:32:16 -08003767 private String smartUrlFilter(Uri inUri) {
3768 if (inUri != null) {
3769 return smartUrlFilter(inUri.toString());
3770 }
3771 return null;
3772 }
3773
Feng Qianb34f87a2009-03-24 21:27:26 -07003774 protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
The Android Open Source Project0c908882009-03-03 19:32:16 -08003775 "(?i)" + // switch on case insensitive matching
3776 "(" + // begin group for schema
3777 "(?:http|https|file):\\/\\/" +
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07003778 "|(?:inline|data|about|content|javascript):" +
The Android Open Source Project0c908882009-03-03 19:32:16 -08003779 ")" +
3780 "(.*)" );
3781
3782 /**
3783 * Attempts to determine whether user input is a URL or search
3784 * terms. Anything with a space is passed to search.
3785 *
3786 * Converts to lowercase any mistakenly uppercased schema (i.e.,
3787 * "Http://" converts to "http://"
3788 *
3789 * @return Original or modified URL
3790 *
3791 */
3792 String smartUrlFilter(String url) {
3793
3794 String inUrl = url.trim();
3795 boolean hasSpace = inUrl.indexOf(' ') != -1;
3796
3797 Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
3798 if (matcher.matches()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003799 // force scheme to lowercase
3800 String scheme = matcher.group(1);
3801 String lcScheme = scheme.toLowerCase();
3802 if (!lcScheme.equals(scheme)) {
Mitsuru Oshima123ecfb2009-05-18 19:11:14 -07003803 inUrl = lcScheme + matcher.group(2);
3804 }
3805 if (hasSpace) {
3806 inUrl = inUrl.replace(" ", "%20");
The Android Open Source Project0c908882009-03-03 19:32:16 -08003807 }
3808 return inUrl;
3809 }
3810 if (hasSpace) {
Satish Sampath565505b2009-05-29 15:37:27 +01003811 // FIXME: Is this the correct place to add to searches?
3812 // what if someone else calls this function?
3813 int shortcut = parseUrlShortcut(inUrl);
3814 if (shortcut != SHORTCUT_INVALID) {
3815 Browser.addSearchUrl(mResolver, inUrl);
3816 String query = inUrl.substring(2);
3817 switch (shortcut) {
3818 case SHORTCUT_GOOGLE_SEARCH:
Grace Kloba47fdfdb2009-06-30 11:15:34 -07003819 return URLUtil.composeSearchUrl(query, QuickSearch_G, QUERY_PLACE_HOLDER);
Satish Sampath565505b2009-05-29 15:37:27 +01003820 case SHORTCUT_WIKIPEDIA_SEARCH:
3821 return URLUtil.composeSearchUrl(query, QuickSearch_W, QUERY_PLACE_HOLDER);
3822 case SHORTCUT_DICTIONARY_SEARCH:
3823 return URLUtil.composeSearchUrl(query, QuickSearch_D, QUERY_PLACE_HOLDER);
3824 case SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH:
The Android Open Source Project0c908882009-03-03 19:32:16 -08003825 // FIXME: we need location in this case
Satish Sampath565505b2009-05-29 15:37:27 +01003826 return URLUtil.composeSearchUrl(query, QuickSearch_L, QUERY_PLACE_HOLDER);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003827 }
3828 }
3829 } else {
Dan Egnor5ee906c2009-11-18 12:11:49 -08003830 if (Patterns.WEB_URL.matcher(inUrl).matches()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003831 return URLUtil.guessUrl(inUrl);
3832 }
3833 }
3834
3835 Browser.addSearchUrl(mResolver, inUrl);
Grace Kloba47fdfdb2009-06-30 11:15:34 -07003836 return URLUtil.composeSearchUrl(inUrl, QuickSearch_G, QUERY_PLACE_HOLDER);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003837 }
3838
Ben Murdochbff2d602009-07-01 20:19:05 +01003839 /* package */ void setShouldShowErrorConsole(boolean flag) {
3840 if (flag == mShouldShowErrorConsole) {
3841 // Nothing to do.
3842 return;
3843 }
3844
3845 mShouldShowErrorConsole = flag;
3846
Grace Kloba22ac16e2009-10-07 18:00:23 -07003847 ErrorConsoleView errorConsole = mTabControl.getCurrentTab()
3848 .getErrorConsole(true);
Ben Murdochbff2d602009-07-01 20:19:05 +01003849
3850 if (flag) {
3851 // Setting the show state of the console will cause it's the layout to be inflated.
3852 if (errorConsole.numberOfErrors() > 0) {
3853 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
3854 } else {
3855 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
3856 }
3857
3858 // Now we can add it to the main view.
3859 mErrorConsoleContainer.addView(errorConsole,
Romain Guy15b8ec62010-01-08 15:06:43 -08003860 new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
Ben Murdochbff2d602009-07-01 20:19:05 +01003861 ViewGroup.LayoutParams.WRAP_CONTENT));
3862 } else {
3863 mErrorConsoleContainer.removeView(errorConsole);
3864 }
3865
3866 }
3867
Grace Kloba22ac16e2009-10-07 18:00:23 -07003868 boolean shouldShowErrorConsole() {
3869 return mShouldShowErrorConsole;
3870 }
3871
Andrei Popescu163ab742009-10-20 17:58:23 +01003872 private void setStatusBarVisibility(boolean visible) {
3873 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
3874 getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
3875 }
3876
Andrei Popescu56199cc2010-01-12 22:39:16 +00003877
3878 private void sendNetworkType(String type, String subtype) {
3879 WebView w = mTabControl.getCurrentWebView();
3880 if (w != null) {
3881 w.setNetworkType(type, subtype);
3882 }
3883 }
3884
Andrei Popescu30995e72010-02-09 16:59:58 +00003885 private void packageChanged(String packageName, boolean wasAdded) {
3886 WebView w = mTabControl.getCurrentWebView();
3887 if (w == null) {
3888 return;
3889 }
3890
3891 if (wasAdded) {
3892 w.addPackageName(packageName);
3893 } else {
3894 w.removePackageName(packageName);
3895 }
3896 }
3897
3898 private void addPackageNames(Set<String> packageNames) {
3899 WebView w = mTabControl.getCurrentWebView();
3900 if (w == null) {
3901 return;
3902 }
3903
3904 w.addPackageNames(packageNames);
3905 }
3906
3907 private void getInstalledPackages() {
3908 AsyncTask<Void, Void, Set<String> > task =
3909 new AsyncTask<Void, Void, Set<String> >() {
3910 protected Set<String> doInBackground(Void... unused) {
3911 Set<String> installedPackages = new HashSet<String>();
3912 PackageManager pm = BrowserActivity.this.getPackageManager();
3913 if (pm != null) {
3914 List<PackageInfo> packages = pm.getInstalledPackages(0);
3915 for (PackageInfo p : packages) {
3916 if (BrowserActivity.this.sGoogleApps.contains(p.packageName)) {
3917 installedPackages.add(p.packageName);
3918 }
3919 }
3920 }
3921
3922 return installedPackages;
3923 }
3924
3925 // Executes on the UI thread
3926 protected void onPostExecute(Set<String> installedPackages) {
3927 addPackageNames(installedPackages);
3928 }
3929 };
3930 task.execute();
3931 }
3932
Grace Klobaeb6eef42009-09-15 17:56:32 -07003933 final static int LOCK_ICON_UNSECURE = 0;
3934 final static int LOCK_ICON_SECURE = 1;
3935 final static int LOCK_ICON_MIXED = 2;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003936
The Android Open Source Project0c908882009-03-03 19:32:16 -08003937 private BrowserSettings mSettings;
3938 private TabControl mTabControl;
3939 private ContentResolver mResolver;
3940 private FrameLayout mContentView;
Andrei Popescuadc008d2009-06-26 14:11:30 +01003941 private View mCustomView;
3942 private FrameLayout mCustomViewContainer;
Andrei Popescuc9b55562009-07-07 10:51:15 +01003943 private WebChromeClient.CustomViewCallback mCustomViewCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003944
3945 // FIXME, temp address onPrepareMenu performance problem. When we move everything out of
3946 // view, we should rewrite this.
3947 private int mCurrentMenuState = 0;
3948 private int mMenuState = R.id.MAIN_MENU;
Andrei Popescuadc008d2009-06-26 14:11:30 +01003949 private int mOldMenuState = EMPTY_MENU;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003950 private static final int EMPTY_MENU = -1;
3951 private Menu mMenu;
3952
3953 private FindDialog mFindDialog;
Cary Clark01cfcdd2010-06-04 16:36:45 -04003954 private SelectDialog mSelectDialog;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003955 // Used to prevent chording to result in firing two shortcuts immediately
3956 // one after another. Fixes bug 1211714.
3957 boolean mCanChord;
3958
3959 private boolean mInLoad;
3960 private boolean mIsNetworkUp;
Ben Murdochb7cc8b42009-09-28 10:59:09 +01003961 private boolean mDidStopLoad;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003962
Cary Clark1f10cbf2010-03-22 11:45:23 -04003963 /* package */ boolean mActivityInPause = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003964
3965 private boolean mMenuIsDown;
3966
The Android Open Source Project0c908882009-03-03 19:32:16 -08003967 private static boolean mInTrace;
3968
3969 // Performance probe
3970 private static final int[] SYSTEM_CPU_FORMAT = new int[] {
3971 Process.PROC_SPACE_TERM | Process.PROC_COMBINE,
3972 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 1: user time
3973 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 2: nice time
3974 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 3: sys time
3975 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 4: idle time
3976 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 5: iowait time
3977 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 6: irq time
3978 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG // 7: softirq time
3979 };
3980
3981 private long mStart;
3982 private long mProcessStart;
3983 private long mUserStart;
3984 private long mSystemStart;
3985 private long mIdleStart;
3986 private long mIrqStart;
3987
3988 private long mUiStart;
3989
3990 private Drawable mMixLockIcon;
3991 private Drawable mSecLockIcon;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003992
3993 /* hold a ref so we can auto-cancel if necessary */
3994 private AlertDialog mAlertDialog;
3995
The Android Open Source Project0c908882009-03-03 19:32:16 -08003996 // The up-to-date URL and title (these can be different from those stored
3997 // in WebView, since it takes some time for the information in WebView to
3998 // get updated)
3999 private String mUrl;
4000 private String mTitle;
4001
4002 // As PageInfo has different style for landscape / portrait, we have
4003 // to re-open it when configuration changed
4004 private AlertDialog mPageInfoDialog;
Grace Kloba22ac16e2009-10-07 18:00:23 -07004005 private Tab mPageInfoView;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004006 // If the Page-Info dialog is launched from the SSL-certificate-on-error
4007 // dialog, we should not just dismiss it, but should get back to the
4008 // SSL-certificate-on-error dialog. This flag is used to store this state
Leon Scrogginsc7b92f82010-01-11 18:17:31 -05004009 private boolean mPageInfoFromShowSSLCertificateOnError;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004010
4011 // as SSLCertificateOnError has different style for landscape / portrait,
4012 // we have to re-open it when configuration changed
4013 private AlertDialog mSSLCertificateOnErrorDialog;
4014 private WebView mSSLCertificateOnErrorView;
4015 private SslErrorHandler mSSLCertificateOnErrorHandler;
4016 private SslError mSSLCertificateOnErrorError;
4017
4018 // as SSLCertificate has different style for landscape / portrait, we
4019 // have to re-open it when configuration changed
4020 private AlertDialog mSSLCertificateDialog;
Grace Kloba22ac16e2009-10-07 18:00:23 -07004021 private Tab mSSLCertificateView;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004022
4023 // as HttpAuthentication has different style for landscape / portrait, we
4024 // have to re-open it when configuration changed
4025 private AlertDialog mHttpAuthenticationDialog;
4026 private HttpAuthHandler mHttpAuthHandler;
4027
4028 /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
4029 new FrameLayout.LayoutParams(
Romain Guy15b8ec62010-01-08 15:06:43 -08004030 ViewGroup.LayoutParams.MATCH_PARENT,
4031 ViewGroup.LayoutParams.MATCH_PARENT);
Andrei Popescuadc008d2009-06-26 14:11:30 +01004032 /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
4033 new FrameLayout.LayoutParams(
Romain Guy15b8ec62010-01-08 15:06:43 -08004034 ViewGroup.LayoutParams.MATCH_PARENT,
4035 ViewGroup.LayoutParams.MATCH_PARENT,
Andrei Popescuadc008d2009-06-26 14:11:30 +01004036 Gravity.CENTER);
Grace Kloba47fdfdb2009-06-30 11:15:34 -07004037 // Google search
4038 final static String QuickSearch_G = "http://www.google.com/m?q=%s";
The Android Open Source Project0c908882009-03-03 19:32:16 -08004039 // Wikipedia search
4040 final static String QuickSearch_W = "http://en.wikipedia.org/w/index.php?search=%s&go=Go";
4041 // Dictionary search
4042 final static String QuickSearch_D = "http://dictionary.reference.com/search?q=%s";
4043 // Google Mobile Local search
4044 final static String QuickSearch_L = "http://www.google.com/m/search?site=local&q=%s&near=mountain+view";
4045
4046 final static String QUERY_PLACE_HOLDER = "%s";
4047
4048 // "source" parameter for Google search through search key
4049 final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key";
4050 // "source" parameter for Google search through goto menu
4051 final static String GOOGLE_SEARCH_SOURCE_GOTO = "browser-goto";
4052 // "source" parameter for Google search through simplily type
4053 final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type";
4054 // "source" parameter for Google search suggested by the browser
4055 final static String GOOGLE_SEARCH_SOURCE_SUGGEST = "browser-suggest";
4056 // "source" parameter for Google search from unknown source
4057 final static String GOOGLE_SEARCH_SOURCE_UNKNOWN = "unknown";
4058
4059 private final static String LOGTAG = "browser";
4060
The Android Open Source Project0c908882009-03-03 19:32:16 -08004061 private String mLastEnteredUrl;
4062
4063 private PowerManager.WakeLock mWakeLock;
4064 private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes
4065
4066 private Toast mStopToast;
4067
Leon Scroggins571b3762010-05-26 10:25:01 -04004068 private TitleBarBase mTitleBar;
Leon Scroggins81db3662009-06-04 17:45:11 -04004069
Ben Murdochbff2d602009-07-01 20:19:05 +01004070 private LinearLayout mErrorConsoleContainer = null;
4071 private boolean mShouldShowErrorConsole = false;
4072
The Android Open Source Project0c908882009-03-03 19:32:16 -08004073 // As the ids are dynamically created, we can't guarantee that they will
4074 // be in sequence, so this static array maps ids to a window number.
4075 final static private int[] WINDOW_SHORTCUT_ID_ARRAY =
4076 { R.id.window_one_menu_id, R.id.window_two_menu_id, R.id.window_three_menu_id,
4077 R.id.window_four_menu_id, R.id.window_five_menu_id, R.id.window_six_menu_id,
4078 R.id.window_seven_menu_id, R.id.window_eight_menu_id };
4079
4080 // monitor platform changes
4081 private IntentFilter mNetworkStateChangedFilter;
4082 private BroadcastReceiver mNetworkStateIntentReceiver;
4083
Grace Klobab4da0ad2009-05-14 14:45:40 -07004084 private BroadcastReceiver mPackageInstallationReceiver;
4085
Bjorn Bringerta7611812010-03-24 11:12:02 +00004086 private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins;
4087
The Android Open Source Project0c908882009-03-03 19:32:16 -08004088 // activity requestCode
Nicolas Roard78a98e42009-05-11 13:34:17 +01004089 final static int COMBO_PAGE = 1;
4090 final static int DOWNLOAD_PAGE = 2;
4091 final static int PREFERENCES_PAGE = 3;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04004092 final static int FILE_SELECTED = 4;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004093
Andrei Popescu540035d2009-09-18 18:59:20 +01004094 // the default <video> poster
4095 private Bitmap mDefaultVideoPoster;
4096 // the video progress view
4097 private View mVideoProgressView;
4098
Andrei Popescu30995e72010-02-09 16:59:58 +00004099 // The Google packages we monitor for the navigator.isApplicationInstalled()
4100 // API. Add as needed.
4101 private static Set<String> sGoogleApps;
4102 static {
4103 sGoogleApps = new HashSet<String>();
4104 sGoogleApps.add("com.google.android.youtube");
4105 }
4106
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004107 /**
4108 * A UrlData class to abstract how the content will be set to WebView.
4109 * This base class uses loadUrl to show the content.
4110 */
Leon Scroggins6eac63e2010-03-15 18:19:14 -04004111 /* package */ static class UrlData {
Grace Kloba068e48b2010-01-26 18:11:27 -08004112 final String mUrl;
4113 final Map<String, String> mHeaders;
Leon Scroggins58d56c62010-01-28 15:12:40 -05004114 final Intent mVoiceIntent;
Grace Kloba60e095c2009-06-16 11:50:55 -07004115
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004116 UrlData(String url) {
4117 this.mUrl = url;
Grace Kloba068e48b2010-01-26 18:11:27 -08004118 this.mHeaders = null;
Leon Scroggins58d56c62010-01-28 15:12:40 -05004119 this.mVoiceIntent = null;
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004120 }
Grace Kloba60e095c2009-06-16 11:50:55 -07004121
Leon Scroggins58d56c62010-01-28 15:12:40 -05004122 UrlData(String url, Map<String, String> headers, Intent intent) {
Grace Kloba068e48b2010-01-26 18:11:27 -08004123 this.mUrl = url;
4124 this.mHeaders = headers;
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -05004125 if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS
4126 .equals(intent.getAction())) {
Leon Scroggins58d56c62010-01-28 15:12:40 -05004127 this.mVoiceIntent = intent;
4128 } else {
4129 this.mVoiceIntent = null;
4130 }
Grace Kloba60e095c2009-06-16 11:50:55 -07004131 }
4132
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004133 boolean isEmpty() {
Leon Scroggins58d56c62010-01-28 15:12:40 -05004134 return mVoiceIntent == null && (mUrl == null || mUrl.length() == 0);
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004135 }
4136
Leon Scroggins92472e82010-02-17 16:32:28 -05004137 /**
4138 * Load this UrlData into the given Tab. Use loadUrlDataIn to update
4139 * the title bar as well.
4140 */
Leon Scroggins58d56c62010-01-28 15:12:40 -05004141 public void loadIn(Tab t) {
4142 if (mVoiceIntent != null) {
4143 t.activateVoiceSearchMode(mVoiceIntent);
4144 } else {
4145 t.getWebView().loadUrl(mUrl, mHeaders);
4146 }
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004147 }
4148 };
4149
Leon Scroggins1f005d32009-08-10 17:36:42 -04004150 /* package */ static final UrlData EMPTY_URL_DATA = new UrlData(null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08004151}