[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 7b5dc00 | 2010-11-16 23:08:10 | [diff] [blame] | 5 | #include "chrome/browser/ui/browser.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 6 | |
[email protected] | aca02cf | 2010-05-03 18:56:01 | [diff] [blame] | 7 | #if defined(OS_WIN) |
[email protected] | 541434c | 2011-06-25 01:38:59 | [diff] [blame] | 8 | #include <windows.h> |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 9 | #include <shellapi.h> |
[email protected] | aca02cf | 2010-05-03 18:56:01 | [diff] [blame] | 10 | #endif // OS_WIN |
| 11 | |
[email protected] | 5dcbc02f | 2010-01-26 22:32:06 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | #include <string> |
| 14 | |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 15 | #include "base/base_paths.h" |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 16 | #include "base/bind.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 17 | #include "base/command_line.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 18 | #include "base/logging.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 19 | #include "base/metrics/field_trial.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 20 | #include "base/metrics/histogram.h" |
[email protected] | b02d038 | 2009-11-30 21:19:50 | [diff] [blame] | 21 | #include "base/path_service.h" |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 22 | #include "base/process_info.h" |
[email protected] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 23 | #include "base/string_number_conversions.h" |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 24 | #include "base/string_util.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 25 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 26 | #include "base/threading/thread.h" |
| 27 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 28 | #include "base/time.h" |
[email protected] | 6524385ef | 2010-08-18 06:34:13 | [diff] [blame] | 29 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 30 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 77a91c7 | 2012-08-13 16:19:34 | [diff] [blame] | 31 | #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 32 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 33 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 34 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 35 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 36 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 37 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 38 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 39 | #include "chrome/browser/character_encoding.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 40 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 41 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 42 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 43 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 44 | #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 45 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 46 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 7fb4bbb | 2012-05-27 18:06:22 | [diff] [blame] | 47 | #include "chrome/browser/download/download_crx_util.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 48 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 49 | #include "chrome/browser/download/download_service.h" |
| 50 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | a1bc3b8 | 2012-04-19 19:32:20 | [diff] [blame] | 51 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 52 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 53 | #include "chrome/browser/download/download_util.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 54 | #include "chrome/browser/extensions/browser_extension_window_controller.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 55 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 57 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | a6394ae | 2012-07-16 20:58:43 | [diff] [blame] | 58 | #include "chrome/browser/extensions/tab_helper.h" |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 59 | #include "chrome/browser/favicon/favicon_tab_helper.h" |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 60 | #include "chrome/browser/file_select_helper.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 61 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 62 | #include "chrome/browser/google/google_url_tracker.h" |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 63 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 65c8114 | 2012-07-31 19:44:43 | [diff] [blame] | 64 | #include "chrome/browser/intents/device_attached_intent_source.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 65 | #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 66 | #include "chrome/browser/intents/web_intents_reporting.h" |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 67 | #include "chrome/browser/intents/web_intents_util.h" |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 68 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 4afde5c | 2012-06-25 17:00:53 | [diff] [blame] | 69 | #include "chrome/browser/media/media_stream_devices_controller.h" |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 70 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 71 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 72 | #include "chrome/browser/platform_util.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 73 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 74 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 75 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 76 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 77 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 78 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 79 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 80 | #include "chrome/browser/profiles/profile_metrics.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 81 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 82 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 83 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 84 | #include "chrome/browser/sessions/session_tab_helper.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 85 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 86 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 87 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 88 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 89 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 90 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 91 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 92 | #include "chrome/browser/tab_contents/retargeting_details.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 93 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 94 | #include "chrome/browser/themes/theme_service.h" |
| 95 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | 82194b5fb | 2012-05-22 23:53:07 | [diff] [blame] | 96 | #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 97 | #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 98 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 99 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 100 | #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 101 | #include "chrome/browser/ui/browser_dialogs.h" |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 102 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 103 | #include "chrome/browser/ui/browser_instant_controller.h" |
[email protected] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 104 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 105 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 106 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 107 | #include "chrome/browser/ui/browser_tab_strip_model_delegate.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 108 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 109 | #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 110 | #include "chrome/browser/ui/browser_ui_prefs.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 111 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 112 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 113 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 114 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 115 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 116 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 117 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | 9d5c059a8 | 2012-06-29 20:13:07 | [diff] [blame] | 118 | #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 119 | #include "chrome/browser/ui/global_error/global_error.h" |
| 120 | #include "chrome/browser/ui/global_error/global_error_service.h" |
| 121 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 122 | #include "chrome/browser/ui/hung_plugin_tab_helper.h" |
[email protected] | 943b861 | 2011-08-31 21:07:13 | [diff] [blame] | 123 | #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 124 | #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 125 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | fe90ca8e | 2011-04-08 20:40:43 | [diff] [blame] | 126 | #include "chrome/browser/ui/panels/panel.h" |
| 127 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 128 | #include "chrome/browser/ui/search/search.h" |
| 129 | #include "chrome/browser/ui/search/search_delegate.h" |
| 130 | #include "chrome/browser/ui/search/search_model.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 131 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 132 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 133 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 134 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 135 | #include "chrome/browser/ui/tab_contents/tab_contents.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 136 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 137 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 138 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 139 | #include "chrome/browser/ui/unload_controller.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 140 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | 6554918 | 2012-02-25 00:45:40 | [diff] [blame] | 141 | #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 142 | #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
[email protected] | 0363942 | 2012-06-28 19:03:37 | [diff] [blame] | 143 | #include "chrome/browser/ui/window_sizer/window_sizer.h" |
[email protected] | b1b7394 | 2010-05-26 20:11:54 | [diff] [blame] | 144 | #include "chrome/browser/upgrade_detector.h" |
[email protected] | 86b5401 | 2009-11-19 09:18:50 | [diff] [blame] | 145 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 146 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 147 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 148 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 149 | #include "chrome/common/custom_handlers/protocol_handler.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 150 | #include "chrome/common/extensions/extension.h" |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 151 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 152 | #include "chrome/common/pref_names.h" |
[email protected] | 7664ab3 | 2011-02-01 23:35:25 | [diff] [blame] | 153 | #include "chrome/common/profiling.h" |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 154 | #include "chrome/common/startup_metric_utils.h" |
[email protected] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 155 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 156 | #include "chrome/common/web_apps.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 157 | #include "content/public/browser/color_chooser.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 158 | #include "content/public/browser/devtools_manager.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 159 | #include "content/public/browser/download_item.h" |
| 160 | #include "content/public/browser/download_manager.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 161 | #include "content/public/browser/interstitial_page.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 162 | #include "content/public/browser/invalidate_type.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 163 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 164 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 165 | #include "content/public/browser/notification_details.h" |
| 166 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 167 | #include "content/public/browser/plugin_service.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 168 | #include "content/public/browser/render_process_host.h" |
| 169 | #include "content/public/browser/render_view_host.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 170 | #include "content/public/browser/site_instance.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 171 | #include "content/public/browser/user_metrics.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 172 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 173 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 174 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 175 | #include "content/public/common/content_restriction.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 176 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 177 | #include "content/public/common/page_zoom.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 178 | #include "content/public/common/renderer_preferences.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 179 | #include "grit/chromium_strings.h" |
| 180 | #include "grit/generated_resources.h" |
| 181 | #include "grit/locale_settings.h" |
[email protected] | 2a28133 | 2012-07-11 22:20:23 | [diff] [blame] | 182 | #include "grit/theme_resources.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 183 | #include "net/base/net_util.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 184 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 185 | #include "net/cookies/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 186 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 187 | #include "ui/base/animation/animation.h" |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 188 | #include "ui/base/dialogs/selected_file_info.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 189 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 190 | #include "ui/gfx/point.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 191 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 192 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 193 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 194 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 195 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 196 | |
| 197 | #if defined(OS_WIN) |
[email protected] | 77cbe50e | 2012-06-14 02:44:38 | [diff] [blame] | 198 | #include "base/win/metro.h" |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 199 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 200 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 201 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 202 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 203 | #include "chrome/browser/ui/view_ids.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 204 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 205 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 206 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 207 | #if defined(OS_CHROMEOS) |
[email protected] | 361c201 | 2012-09-05 16:31:13 | [diff] [blame] | 208 | #include "chrome/browser/chromeos/gdata/drive_file_system_util.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 209 | #endif |
| 210 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 211 | #if defined(USE_ASH) |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 212 | #include "ash/ash_switches.h" |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 213 | #endif |
| 214 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 215 | using base::TimeDelta; |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 216 | using content::NativeWebKeyboardEvent; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 217 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 218 | using content::NavigationEntry; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 219 | using content::OpenURLParams; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 220 | using content::PluginService; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 221 | using content::Referrer; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 222 | using content::SiteInstance; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 223 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 224 | using content::WebContents; |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 225 | using extensions::Extension; |
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 226 | using ui::WebDialogDelegate; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 228 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 229 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 230 | namespace { |
| 231 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 232 | // The URL to be loaded to display the "Report a broken page" form. |
| 233 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 234 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 235 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 236 | |
| 237 | // The URL for the privacy dashboard. |
| 238 | const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 239 | |
| 240 | // How long we wait before updating the browser chrome while loading a page. |
| 241 | const int kUIUpdateCoalescingTimeMS = 200; |
| 242 | |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 243 | bool AllowPanels(const std::string& app_name) { |
[email protected] | cae9765 | 2012-04-20 03:12:12 | [diff] [blame] | 244 | return PanelManager::ShouldUsePanels( |
| 245 | web_app::GetExtensionIdFromApplicationName(app_name)); |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 246 | } |
| 247 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 248 | BrowserWindow* CreateBrowserWindow(Browser* browser) { |
| 249 | #if !defined(USE_ASH) |
| 250 | if (browser->is_type_panel()) |
| 251 | return PanelManager::GetInstance()->CreatePanel(browser)->browser_window(); |
| 252 | #endif |
| 253 | return BrowserWindow::CreateBrowserWindow(browser); |
| 254 | } |
| 255 | |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 256 | #if defined(OS_CHROMEOS) |
| 257 | chrome::HostDesktopType kDefaultHostDesktopType = chrome::HOST_DESKTOP_TYPE_ASH; |
| 258 | #else |
| 259 | chrome::HostDesktopType kDefaultHostDesktopType = |
| 260 | chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 261 | #endif |
| 262 | |
| 263 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 264 | } // namespace |
| 265 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 266 | //////////////////////////////////////////////////////////////////////////////// |
| 267 | // Browser, CreateParams: |
| 268 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 269 | Browser::CreateParams::CreateParams() |
| 270 | : type(TYPE_TABBED), |
| 271 | profile(NULL), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 272 | host_desktop_type(kDefaultHostDesktopType), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 273 | app_type(APP_TYPE_HOST), |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 274 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 275 | is_session_restore(false), |
| 276 | window(NULL) { |
| 277 | } |
| 278 | |
| 279 | Browser::CreateParams::CreateParams(Profile* profile) |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 280 | : type(TYPE_TABBED), |
| 281 | profile(profile), |
| 282 | host_desktop_type(kDefaultHostDesktopType), |
| 283 | app_type(APP_TYPE_HOST), |
| 284 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 285 | is_session_restore(false), |
| 286 | window(NULL) { |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 289 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 290 | : type(type), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 291 | profile(profile), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 292 | host_desktop_type(kDefaultHostDesktopType), |
| 293 | app_type(APP_TYPE_HOST), |
| 294 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 295 | is_session_restore(false), |
| 296 | window(NULL) { |
| 297 | } |
| 298 | |
| 299 | Browser::CreateParams::CreateParams(Type type, |
| 300 | Profile* profile, |
| 301 | chrome::HostDesktopType host_desktop_type) |
| 302 | : type(type), |
| 303 | profile(profile), |
| 304 | host_desktop_type(host_desktop_type), |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 305 | app_type(APP_TYPE_HOST), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 306 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 307 | is_session_restore(false), |
| 308 | window(NULL) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 311 | // static |
| 312 | Browser::CreateParams Browser::CreateParams::CreateForApp( |
| 313 | Type type, |
| 314 | const std::string& app_name, |
| 315 | const gfx::Rect& window_bounds, |
| 316 | Profile* profile) { |
| 317 | DCHECK(type != TYPE_TABBED); |
| 318 | DCHECK(!app_name.empty()); |
| 319 | |
| 320 | if (type == TYPE_PANEL && !AllowPanels(app_name)) |
| 321 | type = TYPE_POPUP; |
| 322 | |
| 323 | CreateParams params(type, profile); |
| 324 | params.app_name = app_name; |
| 325 | params.app_type = APP_TYPE_CHILD; |
| 326 | params.initial_bounds = window_bounds; |
| 327 | |
| 328 | return params; |
| 329 | } |
| 330 | |
| 331 | // static |
| 332 | Browser::CreateParams Browser::CreateParams::CreateForDevTools( |
| 333 | Profile* profile) { |
| 334 | CreateParams params(TYPE_POPUP, profile); |
| 335 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 336 | return params; |
| 337 | } |
| 338 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 339 | /////////////////////////////////////////////////////////////////////////////// |
| 340 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 341 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 342 | Browser::Browser(const CreateParams& params) |
| 343 | : type_(params.type), |
| 344 | profile_(params.profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 345 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 346 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | 85537005 | 2012-07-10 19:30:32 | [diff] [blame] | 347 | tab_strip_model_delegate_( |
| 348 | new chrome::BrowserTabStripModelDelegate(this))), |
| 349 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 350 | tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 351 | params.profile))), |
| 352 | app_name_(params.app_name), |
| 353 | app_type_(params.app_type), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 354 | chrome_updater_factory_(this), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 355 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 356 | override_bounds_(params.initial_bounds), |
| 357 | initial_show_state_(params.initial_show_state), |
| 358 | is_session_restore_(params.is_session_restore), |
[email protected] | 56073dc | 2012-08-10 16:59:06 | [diff] [blame] | 359 | host_desktop_type_(params.host_desktop_type), |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 360 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 361 | unload_controller_(new chrome::UnloadController(this))), |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 362 | weak_factory_(this), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 363 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 364 | content_setting_bubble_model_delegate_( |
| 365 | new BrowserContentSettingBubbleModelDelegate(this))), |
| 366 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 367 | toolbar_model_delegate_( |
| 368 | new BrowserToolbarModelDelegate(this))), |
| 369 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 370 | tab_restore_service_delegate_( |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 371 | new BrowserTabRestoreServiceDelegate(this))), |
[email protected] | afefa74e | 2011-07-26 05:04:23 | [diff] [blame] | 372 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 373 | synced_window_delegate_( |
| 374 | new BrowserSyncedWindowDelegate(this))), |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 375 | bookmark_bar_state_(BookmarkBar::HIDDEN), |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 376 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 377 | command_controller_(new chrome::BrowserCommandController(this))), |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 378 | window_has_shown_(false) { |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 379 | if (!app_name_.empty()) |
| 380 | chrome::RegisterAppPrefs(app_name_, profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 381 | tab_strip_model_->AddObserver(this); |
| 382 | |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 383 | toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 384 | search_model_.reset(new chrome::search::SearchModel(NULL)); |
| 385 | search_delegate_.reset( |
[email protected] | 51a53e8f6 | 2012-08-28 03:08:56 | [diff] [blame] | 386 | new chrome::search::SearchDelegate(search_model_.get(), |
| 387 | toolbar_model_.get())); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 388 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 389 | registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 390 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 391 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 392 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 393 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 394 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 395 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 396 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 397 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 398 | content::NotificationService::AllSources()); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 399 | #if defined(ENABLE_THEMES) |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 400 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 401 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 402 | content::Source<ThemeService>( |
| 403 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 404 | #endif |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 405 | registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 406 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 408 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 409 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 410 | profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 411 | profile_pref_registrar_.Add(prefs::kHomePage, this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 412 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 413 | BrowserList::AddBrowser(this); |
| 414 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 415 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 416 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 417 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 418 | profile_->GetPrefs(), NULL); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 419 | |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 420 | instant_controller_.reset(new chrome::BrowserInstantController(this)); |
[email protected] | e545cb2 | 2012-08-27 23:31:23 | [diff] [blame] | 421 | |
| 422 | #if 0 |
| 423 | // Disabled for M22. See http://crbug.com/144326. |
[email protected] | 65c8114 | 2012-07-31 19:44:43 | [diff] [blame] | 424 | device_attached_intent_source_.reset( |
| 425 | new DeviceAttachedIntentSource(this, (this))); |
[email protected] | e545cb2 | 2012-08-27 23:31:23 | [diff] [blame] | 426 | #endif |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 427 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 428 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 429 | |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 430 | FilePath profile_path = profile_->GetPath(); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 431 | ProfileMetrics::LogProfileLaunch(profile_path); |
[email protected] | a4fe6701 | 2012-07-25 20:14:29 | [diff] [blame] | 432 | |
| 433 | window_ = params.window ? params.window : CreateBrowserWindow(this); |
| 434 | |
| 435 | // TODO(beng): move to BrowserFrameWin. |
| 436 | #if defined(OS_WIN) && !defined(USE_AURA) |
| 437 | // Set the app user model id for this application to that of the application |
| 438 | // name. See http://crbug.com/7028. |
| 439 | ui::win::SetAppIdForWindow( |
| 440 | is_app() && !is_type_panel() ? |
| 441 | ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_), |
| 442 | profile_->GetPath()) : |
| 443 | ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()), |
| 444 | window()->GetNativeWindow()); |
| 445 | |
| 446 | if (is_type_panel()) { |
| 447 | ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(), |
| 448 | window()->GetNativeWindow()); |
| 449 | } |
| 450 | #endif |
| 451 | |
| 452 | // Create the extension window controller before sending notifications. |
| 453 | extension_window_controller_.reset( |
| 454 | new BrowserExtensionWindowController(this)); |
| 455 | |
| 456 | // TODO(beng): Move BrowserList::AddBrowser() to the end of this function and |
| 457 | // replace uses of this with BL's notifications. |
| 458 | content::NotificationService::current()->Notify( |
| 459 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 460 | content::Source<Browser>(this), |
| 461 | content::NotificationService::NoDetails()); |
| 462 | |
| 463 | // TODO(beng): move to ChromeBrowserMain: |
| 464 | PrefService* local_state = g_browser_process->local_state(); |
| 465 | if (local_state && local_state->FindPreference( |
| 466 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 467 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
| 468 | // Notify PDM that this is a first run. |
| 469 | #if defined(OS_WIN) |
| 470 | ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
| 471 | #endif // defined(OS_WIN) |
| 472 | // Reset the preference so we don't call it again for subsequent windows. |
| 473 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
| 474 | } |
| 475 | |
[email protected] | 6fb528e | 2012-08-01 20:32:33 | [diff] [blame] | 476 | fullscreen_controller_.reset(new FullscreenController(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | Browser::~Browser() { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 480 | // The tab strip should not have any tabs at this point. |
| 481 | if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 482 | DCHECK(tab_strip_model_->empty()); |
| 483 | tab_strip_model_->RemoveObserver(this); |
| 484 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 485 | BrowserList::RemoveBrowser(this); |
| 486 | |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 487 | SessionService* session_service = |
| 488 | SessionServiceFactory::GetForProfile(profile_); |
| 489 | if (session_service) |
| 490 | session_service->WindowClosed(session_id_); |
| 491 | |
| 492 | TabRestoreService* tab_restore_service = |
| 493 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 494 | if (tab_restore_service) |
| 495 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 496 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 497 | #if !defined(OS_MACOSX) |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 498 | if (!browser::GetBrowserCount(profile_)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 499 | // We're the last browser window with this profile. We need to nuke the |
| 500 | // TabRestoreService, which will start the shutdown of the |
| 501 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 502 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 503 | // thread tries to use the IO thread (or another thread) that is no longer |
| 504 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 505 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 506 | // the last browser has closed. The Mac equivalent is in its app |
| 507 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 508 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 509 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 510 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 511 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 512 | profile_pref_registrar_.RemoveAll(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 513 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 514 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 515 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 516 | command_controller_.reset(); |
| 517 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 518 | if (profile_->IsOffTheRecord() && |
[email protected] | 474e5db | 2011-08-12 13:02:23 | [diff] [blame] | 519 | !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 520 | // An incognito profile is no longer needed, this indirectly frees |
| 521 | // its cache and cookies once it gets destroyed at the appropriate time. |
[email protected] | 4dffabe | 2012-05-19 14:37:06 | [diff] [blame] | 522 | ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | // There may be pending file dialogs, we need to tell them that we've gone |
| 526 | // away so they don't try and call back to us. |
| 527 | if (select_file_dialog_.get()) |
| 528 | select_file_dialog_->ListenerDestroyed(); |
| 529 | } |
| 530 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 531 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 532 | // Getters & Setters |
| 533 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 534 | FindBarController* Browser::GetFindBarController() { |
| 535 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 536 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 537 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 538 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 539 | find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this)); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 540 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 541 | } |
| 542 | return find_bar_controller_.get(); |
| 543 | } |
| 544 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 545 | bool Browser::HasFindBarController() const { |
| 546 | return find_bar_controller_.get() != NULL; |
| 547 | } |
| 548 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 549 | bool Browser::is_app() const { |
| 550 | return !app_name_.empty(); |
| 551 | } |
| 552 | |
| 553 | bool Browser::is_devtools() const { |
| 554 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 555 | } |
| 556 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 557 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 558 | // Browser, State Storage and Retrieval for UI: |
| 559 | |
[email protected] | 9b125b73 | 2012-08-17 04:43:55 | [diff] [blame] | 560 | gfx::Image Browser::GetCurrentPageIcon() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 561 | TabContents* contents = chrome::GetActiveTabContents(this); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 562 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 563 | // during the window's creation (before tabs have been added). |
[email protected] | 6172089 | 2012-08-03 19:35:33 | [diff] [blame] | 564 | return contents ? |
[email protected] | 9b125b73 | 2012-08-17 04:43:55 | [diff] [blame] | 565 | contents->favicon_tab_helper()->GetFavicon() : gfx::Image(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 568 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 569 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 570 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 571 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 572 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 573 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 574 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 575 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 576 | FormatTitleForDisplay(&title); |
| 577 | } |
| 578 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 579 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 580 | |
[email protected] | cae9765 | 2012-04-20 03:12:12 | [diff] [blame] | 581 | #if defined(OS_MACOSX) || defined(USE_ASH) |
| 582 | // On Mac or Ash, we don't want to suffix the page title with |
[email protected] | 22a3daa | 2009-11-09 22:03:33 | [diff] [blame] | 583 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 584 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 585 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 586 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 587 | // Don't append the app name to window titles on app frames and app popups |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 588 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 589 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 590 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 591 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 595 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 596 | size_t current_index = 0; |
| 597 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 598 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 599 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 600 | current_index = match_index; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /////////////////////////////////////////////////////////////////////////////// |
| 605 | // Browser, OnBeforeUnload handling: |
| 606 | |
| 607 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 608 | if (!CanCloseWithInProgressDownloads()) |
| 609 | return false; |
| 610 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 611 | return unload_controller_->ShouldCloseWindow(); |
| 612 | } |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 613 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 614 | bool Browser::IsAttemptingToCloseBrowser() const { |
| 615 | return unload_controller_->is_attempting_to_close_browser(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | void Browser::OnWindowClosing() { |
| 619 | if (!ShouldCloseWindow()) |
| 620 | return; |
| 621 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 622 | // Application should shutdown on last window close if the user is explicitly |
| 623 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 624 | // AppController on the Mac, or BackgroundContentsService for background |
| 625 | // pages). |
| 626 | bool should_quit_if_last_browser = |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 627 | browser_shutdown::IsTryingToQuit() || !browser::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 628 | |
[email protected] | 1e0c740 | 2012-07-27 10:48:15 | [diff] [blame] | 629 | if (should_quit_if_last_browser && BrowserList::size() == 1) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 630 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
| 631 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 632 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 633 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 634 | SessionService* session_service = |
| 635 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 636 | if (session_service) |
| 637 | session_service->WindowClosing(session_id()); |
| 638 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 639 | TabRestoreService* tab_restore_service = |
| 640 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 641 | |
| 642 | #if defined(USE_AURA) |
| 643 | if (tab_restore_service && is_app()) |
| 644 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 645 | #endif |
| 646 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 647 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 648 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 649 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 650 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 651 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 652 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 653 | content::Source<Browser>(this), |
[email protected] | 1e0c740 | 2012-07-27 10:48:15 | [diff] [blame] | 654 | content::NotificationService::NoDetails()); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 655 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 656 | chrome::CloseAllTabs(this); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 659 | void Browser::OnWindowActivated() { |
| 660 | // On some platforms we want to automatically reload tabs that are |
| 661 | // killed when the user selects them. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 662 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 663 | if (contents && contents->GetCrashedStatus() == |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 664 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 665 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 666 | switches::kReloadKilledTabs)) { |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 667 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | } |
| 671 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 672 | //////////////////////////////////////////////////////////////////////////////// |
| 673 | // In-progress download termination handling: |
| 674 | |
| 675 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 676 | if (cancel_downloads) { |
| 677 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 678 | chrome::CloseWindow(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 683 | // close again we'll show the warning again. |
| 684 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 685 | |
| 686 | // Show the download page so the user can figure-out what downloads are still |
| 687 | // in-progress. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 688 | chrome::ShowDownloads(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 691 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 692 | int* num_downloads_blocking) const { |
| 693 | DCHECK(num_downloads_blocking); |
| 694 | *num_downloads_blocking = 0; |
| 695 | |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 696 | if (IsAttemptingToCloseBrowser()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 697 | return DOWNLOAD_CLOSE_OK; |
| 698 | |
| 699 | // If we're not running a full browser process with a profile manager |
| 700 | // (testing), it's ok to close the browser. |
| 701 | if (!g_browser_process->profile_manager()) |
| 702 | return DOWNLOAD_CLOSE_OK; |
| 703 | |
| 704 | int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 705 | if (total_download_count == 0) |
| 706 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 707 | |
| 708 | // Figure out how many windows are open total, and associated with this |
| 709 | // profile, that are relevant for the ok-to-close decision. |
| 710 | int profile_window_count = 0; |
| 711 | int total_window_count = 0; |
| 712 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 713 | iter != BrowserList::end(); ++iter) { |
| 714 | // Don't count this browser window or any other in the process of closing. |
| 715 | Browser* const browser = *iter; |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 716 | // Window closing may be delayed, and windows that are in the process of |
| 717 | // closing don't count against our totals. |
| 718 | if (browser == this || browser->IsAttemptingToCloseBrowser()) |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 719 | continue; |
| 720 | |
| 721 | if ((*iter)->profile() == profile()) |
| 722 | profile_window_count++; |
| 723 | total_window_count++; |
| 724 | } |
| 725 | |
| 726 | // If there aren't any other windows, we're at browser shutdown, |
| 727 | // which would cancel all current downloads. |
| 728 | if (total_window_count == 0) { |
| 729 | *num_downloads_blocking = total_download_count; |
| 730 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 731 | } |
| 732 | |
| 733 | // If there aren't any other windows on our profile, and we're an incognito |
| 734 | // profile, and there are downloads associated with that profile, |
| 735 | // those downloads would be cancelled by our window (-> profile) close. |
| 736 | DownloadService* download_service = |
| 737 | DownloadServiceFactory::GetForProfile(profile()); |
| 738 | if (profile_window_count == 0 && download_service->DownloadCount() > 0 && |
| 739 | profile()->IsOffTheRecord()) { |
| 740 | *num_downloads_blocking = download_service->DownloadCount(); |
| 741 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 742 | } |
| 743 | |
| 744 | // Those are the only conditions under which we will block shutdown. |
| 745 | return DOWNLOAD_CLOSE_OK; |
| 746 | } |
| 747 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 748 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 749 | // Browser, TabStripModel pass-thrus: |
| 750 | |
| 751 | int Browser::tab_count() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 752 | return tab_strip_model_->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 755 | int Browser::active_index() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 756 | return tab_strip_model_->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 757 | } |
| 758 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 759 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 760 | // Browser, Tab adding/showing functions: |
| 761 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 762 | void Browser::WindowFullscreenStateChanged() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 763 | fullscreen_controller_->WindowFullscreenStateChanged(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 764 | command_controller_->FullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 765 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 766 | } |
| 767 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 768 | /////////////////////////////////////////////////////////////////////////////// |
| 769 | // Browser, Assorted browser commands: |
| 770 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 771 | void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { |
| 772 | fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 773 | } |
| 774 | |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 775 | #if defined(OS_MACOSX) |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 776 | void Browser::TogglePresentationMode() { |
| 777 | fullscreen_controller_->TogglePresentationMode(); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 778 | } |
| 779 | #endif |
| 780 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 781 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 782 | return SupportsWindowFeatureImpl(feature, true); |
| 783 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 784 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 785 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 786 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 789 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 790 | content::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 791 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 792 | // If "auto detect" is turned on, then any current override encoding |
| 793 | // is cleared. This also implicitly performs a reload. |
| 794 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 795 | // active encoding. |
| 796 | if (encoding_auto_detect_.GetValue()) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 797 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 798 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 799 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 800 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 804 | content::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 805 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 806 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 807 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 808 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 809 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 810 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 811 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 812 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 813 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 814 | encoding_id, |
| 815 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 816 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 817 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 818 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 821 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 822 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 823 | select_file_dialog_ = ui::SelectFileDialog::Create( |
[email protected] | 6e1fcd1 | 2012-07-02 17:14:20 | [diff] [blame] | 824 | this, new ChromeSelectFilePolicy( |
| 825 | chrome::GetActiveWebContents(this))); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 826 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 827 | const FilePath directory = profile_->last_selected_directory(); |
| 828 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 829 | // TODO(beng): figure out how to juggle this. |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 830 | gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 831 | select_file_dialog_->SelectFile(ui::SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 832 | string16(), directory, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 833 | NULL, 0, FILE_PATH_LITERAL(""), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 834 | parent_window, NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 837 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
| 838 | if (GetStatusBubble()) |
| 839 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
| 840 | } |
| 841 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 842 | /////////////////////////////////////////////////////////////////////////////// |
| 843 | |
| 844 | // static |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 845 | bool Browser::RunUnloadEventsHelper(WebContents* contents) { |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 846 | // If the WebContents is not connected yet, then there's no unload |
| 847 | // handler we can fire even if the WebContents has an unload listener. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 848 | // One case where we hit this is in a tab that has an infinite loop |
| 849 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 850 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 851 | // If the page has unload listeners, then we tell the renderer to fire |
| 852 | // them. Once they have fired, we'll get a message back saying whether |
| 853 | // to proceed closing the page or not, which sends us back to this method |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 854 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 855 | contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 856 | return true; |
| 857 | } |
| 858 | return false; |
| 859 | } |
| 860 | |
| 861 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 862 | void Browser::JSOutOfMemoryHelper(WebContents* web_contents) { |
| 863 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 864 | if (!tab_contents) |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 865 | return; |
| 866 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 867 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 868 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 869 | infobar_helper, |
| 870 | NULL, |
| 871 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
| 872 | true)); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 876 | void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 877 | const std::string& protocol, |
| 878 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 879 | const string16& title, |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 880 | bool user_gesture, |
| 881 | BrowserWindow* window) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 882 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 883 | if (!tab_contents || tab_contents->profile()->IsOffTheRecord()) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 884 | return; |
| 885 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 886 | ProtocolHandler handler = |
| 887 | ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 888 | |
| 889 | ProtocolHandlerRegistry* registry = |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 890 | tab_contents->profile()->GetProtocolHandlerRegistry(); |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 891 | TabSpecificContentSettings* content_settings = |
| 892 | tab_contents->content_settings(); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 893 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 894 | if (registry->SilentlyHandleRegisterHandlerRequest(handler)) |
| 895 | return; |
| 896 | |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 897 | if (!user_gesture && window) { |
| 898 | content_settings->set_pending_protocol_handler(handler); |
| 899 | content_settings->set_previous_protocol_handler( |
| 900 | registry->GetHandlerFor(handler.protocol())); |
| 901 | window->GetLocationBar()->UpdateContentSettingsIcons(); |
[email protected] | 3fa5e19 | 2012-07-15 00:40:34 | [diff] [blame] | 902 | return; |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | // Make sure content-setting icon is turned off in case the page does |
| 906 | // ungestured and gestured RPH calls. |
| 907 | if (window) { |
| 908 | content_settings->ClearPendingProtocolHandler(); |
| 909 | window->GetLocationBar()->UpdateContentSettingsIcons(); |
| 910 | } |
[email protected] | 3fa5e19 | 2012-07-15 00:40:34 | [diff] [blame] | 911 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 912 | content::RecordAction( |
| 913 | UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
| 914 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 915 | |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 916 | RegisterProtocolHandlerInfoBarDelegate* rph_delegate = |
| 917 | new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, |
| 918 | registry, |
| 919 | handler); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 920 | |
[email protected] | d715fb80 | 2012-08-20 16:34:13 | [diff] [blame] | 921 | for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); i++) { |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 922 | InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); |
| 923 | RegisterProtocolHandlerInfoBarDelegate* cast_delegate = |
| 924 | delegate->AsRegisterProtocolHandlerInfoBarDelegate(); |
| 925 | if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) { |
| 926 | infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate); |
| 927 | rph_delegate = NULL; |
| 928 | break; |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 929 | } |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 930 | } |
[email protected] | 96affbc8 | 2012-07-23 18:04:42 | [diff] [blame] | 931 | |
| 932 | if (rph_delegate != NULL) |
| 933 | infobar_helper->AddInfoBar(rph_delegate); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 937 | void Browser::FindReplyHelper(WebContents* web_contents, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 938 | int request_id, |
| 939 | int number_of_matches, |
| 940 | const gfx::Rect& selection_rect, |
| 941 | int active_match_ordinal, |
| 942 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 943 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 944 | if (!tab_contents || !tab_contents->find_tab_helper()) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 945 | return; |
| 946 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 947 | tab_contents->find_tab_helper()->HandleFindReply(request_id, |
| 948 | number_of_matches, |
| 949 | selection_rect, |
| 950 | active_match_ordinal, |
| 951 | final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 952 | } |
| 953 | |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 954 | // static |
| 955 | void Browser::RequestMediaAccessPermissionHelper( |
| 956 | content::WebContents* web_contents, |
| 957 | const content::MediaStreamRequest* request, |
| 958 | const content::MediaResponseCallback& callback) { |
| 959 | TabContents* tab = TabContents::FromWebContents(web_contents); |
| 960 | |
| 961 | scoped_ptr<MediaStreamDevicesController> |
| 962 | controller(new MediaStreamDevicesController(tab->profile(), |
| 963 | request, |
| 964 | callback)); |
| 965 | if (!controller->DismissInfoBarAndTakeActionOnSettings()) { |
| 966 | InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 967 | InfoBarDelegate* old_infobar = NULL; |
[email protected] | d715fb80 | 2012-08-20 16:34:13 | [diff] [blame] | 968 | for (size_t i = 0; i < infobar_helper->GetInfoBarCount(); ++i) { |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 969 | old_infobar = infobar_helper->GetInfoBarDelegateAt(i)-> |
| 970 | AsMediaStreamInfoBarDelegate(); |
| 971 | if (old_infobar) |
| 972 | break; |
| 973 | } |
| 974 | |
| 975 | InfoBarDelegate* infobar = |
| 976 | new MediaStreamInfoBarDelegate(infobar_helper, controller.release()); |
| 977 | if (old_infobar) |
| 978 | infobar_helper->ReplaceInfoBar(old_infobar, infobar); |
| 979 | else |
| 980 | infobar_helper->AddInfoBar(infobar); |
| 981 | } |
| 982 | } |
| 983 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 984 | void Browser::UpdateUIForNavigationInTab(TabContents* contents, |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 985 | content::PageTransition transition, |
| 986 | bool user_initiated) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 987 | tab_strip_model_->TabNavigating(contents, transition); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 988 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 989 | bool contents_is_selected = contents == chrome::GetActiveTabContents(this); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 990 | if (user_initiated && contents_is_selected && window()->GetLocationBar()) { |
| 991 | // Forcibly reset the location bar if the url is going to change in the |
| 992 | // current tab, since otherwise it won't discard any ongoing user edits, |
| 993 | // since it doesn't realize this is a user-initiated action. |
| 994 | window()->GetLocationBar()->Revert(); |
| 995 | } |
| 996 | |
| 997 | if (GetStatusBubble()) |
| 998 | GetStatusBubble()->Hide(); |
| 999 | |
| 1000 | // Update the location bar. This is synchronous. We specifically don't |
| 1001 | // update the load state since the load hasn't started yet and updating it |
| 1002 | // will put it out of sync with the actual state like whether we're |
| 1003 | // displaying a favicon, which controls the throbber. If we updated it here, |
| 1004 | // the throbber will show the default favicon for a split second when |
| 1005 | // navigating away from the new tab page. |
| 1006 | ScheduleUIUpdate(contents->web_contents(), content::INVALIDATE_TYPE_URL); |
| 1007 | |
[email protected] | e1f288d | 2012-05-23 19:36:10 | [diff] [blame] | 1008 | if (contents_is_selected) |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 1009 | contents->web_contents()->Focus(); |
| 1010 | } |
| 1011 | |
| 1012 | /////////////////////////////////////////////////////////////////////////////// |
| 1013 | // Browser, PageNavigator implementation: |
| 1014 | |
| 1015 | WebContents* Browser::OpenURL(const OpenURLParams& params) { |
| 1016 | return OpenURLFromTab(NULL, params); |
| 1017 | } |
| 1018 | |
[email protected] | 485fba4 | 2009-03-24 23:27:29 | [diff] [blame] | 1019 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1020 | // Browser, TabStripModelObserver implementation: |
| 1021 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1022 | void Browser::TabInsertedAt(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1023 | int index, |
| 1024 | bool foreground) { |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1025 | SetAsDelegate(contents->web_contents(), this); |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 1026 | contents->session_tab_helper()->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 1027 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1028 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1029 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1030 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 1031 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1032 | LoadingStateChanged(contents->web_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1033 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1034 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1035 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 1036 | |
| 1037 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1038 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1039 | } |
| 1040 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1041 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1042 | TabContents* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1043 | int index) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1044 | fullscreen_controller_->OnTabClosing(contents->web_contents()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1045 | content::NotificationService::current()->Notify( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 1046 | chrome::NOTIFICATION_TAB_CLOSING, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1047 | content::Source<NavigationController>( |
[email protected] | cca0f1e | 2012-01-03 18:27:46 | [diff] [blame] | 1048 | &contents->web_contents()->GetController()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1049 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1050 | |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 1051 | // Sever the WebContents' connection back to us. |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1052 | SetAsDelegate(contents->web_contents(), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1055 | void Browser::TabDetachedAt(TabContents* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1056 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1057 | } |
| 1058 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1059 | void Browser::TabDeactivated(TabContents* contents) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1060 | fullscreen_controller_->OnTabDeactivated(contents); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1061 | search_delegate_->OnTabDeactivated(contents); |
| 1062 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1063 | // Save what the user's currently typing, so it can be restored when we |
| 1064 | // switch back to this tab. |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 1065 | window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1066 | } |
| 1067 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1068 | void Browser::ActiveTabChanged(TabContents* old_contents, |
| 1069 | TabContents* new_contents, |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 1070 | int index, |
| 1071 | bool user_gesture) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1072 | // On some platforms we want to automatically reload tabs that are |
| 1073 | // killed when the user selects them. |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1074 | bool did_reload = false; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1075 | if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1076 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1077 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1078 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | 734d2669 | 2012-03-26 18:00:25 | [diff] [blame] | 1079 | LOG(WARNING) << "Reloading killed tab at " << index; |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1080 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1081 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1082 | "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1083 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1084 | did_reload = true; |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1085 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1086 | } |
| 1087 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1088 | // Discarded tabs always get reloaded. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1089 | if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) { |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1090 | LOG(WARNING) << "Reloading discarded tab at " << index; |
| 1091 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1092 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1093 | "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1094 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1095 | } |
| 1096 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1097 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1098 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1099 | ProcessPendingUIUpdates(); |
| 1100 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1101 | // Propagate the profile to the location bar. |
| 1102 | UpdateToolbar(true); |
| 1103 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1104 | // Propagate tab state to toolbar, tab-strip, etc. |
| 1105 | UpdateSearchState(new_contents); |
| 1106 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 1107 | // Update reload/stop state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1108 | command_controller_->LoadingStateChanged( |
| 1109 | new_contents->web_contents()->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1110 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1111 | // Update commands to reflect current state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1112 | command_controller_->TabStateChanged(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1113 | |
| 1114 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1115 | StatusBubble* status_bubble = GetStatusBubble(); |
| 1116 | if (status_bubble) { |
| 1117 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1118 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1119 | // Show the loading state (if any). |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1120 | status_bubble->SetStatus( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1121 | chrome::GetActiveTabContents(this)->core_tab_helper()->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1122 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1123 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 1124 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 1125 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1126 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1127 | } |
| 1128 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1129 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 1130 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1131 | SessionService* session_service = |
| 1132 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1133 | if (session_service && !tab_strip_model_->closing_all()) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1134 | session_service->SetSelectedTabInWindow(session_id(), active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1135 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1136 | |
| 1137 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1138 | } |
| 1139 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1140 | void Browser::TabMoved(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1141 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 1142 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1143 | DCHECK(from_index >= 0 && to_index >= 0); |
| 1144 | // Notify the history service. |
| 1145 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 1146 | } |
| 1147 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 1148 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1149 | TabContents* old_contents, |
| 1150 | TabContents* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 1151 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1152 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1153 | TabInsertedAt(new_contents, index, (index == active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1154 | |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1155 | int entry_count = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1156 | new_contents->web_contents()->GetController().GetEntryCount(); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1157 | if (entry_count > 0) { |
| 1158 | // Send out notification so that observers are updated appropriately. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1159 | new_contents->web_contents()->GetController().NotifyEntryChanged( |
| 1160 | new_contents->web_contents()->GetController().GetEntryAtIndex( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1161 | entry_count - 1), |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1162 | entry_count - 1); |
| 1163 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1164 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1165 | SessionService* session_service = |
| 1166 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1167 | if (session_service) { |
| 1168 | // The new_contents may end up with a different navigation stack. Force |
| 1169 | // the session service to update itself. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1170 | session_service->TabRestored(new_contents, |
| 1171 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1172 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 1173 | |
[email protected] | a026243 | 2012-04-13 15:48:09 | [diff] [blame] | 1174 | content::DevToolsManager::GetInstance()->ContentsReplaced( |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1175 | old_contents->web_contents(), new_contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1176 | } |
| 1177 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1178 | void Browser::TabPinnedStateChanged(TabContents* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1179 | SessionService* session_service = |
| 1180 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1181 | if (session_service) { |
| 1182 | session_service->SetPinnedState( |
| 1183 | session_id(), |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 1184 | chrome::GetTabContentsAt(this, index)->session_tab_helper()-> |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1185 | session_id(), |
| 1186 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1190 | void Browser::TabStripEmpty() { |
| 1191 | // Close the frame after we return to the message loop (not immediately, |
| 1192 | // otherwise it will destroy this object before the stack has a chance to |
| 1193 | // cleanly unwind.) |
| 1194 | // Note: This will be called several times if TabStripEmpty is called several |
| 1195 | // times. This is because it does not close the window if tabs are |
| 1196 | // still present. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1197 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1198 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1199 | } |
| 1200 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1201 | bool Browser::PreHandleKeyboardEvent(content::WebContents* source, |
| 1202 | const NativeWebKeyboardEvent& event, |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1203 | bool* is_keyboard_shortcut) { |
| 1204 | // Escape exits tabbed fullscreen mode. |
| 1205 | // TODO(koz): Write a test for this http://crbug.com/100441. |
| 1206 | if (event.windowsKeyCode == 27 && |
| 1207 | fullscreen_controller_->HandleUserPressedEscape()) { |
| 1208 | return true; |
| 1209 | } |
| 1210 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1211 | } |
| 1212 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1213 | void Browser::HandleKeyboardEvent(content::WebContents* source, |
| 1214 | const NativeWebKeyboardEvent& event) { |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1215 | window()->HandleKeyboardEvent(event); |
| 1216 | } |
| 1217 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1218 | bool Browser::TabsNeedBeforeUnloadFired() { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1219 | return unload_controller_->TabsNeedBeforeUnloadFired(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1220 | } |
| 1221 | |
[email protected] | d013f14 | 2012-04-27 17:31:14 | [diff] [blame] | 1222 | bool Browser::IsMouseLocked() const { |
| 1223 | return fullscreen_controller_->IsMouseLocked(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | void Browser::OnWindowDidShow() { |
| 1227 | if (window_has_shown_) |
| 1228 | return; |
| 1229 | window_has_shown_ = true; |
| 1230 | |
[email protected] | b5febf7 | 2012-07-29 18:10:09 | [diff] [blame] | 1231 | // CurrentProcessInfo::CreationTime() is currently only implemented on Mac and |
| 1232 | // Windows. |
| 1233 | #if defined(OS_MACOSX) || defined(OS_WIN) |
| 1234 | // Measure the latency from startup till the first browser window becomes |
| 1235 | // visible. |
| 1236 | static bool is_first_browser_window = true; |
| 1237 | if (is_first_browser_window && |
| 1238 | !startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 1239 | is_first_browser_window = false; |
| 1240 | const base::Time* process_creation_time = |
| 1241 | base::CurrentProcessInfo::CreationTime(); |
| 1242 | |
| 1243 | if (process_creation_time) { |
| 1244 | UMA_HISTOGRAM_LONG_TIMES( |
| 1245 | "Startup.BrowserWindowDisplay", |
| 1246 | base::Time::Now() - *process_creation_time); |
| 1247 | } |
| 1248 | } |
| 1249 | #endif // OS_MACOSX || OS_WIN |
| 1250 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1251 | // Nothing to do for non-tabbed windows. |
| 1252 | if (!is_type_tabbed()) |
| 1253 | return; |
| 1254 | |
| 1255 | // Show any pending global error bubble. |
| 1256 | GlobalErrorService* service = |
| 1257 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 1258 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 1259 | if (error) |
| 1260 | error->ShowBubbleView(this); |
| 1261 | } |
| 1262 | |
| 1263 | void Browser::ShowFirstRunBubble() { |
| 1264 | window()->GetLocationBar()->ShowFirstRunBubble(); |
| 1265 | } |
| 1266 | |
| 1267 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 1268 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1269 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1270 | WebContents* Browser::OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1271 | const OpenURLParams& params) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1272 | chrome::NavigateParams nav_params(this, params.url, params.transition); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1273 | nav_params.source_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1274 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | cb8fb01a | 2011-12-05 21:01:14 | [diff] [blame] | 1275 | nav_params.referrer = params.referrer; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1276 | nav_params.disposition = params.disposition; |
| 1277 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1278 | nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1279 | nav_params.user_gesture = true; |
| 1280 | nav_params.override_encoding = params.override_encoding; |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1281 | nav_params.is_renderer_initiated = params.is_renderer_initiated; |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1282 | nav_params.transferred_global_request_id = |
| 1283 | params.transferred_global_request_id; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame] | 1284 | chrome::Navigate(&nav_params); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1285 | |
| 1286 | return nav_params.target_contents ? |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1287 | nav_params.target_contents->web_contents() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1290 | void Browser::NavigationStateChanged(const WebContents* source, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1291 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1292 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1293 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1294 | ScheduleUIUpdate(source, changed_flags); |
| 1295 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 1296 | // We can synchronously update commands since they will only change once per |
| 1297 | // navigation, so we don't have to worry about flickering. We do, however, |
| 1298 | // need to update the command state early on load to always present usable |
| 1299 | // actions in the face of slow-to-commit pages. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1300 | if (changed_flags & (content::INVALIDATE_TYPE_URL | |
| 1301 | content::INVALIDATE_TYPE_LOAD)) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1302 | command_controller_->TabStateChanged(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1303 | } |
| 1304 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1305 | void Browser::AddNewContents(WebContents* source, |
| 1306 | WebContents* new_contents, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1307 | WindowOpenDisposition disposition, |
| 1308 | const gfx::Rect& initial_pos, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1309 | bool user_gesture, |
| 1310 | bool* was_blocked) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1311 | chrome::AddWebContents(this, source, new_contents, disposition, initial_pos, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1312 | user_gesture, was_blocked); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1313 | } |
| 1314 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1315 | void Browser::ActivateContents(WebContents* contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1316 | chrome::ActivateTabAt(this, tab_strip_model_->GetIndexOfWebContents(contents), |
| 1317 | false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1318 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1319 | } |
| 1320 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1321 | void Browser::DeactivateContents(WebContents* contents) { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1322 | window_->Deactivate(); |
| 1323 | } |
| 1324 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1325 | void Browser::LoadingStateChanged(WebContents* source) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1326 | window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1327 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1328 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1329 | WebContents* selected_contents = chrome::GetActiveWebContents(this); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1330 | if (source == selected_contents) { |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 1331 | bool is_loading = source->IsLoading(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1332 | command_controller_->LoadingStateChanged(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1333 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1334 | GetStatusBubble()->SetStatus( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1335 | chrome::GetActiveTabContents(this)->core_tab_helper()-> |
| 1336 | GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1337 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 1341 | void Browser::CloseContents(WebContents* source) { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1342 | if (unload_controller_->CanCloseContents(source)) |
| 1343 | chrome::CloseWebContents(this, source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1344 | } |
| 1345 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1346 | void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1347 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1348 | NOTREACHED() << "moving invalid browser type"; |
| 1349 | return; |
| 1350 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 1351 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1352 | } |
| 1353 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1354 | bool Browser::IsPopupOrPanel(const WebContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1355 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1356 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1357 | } |
| 1358 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1359 | void Browser::UpdateTargetURL(WebContents* source, int32 page_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1360 | const GURL& url) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1361 | if (!GetStatusBubble()) |
| 1362 | return; |
| 1363 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1364 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1365 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 1366 | GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1370 | void Browser::ContentsMouseEvent( |
| 1371 | WebContents* source, const gfx::Point& location, bool motion) { |
| 1372 | if (!GetStatusBubble()) |
| 1373 | return; |
| 1374 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1375 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1376 | GetStatusBubble()->MouseMoved(location, !motion); |
| 1377 | if (!motion) |
| 1378 | GetStatusBubble()->SetURL(GURL(), std::string()); |
| 1379 | } |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 1380 | } |
| 1381 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1382 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1383 | chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1384 | } |
| 1385 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1386 | void Browser::WebContentsFocused(WebContents* contents) { |
| 1387 | window_->WebContentsFocused(contents); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1390 | bool Browser::TakeFocus(content::WebContents* source, |
| 1391 | bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1392 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1393 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1394 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1395 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 1396 | return false; |
| 1397 | } |
| 1398 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1399 | bool Browser::IsApplication() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1400 | return is_app(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 1403 | gfx::Rect Browser::GetRootWindowResizerRect() const { |
| 1404 | return window_->GetRootWindowResizerRect(); |
| 1405 | } |
| 1406 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1407 | void Browser::BeforeUnloadFired(WebContents* web_contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1408 | bool proceed, |
| 1409 | bool* proceed_to_fire_unload) { |
[email protected] | f9b6c09 | 2012-07-09 19:32:28 | [diff] [blame] | 1410 | *proceed_to_fire_unload = |
| 1411 | unload_controller_->BeforeUnloadFired(web_contents, proceed); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1412 | } |
| 1413 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1414 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 1415 | // Two differences between this and FocusLocationBar(): |
| 1416 | // (1) This doesn't get recorded in user metrics, since it's called |
| 1417 | // internally. |
| 1418 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 1419 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 1420 | // focusable, but this may be reached at other times, e.g. while in |
| 1421 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1422 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 1423 | } |
| 1424 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 1425 | void Browser::RenderWidgetShowing() { |
| 1426 | window_->DisableInactiveFrame(); |
| 1427 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 1428 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 1429 | int Browser::GetExtraRenderViewHeight() const { |
| 1430 | return window_->GetExtraRenderViewHeight(); |
| 1431 | } |
| 1432 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1433 | void Browser::OnStartDownload(WebContents* source, |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 1434 | content::DownloadItem* download) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1435 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 2ae41f9d | 2012-06-11 20:13:38 | [diff] [blame] | 1436 | TabContents* constrained = GetConstrainingTabContents(tab_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1437 | if (constrained != tab_contents) { |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1438 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1439 | WebContents* constrained_tab = constrained->web_contents(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1440 | constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1441 | return; |
| 1442 | } |
| 1443 | |
| 1444 | if (!window()) |
| 1445 | return; |
| 1446 | |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1447 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 1448 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 1449 | shelf->AddDownload(new DownloadItemModel(download)); |
| 1450 | // Don't show the animation for "Save file" downloads. |
| 1451 | // For non-theme extensions, we don't show the download animation. |
| 1452 | // Show animation in same window as the download shelf. Download shelf |
| 1453 | // may not be in the same window that initiated the download, e.g. |
| 1454 | // Panels. |
| 1455 | // Don't show the animation if the selected tab is not visible (i.e. the |
| 1456 | // window is minimized, we're in a unit test, etc.). |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1457 | WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser()); |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1458 | if ((download->GetTotalBytes() > 0) && |
| 1459 | !download_crx_util::IsExtensionDownload(*download) && |
| 1460 | platform_util::IsVisible(shelf_tab->GetNativeView()) && |
| 1461 | ui::Animation::ShouldRenderRichAnimation()) { |
| 1462 | DownloadStartedAnimation::Show(shelf_tab); |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 1463 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1464 | |
| 1465 | // If the download occurs in a new tab, close it. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1466 | if (source->GetController().IsInitialNavigation() && tab_count() > 1) |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1467 | CloseContents(source); |
| 1468 | } |
| 1469 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1470 | void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1471 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1472 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1473 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1474 | chrome::ViewSource(this, tab_contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1475 | } |
| 1476 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1477 | void Browser::ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1478 | const GURL& frame_url, |
| 1479 | const std::string& frame_content_state) { |
| 1480 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1481 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1482 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1483 | chrome::ViewSource(this, tab_contents, frame_url, frame_content_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1484 | } |
| 1485 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1486 | void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 1487 | chrome::ShowTabModalConfirmDialog(new RepostFormWarningController(source), |
| 1488 | TabContents::FromWebContents(source)); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 1489 | } |
| 1490 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1491 | bool Browser::ShouldAddNavigationToHistory( |
| 1492 | const history::HistoryAddPageArgs& add_page_args, |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 1493 | content::NavigationType navigation_type) { |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 1494 | // Don't update history if running as app. |
| 1495 | return !IsApplication(); |
| 1496 | } |
| 1497 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1498 | bool Browser::ShouldCreateWebContents( |
| 1499 | WebContents* web_contents, |
| 1500 | int route_id, |
| 1501 | WindowContainerType window_container_type, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1502 | const string16& frame_name, |
| 1503 | const GURL& target_url) { |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1504 | if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1505 | // If a BackgroundContents is created, suppress the normal WebContents. |
| 1506 | return !MaybeCreateBackgroundContents( |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1507 | route_id, web_contents, frame_name, target_url); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | return true; |
| 1511 | } |
| 1512 | |
| 1513 | void Browser::WebContentsCreated(WebContents* source_contents, |
| 1514 | int64 source_frame_id, |
| 1515 | const GURL& target_url, |
| 1516 | WebContents* new_contents) { |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1517 | // Adopt the WebContents now, so all observers are in place, as the network |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1518 | // requests for its initial navigation will start immediately. The WebContents |
| 1519 | // will later be inserted into this browser using Browser::Navigate via |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 1520 | // AddNewContents. |
| 1521 | AdoptAsTabContents(new_contents); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1522 | |
| 1523 | // Notify. |
| 1524 | RetargetingDetails details; |
| 1525 | details.source_web_contents = source_contents; |
| 1526 | details.source_frame_id = source_frame_id; |
| 1527 | details.target_url = target_url; |
| 1528 | details.target_web_contents = new_contents; |
| 1529 | details.not_yet_in_tabstrip = true; |
| 1530 | content::NotificationService::current()->Notify( |
| 1531 | chrome::NOTIFICATION_RETARGETING, |
| 1532 | content::Source<Profile>(profile_), |
| 1533 | content::Details<RetargetingDetails>(&details)); |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 1534 | } |
| 1535 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1536 | void Browser::ContentRestrictionsChanged(WebContents* source) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1537 | command_controller_->ContentRestrictionsChanged(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 1538 | } |
| 1539 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1540 | void Browser::RendererUnresponsive(WebContents* source) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1541 | // Ignore hangs if print preview is open. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1542 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1543 | if (tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1544 | printing::PrintPreviewTabController* controller = |
| 1545 | printing::PrintPreviewTabController::GetInstance(); |
| 1546 | if (controller) { |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1547 | TabContents* preview_tab = |
| 1548 | controller->GetPrintPreviewForTab(tab_contents); |
| 1549 | if (preview_tab && preview_tab != tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1550 | return; |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 1555 | chrome::ShowHungRendererDialog(source); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1556 | } |
| 1557 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1558 | void Browser::RendererResponsive(WebContents* source) { |
[email protected] | 87586fb7 | 2012-07-02 13:15:02 | [diff] [blame] | 1559 | chrome::HideHungRendererDialog(source); |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1560 | } |
| 1561 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1562 | void Browser::WorkerCrashed(WebContents* source) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1563 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1564 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 1565 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1566 | infobar_helper, |
| 1567 | NULL, |
| 1568 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1569 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1570 | } |
| 1571 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1572 | void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1573 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1574 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1575 | } |
| 1576 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1577 | void Browser::DidNavigateToPendingEntry(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1578 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1579 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1580 | } |
| 1581 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 1582 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 1583 | return GetJavaScriptDialogCreatorInstance(); |
| 1584 | } |
| 1585 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1586 | content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1587 | int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1588 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1589 | #if defined(OS_WIN) |
| 1590 | // On Windows, only create a color chooser if one doesn't exist, because we |
| 1591 | // can't close the old color chooser dialog. |
| 1592 | if (!color_chooser_.get()) |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1593 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1594 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1595 | color)); |
| 1596 | #else |
| 1597 | if (color_chooser_.get()) |
| 1598 | color_chooser_->End(); |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1599 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1600 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1601 | color)); |
| 1602 | #endif |
| 1603 | return color_chooser_.get(); |
| 1604 | } |
| 1605 | |
| 1606 | void Browser::DidEndColorChooser() { |
| 1607 | color_chooser_.reset(); |
| 1608 | } |
| 1609 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1610 | void Browser::RunFileChooser(WebContents* web_contents, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1611 | const content::FileChooserParams& params) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1612 | FileSelectHelper::RunFileChooser(web_contents, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1613 | } |
| 1614 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1615 | void Browser::EnumerateDirectory(WebContents* web_contents, |
[email protected] | 33f8ad5 | 2012-05-22 18:10:13 | [diff] [blame] | 1616 | int request_id, |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1617 | const FilePath& path) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1618 | FileSelectHelper::EnumerateDirectory(web_contents, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1619 | } |
| 1620 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1621 | void Browser::ToggleFullscreenModeForTab(WebContents* web_contents, |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1622 | bool enter_fullscreen) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1623 | fullscreen_controller_->ToggleFullscreenModeForTab(web_contents, |
| 1624 | enter_fullscreen); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1625 | } |
| 1626 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1627 | bool Browser::IsFullscreenForTabOrPending( |
| 1628 | const WebContents* web_contents) const { |
| 1629 | return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1630 | } |
| 1631 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1632 | void Browser::JSOutOfMemory(WebContents* web_contents) { |
| 1633 | JSOutOfMemoryHelper(web_contents); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1634 | } |
| 1635 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1636 | void Browser::RegisterProtocolHandler(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1637 | const std::string& protocol, |
| 1638 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1639 | const string16& title, |
| 1640 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1641 | RegisterProtocolHandlerHelper( |
[email protected] | 7ae9c32 | 2012-07-17 23:46:44 | [diff] [blame] | 1642 | web_contents, protocol, url, title, user_gesture, window()); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1643 | } |
| 1644 | |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1645 | void Browser::RegisterIntentHandler( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1646 | WebContents* web_contents, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1647 | const webkit_glue::WebIntentServiceData& data, |
| 1648 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1649 | RegisterIntentHandlerHelper(web_contents, data, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1650 | } |
| 1651 | |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1652 | void Browser::WebIntentDispatch( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1653 | WebContents* web_contents, |
| 1654 | content::WebIntentsDispatcher* intents_dispatcher) { |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1655 | if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) { |
| 1656 | web_intents::RecordIntentsDispatchDisabled(); |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 1657 | return; |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1658 | } |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 1659 | |
[email protected] | 59d73ec | 2012-09-01 02:24:27 | [diff] [blame] | 1660 | web_intents::RecordIntentDispatchRequested(); |
[email protected] | 86238d2 | 2012-05-22 20:00:11 | [diff] [blame] | 1661 | |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1662 | if (!web_contents) { |
| 1663 | // Intent is system-caused and the picker will show over the currently |
| 1664 | // active web contents. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1665 | web_contents = chrome::GetActiveWebContents(this); |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1666 | } |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1667 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1668 | tab_contents->web_intent_picker_controller()->SetIntentsDispatcher( |
| 1669 | intents_dispatcher); |
| 1670 | tab_contents->web_intent_picker_controller()->ShowDialog( |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1671 | intents_dispatcher->GetIntent().action, |
| 1672 | intents_dispatcher->GetIntent().type); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1673 | } |
| 1674 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1675 | void Browser::UpdatePreferredSize(WebContents* source, |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1676 | const gfx::Size& pref_size) { |
| 1677 | window_->UpdatePreferredSize(source, pref_size); |
| 1678 | } |
| 1679 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1680 | void Browser::ResizeDueToAutoResize(WebContents* source, |
| 1681 | const gfx::Size& new_size) { |
| 1682 | window_->ResizeDueToAutoResize(source, new_size); |
| 1683 | } |
| 1684 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1685 | void Browser::FindReply(WebContents* web_contents, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1686 | int request_id, |
| 1687 | int number_of_matches, |
| 1688 | const gfx::Rect& selection_rect, |
| 1689 | int active_match_ordinal, |
| 1690 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1691 | FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1692 | active_match_ordinal, final_update); |
| 1693 | } |
| 1694 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1695 | void Browser::RequestToLockMouse(WebContents* web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1696 | bool user_gesture, |
| 1697 | bool last_unlocked_by_target) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1698 | fullscreen_controller_->RequestToLockMouse(web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1699 | user_gesture, |
| 1700 | last_unlocked_by_target); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1701 | } |
| 1702 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1703 | void Browser::LostMouseLock() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1704 | fullscreen_controller_->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1705 | } |
| 1706 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1707 | void Browser::RequestMediaAccessPermission( |
| 1708 | content::WebContents* web_contents, |
| 1709 | const content::MediaStreamRequest* request, |
| 1710 | const content::MediaResponseCallback& callback) { |
[email protected] | c55d3d12 | 2012-07-10 16:53:41 | [diff] [blame] | 1711 | RequestMediaAccessPermissionHelper(web_contents, request, callback); |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1712 | } |
| 1713 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1714 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1715 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 1716 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1717 | void Browser::SwapTabContents(TabContents* old_tab_contents, |
| 1718 | TabContents* new_tab_contents) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1719 | int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1720 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1721 | tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1722 | } |
| 1723 | |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1724 | bool Browser::CanReloadContents(TabContents* source) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1725 | return chrome::CanReload(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | bool Browser::CanSaveContents(TabContents* source) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1729 | return chrome::CanSavePage(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1730 | } |
| 1731 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1732 | /////////////////////////////////////////////////////////////////////////////// |
| 1733 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 1734 | |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 1735 | void Browser::ConfirmAddSearchProvider(TemplateURL* template_url, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1736 | Profile* profile) { |
| 1737 | window()->ConfirmAddSearchProvider(template_url, profile); |
| 1738 | } |
| 1739 | |
| 1740 | /////////////////////////////////////////////////////////////////////////////// |
| 1741 | // Browser, ConstrainedWindowTabHelperDelegate implementation: |
| 1742 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1743 | void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) { |
| 1744 | int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1745 | if (index == TabStripModel::kNoTab) { |
| 1746 | NOTREACHED(); |
| 1747 | return; |
| 1748 | } |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1749 | tab_strip_model_->SetTabBlocked(index, blocked); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1750 | command_controller_->PrintingStateChanged(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1751 | if (!blocked && chrome::GetActiveTabContents(this) == tab_contents) |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1752 | tab_contents->web_contents()->Focus(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1753 | } |
| 1754 | |
| 1755 | /////////////////////////////////////////////////////////////////////////////// |
| 1756 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 1757 | |
[email protected] | 2ae41f9d | 2012-06-11 20:13:38 | [diff] [blame] | 1758 | TabContents* Browser::GetConstrainingTabContents(TabContents* source) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1759 | return source; |
| 1760 | } |
| 1761 | |
| 1762 | /////////////////////////////////////////////////////////////////////////////// |
| 1763 | // Browser, BookmarkTabHelperDelegate implementation: |
| 1764 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1765 | void Browser::URLStarredChanged(TabContents* source, bool starred) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1766 | if (source == chrome::GetActiveTabContents(this)) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1767 | window_->SetStarredState(starred); |
| 1768 | } |
| 1769 | |
| 1770 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1771 | // Browser, ZoomObserver implementation: |
| 1772 | |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1773 | void Browser::OnZoomChanged(TabContents* source, bool can_show_bubble) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1774 | if (source == chrome::GetActiveTabContents(this)) { |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1775 | // Only show the zoom bubble for zoom changes in the active window. |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 1776 | window_->ZoomChangedForActiveTab(can_show_bubble && window_->IsActive()); |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | |
| 1780 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 92f5408 | 2012-07-31 01:43:14 | [diff] [blame] | 1781 | // Browser, ui::SelectFileDialog::Listener implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1782 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 1783 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 53f04c8 | 2012-07-26 02:31:09 | [diff] [blame] | 1784 | FileSelectedWithExtraInfo(ui::SelectedFileInfo(path, path), index, params); |
| 1785 | } |
| 1786 | |
| 1787 | void Browser::FileSelectedWithExtraInfo( |
| 1788 | const ui::SelectedFileInfo& file_info, |
| 1789 | int index, |
| 1790 | void* params) { |
| 1791 | profile_->set_last_selected_directory(file_info.file_path.DirName()); |
| 1792 | |
| 1793 | const FilePath& path = file_info.local_path; |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 1794 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1795 | |
| 1796 | #if defined(OS_CHROMEOS) |
[email protected] | 06809de | 2012-09-07 05:51:05 | [diff] [blame] | 1797 | gdata::util::ModifyDriveFileResourceUrl(profile_, path, &file_url); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 1798 | #endif |
| 1799 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1800 | if (file_url.is_empty()) |
| 1801 | return; |
| 1802 | |
| 1803 | OpenURL(OpenURLParams( |
| 1804 | file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 1805 | false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1809 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1810 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1811 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1812 | const content::NotificationSource& source, |
| 1813 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1814 | switch (type) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1815 | case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1816 | // When the current tab's SSL state changes, we need to update the URL |
[email protected] | 90e8d06 | 2008-09-08 02:26:32 | [diff] [blame] | 1817 | // bar to reflect the new state. Note that it's possible for the selected |
| 1818 | // tab contents to be NULL. This is because we listen for all sources |
| 1819 | // (NavigationControllers) for convenience, so the notification could |
| 1820 | // actually be for a different window while we're doing asynchronous |
| 1821 | // closing of this one. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1822 | if (chrome::GetActiveWebContents(this) && |
| 1823 | &chrome::GetActiveWebContents(this)->GetController() == |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1824 | content::Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1825 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1826 | break; |
| 1827 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1828 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1829 | if (window()->GetLocationBar()) |
| 1830 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 1831 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 1832 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 1833 | // in which case let the sad tabs remain. |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 1834 | if (content::Details<extensions::UnloadedExtensionInfo>( |
| 1835 | details)->reason != extension_misc::UNLOAD_REASON_TERMINATE) { |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 1836 | const Extension* extension = |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 1837 | content::Details<extensions::UnloadedExtensionInfo>( |
| 1838 | details)->extension; |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1839 | for (int i = tab_strip_model_->count() - 1; i >= 0; --i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1840 | WebContents* tc = chrome::GetTabContentsAt(this, i)->web_contents(); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 1841 | bool close_tab_contents = |
| 1842 | tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 1843 | tc->GetURL().host() == extension->id(); |
| 1844 | // We want to close all panels originated by the unloaded extension. |
| 1845 | close_tab_contents = close_tab_contents || |
| 1846 | (type_ == TYPE_PANEL && |
| 1847 | (web_app::GetExtensionIdFromApplicationName(app_name_) == |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 1848 | extension->id())); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1849 | if (close_tab_contents) |
| 1850 | chrome::CloseWebContents(this, tc); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1851 | } |
| 1852 | } |
| 1853 | break; |
| 1854 | } |
| 1855 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1856 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1857 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 1858 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1859 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 1860 | break; |
| 1861 | } |
| 1862 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1863 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| 1864 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
[email protected] | 1797f4a | 2011-08-30 18:00:28 | [diff] [blame] | 1865 | // During window creation on Windows we may end up calling into |
| 1866 | // SHAppBarMessage, which internally spawns a nested message loop. This |
| 1867 | // makes it possible for us to end up here before window creation has |
| 1868 | // completed,at which point window_ is NULL. See 94752 for details. |
| 1869 | if (window() && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 1870 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1871 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 1872 | |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1873 | #if defined(ENABLE_THEMES) |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1874 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1875 | window()->UserChangedTheme(); |
| 1876 | break; |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 1877 | #endif |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 1878 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1879 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1880 | const std::string& pref_name = |
| 1881 | *content::Details<std::string>(details).ptr(); |
[email protected] | 7acfaf9 | 2012-07-11 15:51:59 | [diff] [blame] | 1882 | if (pref_name == prefs::kDevToolsDisabled) { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 1883 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1884 | content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 1885 | } else if (pref_name == prefs::kShowBookmarkBar) { |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 1886 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1887 | } else if (pref_name == prefs::kHomePage) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1888 | PrefService* pref_service = content::Source<PrefService>(source).ptr(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1889 | MarkHomePageAsChanged(pref_service); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 1890 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 1891 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 1892 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 1893 | break; |
| 1894 | } |
| 1895 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 1896 | case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 1897 | WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1898 | if (web_contents == chrome::GetActiveWebContents(this)) { |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 1899 | LocationBar* location_bar = window()->GetLocationBar(); |
| 1900 | if (location_bar) |
| 1901 | location_bar->UpdateContentSettingsIcons(); |
| 1902 | } |
| 1903 | break; |
| 1904 | } |
| 1905 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1906 | case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1907 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 1908 | break; |
| 1909 | |
| 1910 | case content::NOTIFICATION_INTERSTITIAL_DETACHED: |
| 1911 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1912 | break; |
| 1913 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1914 | default: |
| 1915 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1916 | } |
| 1917 | } |
| 1918 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 1919 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1920 | // Browser, Command and state updating (private): |
| 1921 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1922 | void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 1923 | pref_service->SetBoolean(prefs::kHomePageChanged, true); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1924 | } |
| 1925 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1926 | /////////////////////////////////////////////////////////////////////////////// |
| 1927 | // Browser, UI update coalescing and handling (private): |
| 1928 | |
| 1929 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1930 | window_->UpdateToolbar(chrome::GetActiveTabContents(this), |
| 1931 | should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1932 | } |
| 1933 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1934 | void Browser::UpdateSearchState(TabContents* contents) { |
| 1935 | if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) |
| 1936 | search_delegate_->OnTabActivated(contents); |
| 1937 | } |
| 1938 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1939 | void Browser::ScheduleUIUpdate(const WebContents* source, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1940 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1941 | if (!source) |
| 1942 | return; |
| 1943 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1944 | // Do some synchronous updates. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1945 | if (changed_flags & content::INVALIDATE_TYPE_URL && |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1946 | source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1947 | // Only update the URL for the current tab. Note that we do not update |
| 1948 | // the navigation commands since those would have already been updated |
| 1949 | // synchronously by NavigationStateChanged. |
| 1950 | UpdateToolbar(false); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1951 | changed_flags &= ~content::INVALIDATE_TYPE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1952 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1953 | if (changed_flags & content::INVALIDATE_TYPE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1954 | // Update the loading state synchronously. This is so the throbber will |
| 1955 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1956 | // this for any tab so they start & stop quickly. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1957 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1958 | chrome::GetIndexOfTab(this, source), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1959 | TabStripModelObserver::LOADING_ONLY); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1960 | // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, |
| 1961 | // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1962 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 1963 | } |
| 1964 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1965 | if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 1966 | // To correctly calculate whether the title changed while not loading |
| 1967 | // we need to process the update synchronously. This state only matters for |
| 1968 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 1969 | // asynchronously. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1970 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1971 | chrome::GetIndexOfTab(this, source), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 1972 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 1973 | } |
| 1974 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1975 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 1976 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 1977 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1978 | |
| 1979 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 1980 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1981 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1982 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1983 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1984 | MessageLoop::current()->PostDelayedTask( |
| 1985 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1986 | base::Bind(&Browser::ProcessPendingUIUpdates, |
| 1987 | chrome_updater_factory_.GetWeakPtr()), |
[email protected] | 11d6ab1a | 2012-01-12 21:37:26 | [diff] [blame] | 1988 | base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | void Browser::ProcessPendingUIUpdates() { |
| 1993 | #ifndef NDEBUG |
| 1994 | // Validate that all tabs we have pending updates for exist. This is scary |
| 1995 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 1996 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 1997 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 1998 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1999 | bool found = false; |
| 2000 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2001 | if (chrome::GetWebContentsAt(this, tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2002 | found = true; |
| 2003 | break; |
| 2004 | } |
| 2005 | } |
| 2006 | DCHECK(found); |
| 2007 | } |
| 2008 | #endif |
| 2009 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2010 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2011 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2012 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2013 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2014 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2015 | const WebContents* contents = i->first; |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2016 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2017 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2018 | if (contents == chrome::GetActiveWebContents(this)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2019 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 2020 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2021 | if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2022 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2023 | if (location_bar) |
| 2024 | location_bar->UpdatePageActions(); |
| 2025 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2026 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2027 | if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2028 | GetStatusBubble()->SetStatus(chrome::GetActiveTabContents(this)-> |
| 2029 | core_tab_helper()->GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2030 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2031 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2032 | if (flags & (content::INVALIDATE_TYPE_TAB | |
| 2033 | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2034 | window_->UpdateTitleBar(); |
| 2035 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 2036 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2037 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2038 | // Updates that don't depend upon the selected state go here. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2039 | if (flags & |
| 2040 | (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2041 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 2042 | tab_strip_model_->GetIndexOfWebContents(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2043 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 2047 | } |
| 2048 | |
| 2049 | scheduled_updates_.clear(); |
| 2050 | } |
| 2051 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2052 | void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2053 | if (!contents) |
| 2054 | return; |
| 2055 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2056 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 2057 | if (i != scheduled_updates_.end()) |
| 2058 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2059 | } |
| 2060 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 2061 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2062 | /////////////////////////////////////////////////////////////////////////////// |
| 2063 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2064 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2065 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 2066 | // In kiosk mode, we want to always hide the status bubble. |
| 2067 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 2068 | return NULL; |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 2069 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2070 | } |
| 2071 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2072 | /////////////////////////////////////////////////////////////////////////////// |
| 2073 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2074 | |
| 2075 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2076 | SessionService* session_service = |
| 2077 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2078 | if (session_service) { |
| 2079 | for (int i = index; i < tab_count(); ++i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2080 | TabContents* tab = chrome::GetTabContentsAt(this, i); |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 2081 | if (tab) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2082 | session_service->SetTabIndexInWindow( |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 2083 | session_id(), tab->session_tab_helper()->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2084 | session_service->SetPinnedState( |
| 2085 | session_id(), |
[email protected] | bde40b82 | 2012-08-30 17:28:56 | [diff] [blame] | 2086 | tab->session_tab_helper()->session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2087 | tab_strip_model_->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2093 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2094 | // Browser, In-progress download termination handling (private): |
| 2095 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 2096 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2097 | // If we've prompted, we need to hear from the user before we |
| 2098 | // can close. |
| 2099 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 2100 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 2101 | |
| 2102 | int num_downloads_blocking; |
| 2103 | if (DOWNLOAD_CLOSE_OK == |
| 2104 | OkToCloseWithInProgressDownloads(&num_downloads_blocking)) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 2105 | return true; |
| 2106 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2107 | // Closing this window will kill some downloads; prompt to make sure |
| 2108 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2109 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 2110 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 2111 | |
| 2112 | // Return false so the browser does not close. We'll close if the user |
| 2113 | // confirms in the dialog. |
| 2114 | return false; |
| 2115 | } |
| 2116 | |
| 2117 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2118 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2119 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2120 | void Browser::CloseFrame() { |
| 2121 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2122 | } |
| 2123 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2124 | void Browser::TabDetachedAtImpl(TabContents* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2125 | DetachType type) { |
| 2126 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 2127 | // Save the current location bar state, but only if the tab being detached |
| 2128 | // is the selected tab. Because saving state can conditionally revert the |
| 2129 | // location bar, saving the current tab's location bar state to a |
| 2130 | // non-selected tab can corrupt both tabs. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2131 | if (contents == chrome::GetActiveTabContents(this)) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2132 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2133 | if (location_bar) |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 2134 | location_bar->SaveStateToContents(contents->web_contents()); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2135 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2136 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2137 | if (!tab_strip_model_->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2138 | SyncHistoryWithTabs(0); |
| 2139 | } |
| 2140 | |
[email protected] | 6451fe9 | 2012-08-30 18:37:26 | [diff] [blame] | 2141 | SetAsDelegate(contents->web_contents(), NULL); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2142 | RemoveScheduledUpdatesFor(contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2143 | |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2144 | if (find_bar_controller_.get() && index == active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2145 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2146 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2147 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2148 | // Stop observing search model changes for this tab. |
| 2149 | search_delegate_->OnTabDetached(contents); |
| 2150 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2151 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2152 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 2153 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 2154 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2155 | } |
| 2156 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2157 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 2158 | bool check_fullscreen) const { |
| 2159 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 2160 | // other platforms, we hide some controls when in fullscreen mode. |
| 2161 | bool hide_ui_for_fullscreen = false; |
| 2162 | #if !defined(OS_MACOSX) |
| 2163 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 2164 | window_->IsFullscreen(); |
| 2165 | #endif |
| 2166 | |
| 2167 | unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
| 2168 | |
| 2169 | if (is_type_tabbed()) |
| 2170 | features |= FEATURE_BOOKMARKBAR; |
| 2171 | |
| 2172 | if (!hide_ui_for_fullscreen) { |
| 2173 | if (!is_type_tabbed()) |
| 2174 | features |= FEATURE_TITLEBAR; |
| 2175 | |
| 2176 | if (is_type_tabbed()) |
| 2177 | features |= FEATURE_TABSTRIP; |
| 2178 | |
| 2179 | if (is_type_tabbed()) |
| 2180 | features |= FEATURE_TOOLBAR; |
| 2181 | |
| 2182 | if (!is_app()) |
| 2183 | features |= FEATURE_LOCATIONBAR; |
| 2184 | } |
| 2185 | return !!(features & feature); |
| 2186 | } |
| 2187 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2188 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 2189 | BookmarkBar::State state; |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2190 | // The bookmark bar is hidden in fullscreen mode, unless on the new tab page. |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 2191 | if (browser_defaults::bookmarks_enabled && |
| 2192 | profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2193 | (!window_ || !window_->IsFullscreen())) { |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2194 | state = BookmarkBar::SHOW; |
| 2195 | } else { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2196 | TabContents* tab = chrome::GetActiveTabContents(this); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2197 | if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) |
| 2198 | state = BookmarkBar::DETACHED; |
| 2199 | else |
| 2200 | state = BookmarkBar::HIDDEN; |
| 2201 | } |
[email protected] | 2d4e43a0 | 2012-06-26 00:11:55 | [diff] [blame] | 2202 | |
| 2203 | // Only allow the bookmark bar to be shown in default mode. |
| 2204 | if (!search_model_->mode().is_default()) |
| 2205 | state = BookmarkBar::HIDDEN; |
| 2206 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2207 | if (state == bookmark_bar_state_) |
| 2208 | return; |
| 2209 | |
| 2210 | bookmark_bar_state_ = state; |
| 2211 | |
| 2212 | if (!window_) |
| 2213 | return; // This is called from the constructor when window_ is NULL. |
| 2214 | |
| 2215 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 2216 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 2217 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 2218 | // end up querying state once they process the tab switch. |
| 2219 | return; |
| 2220 | } |
| 2221 | |
| 2222 | BookmarkBar::AnimateChangeType animate_type = |
| 2223 | (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
| 2224 | BookmarkBar::ANIMATE_STATE_CHANGE : |
| 2225 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
| 2226 | window_->BookmarkBarStateChanged(animate_type); |
| 2227 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 2228 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2229 | bool Browser::MaybeCreateBackgroundContents(int route_id, |
| 2230 | WebContents* opener_web_contents, |
| 2231 | const string16& frame_name, |
| 2232 | const GURL& target_url) { |
| 2233 | GURL opener_url = opener_web_contents->GetURL(); |
| 2234 | ExtensionService* extensions_service = profile_->GetExtensionService(); |
| 2235 | |
| 2236 | if (!opener_url.is_valid() || |
| 2237 | frame_name.empty() || |
| 2238 | !extensions_service || |
| 2239 | !extensions_service->is_ready()) |
| 2240 | return false; |
| 2241 | |
| 2242 | // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2243 | // can create BackgroundContents. We don't have to check for background |
| 2244 | // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2245 | // message is processed. |
| 2246 | const Extension* extension = |
| 2247 | extensions_service->extensions()->GetHostedAppByURL( |
| 2248 | ExtensionURLInfo(opener_url)); |
| 2249 | if (!extension) |
| 2250 | return false; |
| 2251 | |
| 2252 | // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2253 | BackgroundContentsService* service = |
| 2254 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2255 | if (!service) |
| 2256 | return false; |
| 2257 | |
| 2258 | // Ensure that we're trying to open this from the extension's process. |
| 2259 | SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); |
| 2260 | extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 2261 | if (!opener_site_instance->GetProcess() || |
| 2262 | !process_map->Contains( |
| 2263 | extension->id(), opener_site_instance->GetProcess()->GetID())) { |
| 2264 | return false; |
| 2265 | } |
| 2266 | |
| 2267 | // Only allow a single background contents per app. |
| 2268 | bool allow_js_access = extension->allow_background_js_access(); |
| 2269 | BackgroundContents* existing = |
| 2270 | service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
| 2271 | if (existing) { |
| 2272 | // For non-scriptable background contents, ignore the request altogether, |
| 2273 | // (returning true, so that a regular WebContents isn't created either). |
| 2274 | if (!allow_js_access) |
| 2275 | return true; |
| 2276 | // For scriptable background pages, if one already exists, close it (even |
| 2277 | // if it was specified in the manifest). |
| 2278 | DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
| 2279 | delete existing; |
| 2280 | } |
| 2281 | |
| 2282 | // If script access is not allowed, create the the background contents in a |
| 2283 | // new SiteInstance, so that a separate process is used. |
| 2284 | scoped_refptr<content::SiteInstance> site_instance = |
| 2285 | allow_js_access ? |
| 2286 | opener_site_instance : |
| 2287 | content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); |
| 2288 | |
| 2289 | // Passed all the checks, so this should be created as a BackgroundContents. |
| 2290 | BackgroundContents* contents = service->CreateBackgroundContents( |
| 2291 | site_instance, |
| 2292 | route_id, |
| 2293 | profile_, |
| 2294 | frame_name, |
| 2295 | ASCIIToUTF16(extension->id())); |
| 2296 | |
| 2297 | // When a separate process is used, the original renderer cannot access the |
| 2298 | // new window later, thus we need to navigate the window now. |
| 2299 | if (contents && !allow_js_access) { |
| 2300 | contents->web_contents()->GetController().LoadURL( |
| 2301 | target_url, |
| 2302 | content::Referrer(), |
| 2303 | content::PAGE_TRANSITION_LINK, |
| 2304 | std::string()); // No extra headers. |
| 2305 | } |
| 2306 | |
| 2307 | return contents != NULL; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 2308 | } |