blob: e752711b524fba8bb6e151808d121ca0bb3e6f16 [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();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002104 }
2105
Leon Scrogginsdcc5eeb2010-02-23 17:26:37 -05002106 /* package */ void goBackOnePageOrQuit() {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002107 Tab current = mTabControl.getCurrentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002108 if (current == null) {
2109 /*
2110 * Instead of finishing the activity, simply push this to the back
2111 * of the stack and let ActivityManager to choose the foreground
2112 * activity. As BrowserActivity is singleTask, it will be always the
2113 * root of the task. So we can use either true or false for
2114 * moveTaskToBack().
2115 */
2116 moveTaskToBack(true);
Grace Kloba00d85e72009-09-23 18:50:05 -07002117 return;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002118 }
2119 WebView w = current.getWebView();
2120 if (w.canGoBack()) {
2121 w.goBack();
2122 } else {
2123 // Check to see if we are closing a window that was created by
2124 // another window. If so, we switch back to that window.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002125 Tab parent = current.getParentTab();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002126 if (parent != null) {
Leon Scroggins1f005d32009-08-10 17:36:42 -04002127 switchToTab(mTabControl.getTabIndex(parent));
2128 // Now we close the other tab
2129 closeTab(current);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002130 } else {
2131 if (current.closeOnExit()) {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002132 // force the tab's inLoad() to be false as we are going to
2133 // either finish the activity or remove the tab. This will
2134 // ensure pauseWebViewTimers() taking action.
2135 mTabControl.getCurrentTab().clearInLoad();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002136 if (mTabControl.getTabCount() == 1) {
2137 finish();
2138 return;
2139 }
Mike Reed7bfa63b2009-05-28 11:08:32 -04002140 // call pauseWebViewTimers() now, we won't be able to call
2141 // it in onPause() as the WebView won't be valid.
Grace Klobaec1b5ad2009-08-18 08:42:32 -07002142 // Temporarily change mActivityInPause to be true as
2143 // pauseWebViewTimers() will do nothing if mActivityInPause
2144 // is false.
Grace Kloba918e1d72009-08-13 14:55:06 -07002145 boolean savedState = mActivityInPause;
2146 if (savedState) {
Grace Klobaec1b5ad2009-08-18 08:42:32 -07002147 Log.e(LOGTAG, "BrowserActivity is already paused "
2148 + "while handing goBackOnePageOrQuit.");
Grace Kloba918e1d72009-08-13 14:55:06 -07002149 }
2150 mActivityInPause = true;
Mike Reed7bfa63b2009-05-28 11:08:32 -04002151 pauseWebViewTimers();
Grace Kloba918e1d72009-08-13 14:55:06 -07002152 mActivityInPause = savedState;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002153 removeTabFromContentView(current);
2154 mTabControl.removeTab(current);
2155 }
2156 /*
2157 * Instead of finishing the activity, simply push this to the back
2158 * of the stack and let ActivityManager to choose the foreground
2159 * activity. As BrowserActivity is singleTask, it will be always the
2160 * root of the task. So we can use either true or false for
2161 * moveTaskToBack().
2162 */
2163 moveTaskToBack(true);
2164 }
2165 }
2166 }
2167
Grace Kloba22ac16e2009-10-07 18:00:23 -07002168 boolean isMenuDown() {
2169 return mMenuIsDown;
2170 }
2171
Grace Kloba5942df02009-09-18 11:48:29 -07002172 @Override
2173 public boolean onKeyDown(int keyCode, KeyEvent event) {
Leon Scrogginsf65b50d2009-12-08 10:44:28 -05002174 // Even if MENU is already held down, we need to call to super to open
2175 // the IME on long press.
2176 if (KeyEvent.KEYCODE_MENU == keyCode) {
2177 mMenuIsDown = true;
2178 return super.onKeyDown(keyCode, event);
2179 }
Grace Kloba5942df02009-09-18 11:48:29 -07002180 // The default key mode is DEFAULT_KEYS_SEARCH_LOCAL. As the MENU is
2181 // still down, we don't want to trigger the search. Pretend to consume
2182 // the key and do nothing.
2183 if (mMenuIsDown) return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002184
Grace Kloba5942df02009-09-18 11:48:29 -07002185 switch(keyCode) {
Grace Kloba5942df02009-09-18 11:48:29 -07002186 case KeyEvent.KEYCODE_SPACE:
Grace Klobada0fe552009-09-22 18:17:24 -07002187 // WebView/WebTextView handle the keys in the KeyDown. As
2188 // the Activity's shortcut keys are only handled when WebView
2189 // doesn't, have to do it in onKeyDown instead of onKeyUp.
2190 if (event.isShiftPressed()) {
2191 getTopWindow().pageUp(false);
2192 } else {
2193 getTopWindow().pageDown(false);
2194 }
Grace Kloba5942df02009-09-18 11:48:29 -07002195 return true;
2196 case KeyEvent.KEYCODE_BACK:
2197 if (event.getRepeatCount() == 0) {
2198 event.startTracking();
2199 return true;
2200 } else if (mCustomView == null && mActiveTabsPage == null
2201 && event.isLongPress()) {
2202 bookmarksOrHistoryPicker(true);
2203 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002204 }
Grace Kloba5942df02009-09-18 11:48:29 -07002205 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002206 }
Grace Kloba5942df02009-09-18 11:48:29 -07002207 return super.onKeyDown(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002208 }
2209
Grace Kloba5942df02009-09-18 11:48:29 -07002210 @Override
2211 public boolean onKeyUp(int keyCode, KeyEvent event) {
2212 switch(keyCode) {
2213 case KeyEvent.KEYCODE_MENU:
2214 mMenuIsDown = false;
2215 break;
Grace Kloba5942df02009-09-18 11:48:29 -07002216 case KeyEvent.KEYCODE_BACK:
2217 if (event.isTracking() && !event.isCanceled()) {
2218 if (mCustomView != null) {
2219 // if a custom view is showing, hide it
Grace Kloba22ac16e2009-10-07 18:00:23 -07002220 mTabControl.getCurrentWebView().getWebChromeClient()
2221 .onHideCustomView();
Grace Kloba5942df02009-09-18 11:48:29 -07002222 } else if (mActiveTabsPage != null) {
2223 // if tab page is showing, hide it
2224 removeActiveTabPage(true);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002225 } else {
Grace Kloba5942df02009-09-18 11:48:29 -07002226 WebView subwindow = mTabControl.getCurrentSubWindow();
2227 if (subwindow != null) {
2228 if (subwindow.canGoBack()) {
2229 subwindow.goBack();
2230 } else {
2231 dismissSubWindow(mTabControl.getCurrentTab());
2232 }
2233 } else {
2234 goBackOnePageOrQuit();
2235 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002236 }
Grace Kloba5942df02009-09-18 11:48:29 -07002237 return true;
2238 }
2239 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002240 }
Grace Kloba5942df02009-09-18 11:48:29 -07002241 return super.onKeyUp(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002242 }
2243
Leon Scroggins68579392009-09-15 15:31:54 -04002244 /* package */ void stopLoading() {
Ben Murdochb7cc8b42009-09-28 10:59:09 +01002245 mDidStopLoad = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002246 resetTitleAndRevertLockIcon();
2247 WebView w = getTopWindow();
2248 w.stopLoading();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002249 // FIXME: before refactor, it is using mWebViewClient. So I keep the
2250 // same logic here. But for subwindow case, should we call into the main
2251 // WebView's onPageFinished as we never call its onPageStarted and if
2252 // the page finishes itself, we don't call onPageFinished.
2253 mTabControl.getCurrentWebView().getWebViewClient().onPageFinished(w,
2254 w.getUrl());
The Android Open Source Project0c908882009-03-03 19:32:16 -08002255
2256 cancelStopToast();
2257 mStopToast = Toast
2258 .makeText(this, R.string.stopping, Toast.LENGTH_SHORT);
2259 mStopToast.show();
2260 }
2261
Grace Kloba22ac16e2009-10-07 18:00:23 -07002262 boolean didUserStopLoading() {
2263 return mDidStopLoad;
2264 }
2265
The Android Open Source Project0c908882009-03-03 19:32:16 -08002266 private void cancelStopToast() {
2267 if (mStopToast != null) {
2268 mStopToast.cancel();
2269 mStopToast = null;
2270 }
2271 }
2272
Grace Kloba22ac16e2009-10-07 18:00:23 -07002273 // called by a UI or non-UI thread to post the message
2274 public void postMessage(int what, int arg1, int arg2, Object obj,
2275 long delayMillis) {
2276 mHandler.sendMessageDelayed(mHandler.obtainMessage(what, arg1, arg2,
2277 obj), delayMillis);
2278 }
2279
2280 // called by a UI or non-UI thread to remove the message
2281 void removeMessages(int what, Object object) {
2282 mHandler.removeMessages(what, object);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002283 }
2284
2285 // public message ids
2286 public final static int LOAD_URL = 1001;
2287 public final static int STOP_LOAD = 1002;
2288
2289 // Message Ids
2290 private static final int FOCUS_NODE_HREF = 102;
Grace Kloba92c18a52009-07-31 23:48:32 -07002291 private static final int RELEASE_WAKELOCK = 107;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002292
Grace Kloba22ac16e2009-10-07 18:00:23 -07002293 static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
Ben Murdoch2694e232009-09-29 09:41:11 +01002294
The Android Open Source Project0c908882009-03-03 19:32:16 -08002295 // Private handler for handling javascript and saving passwords
2296 private Handler mHandler = new Handler() {
2297
2298 public void handleMessage(Message msg) {
2299 switch (msg.what) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002300 case FOCUS_NODE_HREF:
Ben Murdoch2694e232009-09-29 09:41:11 +01002301 {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002302 String url = (String) msg.getData().get("url");
Ben Murdoch90d088c2009-11-17 18:14:04 +00002303 String title = (String) msg.getData().get("title");
The Android Open Source Project0c908882009-03-03 19:32:16 -08002304 if (url == null || url.length() == 0) {
2305 break;
2306 }
2307 HashMap focusNodeMap = (HashMap) msg.obj;
2308 WebView view = (WebView) focusNodeMap.get("webview");
2309 // Only apply the action if the top window did not change.
2310 if (getTopWindow() != view) {
2311 break;
2312 }
2313 switch (msg.arg1) {
2314 case R.id.open_context_menu_id:
2315 case R.id.view_image_context_menu_id:
Leon Scroggins92472e82010-02-17 16:32:28 -05002316 loadUrlFromContext(getTopWindow(), url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002317 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002318 case R.id.bookmark_context_menu_id:
2319 Intent intent = new Intent(BrowserActivity.this,
2320 AddBookmarkPage.class);
2321 intent.putExtra("url", url);
Ben Murdoch90d088c2009-11-17 18:14:04 +00002322 intent.putExtra("title", title);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002323 startActivity(intent);
2324 break;
2325 case R.id.share_link_context_menu_id:
Leon Scroggins3e204452010-05-10 11:06:03 -04002326 sharePage(BrowserActivity.this, title, url, null,
Leon Scroggins96afcb12009-12-10 12:35:56 -05002327 null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002328 break;
2329 case R.id.copy_link_context_menu_id:
2330 copy(url);
2331 break;
2332 case R.id.save_link_context_menu_id:
2333 case R.id.download_context_menu_id:
2334 onDownloadStartNoStream(url, null, null, null, -1);
2335 break;
2336 }
2337 break;
Ben Murdoch2694e232009-09-29 09:41:11 +01002338 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002339
2340 case LOAD_URL:
Leon Scroggins92472e82010-02-17 16:32:28 -05002341 loadUrlFromContext(getTopWindow(), (String) msg.obj);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002342 break;
2343
2344 case STOP_LOAD:
2345 stopLoading();
2346 break;
2347
The Android Open Source Project0c908882009-03-03 19:32:16 -08002348 case RELEASE_WAKELOCK:
2349 if (mWakeLock.isHeld()) {
2350 mWakeLock.release();
Grace Kloba5d0e02e2009-10-05 15:15:36 -07002351 // if we reach here, Browser should be still in the
2352 // background loading after WAKELOCK_TIMEOUT (5-min).
2353 // To avoid burning the battery, stop loading.
2354 mTabControl.stopAllLoading();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002355 }
2356 break;
Ben Murdoch2694e232009-09-29 09:41:11 +01002357
2358 case UPDATE_BOOKMARK_THUMBNAIL:
2359 WebView view = (WebView) msg.obj;
2360 if (view != null) {
2361 updateScreenshot(view);
2362 }
2363 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002364 }
2365 }
2366 };
2367
Leon Scroggins96afcb12009-12-10 12:35:56 -05002368 /**
2369 * Share a page, providing the title, url, favicon, and a screenshot. Uses
2370 * an {@link Intent} to launch the Activity chooser.
2371 * @param c Context used to launch a new Activity.
2372 * @param title Title of the page. Stored in the Intent with
Paul Westbrook03e6d392010-02-12 10:33:29 -08002373 * {@link Intent#EXTRA_SUBJECT}
Leon Scroggins96afcb12009-12-10 12:35:56 -05002374 * @param url URL of the page. Stored in the Intent with
2375 * {@link Intent#EXTRA_TEXT}
2376 * @param favicon Bitmap of the favicon for the page. Stored in the Intent
2377 * with {@link Browser#EXTRA_SHARE_FAVICON}
2378 * @param screenshot Bitmap of a screenshot of the page. Stored in the
2379 * Intent with {@link Browser#EXTRA_SHARE_SCREENSHOT}
2380 */
2381 public static final void sharePage(Context c, String title, String url,
2382 Bitmap favicon, Bitmap screenshot) {
2383 Intent send = new Intent(Intent.ACTION_SEND);
2384 send.setType("text/plain");
2385 send.putExtra(Intent.EXTRA_TEXT, url);
Paul Westbrook03e6d392010-02-12 10:33:29 -08002386 send.putExtra(Intent.EXTRA_SUBJECT, title);
Leon Scroggins96afcb12009-12-10 12:35:56 -05002387 send.putExtra(Browser.EXTRA_SHARE_FAVICON, favicon);
2388 send.putExtra(Browser.EXTRA_SHARE_SCREENSHOT, screenshot);
2389 try {
2390 c.startActivity(Intent.createChooser(send, c.getString(
2391 R.string.choosertitle_sharevia)));
2392 } catch(android.content.ActivityNotFoundException ex) {
2393 // if no app handles it, do nothing
2394 }
2395 }
2396
Leon Scroggins89c6d362009-07-15 16:54:37 -04002397 private void updateScreenshot(WebView view) {
2398 // If this is a bookmarked site, add a screenshot to the database.
2399 // FIXME: When should we update? Every time?
2400 // FIXME: Would like to make sure there is actually something to
2401 // draw, but the API for that (WebViewCore.pictureReady()) is not
2402 // currently accessible here.
Ben Murdochaac7aa62009-09-17 16:57:40 +01002403
Patrick Scottcb192b52010-04-14 14:38:55 -04002404 final Bitmap bm = createScreenshot(view);
2405 if (bm == null) {
2406 return;
Leon Scroggins89c6d362009-07-15 16:54:37 -04002407 }
Patrick Scottcb192b52010-04-14 14:38:55 -04002408
2409 final ContentResolver cr = getContentResolver();
2410 final String url = view.getUrl();
2411 final String originalUrl = view.getOriginalUrl();
2412
2413 new AsyncTask<Void, Void, Void>() {
2414 @Override
2415 protected Void doInBackground(Void... unused) {
2416 Cursor c = null;
2417 try {
2418 c = BrowserBookmarksAdapter.queryBookmarksForUrl(
2419 cr, originalUrl, url, true);
2420 if (c != null) {
2421 if (c.moveToFirst()) {
2422 ContentValues values = new ContentValues();
2423 final ByteArrayOutputStream os
2424 = new ByteArrayOutputStream();
2425 bm.compress(Bitmap.CompressFormat.PNG, 100, os);
2426 values.put(Browser.BookmarkColumns.THUMBNAIL,
2427 os.toByteArray());
2428 do {
2429 cr.update(ContentUris.withAppendedId(
2430 Browser.BOOKMARKS_URI, c.getInt(0)),
2431 values, null, null);
2432 } while (c.moveToNext());
2433 }
2434 }
2435 } catch (IllegalStateException e) {
2436 // Ignore
2437 } finally {
2438 if (c != null) c.close();
2439 }
2440 return null;
2441 }
2442 }.execute();
Leon Scroggins89c6d362009-07-15 16:54:37 -04002443 }
2444
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002445 /**
Leon Scrogginsf8551612009-09-24 16:06:02 -04002446 * Values for the size of the thumbnail created when taking a screenshot.
2447 * Lazily initialized. Instead of using these directly, use
2448 * getDesiredThumbnailWidth() or getDesiredThumbnailHeight().
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002449 */
Leon Scrogginsf8551612009-09-24 16:06:02 -04002450 private static int THUMBNAIL_WIDTH = 0;
2451 private static int THUMBNAIL_HEIGHT = 0;
2452
2453 /**
2454 * Return the desired width for thumbnail screenshots, which are stored in
2455 * the database, and used on the bookmarks screen.
2456 * @param context Context for finding out the density of the screen.
2457 * @return int desired width for thumbnail screenshot.
2458 */
2459 /* package */ static int getDesiredThumbnailWidth(Context context) {
2460 if (THUMBNAIL_WIDTH == 0) {
2461 float density = context.getResources().getDisplayMetrics().density;
2462 THUMBNAIL_WIDTH = (int) (90 * density);
2463 THUMBNAIL_HEIGHT = (int) (80 * density);
2464 }
2465 return THUMBNAIL_WIDTH;
2466 }
2467
2468 /**
2469 * Return the desired height for thumbnail screenshots, which are stored in
2470 * the database, and used on the bookmarks screen.
2471 * @param context Context for finding out the density of the screen.
2472 * @return int desired height for thumbnail screenshot.
2473 */
2474 /* package */ static int getDesiredThumbnailHeight(Context context) {
2475 // To ensure that they are both initialized.
2476 getDesiredThumbnailWidth(context);
2477 return THUMBNAIL_HEIGHT;
2478 }
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002479
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002480 private Bitmap createScreenshot(WebView view) {
2481 Picture thumbnail = view.capturePicture();
Leon Scroggins45800572009-09-29 16:38:47 -04002482 if (thumbnail == null) {
2483 return null;
2484 }
Leon Scrogginsf8551612009-09-24 16:06:02 -04002485 Bitmap bm = Bitmap.createBitmap(getDesiredThumbnailWidth(this),
Cary Clarkab168ba2010-04-08 09:11:28 -04002486 getDesiredThumbnailHeight(this), Bitmap.Config.RGB_565);
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002487 Canvas canvas = new Canvas(bm);
2488 // May need to tweak these values to determine what is the
2489 // best scale factor
Ben Murdoch2694e232009-09-29 09:41:11 +01002490 int thumbnailWidth = thumbnail.getWidth();
Ben Murdochae59c3f2009-10-20 18:30:28 +01002491 int thumbnailHeight = thumbnail.getHeight();
2492 float scaleFactorX = 1.0f;
2493 float scaleFactorY = 1.0f;
Ben Murdoch2694e232009-09-29 09:41:11 +01002494 if (thumbnailWidth > 0) {
Ben Murdochae59c3f2009-10-20 18:30:28 +01002495 scaleFactorX = (float) getDesiredThumbnailWidth(this) /
Ben Murdoch2694e232009-09-29 09:41:11 +01002496 (float)thumbnailWidth;
Ben Murdochae59c3f2009-10-20 18:30:28 +01002497 } else {
2498 return null;
Leon Scroggins06ec5f22009-09-17 12:46:04 -04002499 }
Ben Murdochae59c3f2009-10-20 18:30:28 +01002500
2501 if (view.getWidth() > view.getHeight() &&
2502 thumbnailHeight < view.getHeight() && thumbnailHeight > 0) {
2503 // If the device is in landscape and the page is shorter
2504 // than the height of the view, stretch the thumbnail to fill the
2505 // space.
2506 scaleFactorY = (float) getDesiredThumbnailHeight(this) /
2507 (float)thumbnailHeight;
2508 } else {
2509 // In the portrait case, this looks nice.
2510 scaleFactorY = scaleFactorX;
2511 }
2512
2513 canvas.scale(scaleFactorX, scaleFactorY);
2514
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01002515 thumbnail.draw(canvas);
2516 return bm;
2517 }
2518
The Android Open Source Project0c908882009-03-03 19:32:16 -08002519 // -------------------------------------------------------------------------
Grace Kloba22ac16e2009-10-07 18:00:23 -07002520 // Helper function for WebViewClient.
The Android Open Source Project0c908882009-03-03 19:32:16 -08002521 //-------------------------------------------------------------------------
2522
2523 // Use in overrideUrlLoading
2524 /* package */ final static String SCHEME_WTAI = "wtai://wp/";
2525 /* package */ final static String SCHEME_WTAI_MC = "wtai://wp/mc;";
2526 /* package */ final static String SCHEME_WTAI_SD = "wtai://wp/sd;";
2527 /* package */ final static String SCHEME_WTAI_AP = "wtai://wp/ap;";
2528
Leon Scroggins92472e82010-02-17 16:32:28 -05002529 // Keep this initial progress in sync with initialProgressValue (* 100)
2530 // in ProgressTracker.cpp
2531 private final static int INITIAL_PROGRESS = 10;
2532
Grace Kloba22ac16e2009-10-07 18:00:23 -07002533 void onPageStarted(WebView view, String url, Bitmap favicon) {
2534 // when BrowserActivity just starts, onPageStarted may be called before
2535 // onResume as it is triggered from onCreate. Call resumeWebViewTimers
2536 // to start the timer. As we won't switch tabs while an activity is in
2537 // pause state, we can ensure calling resume and pause in pair.
2538 if (mActivityInPause) resumeWebViewTimers();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002539
Grace Kloba22ac16e2009-10-07 18:00:23 -07002540 resetLockIcon(url);
2541 setUrlTitle(url, null);
2542 setFavicon(favicon);
Leon Scroggins8cf8f682009-11-04 11:13:50 -08002543 // Show some progress so that the user knows the page is beginning to
2544 // load
Leon Scroggins92472e82010-02-17 16:32:28 -05002545 onProgressChanged(view, INITIAL_PROGRESS);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002546 mDidStopLoad = false;
Grace Kloba22ac16e2009-10-07 18:00:23 -07002547 if (!mIsNetworkUp) createAndShowNetworkDialog();
Cary Clark01cfcdd2010-06-04 16:36:45 -04002548 closeDialogs();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002549 if (mSettings.isTracing()) {
2550 String host;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002551 try {
Grace Kloba22ac16e2009-10-07 18:00:23 -07002552 WebAddress uri = new WebAddress(url);
2553 host = uri.mHost;
2554 } catch (android.net.ParseException ex) {
2555 host = "browser";
The Android Open Source Project0c908882009-03-03 19:32:16 -08002556 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002557 host = host.replace('.', '_');
2558 host += ".trace";
2559 mInTrace = true;
2560 Debug.startMethodTracing(host, 20 * 1024 * 1024);
2561 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002562
Grace Kloba22ac16e2009-10-07 18:00:23 -07002563 // Performance probe
2564 if (false) {
2565 mStart = SystemClock.uptimeMillis();
2566 mProcessStart = Process.getElapsedCpuTime();
2567 long[] sysCpu = new long[7];
2568 if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null,
2569 sysCpu, null)) {
2570 mUserStart = sysCpu[0] + sysCpu[1];
2571 mSystemStart = sysCpu[2];
2572 mIdleStart = sysCpu[3];
2573 mIrqStart = sysCpu[4] + sysCpu[5] + sysCpu[6];
2574 }
2575 mUiStart = SystemClock.currentThreadTimeMillis();
2576 }
2577 }
2578
2579 void onPageFinished(WebView view, String url) {
2580 // Reset the title and icon in case we stopped a provisional load.
2581 resetTitleAndIcon(view);
2582 // Update the lock icon image only once we are done loading
2583 updateLockIconToLatest();
2584 // pause the WebView timer and release the wake lock if it is finished
2585 // while BrowserActivity is in pause state.
2586 if (mActivityInPause && pauseWebViewTimers()) {
2587 if (mWakeLock.isHeld()) {
2588 mHandler.removeMessages(RELEASE_WAKELOCK);
2589 mWakeLock.release();
2590 }
2591 }
2592
2593 // Performance probe
2594 if (false) {
2595 long[] sysCpu = new long[7];
2596 if (Process.readProcFile("/proc/stat", SYSTEM_CPU_FORMAT, null,
2597 sysCpu, null)) {
2598 String uiInfo = "UI thread used "
2599 + (SystemClock.currentThreadTimeMillis() - mUiStart)
2600 + " ms";
2601 if (LOGD_ENABLED) {
2602 Log.d(LOGTAG, uiInfo);
2603 }
2604 //The string that gets written to the log
2605 String performanceString = "It took total "
2606 + (SystemClock.uptimeMillis() - mStart)
2607 + " ms clock time to load the page."
2608 + "\nbrowser process used "
2609 + (Process.getElapsedCpuTime() - mProcessStart)
2610 + " ms, user processes used "
2611 + (sysCpu[0] + sysCpu[1] - mUserStart) * 10
2612 + " ms, kernel used "
2613 + (sysCpu[2] - mSystemStart) * 10
2614 + " ms, idle took " + (sysCpu[3] - mIdleStart) * 10
2615 + " ms and irq took "
2616 + (sysCpu[4] + sysCpu[5] + sysCpu[6] - mIrqStart)
2617 * 10 + " ms, " + uiInfo;
2618 if (LOGD_ENABLED) {
2619 Log.d(LOGTAG, performanceString + "\nWebpage: " + url);
2620 }
2621 if (url != null) {
2622 // strip the url to maintain consistency
2623 String newUrl = new String(url);
2624 if (newUrl.startsWith("http://www.")) {
2625 newUrl = newUrl.substring(11);
2626 } else if (newUrl.startsWith("http://")) {
2627 newUrl = newUrl.substring(7);
2628 } else if (newUrl.startsWith("https://www.")) {
2629 newUrl = newUrl.substring(12);
2630 } else if (newUrl.startsWith("https://")) {
2631 newUrl = newUrl.substring(8);
2632 }
2633 if (LOGD_ENABLED) {
2634 Log.d(LOGTAG, newUrl + " loaded");
2635 }
Grace Kloba5b078b52009-06-24 20:23:41 -07002636 }
2637 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002638 }
Grace Kloba5b078b52009-06-24 20:23:41 -07002639
Grace Kloba22ac16e2009-10-07 18:00:23 -07002640 if (mInTrace) {
2641 mInTrace = false;
2642 Debug.stopMethodTracing();
2643 }
2644 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002645
Grace Kloba22ac16e2009-10-07 18:00:23 -07002646 boolean shouldOverrideUrlLoading(WebView view, String url) {
2647 if (url.startsWith(SCHEME_WTAI)) {
2648 // wtai://wp/mc;number
2649 // number=string(phone-number)
2650 if (url.startsWith(SCHEME_WTAI_MC)) {
2651 Intent intent = new Intent(Intent.ACTION_VIEW,
2652 Uri.parse(WebView.SCHEME_TEL +
2653 url.substring(SCHEME_WTAI_MC.length())));
2654 startActivity(intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002655 return true;
2656 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002657 // wtai://wp/sd;dtmf
2658 // dtmf=string(dialstring)
2659 if (url.startsWith(SCHEME_WTAI_SD)) {
2660 // TODO: only send when there is active voice connection
2661 return false;
2662 }
2663 // wtai://wp/ap;number;name
2664 // number=string(phone-number)
2665 // name=string
2666 if (url.startsWith(SCHEME_WTAI_AP)) {
2667 // TODO
2668 return false;
2669 }
2670 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002671
Grace Kloba22ac16e2009-10-07 18:00:23 -07002672 // The "about:" schemes are internal to the browser; don't want these to
2673 // be dispatched to other apps.
2674 if (url.startsWith("about:")) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002675 return false;
2676 }
2677
Grace Kloba22ac16e2009-10-07 18:00:23 -07002678 Intent intent;
2679 // perform generic parsing of the URI to turn it into an Intent.
2680 try {
2681 intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
2682 } catch (URISyntaxException ex) {
2683 Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage());
2684 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002685 }
2686
Grace Kloba22ac16e2009-10-07 18:00:23 -07002687 // check whether the intent can be resolved. If not, we will see
2688 // whether we can download it from the Market.
2689 if (getPackageManager().resolveActivity(intent, 0) == null) {
2690 String packagename = intent.getPackage();
2691 if (packagename != null) {
2692 intent = new Intent(Intent.ACTION_VIEW, Uri
2693 .parse("market://search?q=pname:" + packagename));
2694 intent.addCategory(Intent.CATEGORY_BROWSABLE);
2695 startActivity(intent);
2696 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08002697 } else {
2698 return false;
2699 }
2700 }
2701
Grace Kloba22ac16e2009-10-07 18:00:23 -07002702 // sanitize the Intent, ensuring web pages can not bypass browser
2703 // security (only access to BROWSABLE activities).
2704 intent.addCategory(Intent.CATEGORY_BROWSABLE);
2705 intent.setComponent(null);
2706 try {
2707 if (startActivityIfNeeded(intent, -1)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002708 return true;
2709 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002710 } catch (ActivityNotFoundException ex) {
2711 // ignore the error. If no application can handle the URL,
2712 // eg about:blank, assume the browser can handle it.
2713 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002714
Grace Kloba22ac16e2009-10-07 18:00:23 -07002715 if (mMenuIsDown) {
2716 openTab(url);
2717 closeOptionsMenu();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002718 return true;
2719 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002720 return false;
2721 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002722
Grace Kloba22ac16e2009-10-07 18:00:23 -07002723 // -------------------------------------------------------------------------
2724 // Helper function for WebChromeClient
2725 // -------------------------------------------------------------------------
The Android Open Source Project0c908882009-03-03 19:32:16 -08002726
Grace Kloba22ac16e2009-10-07 18:00:23 -07002727 void onProgressChanged(WebView view, int newProgress) {
Leon Scrogginsd746a942010-05-19 13:21:44 -04002728 if (mXLargeScreenSize) {
2729 mTitleBar.setProgress(newProgress);
2730 } else {
2731 // On the phone, the fake title bar will always cover up the
2732 // regular title bar (or the regular one is offscreen), so only the
2733 // fake title bar needs to change its progress
2734 mFakeTitleBar.setProgress(newProgress);
2735 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002736
Grace Kloba22ac16e2009-10-07 18:00:23 -07002737 if (newProgress == 100) {
2738 // onProgressChanged() may continue to be called after the main
2739 // frame has finished loading, as any remaining sub frames continue
2740 // to load. We'll only get called once though with newProgress as
2741 // 100 when everything is loaded. (onPageFinished is called once
2742 // when the main frame completes loading regardless of the state of
2743 // any sub frames so calls to onProgressChanges may continue after
2744 // onPageFinished has executed)
2745 if (mInLoad) {
2746 mInLoad = false;
Leon Scrogginsa27ff192009-09-14 12:58:04 -04002747 updateInLoadMenuItems();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002748 // If the options menu is open, leave the title bar
2749 if (!mOptionsMenuOpen || !mIconView) {
2750 hideFakeTitleBar();
The Android Open Source Projectcb9a0bb2009-03-11 12:11:58 -07002751 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002752 }
Leon Scrogginsaa37e7f2010-03-05 11:51:20 -05002753 } else {
2754 if (!mInLoad) {
2755 // onPageFinished may have already been called but a subframe is
2756 // still loading and updating the progress. Reset mInLoad and
2757 // update the menu items.
2758 mInLoad = true;
2759 updateInLoadMenuItems();
2760 }
2761 // When the page first begins to load, the Activity may still be
2762 // paused, in which case showFakeTitleBar will do nothing. Call
2763 // again as the page continues to load so that it will be shown.
2764 // (Calling it will the fake title bar is already showing will also
2765 // do nothing.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002766 if (!mOptionsMenuOpen || mIconView) {
2767 // This page has begun to load, so show the title bar
2768 showFakeTitleBar();
The Android Open Source Project0c908882009-03-03 19:32:16 -08002769 }
2770 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002771 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002772
Grace Kloba22ac16e2009-10-07 18:00:23 -07002773 void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
Derek Sollenberger8ff57db2009-12-08 15:39:55 -05002774 // if a view already exists then immediately terminate the new one
2775 if (mCustomView != null) {
2776 callback.onCustomViewHidden();
Grace Kloba22ac16e2009-10-07 18:00:23 -07002777 return;
Derek Sollenberger8ff57db2009-12-08 15:39:55 -05002778 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002779
2780 // Add the custom view to its container.
2781 mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
2782 mCustomView = view;
2783 mCustomViewCallback = callback;
2784 // Save the menu state and set it to empty while the custom
2785 // view is showing.
2786 mOldMenuState = mMenuState;
2787 mMenuState = EMPTY_MENU;
2788 // Hide the content view.
2789 mContentView.setVisibility(View.GONE);
2790 // Finally show the custom view container.
Andrei Popescu163ab742009-10-20 17:58:23 +01002791 setStatusBarVisibility(false);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002792 mCustomViewContainer.setVisibility(View.VISIBLE);
2793 mCustomViewContainer.bringToFront();
2794 }
2795
2796 void onHideCustomView() {
2797 if (mCustomView == null)
2798 return;
2799
2800 // Hide the custom view.
2801 mCustomView.setVisibility(View.GONE);
2802 // Remove the custom view from its container.
2803 mCustomViewContainer.removeView(mCustomView);
2804 mCustomView = null;
2805 // Reset the old menu state.
2806 mMenuState = mOldMenuState;
2807 mOldMenuState = EMPTY_MENU;
2808 mCustomViewContainer.setVisibility(View.GONE);
2809 mCustomViewCallback.onCustomViewHidden();
2810 // Show the content view.
Andrei Popescu163ab742009-10-20 17:58:23 +01002811 setStatusBarVisibility(true);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002812 mContentView.setVisibility(View.VISIBLE);
2813 }
2814
2815 Bitmap getDefaultVideoPoster() {
2816 if (mDefaultVideoPoster == null) {
2817 mDefaultVideoPoster = BitmapFactory.decodeResource(
2818 getResources(), R.drawable.default_video_poster);
Patrick Scott3918d442009-08-04 13:22:29 -04002819 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002820 return mDefaultVideoPoster;
2821 }
Patrick Scott3918d442009-08-04 13:22:29 -04002822
Grace Kloba22ac16e2009-10-07 18:00:23 -07002823 View getVideoLoadingProgressView() {
2824 if (mVideoProgressView == null) {
2825 LayoutInflater inflater = LayoutInflater.from(BrowserActivity.this);
2826 mVideoProgressView = inflater.inflate(
2827 R.layout.video_loading_progress, null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08002828 }
Grace Kloba22ac16e2009-10-07 18:00:23 -07002829 return mVideoProgressView;
2830 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002831
Leon Scroggins8d5fa432009-10-02 15:55:59 -04002832 /*
2833 * The Object used to inform the WebView of the file to upload.
2834 */
2835 private ValueCallback<Uri> mUploadMessage;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002836 private String mCameraFilePath;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04002837
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002838 void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
2839
2840 final String imageMimeType = "image/*";
2841 final String imageSourceKey = "source";
2842 final String imageSourceValueCamera = "camera";
2843 final String imageSourceValueGallery = "gallery";
2844
2845 // image source can be 'gallery' or 'camera'.
2846 String imageSource = "";
2847
2848 // We add the camera intent if there was no accept type (or '*/*') or 'image/*'.
2849 boolean addCameraIntent = true;
2850
Grace Kloba22ac16e2009-10-07 18:00:23 -07002851 if (mUploadMessage != null) return;
2852 mUploadMessage = uploadMsg;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002853
2854 // Parse the accept type.
2855 String params[] = acceptType.split(";");
2856 String mimeType = params[0];
2857
2858 for (String p : params) {
2859 String[] keyValue = p.split("=");
2860 if (keyValue.length == 2) {
2861 // Process key=value parameters.
2862 if (imageSourceKey.equals(keyValue[0])) {
2863 imageSource = keyValue[1];
2864 }
2865 }
2866 }
2867
2868 // This intent will display the standard OPENABLE file picker.
Grace Kloba22ac16e2009-10-07 18:00:23 -07002869 Intent i = new Intent(Intent.ACTION_GET_CONTENT);
2870 i.addCategory(Intent.CATEGORY_OPENABLE);
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01002871
2872 // Create an intent to add to the standard file picker that will
2873 // capture an image from the camera. We'll combine this intent with
2874 // the standard OPENABLE picker unless the web developer specifically
2875 // requested the camera or gallery be opened by passing a parameter
2876 // in the accept type.
2877 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
2878 File externalDataDir = Environment.getExternalStoragePublicDirectory(
2879 Environment.DIRECTORY_DCIM);
2880 File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
2881 File.separator + "browser-photos");
2882 cameraDataDir.mkdirs();
2883 mCameraFilePath = cameraDataDir.getAbsolutePath() + File.separator +
2884 System.currentTimeMillis() + ".jpg";
2885 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mCameraFilePath)));
2886
2887 if (mimeType.equals(imageMimeType)) {
2888 i.setType(imageMimeType);
2889 if (imageSource.equals(imageSourceValueCamera)) {
2890 // Specified 'image/*' and requested the camera, so go ahead and launch the camera
2891 // directly.
2892 BrowserActivity.this.startActivityForResult(cameraIntent, FILE_SELECTED);
2893 return;
2894 } else if (imageSource.equals(imageSourceValueGallery)) {
2895 // Specified gallery as the source, so don't want to consider the camera.
2896 addCameraIntent = false;
2897 }
2898 } else {
2899 i.setType("*/*");
2900 }
2901
2902 // Combine the chooser and the extra choices (like camera)
2903 Intent chooser = new Intent(Intent.ACTION_CHOOSER);
2904 chooser.putExtra(Intent.EXTRA_INTENT, i);
2905
2906 if (addCameraIntent) {
2907 // Add the camera Intent
2908 Intent[] choices = new Intent[1];
2909 choices[0] = cameraIntent;
2910 chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, choices);
2911 }
2912
2913 chooser.putExtra(Intent.EXTRA_TITLE, getString(R.string.choose_upload));
2914 BrowserActivity.this.startActivityForResult(chooser, FILE_SELECTED);
Grace Kloba22ac16e2009-10-07 18:00:23 -07002915 }
2916
2917 // -------------------------------------------------------------------------
2918 // Implement functions for DownloadListener
2919 // -------------------------------------------------------------------------
2920
The Android Open Source Project0c908882009-03-03 19:32:16 -08002921 /**
2922 * Notify the host application a download should be done, or that
2923 * the data should be streamed if a streaming viewer is available.
2924 * @param url The full url to the content that should be downloaded
2925 * @param contentDisposition Content-disposition http header, if
2926 * present.
2927 * @param mimetype The mimetype of the content reported by the server
2928 * @param contentLength The file size reported by the server
2929 */
2930 public void onDownloadStart(String url, String userAgent,
2931 String contentDisposition, String mimetype, long contentLength) {
2932 // if we're dealing wih A/V content that's not explicitly marked
2933 // for download, check if it's streamable.
2934 if (contentDisposition == null
Patrick Scotte1fb9662009-08-31 14:31:52 -04002935 || !contentDisposition.regionMatches(
2936 true, 0, "attachment", 0, 10)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08002937 // query the package manager to see if there's a registered handler
2938 // that matches.
2939 Intent intent = new Intent(Intent.ACTION_VIEW);
2940 intent.setDataAndType(Uri.parse(url), mimetype);
Patrick Scotte1fb9662009-08-31 14:31:52 -04002941 ResolveInfo info = getPackageManager().resolveActivity(intent,
2942 PackageManager.MATCH_DEFAULT_ONLY);
2943 if (info != null) {
2944 ComponentName myName = getComponentName();
2945 // If we resolved to ourselves, we don't want to attempt to
2946 // load the url only to try and download it again.
2947 if (!myName.getPackageName().equals(
2948 info.activityInfo.packageName)
2949 || !myName.getClassName().equals(
2950 info.activityInfo.name)) {
2951 // someone (other than us) knows how to handle this mime
2952 // type with this scheme, don't download.
2953 try {
2954 startActivity(intent);
2955 return;
2956 } catch (ActivityNotFoundException ex) {
2957 if (LOGD_ENABLED) {
2958 Log.d(LOGTAG, "activity not found for " + mimetype
2959 + " over " + Uri.parse(url).getScheme(),
2960 ex);
2961 }
2962 // Best behavior is to fall back to a download in this
2963 // case
The Android Open Source Project0c908882009-03-03 19:32:16 -08002964 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08002965 }
2966 }
2967 }
2968 onDownloadStartNoStream(url, userAgent, contentDisposition, mimetype, contentLength);
2969 }
2970
Kristian Monsenfa52d172010-03-25 18:29:21 +00002971 // This is to work around the fact that java.net.URI throws Exceptions
2972 // instead of just encoding URL's properly
2973 // Helper method for onDownloadStartNoStream
2974 private static String encodePath(String path) {
2975 char[] chars = path.toCharArray();
2976
2977 boolean needed = false;
2978 for (char c : chars) {
2979 if (c == '[' || c == ']') {
2980 needed = true;
2981 break;
2982 }
2983 }
2984 if (needed == false) {
2985 return path;
2986 }
2987
2988 StringBuilder sb = new StringBuilder("");
2989 for (char c : chars) {
2990 if (c == '[' || c == ']') {
2991 sb.append('%');
2992 sb.append(Integer.toHexString(c));
2993 } else {
2994 sb.append(c);
2995 }
2996 }
2997
2998 return sb.toString();
2999 }
3000
The Android Open Source Project0c908882009-03-03 19:32:16 -08003001 /**
3002 * Notify the host application a download should be done, even if there
3003 * is a streaming viewer available for thise type.
3004 * @param url The full url to the content that should be downloaded
3005 * @param contentDisposition Content-disposition http header, if
3006 * present.
3007 * @param mimetype The mimetype of the content reported by the server
3008 * @param contentLength The file size reported by the server
3009 */
3010 /*package */ void onDownloadStartNoStream(String url, String userAgent,
3011 String contentDisposition, String mimetype, long contentLength) {
3012
3013 String filename = URLUtil.guessFileName(url,
3014 contentDisposition, mimetype);
3015
3016 // Check to see if we have an SDCard
3017 String status = Environment.getExternalStorageState();
3018 if (!status.equals(Environment.MEDIA_MOUNTED)) {
3019 int title;
3020 String msg;
3021
3022 // Check to see if the SDCard is busy, same as the music app
3023 if (status.equals(Environment.MEDIA_SHARED)) {
3024 msg = getString(R.string.download_sdcard_busy_dlg_msg);
3025 title = R.string.download_sdcard_busy_dlg_title;
3026 } else {
3027 msg = getString(R.string.download_no_sdcard_dlg_msg, filename);
3028 title = R.string.download_no_sdcard_dlg_title;
3029 }
3030
3031 new AlertDialog.Builder(this)
3032 .setTitle(title)
3033 .setIcon(android.R.drawable.ic_dialog_alert)
3034 .setMessage(msg)
3035 .setPositiveButton(R.string.ok, null)
3036 .show();
3037 return;
3038 }
3039
Kristian Monsenfa52d172010-03-25 18:29:21 +00003040 // java.net.URI is a lot stricter than KURL so we have to encode some
3041 // extra characters. Fix for b 2538060 and b 1634719
3042 WebAddress webAddress;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003043 try {
Kristian Monsenfa52d172010-03-25 18:29:21 +00003044 webAddress = new WebAddress(url);
3045 webAddress.mPath = encodePath(webAddress.mPath);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003046 } catch (Exception e) {
Kristian Monsenfa52d172010-03-25 18:29:21 +00003047 // This only happens for very bad urls, we want to chatch the
3048 // exception here
3049 Log.e(LOGTAG, "Exception trying to parse url:" + url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003050 return;
3051 }
3052
3053 // XXX: Have to use the old url since the cookies were stored using the
3054 // old percent-encoded url.
3055 String cookies = CookieManager.getInstance().getCookie(url);
3056
3057 ContentValues values = new ContentValues();
Kristian Monsenfa52d172010-03-25 18:29:21 +00003058 values.put(Downloads.Impl.COLUMN_URI, webAddress.toString());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003059 values.put(Downloads.Impl.COLUMN_COOKIE_DATA, cookies);
3060 values.put(Downloads.Impl.COLUMN_USER_AGENT, userAgent);
3061 values.put(Downloads.Impl.COLUMN_NOTIFICATION_PACKAGE,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003062 getPackageName());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003063 values.put(Downloads.Impl.COLUMN_NOTIFICATION_CLASS,
Leon Scrogginsa563d092010-04-19 16:53:49 -04003064 OpenDownloadReceiver.class.getCanonicalName());
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003065 values.put(Downloads.Impl.COLUMN_VISIBILITY,
3066 Downloads.Impl.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
3067 values.put(Downloads.Impl.COLUMN_MIME_TYPE, mimetype);
3068 values.put(Downloads.Impl.COLUMN_FILE_NAME_HINT, filename);
Kristian Monsenfa52d172010-03-25 18:29:21 +00003069 values.put(Downloads.Impl.COLUMN_DESCRIPTION, webAddress.mHost);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003070 if (contentLength > 0) {
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003071 values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, contentLength);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003072 }
3073 if (mimetype == null) {
3074 // We must have long pressed on a link or image to download it. We
3075 // are not sure of the mimetype in this case, so do a head request
3076 new FetchUrlMimeType(this).execute(values);
3077 } else {
3078 final Uri contentUri =
Jean-Baptiste Queru1e5bad92010-01-14 16:09:03 -08003079 getContentResolver().insert(Downloads.Impl.CONTENT_URI, values);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003080 }
Leon Scroggins9191a7f2010-03-18 14:44:44 -04003081 Toast.makeText(this, R.string.download_pending, Toast.LENGTH_SHORT)
3082 .show();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003083 }
3084
Grace Kloba22ac16e2009-10-07 18:00:23 -07003085 // -------------------------------------------------------------------------
3086
The Android Open Source Project0c908882009-03-03 19:32:16 -08003087 /**
3088 * Resets the lock icon. This method is called when we start a new load and
3089 * know the url to be loaded.
3090 */
3091 private void resetLockIcon(String url) {
3092 // Save the lock-icon state (we revert to it if the load gets cancelled)
Grace Kloba22ac16e2009-10-07 18:00:23 -07003093 mTabControl.getCurrentTab().resetLockIcon(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003094 updateLockIconImage(LOCK_ICON_UNSECURE);
3095 }
3096
The Android Open Source Project0c908882009-03-03 19:32:16 -08003097 /**
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -04003098 * Update the lock icon to correspond to our latest state.
3099 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003100 private void updateLockIconToLatest() {
3101 updateLockIconImage(mTabControl.getCurrentTab().getLockIconType());
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -04003102 }
3103
3104 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -08003105 * Updates the lock-icon image in the title-bar.
3106 */
3107 private void updateLockIconImage(int lockIconType) {
3108 Drawable d = null;
3109 if (lockIconType == LOCK_ICON_SECURE) {
3110 d = mSecLockIcon;
3111 } else if (lockIconType == LOCK_ICON_MIXED) {
3112 d = mMixLockIcon;
3113 }
Leon Scroggins68579392009-09-15 15:31:54 -04003114 mTitleBar.setLock(d);
Leon Scrogginsd746a942010-05-19 13:21:44 -04003115 if (!mXLargeScreenSize) {
3116 mFakeTitleBar.setLock(d);
3117 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003118 }
3119
3120 /**
3121 * Displays a page-info dialog.
3122 * @param tab The tab to show info about
3123 * @param fromShowSSLCertificateOnError The flag that indicates whether
3124 * this dialog was opened from the SSL-certificate-on-error dialog or
3125 * not. This is important, since we need to know whether to return to
3126 * the parent dialog or simply dismiss.
3127 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003128 private void showPageInfo(final Tab tab,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003129 final boolean fromShowSSLCertificateOnError) {
3130 final LayoutInflater factory = LayoutInflater
3131 .from(this);
3132
3133 final View pageInfoView = factory.inflate(R.layout.page_info, null);
3134
3135 final WebView view = tab.getWebView();
3136
3137 String url = null;
3138 String title = null;
3139
3140 if (view == null) {
3141 url = tab.getUrl();
3142 title = tab.getTitle();
3143 } else if (view == mTabControl.getCurrentWebView()) {
3144 // Use the cached title and url if this is the current WebView
3145 url = mUrl;
3146 title = mTitle;
3147 } else {
3148 url = view.getUrl();
3149 title = view.getTitle();
3150 }
3151
3152 if (url == null) {
3153 url = "";
3154 }
3155 if (title == null) {
3156 title = "";
3157 }
3158
3159 ((TextView) pageInfoView.findViewById(R.id.address)).setText(url);
3160 ((TextView) pageInfoView.findViewById(R.id.title)).setText(title);
3161
3162 mPageInfoView = tab;
Leon Scrogginsc7b92f82010-01-11 18:17:31 -05003163 mPageInfoFromShowSSLCertificateOnError = fromShowSSLCertificateOnError;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003164
3165 AlertDialog.Builder alertDialogBuilder =
3166 new AlertDialog.Builder(this)
3167 .setTitle(R.string.page_info).setIcon(android.R.drawable.ic_dialog_info)
3168 .setView(pageInfoView)
3169 .setPositiveButton(
3170 R.string.ok,
3171 new DialogInterface.OnClickListener() {
3172 public void onClick(DialogInterface dialog,
3173 int whichButton) {
3174 mPageInfoDialog = null;
3175 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003176
3177 // if we came here from the SSL error dialog
3178 if (fromShowSSLCertificateOnError) {
3179 // go back to the SSL error dialog
3180 showSSLCertificateOnError(
3181 mSSLCertificateOnErrorView,
3182 mSSLCertificateOnErrorHandler,
3183 mSSLCertificateOnErrorError);
3184 }
3185 }
3186 })
3187 .setOnCancelListener(
3188 new DialogInterface.OnCancelListener() {
3189 public void onCancel(DialogInterface dialog) {
3190 mPageInfoDialog = null;
3191 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003192
3193 // if we came here from the SSL error dialog
3194 if (fromShowSSLCertificateOnError) {
3195 // go back to the SSL error dialog
3196 showSSLCertificateOnError(
3197 mSSLCertificateOnErrorView,
3198 mSSLCertificateOnErrorHandler,
3199 mSSLCertificateOnErrorError);
3200 }
3201 }
3202 });
3203
3204 // if we have a main top-level page SSL certificate set or a certificate
3205 // error
3206 if (fromShowSSLCertificateOnError ||
3207 (view != null && view.getCertificate() != null)) {
3208 // add a 'View Certificate' button
3209 alertDialogBuilder.setNeutralButton(
3210 R.string.view_certificate,
3211 new DialogInterface.OnClickListener() {
3212 public void onClick(DialogInterface dialog,
3213 int whichButton) {
3214 mPageInfoDialog = null;
3215 mPageInfoView = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003216
3217 // if we came here from the SSL error dialog
3218 if (fromShowSSLCertificateOnError) {
3219 // go back to the SSL error dialog
3220 showSSLCertificateOnError(
3221 mSSLCertificateOnErrorView,
3222 mSSLCertificateOnErrorHandler,
3223 mSSLCertificateOnErrorError);
3224 } else {
3225 // otherwise, display the top-most certificate from
3226 // the chain
3227 if (view.getCertificate() != null) {
3228 showSSLCertificate(tab);
3229 }
3230 }
3231 }
3232 });
3233 }
3234
3235 mPageInfoDialog = alertDialogBuilder.show();
3236 }
3237
3238 /**
3239 * Displays the main top-level page SSL certificate dialog
3240 * (accessible from the Page-Info dialog).
3241 * @param tab The tab to show certificate for.
3242 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003243 private void showSSLCertificate(final Tab tab) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003244 final View certificateView =
3245 inflateCertificateView(tab.getWebView().getCertificate());
3246 if (certificateView == null) {
3247 return;
3248 }
3249
3250 LayoutInflater factory = LayoutInflater.from(this);
3251
3252 final LinearLayout placeholder =
3253 (LinearLayout)certificateView.findViewById(R.id.placeholder);
3254
3255 LinearLayout ll = (LinearLayout) factory.inflate(
3256 R.layout.ssl_success, placeholder);
3257 ((TextView)ll.findViewById(R.id.success))
3258 .setText(R.string.ssl_certificate_is_valid);
3259
3260 mSSLCertificateView = tab;
3261 mSSLCertificateDialog =
3262 new AlertDialog.Builder(this)
3263 .setTitle(R.string.ssl_certificate).setIcon(
3264 R.drawable.ic_dialog_browser_certificate_secure)
3265 .setView(certificateView)
3266 .setPositiveButton(R.string.ok,
3267 new DialogInterface.OnClickListener() {
3268 public void onClick(DialogInterface dialog,
3269 int whichButton) {
3270 mSSLCertificateDialog = null;
3271 mSSLCertificateView = null;
3272
3273 showPageInfo(tab, false);
3274 }
3275 })
3276 .setOnCancelListener(
3277 new DialogInterface.OnCancelListener() {
3278 public void onCancel(DialogInterface dialog) {
3279 mSSLCertificateDialog = null;
3280 mSSLCertificateView = null;
3281
3282 showPageInfo(tab, false);
3283 }
3284 })
3285 .show();
3286 }
3287
3288 /**
3289 * Displays the SSL error certificate dialog.
3290 * @param view The target web-view.
3291 * @param handler The SSL error handler responsible for cancelling the
3292 * connection that resulted in an SSL error or proceeding per user request.
3293 * @param error The SSL error object.
3294 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003295 void showSSLCertificateOnError(
The Android Open Source Project0c908882009-03-03 19:32:16 -08003296 final WebView view, final SslErrorHandler handler, final SslError error) {
3297
3298 final View certificateView =
3299 inflateCertificateView(error.getCertificate());
3300 if (certificateView == null) {
3301 return;
3302 }
3303
3304 LayoutInflater factory = LayoutInflater.from(this);
3305
3306 final LinearLayout placeholder =
3307 (LinearLayout)certificateView.findViewById(R.id.placeholder);
3308
3309 if (error.hasError(SslError.SSL_UNTRUSTED)) {
3310 LinearLayout ll = (LinearLayout)factory
3311 .inflate(R.layout.ssl_warning, placeholder);
3312 ((TextView)ll.findViewById(R.id.warning))
3313 .setText(R.string.ssl_untrusted);
3314 }
3315
3316 if (error.hasError(SslError.SSL_IDMISMATCH)) {
3317 LinearLayout ll = (LinearLayout)factory
3318 .inflate(R.layout.ssl_warning, placeholder);
3319 ((TextView)ll.findViewById(R.id.warning))
3320 .setText(R.string.ssl_mismatch);
3321 }
3322
3323 if (error.hasError(SslError.SSL_EXPIRED)) {
3324 LinearLayout ll = (LinearLayout)factory
3325 .inflate(R.layout.ssl_warning, placeholder);
3326 ((TextView)ll.findViewById(R.id.warning))
3327 .setText(R.string.ssl_expired);
3328 }
3329
3330 if (error.hasError(SslError.SSL_NOTYETVALID)) {
3331 LinearLayout ll = (LinearLayout)factory
3332 .inflate(R.layout.ssl_warning, placeholder);
3333 ((TextView)ll.findViewById(R.id.warning))
3334 .setText(R.string.ssl_not_yet_valid);
3335 }
3336
3337 mSSLCertificateOnErrorHandler = handler;
3338 mSSLCertificateOnErrorView = view;
3339 mSSLCertificateOnErrorError = error;
3340 mSSLCertificateOnErrorDialog =
3341 new AlertDialog.Builder(this)
3342 .setTitle(R.string.ssl_certificate).setIcon(
3343 R.drawable.ic_dialog_browser_certificate_partially_secure)
3344 .setView(certificateView)
3345 .setPositiveButton(R.string.ok,
3346 new DialogInterface.OnClickListener() {
3347 public void onClick(DialogInterface dialog,
3348 int whichButton) {
3349 mSSLCertificateOnErrorDialog = null;
3350 mSSLCertificateOnErrorView = null;
3351 mSSLCertificateOnErrorHandler = null;
3352 mSSLCertificateOnErrorError = null;
3353
Grace Kloba22ac16e2009-10-07 18:00:23 -07003354 view.getWebViewClient().onReceivedSslError(
3355 view, handler, error);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003356 }
3357 })
3358 .setNeutralButton(R.string.page_info_view,
3359 new DialogInterface.OnClickListener() {
3360 public void onClick(DialogInterface dialog,
3361 int whichButton) {
3362 mSSLCertificateOnErrorDialog = null;
3363
3364 // do not clear the dialog state: we will
3365 // need to show the dialog again once the
3366 // user is done exploring the page-info details
3367
3368 showPageInfo(mTabControl.getTabFromView(view),
3369 true);
3370 }
3371 })
3372 .setOnCancelListener(
3373 new DialogInterface.OnCancelListener() {
3374 public void onCancel(DialogInterface dialog) {
3375 mSSLCertificateOnErrorDialog = null;
3376 mSSLCertificateOnErrorView = null;
3377 mSSLCertificateOnErrorHandler = null;
3378 mSSLCertificateOnErrorError = null;
3379
Grace Kloba22ac16e2009-10-07 18:00:23 -07003380 view.getWebViewClient().onReceivedSslError(
3381 view, handler, error);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003382 }
3383 })
3384 .show();
3385 }
3386
3387 /**
3388 * Inflates the SSL certificate view (helper method).
3389 * @param certificate The SSL certificate.
3390 * @return The resultant certificate view with issued-to, issued-by,
3391 * issued-on, expires-on, and possibly other fields set.
3392 * If the input certificate is null, returns null.
3393 */
3394 private View inflateCertificateView(SslCertificate certificate) {
3395 if (certificate == null) {
3396 return null;
3397 }
3398
3399 LayoutInflater factory = LayoutInflater.from(this);
3400
3401 View certificateView = factory.inflate(
3402 R.layout.ssl_certificate, null);
3403
3404 // issued to:
3405 SslCertificate.DName issuedTo = certificate.getIssuedTo();
3406 if (issuedTo != null) {
3407 ((TextView) certificateView.findViewById(R.id.to_common))
3408 .setText(issuedTo.getCName());
3409 ((TextView) certificateView.findViewById(R.id.to_org))
3410 .setText(issuedTo.getOName());
3411 ((TextView) certificateView.findViewById(R.id.to_org_unit))
3412 .setText(issuedTo.getUName());
3413 }
3414
3415 // issued by:
3416 SslCertificate.DName issuedBy = certificate.getIssuedBy();
3417 if (issuedBy != null) {
3418 ((TextView) certificateView.findViewById(R.id.by_common))
3419 .setText(issuedBy.getCName());
3420 ((TextView) certificateView.findViewById(R.id.by_org))
3421 .setText(issuedBy.getOName());
3422 ((TextView) certificateView.findViewById(R.id.by_org_unit))
3423 .setText(issuedBy.getUName());
3424 }
3425
3426 // issued on:
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003427 String issuedOn = formatCertificateDate(
3428 certificate.getValidNotBeforeDate());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003429 ((TextView) certificateView.findViewById(R.id.issued_on))
3430 .setText(issuedOn);
3431
3432 // expires on:
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003433 String expiresOn = formatCertificateDate(
3434 certificate.getValidNotAfterDate());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003435 ((TextView) certificateView.findViewById(R.id.expires_on))
3436 .setText(expiresOn);
3437
3438 return certificateView;
3439 }
3440
3441 /**
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003442 * Formats the certificate date to a properly localized date string.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003443 * @return Properly localized version of the certificate date string and
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003444 * the "" if it fails to localize.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003445 */
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003446 private String formatCertificateDate(Date certificateDate) {
3447 if (certificateDate == null) {
3448 return "";
The Android Open Source Project0c908882009-03-03 19:32:16 -08003449 }
Brian Carlstrom95a2e4a2010-03-02 10:02:34 -08003450 String formattedDate = DateFormat.getDateFormat(this).format(certificateDate);
3451 if (formattedDate == null) {
3452 return "";
3453 }
3454 return formattedDate;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003455 }
3456
3457 /**
3458 * Displays an http-authentication dialog.
3459 */
Grace Kloba22ac16e2009-10-07 18:00:23 -07003460 void showHttpAuthentication(final HttpAuthHandler handler,
The Android Open Source Project0c908882009-03-03 19:32:16 -08003461 final String host, final String realm, final String title,
3462 final String name, final String password, int focusId) {
3463 LayoutInflater factory = LayoutInflater.from(this);
3464 final View v = factory
3465 .inflate(R.layout.http_authentication, null);
3466 if (name != null) {
3467 ((EditText) v.findViewById(R.id.username_edit)).setText(name);
3468 }
3469 if (password != null) {
3470 ((EditText) v.findViewById(R.id.password_edit)).setText(password);
3471 }
3472
3473 String titleText = title;
3474 if (titleText == null) {
3475 titleText = getText(R.string.sign_in_to).toString().replace(
3476 "%s1", host).replace("%s2", realm);
3477 }
3478
3479 mHttpAuthHandler = handler;
3480 AlertDialog dialog = new AlertDialog.Builder(this)
3481 .setTitle(titleText)
3482 .setIcon(android.R.drawable.ic_dialog_alert)
3483 .setView(v)
3484 .setPositiveButton(R.string.action,
3485 new DialogInterface.OnClickListener() {
3486 public void onClick(DialogInterface dialog,
3487 int whichButton) {
3488 String nm = ((EditText) v
3489 .findViewById(R.id.username_edit))
3490 .getText().toString();
3491 String pw = ((EditText) v
3492 .findViewById(R.id.password_edit))
3493 .getText().toString();
3494 BrowserActivity.this.setHttpAuthUsernamePassword
3495 (host, realm, nm, pw);
3496 handler.proceed(nm, pw);
3497 mHttpAuthenticationDialog = null;
3498 mHttpAuthHandler = null;
3499 }})
3500 .setNegativeButton(R.string.cancel,
3501 new DialogInterface.OnClickListener() {
3502 public void onClick(DialogInterface dialog,
3503 int whichButton) {
3504 handler.cancel();
3505 BrowserActivity.this.resetTitleAndRevertLockIcon();
3506 mHttpAuthenticationDialog = null;
3507 mHttpAuthHandler = null;
3508 }})
3509 .setOnCancelListener(new DialogInterface.OnCancelListener() {
3510 public void onCancel(DialogInterface dialog) {
3511 handler.cancel();
3512 BrowserActivity.this.resetTitleAndRevertLockIcon();
3513 mHttpAuthenticationDialog = null;
3514 mHttpAuthHandler = null;
3515 }})
3516 .create();
3517 // Make the IME appear when the dialog is displayed if applicable.
3518 dialog.getWindow().setSoftInputMode(
3519 WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
3520 dialog.show();
3521 if (focusId != 0) {
3522 dialog.findViewById(focusId).requestFocus();
3523 } else {
3524 v.findViewById(R.id.username_edit).requestFocus();
3525 }
3526 mHttpAuthenticationDialog = dialog;
3527 }
3528
3529 public int getProgress() {
3530 WebView w = mTabControl.getCurrentWebView();
3531 if (w != null) {
3532 return w.getProgress();
3533 } else {
3534 return 100;
3535 }
3536 }
3537
3538 /**
3539 * Set HTTP authentication password.
3540 *
3541 * @param host The host for the password
3542 * @param realm The realm for the password
3543 * @param username The username for the password. If it is null, it means
3544 * password can't be saved.
3545 * @param password The password
3546 */
3547 public void setHttpAuthUsernamePassword(String host, String realm,
3548 String username,
3549 String password) {
Steve Block95a53b22010-03-25 17:24:58 +00003550 WebView w = getTopWindow();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003551 if (w != null) {
3552 w.setHttpAuthUsernamePassword(host, realm, username, password);
3553 }
3554 }
3555
3556 /**
3557 * connectivity manager says net has come or gone... inform the user
3558 * @param up true if net has come up, false if net has gone down
3559 */
3560 public void onNetworkToggle(boolean up) {
3561 if (up == mIsNetworkUp) {
3562 return;
3563 } else if (up) {
3564 mIsNetworkUp = true;
3565 if (mAlertDialog != null) {
3566 mAlertDialog.cancel();
3567 mAlertDialog = null;
3568 }
3569 } else {
3570 mIsNetworkUp = false;
Patrick Scotteb6ab2a2009-09-16 10:00:17 -04003571 if (mInLoad) {
3572 createAndShowNetworkDialog();
3573 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003574 }
3575 WebView w = mTabControl.getCurrentWebView();
3576 if (w != null) {
3577 w.setNetworkAvailable(up);
3578 }
3579 }
3580
Grace Kloba22ac16e2009-10-07 18:00:23 -07003581 boolean isNetworkUp() {
3582 return mIsNetworkUp;
3583 }
3584
Patrick Scotteb6ab2a2009-09-16 10:00:17 -04003585 // This method shows the network dialog alerting the user that the net is
3586 // down. It will only show the dialog if mAlertDialog is null.
3587 private void createAndShowNetworkDialog() {
3588 if (mAlertDialog == null) {
3589 mAlertDialog = new AlertDialog.Builder(this)
3590 .setTitle(R.string.loadSuspendedTitle)
3591 .setMessage(R.string.loadSuspended)
3592 .setPositiveButton(R.string.ok, null)
3593 .show();
3594 }
3595 }
3596
The Android Open Source Project0c908882009-03-03 19:32:16 -08003597 @Override
3598 protected void onActivityResult(int requestCode, int resultCode,
3599 Intent intent) {
Grace Klobabb394f32009-11-19 10:26:37 -08003600 if (getTopWindow() == null) return;
3601
The Android Open Source Project0c908882009-03-03 19:32:16 -08003602 switch (requestCode) {
3603 case COMBO_PAGE:
3604 if (resultCode == RESULT_OK && intent != null) {
3605 String data = intent.getAction();
3606 Bundle extras = intent.getExtras();
3607 if (extras != null && extras.getBoolean("new_window", false)) {
Leon Scroggins25d35472009-09-15 11:37:27 -04003608 openTab(data);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003609 } else {
Grace Kloba22ac16e2009-10-07 18:00:23 -07003610 final Tab currentTab =
The Android Open Source Project0c908882009-03-03 19:32:16 -08003611 mTabControl.getCurrentTab();
Leon Scroggins1f005d32009-08-10 17:36:42 -04003612 dismissSubWindow(currentTab);
3613 if (data != null && data.length() != 0) {
Leon Scroggins92472e82010-02-17 16:32:28 -05003614 loadUrl(getTopWindow(), data);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003615 }
3616 }
3617 }
Leon Scrogginsfde97462010-01-11 13:06:21 -05003618 // Deliberately fall through to PREFERENCES_PAGE, since the
3619 // same extra may be attached to the COMBO_PAGE
3620 case PREFERENCES_PAGE:
3621 if (resultCode == RESULT_OK && intent != null) {
3622 String action = intent.getStringExtra(Intent.EXTRA_TEXT);
3623 if (BrowserSettings.PREF_CLEAR_HISTORY.equals(action)) {
3624 mTabControl.removeParentChildRelationShips();
3625 }
3626 }
The Android Open Source Project0c908882009-03-03 19:32:16 -08003627 break;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003628 // Choose a file from the file picker.
3629 case FILE_SELECTED:
3630 if (null == mUploadMessage) break;
3631 Uri result = intent == null || resultCode != RESULT_OK ? null
3632 : intent.getData();
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003633
3634 // As we ask the camera to save the result of the user taking
3635 // a picture, the camera application does not return anything other
3636 // than RESULT_OK. So we need to check whether the file we expected
3637 // was written to disk in the in the case that we
3638 // did not get an intent returned but did get a RESULT_OK. If it was,
3639 // we assume that this result has came back from the camera.
3640 if (result == null && intent == null && resultCode == RESULT_OK) {
3641 File cameraFile = new File(mCameraFilePath);
3642 if (cameraFile.exists()) {
3643 result = Uri.fromFile(cameraFile);
Ben Murdoch07d34732010-05-27 18:34:46 +01003644 // Broadcast to the media scanner that we have a new photo
3645 // so it will be added into the gallery for the user.
3646 sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003647 }
3648 }
3649
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003650 mUploadMessage.onReceiveValue(result);
3651 mUploadMessage = null;
Ben Murdoch62b1b7e2010-05-19 20:38:56 +01003652 mCameraFilePath = null;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04003653 break;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003654 default:
3655 break;
3656 }
Leon Scroggins30444232009-09-04 18:36:20 -04003657 getTopWindow().requestFocus();
The Android Open Source Project0c908882009-03-03 19:32:16 -08003658 }
3659
3660 /*
3661 * This method is called as a result of the user selecting the options
Leon Scrogginsf08809b2010-01-21 09:27:46 -05003662 * menu to see the download window. It shows the download window on top of
3663 * the current window.
The Android Open Source Project0c908882009-03-03 19:32:16 -08003664 */
Leon Scrogginsf08809b2010-01-21 09:27:46 -05003665 private void viewDownloads(Uri downloadRecord) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003666 Intent intent = new Intent(this,
3667 BrowserDownloadPage.class);
3668 intent.setData(downloadRecord);
Grace Kloba22ac16e2009-10-07 18:00:23 -07003669 startActivityForResult(intent, BrowserActivity.DOWNLOAD_PAGE);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003670
3671 }
3672
Leon Scroggins160a7e72009-08-14 18:28:01 -04003673 /**
3674 * Open the Go page.
3675 * @param startWithHistory If true, open starting on the history tab.
3676 * Otherwise, start with the bookmarks tab.
Leon Scroggins160a7e72009-08-14 18:28:01 -04003677 */
Leon Scroggins30444232009-09-04 18:36:20 -04003678 /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003679 WebView current = mTabControl.getCurrentWebView();
3680 if (current == null) {
3681 return;
3682 }
3683 Intent intent = new Intent(this,
3684 CombinedBookmarkHistoryActivity.class);
3685 String title = current.getTitle();
3686 String url = current.getUrl();
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01003687 Bitmap thumbnail = createScreenshot(current);
3688
The Android Open Source Project0c908882009-03-03 19:32:16 -08003689 // Just in case the user opens bookmarks before a page finishes loading
3690 // so the current history item, and therefore the page, is null.
3691 if (null == url) {
3692 url = mLastEnteredUrl;
3693 // This can happen.
3694 if (null == url) {
3695 url = mSettings.getHomePage();
3696 }
3697 }
3698 // In case the web page has not yet received its associated title.
3699 if (title == null) {
3700 title = url;
3701 }
3702 intent.putExtra("title", title);
3703 intent.putExtra("url", url);
Ben Murdochdcc2b6f2009-09-21 14:29:20 +01003704 intent.putExtra("thumbnail", thumbnail);
Leon Scroggins30444232009-09-04 18:36:20 -04003705 // Disable opening in a new window if we have maxed out the windows
Grace Kloba22ac16e2009-10-07 18:00:23 -07003706 intent.putExtra("disable_new_window", !mTabControl.canCreateNewTab());
Patrick Scott3918d442009-08-04 13:22:29 -04003707 intent.putExtra("touch_icon_url", current.getTouchIconUrl());
The Android Open Source Project0c908882009-03-03 19:32:16 -08003708 if (startWithHistory) {
3709 intent.putExtra(CombinedBookmarkHistoryActivity.STARTING_TAB,
3710 CombinedBookmarkHistoryActivity.HISTORY_TAB);
3711 }
3712 startActivityForResult(intent, COMBO_PAGE);
3713 }
3714
3715 // Called when loading from context menu or LOAD_URL message
Leon Scroggins92472e82010-02-17 16:32:28 -05003716 private void loadUrlFromContext(WebView view, String url) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003717 // In case the user enters nothing.
3718 if (url != null && url.length() != 0 && view != null) {
3719 url = smartUrlFilter(url);
Grace Kloba22ac16e2009-10-07 18:00:23 -07003720 if (!view.getWebViewClient().shouldOverrideUrlLoading(view, url)) {
Leon Scroggins92472e82010-02-17 16:32:28 -05003721 loadUrl(view, url);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003722 }
3723 }
3724 }
3725
Leon Scroggins92472e82010-02-17 16:32:28 -05003726 /**
3727 * Load the URL into the given WebView and update the title bar
3728 * to reflect the new load. Call this instead of WebView.loadUrl
3729 * directly.
3730 * @param view The WebView used to load url.
3731 * @param url The URL to load.
3732 */
3733 private void loadUrl(WebView view, String url) {
3734 updateTitleBarForNewLoad(view, url);
3735 view.loadUrl(url);
3736 }
3737
3738 /**
3739 * Load UrlData into a Tab and update the title bar to reflect the new
3740 * load. Call this instead of UrlData.loadIn directly.
3741 * @param t The Tab used to load.
3742 * @param data The UrlData being loaded.
3743 */
3744 private void loadUrlDataIn(Tab t, UrlData data) {
3745 updateTitleBarForNewLoad(t.getWebView(), data.mUrl);
3746 data.loadIn(t);
3747 }
3748
3749 /**
3750 * If the WebView is the top window, update the title bar to reflect
3751 * loading the new URL. i.e. set its text, clear the favicon (which
3752 * will be set once the page begins loading), and set the progress to
3753 * INITIAL_PROGRESS to show that the page has begun to load. Called
3754 * by loadUrl and loadUrlDataIn.
3755 * @param view The WebView that is starting a load.
3756 * @param url The URL that is being loaded.
3757 */
3758 private void updateTitleBarForNewLoad(WebView view, String url) {
3759 if (view == getTopWindow()) {
3760 setUrlTitle(url, null);
3761 setFavicon(null);
3762 onProgressChanged(view, INITIAL_PROGRESS);
3763 }
3764 }
3765
The Android Open Source Project0c908882009-03-03 19:32:16 -08003766 private String smartUrlFilter(Uri inUri) {
3767 if (inUri != null) {
3768 return smartUrlFilter(inUri.toString());
3769 }
3770 return null;
3771 }
3772
Feng Qianb34f87a2009-03-24 21:27:26 -07003773 protected static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile(
The Android Open Source Project0c908882009-03-03 19:32:16 -08003774 "(?i)" + // switch on case insensitive matching
3775 "(" + // begin group for schema
3776 "(?:http|https|file):\\/\\/" +
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07003777 "|(?:inline|data|about|content|javascript):" +
The Android Open Source Project0c908882009-03-03 19:32:16 -08003778 ")" +
3779 "(.*)" );
3780
3781 /**
3782 * Attempts to determine whether user input is a URL or search
3783 * terms. Anything with a space is passed to search.
3784 *
3785 * Converts to lowercase any mistakenly uppercased schema (i.e.,
3786 * "Http://" converts to "http://"
3787 *
3788 * @return Original or modified URL
3789 *
3790 */
3791 String smartUrlFilter(String url) {
3792
3793 String inUrl = url.trim();
3794 boolean hasSpace = inUrl.indexOf(' ') != -1;
3795
3796 Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
3797 if (matcher.matches()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003798 // force scheme to lowercase
3799 String scheme = matcher.group(1);
3800 String lcScheme = scheme.toLowerCase();
3801 if (!lcScheme.equals(scheme)) {
Mitsuru Oshima123ecfb2009-05-18 19:11:14 -07003802 inUrl = lcScheme + matcher.group(2);
3803 }
3804 if (hasSpace) {
3805 inUrl = inUrl.replace(" ", "%20");
The Android Open Source Project0c908882009-03-03 19:32:16 -08003806 }
3807 return inUrl;
3808 }
3809 if (hasSpace) {
Satish Sampath565505b2009-05-29 15:37:27 +01003810 // FIXME: Is this the correct place to add to searches?
3811 // what if someone else calls this function?
3812 int shortcut = parseUrlShortcut(inUrl);
3813 if (shortcut != SHORTCUT_INVALID) {
3814 Browser.addSearchUrl(mResolver, inUrl);
3815 String query = inUrl.substring(2);
3816 switch (shortcut) {
3817 case SHORTCUT_GOOGLE_SEARCH:
Grace Kloba47fdfdb2009-06-30 11:15:34 -07003818 return URLUtil.composeSearchUrl(query, QuickSearch_G, QUERY_PLACE_HOLDER);
Satish Sampath565505b2009-05-29 15:37:27 +01003819 case SHORTCUT_WIKIPEDIA_SEARCH:
3820 return URLUtil.composeSearchUrl(query, QuickSearch_W, QUERY_PLACE_HOLDER);
3821 case SHORTCUT_DICTIONARY_SEARCH:
3822 return URLUtil.composeSearchUrl(query, QuickSearch_D, QUERY_PLACE_HOLDER);
3823 case SHORTCUT_GOOGLE_MOBILE_LOCAL_SEARCH:
The Android Open Source Project0c908882009-03-03 19:32:16 -08003824 // FIXME: we need location in this case
Satish Sampath565505b2009-05-29 15:37:27 +01003825 return URLUtil.composeSearchUrl(query, QuickSearch_L, QUERY_PLACE_HOLDER);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003826 }
3827 }
3828 } else {
Dan Egnor5ee906c2009-11-18 12:11:49 -08003829 if (Patterns.WEB_URL.matcher(inUrl).matches()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -08003830 return URLUtil.guessUrl(inUrl);
3831 }
3832 }
3833
3834 Browser.addSearchUrl(mResolver, inUrl);
Grace Kloba47fdfdb2009-06-30 11:15:34 -07003835 return URLUtil.composeSearchUrl(inUrl, QuickSearch_G, QUERY_PLACE_HOLDER);
The Android Open Source Project0c908882009-03-03 19:32:16 -08003836 }
3837
Ben Murdochbff2d602009-07-01 20:19:05 +01003838 /* package */ void setShouldShowErrorConsole(boolean flag) {
3839 if (flag == mShouldShowErrorConsole) {
3840 // Nothing to do.
3841 return;
3842 }
3843
3844 mShouldShowErrorConsole = flag;
3845
Grace Kloba22ac16e2009-10-07 18:00:23 -07003846 ErrorConsoleView errorConsole = mTabControl.getCurrentTab()
3847 .getErrorConsole(true);
Ben Murdochbff2d602009-07-01 20:19:05 +01003848
3849 if (flag) {
3850 // Setting the show state of the console will cause it's the layout to be inflated.
3851 if (errorConsole.numberOfErrors() > 0) {
3852 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
3853 } else {
3854 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
3855 }
3856
3857 // Now we can add it to the main view.
3858 mErrorConsoleContainer.addView(errorConsole,
Romain Guy15b8ec62010-01-08 15:06:43 -08003859 new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
Ben Murdochbff2d602009-07-01 20:19:05 +01003860 ViewGroup.LayoutParams.WRAP_CONTENT));
3861 } else {
3862 mErrorConsoleContainer.removeView(errorConsole);
3863 }
3864
3865 }
3866
Grace Kloba22ac16e2009-10-07 18:00:23 -07003867 boolean shouldShowErrorConsole() {
3868 return mShouldShowErrorConsole;
3869 }
3870
Andrei Popescu163ab742009-10-20 17:58:23 +01003871 private void setStatusBarVisibility(boolean visible) {
3872 int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
3873 getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
3874 }
3875
Andrei Popescu56199cc2010-01-12 22:39:16 +00003876
3877 private void sendNetworkType(String type, String subtype) {
3878 WebView w = mTabControl.getCurrentWebView();
3879 if (w != null) {
3880 w.setNetworkType(type, subtype);
3881 }
3882 }
3883
Andrei Popescu30995e72010-02-09 16:59:58 +00003884 private void packageChanged(String packageName, boolean wasAdded) {
3885 WebView w = mTabControl.getCurrentWebView();
3886 if (w == null) {
3887 return;
3888 }
3889
3890 if (wasAdded) {
3891 w.addPackageName(packageName);
3892 } else {
3893 w.removePackageName(packageName);
3894 }
3895 }
3896
3897 private void addPackageNames(Set<String> packageNames) {
3898 WebView w = mTabControl.getCurrentWebView();
3899 if (w == null) {
3900 return;
3901 }
3902
3903 w.addPackageNames(packageNames);
3904 }
3905
3906 private void getInstalledPackages() {
3907 AsyncTask<Void, Void, Set<String> > task =
3908 new AsyncTask<Void, Void, Set<String> >() {
3909 protected Set<String> doInBackground(Void... unused) {
3910 Set<String> installedPackages = new HashSet<String>();
3911 PackageManager pm = BrowserActivity.this.getPackageManager();
3912 if (pm != null) {
3913 List<PackageInfo> packages = pm.getInstalledPackages(0);
3914 for (PackageInfo p : packages) {
3915 if (BrowserActivity.this.sGoogleApps.contains(p.packageName)) {
3916 installedPackages.add(p.packageName);
3917 }
3918 }
3919 }
3920
3921 return installedPackages;
3922 }
3923
3924 // Executes on the UI thread
3925 protected void onPostExecute(Set<String> installedPackages) {
3926 addPackageNames(installedPackages);
3927 }
3928 };
3929 task.execute();
3930 }
3931
Grace Klobaeb6eef42009-09-15 17:56:32 -07003932 final static int LOCK_ICON_UNSECURE = 0;
3933 final static int LOCK_ICON_SECURE = 1;
3934 final static int LOCK_ICON_MIXED = 2;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003935
The Android Open Source Project0c908882009-03-03 19:32:16 -08003936 private BrowserSettings mSettings;
3937 private TabControl mTabControl;
3938 private ContentResolver mResolver;
3939 private FrameLayout mContentView;
Andrei Popescuadc008d2009-06-26 14:11:30 +01003940 private View mCustomView;
3941 private FrameLayout mCustomViewContainer;
Andrei Popescuc9b55562009-07-07 10:51:15 +01003942 private WebChromeClient.CustomViewCallback mCustomViewCallback;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003943
3944 // FIXME, temp address onPrepareMenu performance problem. When we move everything out of
3945 // view, we should rewrite this.
3946 private int mCurrentMenuState = 0;
3947 private int mMenuState = R.id.MAIN_MENU;
Andrei Popescuadc008d2009-06-26 14:11:30 +01003948 private int mOldMenuState = EMPTY_MENU;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003949 private static final int EMPTY_MENU = -1;
3950 private Menu mMenu;
3951
3952 private FindDialog mFindDialog;
Cary Clark01cfcdd2010-06-04 16:36:45 -04003953 private SelectDialog mSelectDialog;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003954 // Used to prevent chording to result in firing two shortcuts immediately
3955 // one after another. Fixes bug 1211714.
3956 boolean mCanChord;
3957
3958 private boolean mInLoad;
3959 private boolean mIsNetworkUp;
Ben Murdochb7cc8b42009-09-28 10:59:09 +01003960 private boolean mDidStopLoad;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003961
Cary Clark1f10cbf2010-03-22 11:45:23 -04003962 /* package */ boolean mActivityInPause = true;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003963
3964 private boolean mMenuIsDown;
3965
The Android Open Source Project0c908882009-03-03 19:32:16 -08003966 private static boolean mInTrace;
3967
3968 // Performance probe
3969 private static final int[] SYSTEM_CPU_FORMAT = new int[] {
3970 Process.PROC_SPACE_TERM | Process.PROC_COMBINE,
3971 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 1: user time
3972 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 2: nice time
3973 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 3: sys time
3974 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 4: idle time
3975 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 5: iowait time
3976 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG, // 6: irq time
3977 Process.PROC_SPACE_TERM | Process.PROC_OUT_LONG // 7: softirq time
3978 };
3979
3980 private long mStart;
3981 private long mProcessStart;
3982 private long mUserStart;
3983 private long mSystemStart;
3984 private long mIdleStart;
3985 private long mIrqStart;
3986
3987 private long mUiStart;
3988
3989 private Drawable mMixLockIcon;
3990 private Drawable mSecLockIcon;
The Android Open Source Project0c908882009-03-03 19:32:16 -08003991
3992 /* hold a ref so we can auto-cancel if necessary */
3993 private AlertDialog mAlertDialog;
3994
The Android Open Source Project0c908882009-03-03 19:32:16 -08003995 // The up-to-date URL and title (these can be different from those stored
3996 // in WebView, since it takes some time for the information in WebView to
3997 // get updated)
3998 private String mUrl;
3999 private String mTitle;
4000
4001 // As PageInfo has different style for landscape / portrait, we have
4002 // to re-open it when configuration changed
4003 private AlertDialog mPageInfoDialog;
Grace Kloba22ac16e2009-10-07 18:00:23 -07004004 private Tab mPageInfoView;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004005 // If the Page-Info dialog is launched from the SSL-certificate-on-error
4006 // dialog, we should not just dismiss it, but should get back to the
4007 // SSL-certificate-on-error dialog. This flag is used to store this state
Leon Scrogginsc7b92f82010-01-11 18:17:31 -05004008 private boolean mPageInfoFromShowSSLCertificateOnError;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004009
4010 // as SSLCertificateOnError has different style for landscape / portrait,
4011 // we have to re-open it when configuration changed
4012 private AlertDialog mSSLCertificateOnErrorDialog;
4013 private WebView mSSLCertificateOnErrorView;
4014 private SslErrorHandler mSSLCertificateOnErrorHandler;
4015 private SslError mSSLCertificateOnErrorError;
4016
4017 // as SSLCertificate has different style for landscape / portrait, we
4018 // have to re-open it when configuration changed
4019 private AlertDialog mSSLCertificateDialog;
Grace Kloba22ac16e2009-10-07 18:00:23 -07004020 private Tab mSSLCertificateView;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004021
4022 // as HttpAuthentication has different style for landscape / portrait, we
4023 // have to re-open it when configuration changed
4024 private AlertDialog mHttpAuthenticationDialog;
4025 private HttpAuthHandler mHttpAuthHandler;
4026
4027 /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
4028 new FrameLayout.LayoutParams(
Romain Guy15b8ec62010-01-08 15:06:43 -08004029 ViewGroup.LayoutParams.MATCH_PARENT,
4030 ViewGroup.LayoutParams.MATCH_PARENT);
Andrei Popescuadc008d2009-06-26 14:11:30 +01004031 /*package*/ static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
4032 new FrameLayout.LayoutParams(
Romain Guy15b8ec62010-01-08 15:06:43 -08004033 ViewGroup.LayoutParams.MATCH_PARENT,
4034 ViewGroup.LayoutParams.MATCH_PARENT,
Andrei Popescuadc008d2009-06-26 14:11:30 +01004035 Gravity.CENTER);
Grace Kloba47fdfdb2009-06-30 11:15:34 -07004036 // Google search
4037 final static String QuickSearch_G = "http://www.google.com/m?q=%s";
The Android Open Source Project0c908882009-03-03 19:32:16 -08004038 // Wikipedia search
4039 final static String QuickSearch_W = "http://en.wikipedia.org/w/index.php?search=%s&go=Go";
4040 // Dictionary search
4041 final static String QuickSearch_D = "http://dictionary.reference.com/search?q=%s";
4042 // Google Mobile Local search
4043 final static String QuickSearch_L = "http://www.google.com/m/search?site=local&q=%s&near=mountain+view";
4044
4045 final static String QUERY_PLACE_HOLDER = "%s";
4046
4047 // "source" parameter for Google search through search key
4048 final static String GOOGLE_SEARCH_SOURCE_SEARCHKEY = "browser-key";
4049 // "source" parameter for Google search through goto menu
4050 final static String GOOGLE_SEARCH_SOURCE_GOTO = "browser-goto";
4051 // "source" parameter for Google search through simplily type
4052 final static String GOOGLE_SEARCH_SOURCE_TYPE = "browser-type";
4053 // "source" parameter for Google search suggested by the browser
4054 final static String GOOGLE_SEARCH_SOURCE_SUGGEST = "browser-suggest";
4055 // "source" parameter for Google search from unknown source
4056 final static String GOOGLE_SEARCH_SOURCE_UNKNOWN = "unknown";
4057
4058 private final static String LOGTAG = "browser";
4059
The Android Open Source Project0c908882009-03-03 19:32:16 -08004060 private String mLastEnteredUrl;
4061
4062 private PowerManager.WakeLock mWakeLock;
4063 private final static int WAKELOCK_TIMEOUT = 5 * 60 * 1000; // 5 minutes
4064
4065 private Toast mStopToast;
4066
Leon Scroggins571b3762010-05-26 10:25:01 -04004067 private TitleBarBase mTitleBar;
Leon Scroggins81db3662009-06-04 17:45:11 -04004068
Ben Murdochbff2d602009-07-01 20:19:05 +01004069 private LinearLayout mErrorConsoleContainer = null;
4070 private boolean mShouldShowErrorConsole = false;
4071
The Android Open Source Project0c908882009-03-03 19:32:16 -08004072 // As the ids are dynamically created, we can't guarantee that they will
4073 // be in sequence, so this static array maps ids to a window number.
4074 final static private int[] WINDOW_SHORTCUT_ID_ARRAY =
4075 { R.id.window_one_menu_id, R.id.window_two_menu_id, R.id.window_three_menu_id,
4076 R.id.window_four_menu_id, R.id.window_five_menu_id, R.id.window_six_menu_id,
4077 R.id.window_seven_menu_id, R.id.window_eight_menu_id };
4078
4079 // monitor platform changes
4080 private IntentFilter mNetworkStateChangedFilter;
4081 private BroadcastReceiver mNetworkStateIntentReceiver;
4082
Grace Klobab4da0ad2009-05-14 14:45:40 -07004083 private BroadcastReceiver mPackageInstallationReceiver;
4084
Bjorn Bringerta7611812010-03-24 11:12:02 +00004085 private SystemAllowGeolocationOrigins mSystemAllowGeolocationOrigins;
4086
The Android Open Source Project0c908882009-03-03 19:32:16 -08004087 // activity requestCode
Nicolas Roard78a98e42009-05-11 13:34:17 +01004088 final static int COMBO_PAGE = 1;
4089 final static int DOWNLOAD_PAGE = 2;
4090 final static int PREFERENCES_PAGE = 3;
Leon Scroggins8d5fa432009-10-02 15:55:59 -04004091 final static int FILE_SELECTED = 4;
The Android Open Source Project0c908882009-03-03 19:32:16 -08004092
Andrei Popescu540035d2009-09-18 18:59:20 +01004093 // the default <video> poster
4094 private Bitmap mDefaultVideoPoster;
4095 // the video progress view
4096 private View mVideoProgressView;
4097
Andrei Popescu30995e72010-02-09 16:59:58 +00004098 // The Google packages we monitor for the navigator.isApplicationInstalled()
4099 // API. Add as needed.
4100 private static Set<String> sGoogleApps;
4101 static {
4102 sGoogleApps = new HashSet<String>();
4103 sGoogleApps.add("com.google.android.youtube");
4104 }
4105
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004106 /**
4107 * A UrlData class to abstract how the content will be set to WebView.
4108 * This base class uses loadUrl to show the content.
4109 */
Leon Scroggins6eac63e2010-03-15 18:19:14 -04004110 /* package */ static class UrlData {
Grace Kloba068e48b2010-01-26 18:11:27 -08004111 final String mUrl;
4112 final Map<String, String> mHeaders;
Leon Scroggins58d56c62010-01-28 15:12:40 -05004113 final Intent mVoiceIntent;
Grace Kloba60e095c2009-06-16 11:50:55 -07004114
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004115 UrlData(String url) {
4116 this.mUrl = url;
Grace Kloba068e48b2010-01-26 18:11:27 -08004117 this.mHeaders = null;
Leon Scroggins58d56c62010-01-28 15:12:40 -05004118 this.mVoiceIntent = null;
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004119 }
Grace Kloba60e095c2009-06-16 11:50:55 -07004120
Leon Scroggins58d56c62010-01-28 15:12:40 -05004121 UrlData(String url, Map<String, String> headers, Intent intent) {
Grace Kloba068e48b2010-01-26 18:11:27 -08004122 this.mUrl = url;
4123 this.mHeaders = headers;
Leon Scrogginsa1cc3fd2010-02-01 16:14:11 -05004124 if (RecognizerResultsIntent.ACTION_VOICE_SEARCH_RESULTS
4125 .equals(intent.getAction())) {
Leon Scroggins58d56c62010-01-28 15:12:40 -05004126 this.mVoiceIntent = intent;
4127 } else {
4128 this.mVoiceIntent = null;
4129 }
Grace Kloba60e095c2009-06-16 11:50:55 -07004130 }
4131
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004132 boolean isEmpty() {
Leon Scroggins58d56c62010-01-28 15:12:40 -05004133 return mVoiceIntent == null && (mUrl == null || mUrl.length() == 0);
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004134 }
4135
Leon Scroggins92472e82010-02-17 16:32:28 -05004136 /**
4137 * Load this UrlData into the given Tab. Use loadUrlDataIn to update
4138 * the title bar as well.
4139 */
Leon Scroggins58d56c62010-01-28 15:12:40 -05004140 public void loadIn(Tab t) {
4141 if (mVoiceIntent != null) {
4142 t.activateVoiceSearchMode(mVoiceIntent);
4143 } else {
4144 t.getWebView().loadUrl(mUrl, mHeaders);
4145 }
Mitsuru Oshima25ad8ab2009-06-10 16:26:07 -07004146 }
4147 };
4148
Leon Scroggins1f005d32009-08-10 17:36:42 -04004149 /* package */ static final UrlData EMPTY_URL_DATA = new UrlData(null);
The Android Open Source Project0c908882009-03-03 19:32:16 -08004150}