[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] | 0af8f13 | 2011-07-16 01:37:02 | [diff] [blame] | 22 | #include "base/string_number_conversions.h" |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 23 | #include "base/string_util.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 24 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 25 | #include "base/threading/thread.h" |
| 26 | #include "base/threading/thread_restrictions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 27 | #include "base/time.h" |
[email protected] | 6524385ef | 2010-08-18 06:34:13 | [diff] [blame] | 28 | #include "base/utf_string_conversions.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 29 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 30 | #include "chrome/browser/autofill/personal_data_manager_factory.h" |
[email protected] | a07676b2 | 2011-06-17 16:36:53 | [diff] [blame] | 31 | #include "chrome/browser/background/background_contents_service.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 32 | #include "chrome/browser/background/background_contents_service_factory.h" |
[email protected] | a9afddb | 2009-02-12 17:49:42 | [diff] [blame] | 33 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 34 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 35 | #include "chrome/browser/browser_process.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 36 | #include "chrome/browser/browser_shutdown.h" |
[email protected] | 40d59ce5 | 2009-03-06 23:20:14 | [diff] [blame] | 37 | #include "chrome/browser/character_encoding.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 38 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 39 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 40 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 41 | #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 42 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 43 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 7fb4bbb | 2012-05-27 18:06:22 | [diff] [blame] | 44 | #include "chrome/browser/download/download_crx_util.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 45 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 9bb54ee | 2011-10-12 17:43:35 | [diff] [blame] | 46 | #include "chrome/browser/download/download_service.h" |
| 47 | #include "chrome/browser/download/download_service_factory.h" |
[email protected] | a1bc3b8 | 2012-04-19 19:32:20 | [diff] [blame] | 48 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 49 | #include "chrome/browser/download/download_started_animation.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 50 | #include "chrome/browser/download/download_util.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 51 | #include "chrome/browser/extensions/browser_extension_window_controller.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 52 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 53 | #include "chrome/browser/extensions/default_apps_trial.h" |
[email protected] | 10abd19 | 2010-09-30 02:03:49 | [diff] [blame] | 54 | #include "chrome/browser/extensions/extension_prefs.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 55 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 56 | #include "chrome/browser/extensions/extension_tab_helper.h" |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 57 | #include "chrome/browser/favicon/favicon_tab_helper.h" |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 58 | #include "chrome/browser/file_select_helper.h" |
[email protected] | 82073579 | 2010-07-29 23:40:01 | [diff] [blame] | 59 | #include "chrome/browser/first_run/first_run.h" |
[email protected] | f7578f5 | 2010-08-30 22:22:49 | [diff] [blame] | 60 | #include "chrome/browser/google/google_url_tracker.h" |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 61 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 62 | #include "chrome/browser/instant/instant_controller.h" |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 63 | #include "chrome/browser/instant/instant_unload_handler.h" |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 64 | #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" |
[email protected] | 8f0bbd6 | 2012-02-22 03:37:18 | [diff] [blame] | 65 | #include "chrome/browser/intents/web_intents_util.h" |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 66 | #include "chrome/browser/lifetime/application_lifetime.h" |
[email protected] | 4afde5c | 2012-06-25 17:00:53 | [diff] [blame] | 67 | #include "chrome/browser/media/media_stream_devices_controller.h" |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 68 | #include "chrome/browser/net/url_fixer_upper.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 69 | #include "chrome/browser/notifications/notification_ui_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 70 | #include "chrome/browser/platform_util.h" |
[email protected] | 4e94ab3 | 2011-08-05 05:28:27 | [diff] [blame] | 71 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 72 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0233759 | 2010-09-27 18:38:25 | [diff] [blame] | 73 | #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" |
[email protected] | 0996e9b | 2011-08-26 17:59:01 | [diff] [blame] | 74 | #include "chrome/browser/printing/print_preview_tab_controller.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 75 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 76 | #include "chrome/browser/profiles/profile_destroyer.h" |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 77 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 78 | #include "chrome/browser/profiles/profile_metrics.h" |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 79 | #include "chrome/browser/repost_form_warning_controller.h" |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 80 | #include "chrome/browser/sessions/restore_tab_helper.h" |
[email protected] | 85e921fb8 | 2009-02-11 23:19:44 | [diff] [blame] | 81 | #include "chrome/browser/sessions/session_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 82 | #include "chrome/browser/sessions/session_service_factory.h" |
[email protected] | c61db1d | 2009-02-06 03:39:18 | [diff] [blame] | 83 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | 92926d9 | 2010-09-02 18:35:06 | [diff] [blame] | 84 | #include "chrome/browser/sessions/tab_restore_service.h" |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 85 | #include "chrome/browser/sessions/tab_restore_service_factory.h" |
[email protected] | 066629f | 2009-10-17 00:28:13 | [diff] [blame] | 86 | #include "chrome/browser/sync/profile_sync_service.h" |
[email protected] | 5e61afb9 | 2012-01-27 20:09:13 | [diff] [blame] | 87 | #include "chrome/browser/sync/profile_sync_service_factory.h" |
[email protected] | 40f04797 | 2009-11-25 03:54:40 | [diff] [blame] | 88 | #include "chrome/browser/sync/sync_ui_util.h" |
[email protected] | 2c4fb7b | 2011-04-02 06:33:29 | [diff] [blame] | 89 | #include "chrome/browser/tab_contents/background_contents.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 90 | #include "chrome/browser/tab_contents/retargeting_details.h" |
[email protected] | 7cceebac | 2011-03-03 00:32:21 | [diff] [blame] | 91 | #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
[email protected] | 1ab4ddf | 2011-07-21 04:48:04 | [diff] [blame] | 92 | #include "chrome/browser/tab_contents/tab_util.h" |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 93 | #include "chrome/browser/themes/theme_service.h" |
| 94 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | 82194b5fb | 2012-05-22 23:53:07 | [diff] [blame] | 95 | #include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_creator.h" |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 96 | #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.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] | 6768ac0 | 2011-04-06 17:41:04 | [diff] [blame] | 103 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | fcca741b | 2011-06-17 22:46:37 | [diff] [blame] | 104 | #include "chrome/browser/ui/browser_navigator.h" |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 105 | #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 106 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 107 | #include "chrome/browser/ui/browser_toolbar_model_delegate.h" |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 108 | #include "chrome/browser/ui/browser_ui_prefs.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 109 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 110 | #include "chrome/browser/ui/chrome_pages.h" |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 111 | #include "chrome/browser/ui/constrained_window_tab_helper.h" |
[email protected] | a4465720 | 2012-01-09 05:48:31 | [diff] [blame] | 112 | #include "chrome/browser/ui/extensions/shell_window.h" |
[email protected] | 45300ad4 | 2010-12-02 15:51:14 | [diff] [blame] | 113 | #include "chrome/browser/ui/find_bar/find_bar.h" |
| 114 | #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 115 | #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
[email protected] | 9d5c059a8 | 2012-06-29 20:13:07 | [diff] [blame] | 116 | #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
[email protected] | 1ba55cf | 2012-06-29 19:11:39 | [diff] [blame] | 117 | #include "chrome/browser/ui/global_error/global_error.h" |
| 118 | #include "chrome/browser/ui/global_error/global_error_service.h" |
| 119 | #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 120 | #include "chrome/browser/ui/hung_plugin_tab_helper.h" |
[email protected] | 943b861 | 2011-08-31 21:07:13 | [diff] [blame] | 121 | #include "chrome/browser/ui/intents/web_intent_picker_controller.h" |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 122 | #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 123 | #include "chrome/browser/ui/omnibox/location_bar.h" |
[email protected] | fe90ca8e | 2011-04-08 20:40:43 | [diff] [blame] | 124 | #include "chrome/browser/ui/panels/panel.h" |
| 125 | #include "chrome/browser/ui/panels/panel_manager.h" |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 126 | #include "chrome/browser/ui/search/search.h" |
| 127 | #include "chrome/browser/ui/search/search_delegate.h" |
| 128 | #include "chrome/browser/ui/search/search_model.h" |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 129 | #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h" |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 130 | #include "chrome/browser/ui/singleton_tabs.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 131 | #include "chrome/browser/ui/status_bubble.h" |
[email protected] | 3da95a10 | 2011-11-30 21:47:45 | [diff] [blame] | 132 | #include "chrome/browser/ui/sync/browser_synced_window_delegate.h" |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 133 | #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 134 | #include "chrome/browser/ui/tab_contents/tab_contents.h" |
[email protected] | 9a80065 | 2010-12-02 17:08:44 | [diff] [blame] | 135 | #include "chrome/browser/ui/tabs/dock_info.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 136 | #include "chrome/browser/ui/tabs/tab_menu_model.h" |
[email protected] | b56e2e3 | 2012-05-11 21:18:04 | [diff] [blame] | 137 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | f847e608 | 2011-03-24 00:08:26 | [diff] [blame] | 138 | #include "chrome/browser/ui/web_applications/web_app_ui.h" |
[email protected] | daa9e38 | 2012-01-06 00:30:34 | [diff] [blame] | 139 | #include "chrome/browser/ui/webui/feedback_ui.h" |
[email protected] | a9acdff | 2012-03-08 04:04:52 | [diff] [blame] | 140 | #include "chrome/browser/ui/webui/ntp/app_launcher_handler.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] | b689fce7 | 2009-03-17 22:45:34 | [diff] [blame] | 154 | #include "chrome/common/url_constants.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 155 | #include "chrome/common/web_apps.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 156 | #include "content/public/browser/color_chooser.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 157 | #include "content/public/browser/devtools_manager.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 158 | #include "content/public/browser/download_item.h" |
| 159 | #include "content/public/browser/download_manager.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 160 | #include "content/public/browser/interstitial_page.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 161 | #include "content/public/browser/invalidate_type.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 162 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 163 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 164 | #include "content/public/browser/notification_details.h" |
| 165 | #include "content/public/browser/notification_service.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 166 | #include "content/public/browser/plugin_service.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 167 | #include "content/public/browser/render_process_host.h" |
| 168 | #include "content/public/browser/render_view_host.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 169 | #include "content/public/browser/site_instance.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 170 | #include "content/public/browser/user_metrics.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 171 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 172 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 173 | #include "content/public/browser/web_intents_dispatcher.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 174 | #include "content/public/common/content_restriction.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 175 | #include "content/public/common/content_switches.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 176 | #include "content/public/common/page_zoom.h" |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 177 | #include "content/public/common/renderer_preferences.h" |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 178 | #include "grit/chromium_strings.h" |
| 179 | #include "grit/generated_resources.h" |
| 180 | #include "grit/locale_settings.h" |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 181 | #include "grit/theme_resources_standard.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 182 | #include "net/base/net_util.h" |
| 183 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 4d7c4ef | 2012-03-16 01:47:12 | [diff] [blame] | 184 | #include "net/cookies/cookie_monster.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 185 | #include "net/url_request/url_request_context.h" |
[email protected] | f6767806 | 2011-01-07 17:33:39 | [diff] [blame] | 186 | #include "ui/base/animation/animation.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 187 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 188 | #include "ui/gfx/point.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 189 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 190 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 4a19be9 | 2011-09-22 14:25:02 | [diff] [blame] | 191 | #include "webkit/glue/webkit_glue.h" |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 192 | #include "webkit/glue/window_open_disposition.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 193 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 194 | |
| 195 | #if defined(OS_WIN) |
[email protected] | 77cbe50e | 2012-06-14 02:44:38 | [diff] [blame] | 196 | #include "base/win/metro.h" |
[email protected] | 36d5e559 | 2010-11-15 20:45:59 | [diff] [blame] | 197 | #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" |
[email protected] | 12f520c | 2010-01-06 18:11:15 | [diff] [blame] | 198 | #include "chrome/browser/shell_integration.h" |
[email protected] | b17d41c | 2011-02-17 22:09:59 | [diff] [blame] | 199 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | a5d1e1e | 2010-09-23 19:34:12 | [diff] [blame] | 200 | #include "chrome/browser/task_manager/task_manager.h" |
[email protected] | 6a3ec231 | 2010-12-02 19:30:19 | [diff] [blame] | 201 | #include "chrome/browser/ui/view_ids.h" |
[email protected] | dcd5776 | 2011-06-25 12:18:51 | [diff] [blame] | 202 | #include "ui/base/win/shell.h" |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 203 | #endif // OS_WIN |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 204 | |
[email protected] | b796920 | 2010-05-14 21:29:26 | [diff] [blame] | 205 | #if defined(OS_CHROMEOS) |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 206 | #include "chrome/browser/chromeos/gdata/gdata_util.h" |
[email protected] | eab8c0f | 2011-11-18 22:33:50 | [diff] [blame] | 207 | #endif |
| 208 | |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 209 | #if defined(USE_ASH) |
[email protected] | bafda13 | 2012-02-16 19:32:51 | [diff] [blame] | 210 | #include "ash/ash_switches.h" |
[email protected] | c2f0a89 | 2012-01-24 22:19:21 | [diff] [blame] | 211 | #endif |
| 212 | |
[email protected] | 8a53ee04 | 2009-01-21 16:41:33 | [diff] [blame] | 213 | using base::TimeDelta; |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 214 | using content::NativeWebKeyboardEvent; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 215 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 216 | using content::NavigationEntry; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 217 | using content::OpenURLParams; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 218 | using content::PluginService; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 219 | using content::Referrer; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 220 | using content::SiteInstance; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 221 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 222 | using content::WebContents; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 223 | using extensions::Extension; |
[email protected] | 20c07f8e | 2012-05-31 08:43:14 | [diff] [blame] | 224 | using ui::WebDialogDelegate; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 226 | /////////////////////////////////////////////////////////////////////////////// |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 228 | namespace { |
| 229 | |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 230 | // The URL to be loaded to display the "Report a broken page" form. |
| 231 | const char kBrokenPageUrl[] = |
[email protected] | 95fc6f9 | 2011-04-13 00:37:20 | [diff] [blame] | 232 | "https://www.google.com/support/chrome/bin/request.py?contact_type=" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 233 | "broken_website&format=inproduct&p.page_title=$1&p.page_url=$2"; |
| 234 | |
| 235 | // The URL for the privacy dashboard. |
| 236 | const char kPrivacyDashboardUrl[] = "https://www.google.com/dashboard"; |
| 237 | |
| 238 | // How long we wait before updating the browser chrome while loading a page. |
| 239 | const int kUIUpdateCoalescingTimeMS = 200; |
| 240 | |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 241 | bool AllowPanels(const std::string& app_name) { |
[email protected] | cae9765 | 2012-04-20 03:12:12 | [diff] [blame] | 242 | return PanelManager::ShouldUsePanels( |
| 243 | web_app::GetExtensionIdFromApplicationName(app_name)); |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 246 | } // namespace |
| 247 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 248 | //////////////////////////////////////////////////////////////////////////////// |
| 249 | // Browser, CreateParams: |
| 250 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 251 | Browser::CreateParams::CreateParams() |
| 252 | : type(TYPE_TABBED), |
| 253 | profile(NULL), |
| 254 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 255 | is_session_restore(false) { |
| 256 | } |
| 257 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 258 | Browser::CreateParams::CreateParams(Type type, Profile* profile) |
| 259 | : type(type), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 260 | profile(profile), |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 261 | app_type(APP_TYPE_HOST), |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 262 | initial_show_state(ui::SHOW_STATE_DEFAULT), |
| 263 | is_session_restore(false) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 266 | // static |
| 267 | Browser::CreateParams Browser::CreateParams::CreateForApp( |
| 268 | Type type, |
| 269 | const std::string& app_name, |
| 270 | const gfx::Rect& window_bounds, |
| 271 | Profile* profile) { |
| 272 | DCHECK(type != TYPE_TABBED); |
| 273 | DCHECK(!app_name.empty()); |
| 274 | |
| 275 | if (type == TYPE_PANEL && !AllowPanels(app_name)) |
| 276 | type = TYPE_POPUP; |
| 277 | |
| 278 | CreateParams params(type, profile); |
| 279 | params.app_name = app_name; |
| 280 | params.app_type = APP_TYPE_CHILD; |
| 281 | params.initial_bounds = window_bounds; |
| 282 | |
| 283 | return params; |
| 284 | } |
| 285 | |
| 286 | // static |
| 287 | Browser::CreateParams Browser::CreateParams::CreateForDevTools( |
| 288 | Profile* profile) { |
| 289 | CreateParams params(TYPE_POPUP, profile); |
| 290 | params.app_name = DevToolsWindow::kDevToolsApp; |
| 291 | return params; |
| 292 | } |
| 293 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 294 | /////////////////////////////////////////////////////////////////////////////// |
| 295 | // Browser, Constructors, Creation, Showing: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 296 | |
[email protected] | 299dabd | 2008-11-19 02:27:16 | [diff] [blame] | 297 | Browser::Browser(Type type, Profile* profile) |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 298 | : type_(type), |
| 299 | profile_(profile), |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 300 | window_(NULL), |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 301 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 302 | tab_strip_model_(new TabStripModel(this, profile))), |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 303 | app_type_(APP_TYPE_HOST), |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 304 | chrome_updater_factory_(this), |
| 305 | is_attempting_to_close_browser_(false), |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 306 | cancel_download_confirmation_state_(NOT_PROMPTED), |
[email protected] | 1f0b50b | 2012-06-22 20:37:16 | [diff] [blame] | 307 | initial_show_state_(ui::SHOW_STATE_DEFAULT), |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 308 | is_session_restore_(false), |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 309 | weak_factory_(this), |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 310 | pending_web_app_action_(NONE), |
| 311 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 312 | content_setting_bubble_model_delegate_( |
| 313 | new BrowserContentSettingBubbleModelDelegate(this))), |
| 314 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 315 | toolbar_model_delegate_( |
| 316 | new BrowserToolbarModelDelegate(this))), |
| 317 | ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 318 | tab_restore_service_delegate_( |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 319 | new BrowserTabRestoreServiceDelegate(this))), |
[email protected] | afefa74e | 2011-07-26 05:04:23 | [diff] [blame] | 320 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 321 | synced_window_delegate_( |
| 322 | new BrowserSyncedWindowDelegate(this))), |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 323 | bookmark_bar_state_(BookmarkBar::HIDDEN), |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 324 | device_attached_intent_source_(this, this), |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 325 | ALLOW_THIS_IN_INITIALIZER_LIST( |
| 326 | command_controller_(new chrome::BrowserCommandController(this))), |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 327 | window_has_shown_(false) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 328 | tab_strip_model_->AddObserver(this); |
| 329 | |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 330 | toolbar_model_.reset(new ToolbarModel(toolbar_model_delegate_.get())); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 331 | search_model_.reset(new chrome::search::SearchModel(NULL)); |
| 332 | search_delegate_.reset( |
| 333 | new chrome::search::SearchDelegate(search_model_.get())); |
[email protected] | ef55702 | 2012-03-16 10:05:33 | [diff] [blame] | 334 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 335 | registrar_.Add(this, content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 336 | content::NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 337 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 338 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 339 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 340 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 341 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | a93089b1 | 2011-11-22 20:47:38 | [diff] [blame] | 342 | content::Source<Profile>(profile_->GetOriginalProfile())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 343 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 344 | content::NotificationService::AllSources()); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 345 | #if defined(ENABLE_THEMES) |
[email protected] | ffa6f59 | 2011-06-24 22:03:57 | [diff] [blame] | 346 | registrar_.Add( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 347 | this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 348 | content::Source<ThemeService>( |
| 349 | ThemeServiceFactory::GetForProfile(profile_))); |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 350 | #endif |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 351 | registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 352 | content::NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 354 | profile_pref_registrar_.Init(profile_->GetPrefs()); |
| 355 | profile_pref_registrar_.Add(prefs::kDevToolsDisabled, this); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 356 | profile_pref_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 357 | profile_pref_registrar_.Add(prefs::kHomePage, this); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 358 | profile_pref_registrar_.Add(prefs::kInstantEnabled, this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 359 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 360 | BrowserList::AddBrowser(this); |
| 361 | |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 362 | // NOTE: These prefs all need to be explicitly destroyed in the destructor |
| 363 | // or you'll get a nasty surprise when you run the incognito tests. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 364 | encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, |
| 365 | profile_->GetPrefs(), NULL); |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 366 | |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 367 | CreateInstantIfNecessary(); |
[email protected] | 07d490bc | 2011-03-07 17:05:26 | [diff] [blame] | 368 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 369 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); |
[email protected] | a7be698 | 2011-12-12 21:53:57 | [diff] [blame] | 370 | |
| 371 | FilePath profile_path = profile->GetPath(); |
| 372 | ProfileMetrics::LogProfileLaunch(profile_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | Browser::~Browser() { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 376 | // The tab strip should not have any tabs at this point. |
| 377 | if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) |
| 378 | DCHECK(tab_strip_model_->empty()); |
| 379 | tab_strip_model_->RemoveObserver(this); |
| 380 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 381 | BrowserList::RemoveBrowser(this); |
| 382 | |
[email protected] | bdc6ccd1 | 2012-03-20 22:06:13 | [diff] [blame] | 383 | SessionService* session_service = |
| 384 | SessionServiceFactory::GetForProfile(profile_); |
| 385 | if (session_service) |
| 386 | session_service->WindowClosed(session_id_); |
| 387 | |
| 388 | TabRestoreService* tab_restore_service = |
| 389 | TabRestoreServiceFactory::GetForProfile(profile()); |
| 390 | if (tab_restore_service) |
| 391 | tab_restore_service->BrowserClosed(tab_restore_service_delegate()); |
| 392 | |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 393 | #if !defined(OS_MACOSX) |
[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 394 | if (!browser::GetBrowserCount(profile_)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 395 | // We're the last browser window with this profile. We need to nuke the |
| 396 | // TabRestoreService, which will start the shutdown of the |
| 397 | // NavigationControllers and allow for proper shutdown. If we don't do this |
| 398 | // chrome won't shutdown cleanly, and may end up crashing when some |
| 399 | // thread tries to use the IO thread (or another thread) that is no longer |
| 400 | // valid. |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 401 | // This isn't a valid assumption for Mac OS, as it stays running after |
| 402 | // the last browser has closed. The Mac equivalent is in its app |
| 403 | // controller. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 404 | TabRestoreServiceFactory::ResetForProfile(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 405 | } |
[email protected] | fbc947b | 2009-06-19 13:28:24 | [diff] [blame] | 406 | #endif |
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_.RemoveAll(); |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 409 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 410 | encoding_auto_detect_.Destroy(); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 411 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 412 | command_controller_.reset(); |
| 413 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 414 | if (profile_->IsOffTheRecord() && |
[email protected] | 474e5db | 2011-08-12 13:02:23 | [diff] [blame] | 415 | !BrowserList::IsOffTheRecordSessionActiveForProfile(profile_)) { |
[email protected] | 5e91924 | 2012-02-13 23:59:35 | [diff] [blame] | 416 | // An incognito profile is no longer needed, this indirectly frees |
| 417 | // its cache and cookies once it gets destroyed at the appropriate time. |
[email protected] | 4dffabe | 2012-05-19 14:37:06 | [diff] [blame] | 418 | ProfileDestroyer::DestroyProfileWhenAppropriate(profile_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | // There may be pending file dialogs, we need to tell them that we've gone |
| 422 | // away so they don't try and call back to us. |
| 423 | if (select_file_dialog_.get()) |
| 424 | select_file_dialog_->ListenerDestroyed(); |
| 425 | } |
| 426 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 427 | // static |
| 428 | Browser* Browser::Create(Profile* profile) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 429 | Browser* browser = new Browser(TYPE_TABBED, profile); |
| 430 | browser->InitBrowserWindow(); |
| 431 | return browser; |
| 432 | } |
| 433 | |
| 434 | // static |
| 435 | Browser* Browser::CreateWithParams(const CreateParams& params) { |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 436 | if (!params.app_name.empty()) |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 437 | chrome::RegisterAppPrefs(params.app_name, params.profile); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 438 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 439 | Browser* browser = new Browser(params.type, params.profile); |
| 440 | browser->app_name_ = params.app_name; |
[email protected] | 0da5829 | 2012-03-22 20:37:21 | [diff] [blame] | 441 | browser->app_type_ = params.app_type; |
[email protected] | 81b2b0ac | 2011-11-23 01:54:48 | [diff] [blame] | 442 | browser->set_override_bounds(params.initial_bounds); |
[email protected] | 1f0b50b | 2012-06-22 20:37:16 | [diff] [blame] | 443 | browser->set_initial_show_state(params.initial_show_state); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 444 | browser->set_is_session_restore(params.is_session_restore); |
| 445 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 446 | browser->InitBrowserWindow(); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 447 | return browser; |
| 448 | } |
[email protected] | 6104acf | 2008-11-11 22:27:34 | [diff] [blame] | 449 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 450 | void Browser::InitBrowserWindow() { |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 451 | DCHECK(!window_); |
[email protected] | 9c45b718 | 2009-08-04 16:44:43 | [diff] [blame] | 452 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 453 | window_ = CreateBrowserWindow(); |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 454 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 455 | |
[email protected] | 5e37c45 | 2011-09-06 19:31:39 | [diff] [blame] | 456 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 6a34951a | 2012-01-17 18:10:40 | [diff] [blame] | 457 | // Set the app user model id for this application to that of the application |
| 458 | // name. See http://crbug.com/7028. |
| 459 | ui::win::SetAppIdForWindow( |
| 460 | is_app() && !is_type_panel() ? |
[email protected] | a044800 | 2012-06-19 04:32:10 | [diff] [blame] | 461 | ShellIntegration::GetAppModelIdForProfile(UTF8ToWide(app_name_), |
| 462 | profile_->GetPath()) : |
| 463 | ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()), |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 464 | window()->GetNativeWindow()); |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 465 | |
[email protected] | 6a34951a | 2012-01-17 18:10:40 | [diff] [blame] | 466 | if (is_type_panel()) { |
| 467 | ui::win::SetAppIconForWindow(ShellIntegration::GetChromiumIconPath(), |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 468 | window()->GetNativeWindow()); |
[email protected] | 45446a5 | 2010-11-04 17:41:00 | [diff] [blame] | 469 | } |
[email protected] | 80cf356 | 2009-11-17 08:17:24 | [diff] [blame] | 470 | #endif |
| 471 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 472 | // Create the extension window controller before sending notifications. |
| 473 | extension_window_controller_.reset( |
| 474 | new BrowserExtensionWindowController(this)); |
| 475 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 476 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 477 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 478 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 479 | content::NotificationService::NoDetails()); |
[email protected] | 14d8c66e | 2009-09-22 00:32:52 | [diff] [blame] | 480 | |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 481 | PrefService* local_state = g_browser_process->local_state(); |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 482 | if (local_state && local_state->FindPreference( |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 483 | prefs::kAutofillPersonalDataManagerFirstRun) && |
| 484 | local_state->GetBoolean(prefs::kAutofillPersonalDataManagerFirstRun)) { |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 485 | // Notify PDM that this is a first run. |
| 486 | #if defined(OS_WIN) |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 487 | ImportAutofillDataWin(PersonalDataManagerFactory::GetForProfile(profile_)); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 488 | #endif // defined(OS_WIN) |
| 489 | // Reset the preference so we don't call it again for subsequent windows. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 490 | local_state->ClearPref(prefs::kAutofillPersonalDataManagerFirstRun); |
[email protected] | f69c885 | 2010-10-12 02:36:46 | [diff] [blame] | 491 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 492 | } |
| 493 | |
[email protected] | bf870869 | 2011-12-20 21:24:28 | [diff] [blame] | 494 | void Browser::SetWindowForTesting(BrowserWindow* window) { |
| 495 | DCHECK(!window_); |
| 496 | window_ = window; |
| 497 | fullscreen_controller_ = new FullscreenController(window_, profile_, this); |
| 498 | } |
| 499 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 500 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 501 | // Getters & Setters |
| 502 | |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 503 | FindBarController* Browser::GetFindBarController() { |
| 504 | if (!find_bar_controller_.get()) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 505 | FindBar* find_bar = window_->CreateFindBar(); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 506 | find_bar_controller_.reset(new FindBarController(find_bar)); |
| 507 | find_bar->SetFindBarController(find_bar_controller_.get()); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 508 | find_bar_controller_->ChangeTabContents(chrome::GetActiveTabContents(this)); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 509 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
| 510 | } |
| 511 | return find_bar_controller_.get(); |
| 512 | } |
| 513 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 514 | bool Browser::HasFindBarController() const { |
| 515 | return find_bar_controller_.get() != NULL; |
| 516 | } |
| 517 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 518 | bool Browser::is_app() const { |
| 519 | return !app_name_.empty(); |
| 520 | } |
| 521 | |
| 522 | bool Browser::is_devtools() const { |
| 523 | return app_name_ == DevToolsWindow::kDevToolsApp; |
| 524 | } |
| 525 | |
[email protected] | 5c23875 | 2009-06-13 10:29:07 | [diff] [blame] | 526 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 527 | // Browser, State Storage and Retrieval for UI: |
| 528 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 529 | SkBitmap Browser::GetCurrentPageIcon() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 530 | TabContents* contents = chrome::GetActiveTabContents(this); |
[email protected] | ce5348a8 | 2008-12-18 18:36:23 | [diff] [blame] | 531 | // |contents| can be NULL since GetCurrentPageIcon() is called by the window |
| 532 | // during the window's creation (before tabs have been added). |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 533 | return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 534 | } |
| 535 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 536 | string16 Browser::GetWindowTitleForCurrentTab() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 537 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 538 | string16 title; |
[email protected] | c7c4233 | 2008-11-15 01:10:54 | [diff] [blame] | 539 | |
[email protected] | 731f8a4 | 2009-07-20 22:07:32 | [diff] [blame] | 540 | // |contents| can be NULL because GetWindowTitleForCurrentTab is called by the |
| 541 | // window during the window's creation (before tabs have been added). |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 542 | if (contents) { |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 543 | title = contents->GetTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 544 | FormatTitleForDisplay(&title); |
| 545 | } |
| 546 | if (title.empty()) |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 547 | title = CoreTabHelper::GetDefaultTitle(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 548 | |
[email protected] | cae9765 | 2012-04-20 03:12:12 | [diff] [blame] | 549 | #if defined(OS_MACOSX) || defined(USE_ASH) |
| 550 | // 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] | 551 | // the application name. |
[email protected] | d904bc8 | 2009-07-07 00:41:04 | [diff] [blame] | 552 | return title; |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 553 | #else |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 554 | int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT; |
[email protected] | dff52973 | 2010-04-01 23:50:55 | [diff] [blame] | 555 | // 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] | 556 | if (is_app()) |
[email protected] | edb5e6a | 2009-04-08 23:46:17 | [diff] [blame] | 557 | string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO; |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 558 | return l10n_util::GetStringFUTF16(string_id, title); |
[email protected] | 57e68dba | 2009-05-15 21:30:50 | [diff] [blame] | 559 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | // static |
[email protected] | dda5dfa3 | 2009-07-10 00:33:29 | [diff] [blame] | 563 | void Browser::FormatTitleForDisplay(string16* title) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 564 | size_t current_index = 0; |
| 565 | size_t match_index; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 566 | while ((match_index = title->find(L'\n', current_index)) != string16::npos) { |
[email protected] | 810a52ef | 2010-01-08 01:22:15 | [diff] [blame] | 567 | title->replace(match_index, 1, string16()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 568 | current_index = match_index; |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /////////////////////////////////////////////////////////////////////////////// |
| 573 | // Browser, OnBeforeUnload handling: |
| 574 | |
| 575 | bool Browser::ShouldCloseWindow() { |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 576 | if (!CanCloseWithInProgressDownloads()) |
| 577 | return false; |
| 578 | |
| 579 | if (HasCompletedUnloadProcessing()) |
[email protected] | 22bf2c1 | 2012-06-23 08:35:55 | [diff] [blame] | 580 | return true; |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 581 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 582 | is_attempting_to_close_browser_ = true; |
| 583 | |
[email protected] | 460a294 | 2010-12-15 19:43:15 | [diff] [blame] | 584 | if (!TabsNeedBeforeUnloadFired()) |
[email protected] | 22bf2c1 | 2012-06-23 08:35:55 | [diff] [blame] | 585 | return true; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 586 | |
| 587 | ProcessPendingTabs(); |
| 588 | return false; |
| 589 | } |
| 590 | |
| 591 | void Browser::OnWindowClosing() { |
| 592 | if (!ShouldCloseWindow()) |
| 593 | return; |
| 594 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 595 | bool exiting = false; |
| 596 | |
[email protected] | c984d9f | 2010-07-20 20:52:20 | [diff] [blame] | 597 | // Application should shutdown on last window close if the user is explicitly |
| 598 | // trying to quit, or if there is nothing keeping the browser alive (such as |
| 599 | // AppController on the Mac, or BackgroundContentsService for background |
| 600 | // pages). |
| 601 | bool should_quit_if_last_browser = |
[email protected] | 2e6389f | 2012-05-18 19:41:25 | [diff] [blame] | 602 | browser_shutdown::IsTryingToQuit() || !browser::WillKeepAlive(); |
[email protected] | 7dc8c6b | 2010-04-09 17:02:50 | [diff] [blame] | 603 | |
| 604 | if (should_quit_if_last_browser && BrowserList::size() == 1) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 605 | browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 606 | exiting = true; |
| 607 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 608 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 609 | // Don't use GetForProfileIfExisting here, we want to force creation of the |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 610 | // session service so that user can restore what was open. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 611 | SessionService* session_service = |
| 612 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 613 | if (session_service) |
| 614 | session_service->WindowClosing(session_id()); |
| 615 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 616 | TabRestoreService* tab_restore_service = |
| 617 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | a636d8e5 | 2012-02-28 15:40:41 | [diff] [blame] | 618 | |
| 619 | #if defined(USE_AURA) |
| 620 | if (tab_restore_service && is_app()) |
| 621 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
| 622 | #endif |
| 623 | |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 624 | if (tab_restore_service && is_type_tabbed() && tab_count()) |
[email protected] | fb7da413 | 2011-03-15 15:51:00 | [diff] [blame] | 625 | tab_restore_service->BrowserClosing(tab_restore_service_delegate()); |
[email protected] | d8375fd | 2008-11-25 22:45:39 | [diff] [blame] | 626 | |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 627 | // TODO(sky): convert session/tab restore to use notification. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 628 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 629 | chrome::NOTIFICATION_BROWSER_CLOSING, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 630 | content::Source<Browser>(this), |
| 631 | content::Details<bool>(&exiting)); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 632 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 633 | chrome::CloseAllTabs(this); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 636 | void Browser::OnWindowActivated() { |
| 637 | // On some platforms we want to automatically reload tabs that are |
| 638 | // killed when the user selects them. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 639 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 640 | if (contents && contents->GetCrashedStatus() == |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 641 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 642 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 643 | switches::kReloadKilledTabs)) { |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 644 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 28788c7d | 2011-05-20 23:03:45 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 649 | //////////////////////////////////////////////////////////////////////////////// |
| 650 | // In-progress download termination handling: |
| 651 | |
| 652 | void Browser::InProgressDownloadResponse(bool cancel_downloads) { |
| 653 | if (cancel_downloads) { |
| 654 | cancel_download_confirmation_state_ = RESPONSE_RECEIVED; |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 655 | chrome::CloseWindow(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 656 | return; |
| 657 | } |
| 658 | |
| 659 | // Sets the confirmation state to NOT_PROMPTED so that if the user tries to |
| 660 | // close again we'll show the warning again. |
| 661 | cancel_download_confirmation_state_ = NOT_PROMPTED; |
| 662 | |
| 663 | // Show the download page so the user can figure-out what downloads are still |
| 664 | // in-progress. |
[email protected] | 5d9cace7 | 2012-06-21 16:07:12 | [diff] [blame] | 665 | chrome::ShowDownloads(this); |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 668 | Browser::DownloadClosePreventionType Browser::OkToCloseWithInProgressDownloads( |
| 669 | int* num_downloads_blocking) const { |
| 670 | DCHECK(num_downloads_blocking); |
| 671 | *num_downloads_blocking = 0; |
| 672 | |
| 673 | if (is_attempting_to_close_browser_) |
| 674 | return DOWNLOAD_CLOSE_OK; |
| 675 | |
| 676 | // If we're not running a full browser process with a profile manager |
| 677 | // (testing), it's ok to close the browser. |
| 678 | if (!g_browser_process->profile_manager()) |
| 679 | return DOWNLOAD_CLOSE_OK; |
| 680 | |
| 681 | int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 682 | if (total_download_count == 0) |
| 683 | return DOWNLOAD_CLOSE_OK; // No downloads; can definitely close. |
| 684 | |
| 685 | // Figure out how many windows are open total, and associated with this |
| 686 | // profile, that are relevant for the ok-to-close decision. |
| 687 | int profile_window_count = 0; |
| 688 | int total_window_count = 0; |
| 689 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 690 | iter != BrowserList::end(); ++iter) { |
| 691 | // Don't count this browser window or any other in the process of closing. |
| 692 | Browser* const browser = *iter; |
| 693 | // Check is_attempting_to_close_browser_ as window closing may be |
| 694 | // delayed, and windows that are in the process of closing don't |
| 695 | // count against our totals. |
| 696 | if (browser == this || browser->is_attempting_to_close_browser_) |
| 697 | continue; |
| 698 | |
| 699 | if ((*iter)->profile() == profile()) |
| 700 | profile_window_count++; |
| 701 | total_window_count++; |
| 702 | } |
| 703 | |
| 704 | // If there aren't any other windows, we're at browser shutdown, |
| 705 | // which would cancel all current downloads. |
| 706 | if (total_window_count == 0) { |
| 707 | *num_downloads_blocking = total_download_count; |
| 708 | return DOWNLOAD_CLOSE_BROWSER_SHUTDOWN; |
| 709 | } |
| 710 | |
| 711 | // If there aren't any other windows on our profile, and we're an incognito |
| 712 | // profile, and there are downloads associated with that profile, |
| 713 | // those downloads would be cancelled by our window (-> profile) close. |
| 714 | DownloadService* download_service = |
| 715 | DownloadServiceFactory::GetForProfile(profile()); |
| 716 | if (profile_window_count == 0 && download_service->DownloadCount() > 0 && |
| 717 | profile()->IsOffTheRecord()) { |
| 718 | *num_downloads_blocking = download_service->DownloadCount(); |
| 719 | return DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE; |
| 720 | } |
| 721 | |
| 722 | // Those are the only conditions under which we will block shutdown. |
| 723 | return DOWNLOAD_CLOSE_OK; |
| 724 | } |
| 725 | |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 726 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 727 | // Browser, TabStripModel pass-thrus: |
| 728 | |
| 729 | int Browser::tab_count() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 730 | return tab_strip_model_->count(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 731 | } |
| 732 | |
[email protected] | 1ea49d5 | 2011-04-12 17:44:44 | [diff] [blame] | 733 | int Browser::active_index() const { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 734 | return tab_strip_model_->active_index(); |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 735 | } |
| 736 | |
[email protected] | c848d3d9 | 2010-09-16 21:57:45 | [diff] [blame] | 737 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 738 | // Browser, Tab adding/showing functions: |
| 739 | |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 740 | void Browser::WindowFullscreenStateChanged() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 741 | fullscreen_controller_->WindowFullscreenStateChanged(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 742 | command_controller_->FullscreenStateChanged(); |
[email protected] | 9adb8b1 | 2011-12-09 06:49:13 | [diff] [blame] | 743 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN); |
[email protected] | ae2622c | 2009-07-30 23:47:58 | [diff] [blame] | 744 | } |
| 745 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 746 | /////////////////////////////////////////////////////////////////////////////// |
| 747 | // Browser, Assorted browser commands: |
| 748 | |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 749 | void Browser::ToggleFullscreenMode() { |
| 750 | fullscreen_controller_->ToggleFullscreenMode(); |
| 751 | } |
| 752 | |
[email protected] | 41d9faf | 2012-02-28 23:46:02 | [diff] [blame] | 753 | void Browser::ToggleFullscreenModeWithExtension(const GURL& extension_url) { |
| 754 | fullscreen_controller_->ToggleFullscreenModeWithExtension(extension_url); |
[email protected] | 9282cea | 2009-02-18 18:49:00 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 757 | #if defined(OS_MACOSX) |
[email protected] | 184717d5 | 2012-02-22 04:46:16 | [diff] [blame] | 758 | void Browser::TogglePresentationMode() { |
| 759 | fullscreen_controller_->TogglePresentationMode(); |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 760 | } |
| 761 | #endif |
| 762 | |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 763 | bool Browser::SupportsWindowFeature(WindowFeature feature) const { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 764 | return SupportsWindowFeatureImpl(feature, true); |
| 765 | } |
[email protected] | f5bf8ccf | 2010-02-05 18:19:25 | [diff] [blame] | 766 | |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 767 | bool Browser::CanSupportWindowFeature(WindowFeature feature) const { |
| 768 | return SupportsWindowFeatureImpl(feature, false); |
[email protected] | a3e18c4 | 2009-03-04 23:36:05 | [diff] [blame] | 769 | } |
| 770 | |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 771 | void Browser::ToggleEncodingAutoDetect() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 772 | content::RecordAction(UserMetricsAction("AutoDetectChange")); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 773 | encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue()); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 774 | // If "auto detect" is turned on, then any current override encoding |
| 775 | // is cleared. This also implicitly performs a reload. |
| 776 | // OTOH, if "auto detect" is turned off, we don't change the currently |
| 777 | // active encoding. |
| 778 | if (encoding_auto_detect_.GetValue()) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 779 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 780 | if (contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 781 | contents->ResetOverrideEncoding(); |
[email protected] | a697f4c | 2009-09-14 22:30:18 | [diff] [blame] | 782 | } |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | void Browser::OverrideEncoding(int encoding_id) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 786 | content::RecordAction(UserMetricsAction("OverrideEncoding")); |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 787 | const std::string selected_encoding = |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 788 | CharacterEncoding::GetCanonicalEncodingNameByCommandId(encoding_id); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 789 | WebContents* contents = chrome::GetActiveWebContents(this); |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 790 | if (!selected_encoding.empty() && contents) |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 791 | contents->SetOverrideEncoding(selected_encoding); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 792 | // Update the list of recently selected encodings. |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 793 | std::string new_selected_encoding_list; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 794 | if (CharacterEncoding::UpdateRecentlySelectedEncoding( |
| 795 | profile_->GetPrefs()->GetString(prefs::kRecentlySelectedEncoding), |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 796 | encoding_id, |
| 797 | &new_selected_encoding_list)) { |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 798 | profile_->GetPrefs()->SetString(prefs::kRecentlySelectedEncoding, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 799 | new_selected_encoding_list); |
[email protected] | fbd7759 | 2008-11-12 20:50:27 | [diff] [blame] | 800 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 801 | } |
| 802 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 803 | void Browser::OpenFile() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 804 | content::RecordAction(UserMetricsAction("OpenFile")); |
[email protected] | 9125457 | 2012-06-29 19:00:46 | [diff] [blame] | 805 | if (!select_file_dialog_.get()) |
| 806 | select_file_dialog_ = SelectFileDialog::Create(this); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 807 | |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 808 | const FilePath directory = profile_->last_selected_directory(); |
| 809 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 810 | // TODO(beng): figure out how to juggle this. |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 811 | gfx::NativeWindow parent_window = window_->GetNativeWindow(); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 812 | select_file_dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 813 | string16(), directory, |
[email protected] | b949f111 | 2009-04-12 20:03:08 | [diff] [blame] | 814 | NULL, 0, FILE_PATH_LITERAL(""), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 815 | chrome::GetActiveWebContents(this), |
[email protected] | d56bcd2 | 2009-03-16 19:51:56 | [diff] [blame] | 816 | parent_window, NULL); |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | void Browser::OpenCreateShortcutsDialog() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 820 | content::RecordAction(UserMetricsAction("CreateShortcut")); |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 821 | #if !defined(OS_MACOSX) |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 822 | TabContents* current_tab = chrome::GetActiveTabContents(this); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 823 | DCHECK(current_tab && |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 824 | web_app::IsValidUrl(current_tab->web_contents()->GetURL())) << |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 825 | "Menu item should be disabled."; |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 826 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 827 | NavigationEntry* entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 828 | current_tab->web_contents()->GetController().GetLastCommittedEntry(); |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 829 | if (!entry) |
| 830 | return; |
| 831 | |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 832 | // RVH's GetApplicationInfo should not be called before it returns. |
| 833 | DCHECK(pending_web_app_action_ == NONE); |
| 834 | pending_web_app_action_ = CREATE_SHORTCUT; |
| 835 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 836 | // Start fetching web app info for CreateApplicationShortcut dialog and show |
| 837 | // the dialog when the data is available in OnDidGetApplicationInfo. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 838 | current_tab->extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); |
[email protected] | 98f6e02 | 2009-06-05 22:49:53 | [diff] [blame] | 839 | #else |
| 840 | NOTIMPLEMENTED(); |
| 841 | #endif |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 842 | } |
| 843 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 844 | void Browser::UpdateDownloadShelfVisibility(bool visible) { |
| 845 | if (GetStatusBubble()) |
| 846 | GetStatusBubble()->UpdateDownloadShelfVisibility(visible); |
| 847 | } |
| 848 | |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 849 | bool Browser::OpenInstant(WindowOpenDisposition disposition) { |
| 850 | if (!instant() || !instant()->PrepareForCommit() || |
| 851 | disposition == NEW_BACKGROUND_TAB) { |
| 852 | // NEW_BACKGROUND_TAB results in leaving the omnibox open, so we don't |
| 853 | // attempt to use the instant preview. |
| 854 | return false; |
| 855 | } |
| 856 | |
| 857 | if (disposition == CURRENT_TAB) { |
| 858 | content::NotificationService::current()->Notify( |
| 859 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 860 | content::Source<TabContents>(instant()->CommitCurrentPreview( |
| 861 | INSTANT_COMMIT_PRESSED_ENTER)), |
| 862 | content::NotificationService::NoDetails()); |
| 863 | return true; |
| 864 | } |
| 865 | if (disposition == NEW_FOREGROUND_TAB) { |
| 866 | TabContents* preview_contents = instant()->ReleasePreviewContents( |
| 867 | INSTANT_COMMIT_PRESSED_ENTER, NULL); |
| 868 | // HideInstant is invoked after release so that InstantController is not |
| 869 | // active when HideInstant asks it for its state. |
| 870 | HideInstant(); |
| 871 | preview_contents->web_contents()->GetController().PruneAllButActive(); |
| 872 | tab_strip_model_->AddTabContents( |
| 873 | preview_contents, |
| 874 | -1, |
| 875 | instant()->last_transition_type(), |
| 876 | TabStripModel::ADD_ACTIVE); |
| 877 | instant()->CompleteRelease(preview_contents); |
| 878 | content::NotificationService::current()->Notify( |
| 879 | chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 880 | content::Source<TabContents>(preview_contents), |
| 881 | content::NotificationService::NoDetails()); |
| 882 | return true; |
| 883 | } |
| 884 | // The omnibox currently doesn't use other dispositions, so we don't attempt |
| 885 | // to handle them. If you hit this NOTREACHED file a bug and I'll (sky) add |
| 886 | // support for the new disposition. |
| 887 | NOTREACHED(); |
| 888 | return false; |
| 889 | } |
| 890 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 891 | /////////////////////////////////////////////////////////////////////////////// |
| 892 | |
| 893 | // static |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 894 | bool Browser::RunUnloadEventsHelper(WebContents* contents) { |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 895 | // If the WebContents is not connected yet, then there's no unload |
| 896 | // handler we can fire even if the WebContents has an unload listener. |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 897 | // One case where we hit this is in a tab that has an infinite loop |
| 898 | // before load. |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 899 | if (contents->NeedToFireBeforeUnload()) { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 900 | // If the page has unload listeners, then we tell the renderer to fire |
| 901 | // them. Once they have fired, we'll get a message back saying whether |
| 902 | // 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] | 903 | // with the NeedToFireBeforeUnload bit cleared. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 904 | contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 905 | return true; |
| 906 | } |
| 907 | return false; |
| 908 | } |
| 909 | |
| 910 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 911 | void Browser::JSOutOfMemoryHelper(WebContents* web_contents) { |
| 912 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 913 | if (!tab_contents) |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 914 | return; |
| 915 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 916 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 917 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 918 | infobar_helper, |
| 919 | NULL, |
| 920 | l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), |
| 921 | true)); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 925 | void Browser::RegisterProtocolHandlerHelper(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 926 | const std::string& protocol, |
| 927 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 928 | const string16& title, |
[email protected] | 9b4d241c9 | 2012-06-29 19:48:31 | [diff] [blame] | 929 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 930 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 931 | if (!tab_contents || tab_contents->profile()->IsOffTheRecord()) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 932 | return; |
| 933 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 934 | ProtocolHandler handler = |
| 935 | ProtocolHandler::CreateProtocolHandler(protocol, url, title); |
| 936 | |
| 937 | ProtocolHandlerRegistry* registry = |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 938 | tab_contents->profile()->GetProtocolHandlerRegistry(); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 939 | |
[email protected] | a50af29 | 2011-10-25 03:07:40 | [diff] [blame] | 940 | if (!registry->SilentlyHandleRegisterHandlerRequest(handler)) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 941 | content::RecordAction( |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 942 | UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 943 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 944 | |
| 945 | RegisterProtocolHandlerInfoBarDelegate* rph_delegate = |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 946 | new RegisterProtocolHandlerInfoBarDelegate(infobar_helper, |
| 947 | registry, |
[email protected] | d3ddb6d | 2012-01-06 02:51:17 | [diff] [blame] | 948 | handler); |
| 949 | |
| 950 | for (size_t i = 0; i < infobar_helper->infobar_count(); i++) { |
| 951 | InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); |
| 952 | RegisterProtocolHandlerInfoBarDelegate* cast_delegate = |
| 953 | delegate->AsRegisterProtocolHandlerInfoBarDelegate(); |
| 954 | if (cast_delegate != NULL && cast_delegate->IsReplacedBy(rph_delegate)) { |
| 955 | infobar_helper->ReplaceInfoBar(cast_delegate, rph_delegate); |
| 956 | rph_delegate = NULL; |
| 957 | break; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (rph_delegate != NULL) |
| 962 | infobar_helper->AddInfoBar(rph_delegate); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
| 966 | // static |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 967 | void Browser::FindReplyHelper(WebContents* web_contents, |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 968 | int request_id, |
| 969 | int number_of_matches, |
| 970 | const gfx::Rect& selection_rect, |
| 971 | int active_match_ordinal, |
| 972 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 973 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 974 | if (!tab_contents || !tab_contents->find_tab_helper()) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 975 | return; |
| 976 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 977 | tab_contents->find_tab_helper()->HandleFindReply(request_id, |
| 978 | number_of_matches, |
| 979 | selection_rect, |
| 980 | active_match_ordinal, |
| 981 | final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 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, TabStripModelDelegate implementation: |
| 1021 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1022 | TabContents* Browser::AddBlankTab(bool foreground) { |
[email protected] | 22735af6 | 2009-04-07 21:09:58 | [diff] [blame] | 1023 | return AddBlankTabAt(-1, foreground); |
| 1024 | } |
| 1025 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1026 | TabContents* Browser::AddBlankTabAt(int index, bool foreground) { |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1027 | // Time new tab page creation time. We keep track of the timing data in |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 1028 | // WebContents, but we want to include the time it takes to create the |
| 1029 | // WebContents object too. |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1030 | base::TimeTicks new_tab_start_time = base::TimeTicks::Now(); |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame^] | 1031 | chrome::NavigateParams params(this, GURL(chrome::kChromeUINewTabURL), |
| 1032 | content::PAGE_TRANSITION_TYPED); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1033 | params.disposition = foreground ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 1034 | params.tabstrip_index = index; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame^] | 1035 | chrome::Navigate(¶ms); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1036 | params.target_contents->web_contents()->SetNewTabStartTime( |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1037 | new_tab_start_time); |
[email protected] | 616381f0 | 2010-11-02 15:15:33 | [diff] [blame] | 1038 | return params.target_contents; |
[email protected] | 15952e46 | 2008-11-14 00:29:05 | [diff] [blame] | 1039 | } |
| 1040 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1041 | Browser* Browser::CreateNewStripWithContents( |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1042 | TabContents* detached_contents, |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1043 | const gfx::Rect& window_bounds, |
| 1044 | const DockInfo& dock_info, |
| 1045 | bool maximize) { |
[email protected] | 018cf36 | 2010-05-05 22:43:22 | [diff] [blame] | 1046 | DCHECK(CanSupportWindowFeature(FEATURE_TABSTRIP)); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 1047 | |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 1048 | gfx::Rect new_window_bounds = window_bounds; |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 1049 | if (dock_info.GetNewWindowBounds(&new_window_bounds, &maximize)) |
| 1050 | dock_info.AdjustOtherWindowBounds(); |
| 1051 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1052 | // Create an empty new browser window the same size as the old one. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1053 | Browser* browser = new Browser(TYPE_TABBED, profile_); |
[email protected] | 5e49546 | 2008-11-20 23:07:41 | [diff] [blame] | 1054 | browser->set_override_bounds(new_window_bounds); |
[email protected] | 1f0b50b | 2012-06-22 20:37:16 | [diff] [blame] | 1055 | browser->set_initial_show_state( |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 1056 | maximize ? ui::SHOW_STATE_MAXIMIZED : ui::SHOW_STATE_NORMAL); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 1057 | browser->InitBrowserWindow(); |
[email protected] | c084925 | 2012-05-12 13:51:27 | [diff] [blame] | 1058 | browser->tab_strip_model()->AppendTabContents(detached_contents, true); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1059 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 1060 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1061 | browser->LoadingStateChanged(detached_contents->web_contents()); |
[email protected] | 3d1104f | 2009-03-26 15:30:28 | [diff] [blame] | 1062 | return browser; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | int Browser::GetDragActions() const { |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 1066 | return TabStripModelDelegate::TAB_TEAROFF_ACTION | (tab_count() > 1 ? |
| 1067 | TabStripModelDelegate::TAB_MOVE_ACTION : 0); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1068 | } |
| 1069 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1070 | TabContents* Browser::CreateTabContentsForURL( |
[email protected] | 3ebe558b | 2011-12-06 08:05:08 | [diff] [blame] | 1071 | const GURL& url, const content::Referrer& referrer, Profile* profile, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1072 | content::PageTransition transition, bool defer_load, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1073 | SiteInstance* instance) const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1074 | TabContents* contents = chrome::TabContentsFactory(profile, instance, |
| 1075 | MSG_ROUTING_NONE, chrome::GetActiveWebContents(this), NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1076 | if (!defer_load) { |
| 1077 | // Load the initial URL before adding the new tab contents to the tab strip |
| 1078 | // so that the tab contents has navigation state. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1079 | contents->web_contents()->GetController().LoadURL( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1080 | url, referrer, transition, std::string()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | return contents; |
| 1084 | } |
| 1085 | |
| 1086 | bool Browser::CanDuplicateContentsAt(int index) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1087 | NavigationController& nc = |
| 1088 | chrome::GetWebContentsAt(this, index)->GetController(); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1089 | return nc.GetWebContents() && nc.GetLastCommittedEntry(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | void Browser::DuplicateContentsAt(int index) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1093 | TabContents* contents = chrome::GetTabContentsAt(this, index); |
[email protected] | 94ce725 | 2010-12-20 21:46:33 | [diff] [blame] | 1094 | CHECK(contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1095 | TabContents* contents_dupe = contents->Clone(); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1096 | |
| 1097 | bool pinned = false; |
| 1098 | if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
| 1099 | // If this is a tabbed browser, just create a duplicate tab inside the same |
| 1100 | // window next to the tab being duplicated. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1101 | int index = tab_strip_model_->GetIndexOfTabContents(contents); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1102 | pinned = tab_strip_model_->IsTabPinned(index); |
[email protected] | eaca0ad1 | 2011-04-18 15:53:41 | [diff] [blame] | 1103 | int add_types = TabStripModel::ADD_ACTIVE | |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1104 | TabStripModel::ADD_INHERIT_GROUP | |
| 1105 | (pinned ? TabStripModel::ADD_PINNED : 0); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1106 | tab_strip_model_->InsertTabContentsAt(index + 1, contents_dupe, add_types); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1107 | } else { |
| 1108 | Browser* browser = NULL; |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1109 | if (is_app()) { |
| 1110 | CHECK(!is_type_popup()); |
| 1111 | CHECK(!is_type_panel()); |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 1112 | browser = Browser::CreateWithParams( |
| 1113 | Browser::CreateParams::CreateForApp( |
| 1114 | TYPE_POPUP, app_name_, gfx::Rect(),profile_)); |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1115 | } else if (is_type_popup()) { |
[email protected] | da22aa6 | 2012-04-04 18:54:35 | [diff] [blame] | 1116 | browser = Browser::CreateWithParams( |
| 1117 | Browser::CreateParams(TYPE_POPUP, profile_)); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | // Preserve the size of the original window. The new window has already |
| 1121 | // been given an offset by the OS, so we shouldn't copy the old bounds. |
| 1122 | BrowserWindow* new_window = browser->window(); |
| 1123 | new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), |
| 1124 | window()->GetRestoredBounds().size())); |
| 1125 | |
[email protected] | 4e59568 | 2011-02-09 17:07:02 | [diff] [blame] | 1126 | // We need to show the browser now. Otherwise ContainerWin assumes the |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 1127 | // WebContents is invisible and won't size it. |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1128 | browser->window()->Show(); |
| 1129 | |
| 1130 | // The page transition below is only for the purpose of inserting the tab. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1131 | chrome::AddTab(browser, contents_dupe, content::PAGE_TRANSITION_LINK); |
[email protected] | 47b309f | 2010-12-28 17:35:56 | [diff] [blame] | 1132 | } |
| 1133 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1134 | SessionService* session_service = |
| 1135 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
| 1136 | if (session_service) |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 1137 | session_service->TabRestored(contents_dupe, pinned); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1138 | } |
| 1139 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1140 | void Browser::CloseFrameAfterDragSession() { |
[email protected] | 7be6450 | 2011-05-03 17:51:47 | [diff] [blame] | 1141 | #if !defined(OS_MACOSX) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1142 | // This is scheduled to run after we return to the message loop because |
| 1143 | // otherwise the frame will think the drag session is still active and ignore |
| 1144 | // the request. |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 1145 | // TODO(port): figure out what is required here in a cross-platform world |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1146 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1147 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | d6a3c77 | 2009-01-27 19:41:20 | [diff] [blame] | 1148 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | } |
| 1150 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1151 | void Browser::CreateHistoricalTab(TabContents* contents) { |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 1152 | // We don't create historical tabs for incognito windows or windows without |
| 1153 | // profiles. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1154 | if (!profile() || profile()->IsOffTheRecord()) |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 1155 | return; |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1156 | |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 1157 | // We don't create historical tabs for print preview tabs. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1158 | if (contents->web_contents()->GetURL() == GURL(chrome::kChromeUIPrintURL)) |
[email protected] | 0d4ef7f | 2011-05-12 22:38:57 | [diff] [blame] | 1159 | return; |
| 1160 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1161 | TabRestoreService* service = |
| 1162 | TabRestoreServiceFactory::GetForProfile(profile()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 1163 | |
[email protected] | fb5ff42 | 2010-05-03 20:46:10 | [diff] [blame] | 1164 | // We only create historical tab entries for tabbed browser windows. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1165 | if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) { |
[email protected] | c08337f | 2012-06-19 20:34:47 | [diff] [blame] | 1166 | service->CreateHistoricalTab(contents->web_contents(), |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1167 | tab_strip_model_->GetIndexOfTabContents(contents)); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1171 | bool Browser::RunUnloadListenerBeforeClosing(TabContents* contents) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1172 | return Browser::RunUnloadEventsHelper(contents->web_contents()); |
[email protected] | 505323e2 | 2009-01-24 02:47:58 | [diff] [blame] | 1173 | } |
| 1174 | |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 1175 | bool Browser::CanBookmarkAllTabs() const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1176 | return chrome::CanBookmarkAllTabs(this); |
[email protected] | a206b44 | 2009-10-08 23:20:20 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 1179 | void Browser::BookmarkAllTabs() { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1180 | chrome::BookmarkAllTabs(this); |
[email protected] | b3ac5c8 | 2009-10-08 20:56:54 | [diff] [blame] | 1181 | } |
| 1182 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1183 | bool Browser::CanRestoreTab() { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1184 | return chrome::CanRestoreTab(this); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | void Browser::RestoreTab() { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1188 | chrome::RestoreTab(this); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 1191 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1192 | // Browser, TabStripModelObserver implementation: |
| 1193 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1194 | void Browser::TabInsertedAt(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1195 | int index, |
| 1196 | bool foreground) { |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 1197 | SetAsDelegate(contents, this); |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 1198 | contents->restore_tab_helper()->SetWindowID(session_id()); |
[email protected] | e524ff9 | 2011-03-30 13:26:58 | [diff] [blame] | 1199 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1200 | SyncHistoryWithTabs(index); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1201 | |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1202 | // Make sure the loading state is updated correctly, otherwise the throbber |
| 1203 | // won't start if the page is loading. |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1204 | LoadingStateChanged(contents->web_contents()); |
[email protected] | 159f776 | 2008-12-19 14:58:27 | [diff] [blame] | 1205 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1206 | // If the tab crashes in the beforeunload or unload handler, it won't be |
| 1207 | // able to ack. But we know we can close it. |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1208 | registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 1209 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1210 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1211 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1212 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 1213 | |
| 1214 | registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1215 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1216 | } |
| 1217 | |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1218 | void Browser::TabClosingAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1219 | TabContents* contents, |
[email protected] | f2cc738 | 2010-10-15 18:03:05 | [diff] [blame] | 1220 | int index) { |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1221 | fullscreen_controller_->OnTabClosing(contents->web_contents()); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1222 | content::NotificationService::current()->Notify( |
[email protected] | 884033e | 2012-04-16 19:38:42 | [diff] [blame] | 1223 | chrome::NOTIFICATION_TAB_CLOSING, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1224 | content::Source<NavigationController>( |
[email protected] | cca0f1e | 2012-01-03 18:27:46 | [diff] [blame] | 1225 | &contents->web_contents()->GetController()), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1226 | content::NotificationService::NoDetails()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1227 | |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 1228 | // Sever the WebContents' connection back to us. |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 1229 | SetAsDelegate(contents, NULL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1230 | } |
| 1231 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1232 | void Browser::TabDetachedAt(TabContents* contents, int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1233 | TabDetachedAtImpl(contents, index, DETACH_TYPE_DETACH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1234 | } |
| 1235 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1236 | void Browser::TabDeactivated(TabContents* contents) { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1237 | fullscreen_controller_->OnTabDeactivated(contents); |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1238 | search_delegate_->OnTabDeactivated(contents); |
| 1239 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 1240 | if (instant()) |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 1241 | instant()->Hide(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 1242 | |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1243 | // Save what the user's currently typing, so it can be restored when we |
| 1244 | // switch back to this tab. |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 1245 | window_->GetLocationBar()->SaveStateToContents(contents->web_contents()); |
[email protected] | 85ff2c4 | 2009-05-29 21:22:03 | [diff] [blame] | 1246 | } |
| 1247 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1248 | void Browser::ActiveTabChanged(TabContents* old_contents, |
| 1249 | TabContents* new_contents, |
[email protected] | 3aca95d4 | 2011-05-24 22:06:54 | [diff] [blame] | 1250 | int index, |
| 1251 | bool user_gesture) { |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1252 | // On some platforms we want to automatically reload tabs that are |
| 1253 | // killed when the user selects them. |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1254 | bool did_reload = false; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1255 | if (user_gesture && new_contents->web_contents()->GetCrashedStatus() == |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1256 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED) { |
| 1257 | const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1258 | if (parsed_command_line.HasSwitch(switches::kReloadKilledTabs)) { |
[email protected] | 734d2669 | 2012-03-26 18:00:25 | [diff] [blame] | 1259 | LOG(WARNING) << "Reloading killed tab at " << index; |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1260 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1261 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1262 | "Tabs.SadTab.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1263 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 9d7518f | 2012-04-17 02:15:20 | [diff] [blame] | 1264 | did_reload = true; |
[email protected] | f8a3577 | 2011-02-02 23:17:56 | [diff] [blame] | 1265 | } |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 1266 | } |
| 1267 | |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1268 | // Discarded tabs always get reloaded. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1269 | if (!did_reload && tab_strip_model_->IsTabDiscarded(index)) { |
[email protected] | d6d4dae | 2012-04-18 17:47:32 | [diff] [blame] | 1270 | LOG(WARNING) << "Reloading discarded tab at " << index; |
| 1271 | static int reload_count = 0; |
[email protected] | 24c463a | 2012-04-20 22:33:50 | [diff] [blame] | 1272 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1273 | "Tabs.Discard.ReloadCount", ++reload_count, 1, 1000, 50); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 1274 | chrome::Reload(this, CURRENT_TAB); |
[email protected] | 002efb04 | 2011-10-07 17:30:24 | [diff] [blame] | 1275 | } |
| 1276 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1277 | // If we have any update pending, do it now. |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1278 | if (chrome_updater_factory_.HasWeakPtrs() && old_contents) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1279 | ProcessPendingUIUpdates(); |
| 1280 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1281 | // Propagate the profile to the location bar. |
| 1282 | UpdateToolbar(true); |
| 1283 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 1284 | // Propagate tab state to toolbar, tab-strip, etc. |
| 1285 | UpdateSearchState(new_contents); |
| 1286 | |
[email protected] | 943d812 | 2010-06-11 02:13:45 | [diff] [blame] | 1287 | // Update reload/stop state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1288 | command_controller_->LoadingStateChanged( |
| 1289 | new_contents->web_contents()->IsLoading(), true); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1290 | |
[email protected] | 8421498 | 2008-12-10 18:49:10 | [diff] [blame] | 1291 | // Update commands to reflect current state. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1292 | command_controller_->TabStateChanged(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1293 | |
| 1294 | // Reset the status bubble. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1295 | StatusBubble* status_bubble = GetStatusBubble(); |
| 1296 | if (status_bubble) { |
| 1297 | status_bubble->Hide(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1298 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1299 | // Show the loading state (if any). |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1300 | status_bubble->SetStatus( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1301 | chrome::GetActiveTabContents(this)->core_tab_helper()->GetStatusText()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1302 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1303 | |
[email protected] | 24db8a07 | 2009-10-29 20:35:37 | [diff] [blame] | 1304 | if (HasFindBarController()) { |
[email protected] | 9c31886 | 2011-02-01 22:27:24 | [diff] [blame] | 1305 | find_bar_controller_->ChangeTabContents(new_contents); |
[email protected] | b77cb30 | 2009-10-29 04:09:17 | [diff] [blame] | 1306 | find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); |
[email protected] | 4801ecc | 2009-04-05 04:52:58 | [diff] [blame] | 1307 | } |
| 1308 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1309 | // Update sessions. Don't force creation of sessions. If sessions doesn't |
| 1310 | // exist, the change will be picked up by sessions when created. |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1311 | SessionService* session_service = |
| 1312 | SessionServiceFactory::GetForProfileIfExisting(profile_); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1313 | if (session_service && !tab_strip_model_->closing_all()) { |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1314 | session_service->SetSelectedTabInWindow(session_id(), active_index()); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1315 | } |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1316 | |
| 1317 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1318 | } |
| 1319 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1320 | void Browser::TabMoved(TabContents* contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1321 | int from_index, |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 1322 | int to_index) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1323 | DCHECK(from_index >= 0 && to_index >= 0); |
| 1324 | // Notify the history service. |
| 1325 | SyncHistoryWithTabs(std::min(from_index, to_index)); |
| 1326 | } |
| 1327 | |
[email protected] | da25dd5 | 2011-01-11 19:06:30 | [diff] [blame] | 1328 | void Browser::TabReplacedAt(TabStripModel* tab_strip_model, |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1329 | TabContents* old_contents, |
| 1330 | TabContents* new_contents, |
[email protected] | 8a34e660 | 2010-10-02 17:29:43 | [diff] [blame] | 1331 | int index) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1332 | TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 1333 | TabInsertedAt(new_contents, index, (index == active_index())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1334 | |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1335 | int entry_count = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1336 | new_contents->web_contents()->GetController().GetEntryCount(); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1337 | if (entry_count > 0) { |
| 1338 | // Send out notification so that observers are updated appropriately. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1339 | new_contents->web_contents()->GetController().NotifyEntryChanged( |
| 1340 | new_contents->web_contents()->GetController().GetEntryAtIndex( |
[email protected] | 4a63e24 | 2011-12-12 15:23:08 | [diff] [blame] | 1341 | entry_count - 1), |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1342 | entry_count - 1); |
| 1343 | } |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1344 | |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1345 | SessionService* session_service = |
| 1346 | SessionServiceFactory::GetForProfile(profile()); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1347 | if (session_service) { |
| 1348 | // The new_contents may end up with a different navigation stack. Force |
| 1349 | // the session service to update itself. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1350 | session_service->TabRestored(new_contents, |
| 1351 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 47e020a | 2010-10-15 14:43:37 | [diff] [blame] | 1352 | } |
[email protected] | 2914600d | 2011-01-31 23:25:14 | [diff] [blame] | 1353 | |
[email protected] | a026243 | 2012-04-13 15:48:09 | [diff] [blame] | 1354 | content::DevToolsManager::GetInstance()->ContentsReplaced( |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1355 | old_contents->web_contents(), new_contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1356 | } |
| 1357 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1358 | void Browser::TabPinnedStateChanged(TabContents* contents, int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 1359 | SessionService* session_service = |
| 1360 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1361 | if (session_service) { |
| 1362 | session_service->SetPinnedState( |
| 1363 | session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1364 | chrome::GetTabContentsAt(this, index)->restore_tab_helper()-> |
| 1365 | session_id(), |
| 1366 | tab_strip_model_->IsTabPinned(index)); |
[email protected] | 5c0e648 | 2009-07-14 20:20:09 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1370 | void Browser::TabStripEmpty() { |
| 1371 | // Close the frame after we return to the message loop (not immediately, |
| 1372 | // otherwise it will destroy this object before the stack has a chance to |
| 1373 | // cleanly unwind.) |
| 1374 | // Note: This will be called several times if TabStripEmpty is called several |
| 1375 | // times. This is because it does not close the window if tabs are |
| 1376 | // still present. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 1377 | MessageLoop::current()->PostTask( |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 1378 | FROM_HERE, base::Bind(&Browser::CloseFrame, weak_factory_.GetWeakPtr())); |
[email protected] | 49d864f | 2012-04-09 21:14:39 | [diff] [blame] | 1379 | // Set is_attempting_to_close_browser_ here, so that extensions, etc, do not |
| 1380 | // attempt to add tabs to the browser before it closes. |
| 1381 | is_attempting_to_close_browser_ = true; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1382 | } |
| 1383 | |
[email protected] | fc76114 | 2012-06-08 04:49:20 | [diff] [blame] | 1384 | bool Browser::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 1385 | bool* is_keyboard_shortcut) { |
| 1386 | // Escape exits tabbed fullscreen mode. |
| 1387 | // TODO(koz): Write a test for this http://crbug.com/100441. |
| 1388 | if (event.windowsKeyCode == 27 && |
| 1389 | fullscreen_controller_->HandleUserPressedEscape()) { |
| 1390 | return true; |
| 1391 | } |
| 1392 | return window()->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1393 | } |
| 1394 | |
| 1395 | void Browser::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 1396 | window()->HandleKeyboardEvent(event); |
| 1397 | } |
| 1398 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1399 | void Browser::OnAcceptFullscreenPermission( |
| 1400 | const GURL& url, |
| 1401 | FullscreenExitBubbleType bubble_type) { |
| 1402 | fullscreen_controller_->OnAcceptFullscreenPermission(url, bubble_type); |
| 1403 | } |
| 1404 | |
| 1405 | void Browser::OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type) { |
| 1406 | fullscreen_controller_->OnDenyFullscreenPermission(bubble_type); |
| 1407 | } |
| 1408 | |
| 1409 | bool Browser::TabsNeedBeforeUnloadFired() { |
| 1410 | if (tabs_needing_before_unload_fired_.empty()) { |
| 1411 | for (int i = 0; i < tab_count(); ++i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1412 | WebContents* contents = chrome::GetTabContentsAt(this, i)->web_contents(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1413 | if (contents->NeedToFireBeforeUnload()) |
| 1414 | tabs_needing_before_unload_fired_.insert(contents); |
| 1415 | } |
| 1416 | } |
| 1417 | return !tabs_needing_before_unload_fired_.empty(); |
| 1418 | } |
| 1419 | |
| 1420 | bool Browser::IsFullscreenForTabOrPending() const { |
| 1421 | return fullscreen_controller_->IsFullscreenForTabOrPending(); |
| 1422 | } |
| 1423 | |
[email protected] | d013f14 | 2012-04-27 17:31:14 | [diff] [blame] | 1424 | bool Browser::IsMouseLocked() const { |
| 1425 | return fullscreen_controller_->IsMouseLocked(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | void Browser::OnWindowDidShow() { |
| 1429 | if (window_has_shown_) |
| 1430 | return; |
| 1431 | window_has_shown_ = true; |
| 1432 | |
| 1433 | // Nothing to do for non-tabbed windows. |
| 1434 | if (!is_type_tabbed()) |
| 1435 | return; |
| 1436 | |
| 1437 | // Show any pending global error bubble. |
| 1438 | GlobalErrorService* service = |
| 1439 | GlobalErrorServiceFactory::GetForProfile(profile()); |
| 1440 | GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); |
| 1441 | if (error) |
| 1442 | error->ShowBubbleView(this); |
| 1443 | } |
| 1444 | |
| 1445 | void Browser::ShowFirstRunBubble() { |
| 1446 | window()->GetLocationBar()->ShowFirstRunBubble(); |
| 1447 | } |
| 1448 | |
| 1449 | /////////////////////////////////////////////////////////////////////////////// |
| 1450 | // Browser, protected: |
| 1451 | |
| 1452 | BrowserWindow* Browser::CreateBrowserWindow() { |
| 1453 | bool create_panel = false; |
| 1454 | #if defined(USE_ASH) |
| 1455 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 1456 | ash::switches::kAuraPanelManager)) |
| 1457 | create_panel = is_type_panel(); |
| 1458 | #elif !defined(OS_CHROMEOS) |
| 1459 | create_panel = is_type_panel(); |
| 1460 | #endif |
| 1461 | if (create_panel) |
[email protected] | 4d61783 | 2012-05-22 19:10:26 | [diff] [blame] | 1462 | return PanelManager::GetInstance()->CreatePanel(this)->browser_window(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1463 | |
| 1464 | return BrowserWindow::CreateBrowserWindow(this); |
| 1465 | } |
| 1466 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1467 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 1468 | // Browser, content::WebContentsDelegate implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1469 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1470 | WebContents* Browser::OpenURLFromTab(WebContents* source, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1471 | const OpenURLParams& params) { |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame^] | 1472 | chrome::NavigateParams nav_params(this, params.url, params.transition); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1473 | nav_params.source_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1474 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | cb8fb01a | 2011-12-05 21:01:14 | [diff] [blame] | 1475 | nav_params.referrer = params.referrer; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1476 | nav_params.disposition = params.disposition; |
| 1477 | nav_params.tabstrip_add_types = TabStripModel::ADD_NONE; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame^] | 1478 | nav_params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1479 | nav_params.user_gesture = true; |
| 1480 | nav_params.override_encoding = params.override_encoding; |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1481 | nav_params.is_renderer_initiated = params.is_renderer_initiated; |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1482 | nav_params.transferred_global_request_id = |
| 1483 | params.transferred_global_request_id; |
[email protected] | 78e2edc | 2012-07-01 23:32:28 | [diff] [blame^] | 1484 | chrome::Navigate(&nav_params); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1485 | |
| 1486 | return nav_params.target_contents ? |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1487 | nav_params.target_contents->web_contents() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1488 | } |
| 1489 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1490 | void Browser::NavigationStateChanged(const WebContents* source, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1491 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1492 | // Only update the UI when something visible has changed. |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 1493 | if (changed_flags) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1494 | ScheduleUIUpdate(source, changed_flags); |
| 1495 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 1496 | // We can synchronously update commands since they will only change once per |
| 1497 | // navigation, so we don't have to worry about flickering. We do, however, |
| 1498 | // need to update the command state early on load to always present usable |
| 1499 | // actions in the face of slow-to-commit pages. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1500 | if (changed_flags & (content::INVALIDATE_TYPE_URL | |
| 1501 | content::INVALIDATE_TYPE_LOAD)) |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1502 | command_controller_->TabStateChanged(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1503 | } |
| 1504 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1505 | void Browser::AddNewContents(WebContents* source, |
| 1506 | WebContents* new_contents, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1507 | WindowOpenDisposition disposition, |
| 1508 | const gfx::Rect& initial_pos, |
| 1509 | bool user_gesture) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1510 | chrome::AddWebContents(this, source, new_contents, disposition, initial_pos, |
| 1511 | user_gesture); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1512 | } |
| 1513 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1514 | void Browser::ActivateContents(WebContents* contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1515 | chrome::ActivateTabAt(this, tab_strip_model_->GetIndexOfWebContents(contents), |
| 1516 | false); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1517 | window_->Activate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1518 | } |
| 1519 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1520 | void Browser::DeactivateContents(WebContents* contents) { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1521 | window_->Deactivate(); |
| 1522 | } |
| 1523 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1524 | void Browser::LoadingStateChanged(WebContents* source) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1525 | window_->UpdateLoadingAnimations(tab_strip_model_->TabsAreLoading()); |
[email protected] | f3e99e3 | 2008-07-30 04:48:39 | [diff] [blame] | 1526 | window_->UpdateTitleBar(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1527 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1528 | WebContents* selected_contents = chrome::GetActiveWebContents(this); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1529 | if (source == selected_contents) { |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 1530 | bool is_loading = source->IsLoading(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1531 | command_controller_->LoadingStateChanged(is_loading, false); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1532 | if (GetStatusBubble()) { |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1533 | GetStatusBubble()->SetStatus( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1534 | chrome::GetActiveTabContents(this)->core_tab_helper()-> |
| 1535 | GetStatusText()); |
[email protected] | 43d259d | 2010-09-03 21:37:46 | [diff] [blame] | 1536 | } |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 1537 | |
[email protected] | f5d978c | 2011-07-21 14:43:51 | [diff] [blame] | 1538 | if (!is_loading && pending_web_app_action_ == UPDATE_SHORTCUT) { |
[email protected] | 867dff8 | 2010-04-23 21:30:33 | [diff] [blame] | 1539 | // Schedule a shortcut update when web application info is available if |
| 1540 | // last committed entry is not NULL. Last committed entry could be NULL |
| 1541 | // when an interstitial page is injected (e.g. bad https certificate, |
| 1542 | // malware site etc). When this happens, we abort the shortcut update. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1543 | NavigationEntry* entry = source->GetController().GetLastCommittedEntry(); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 1544 | if (entry) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1545 | TabContents::FromWebContents(source)-> |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1546 | extension_tab_helper()->GetApplicationInfo(entry->GetPageID()); |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 1547 | } else { |
| 1548 | pending_web_app_action_ = NONE; |
[email protected] | eabfdae9 | 2009-12-11 06:13:51 | [diff] [blame] | 1549 | } |
| 1550 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1551 | } |
| 1552 | } |
| 1553 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 1554 | void Browser::CloseContents(WebContents* source) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 1555 | if (is_attempting_to_close_browser_) { |
| 1556 | // If we're trying to close the browser, just clear the state related to |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 1557 | // waiting for unload to fire. Don't actually try to close the tab as it |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 1558 | // will go down the slow shutdown path instead of the fast path of killing |
| 1559 | // all the renderer processes. |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 1560 | ClearUnloadState(source, true); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 1561 | return; |
| 1562 | } |
| 1563 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1564 | chrome::CloseWebContents(this, source); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1565 | } |
| 1566 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1567 | void Browser::MoveContents(WebContents* source, const gfx::Rect& pos) { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1568 | if (!IsPopupOrPanel(source)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1569 | NOTREACHED() << "moving invalid browser type"; |
| 1570 | return; |
| 1571 | } |
[email protected] | e561e20 | 2010-03-24 17:57:12 | [diff] [blame] | 1572 | window_->SetBounds(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1573 | } |
| 1574 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1575 | bool Browser::IsPopupOrPanel(const WebContents* source) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1576 | // A non-tabbed BROWSER is an unconstrained popup. |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1577 | return is_type_popup() || is_type_panel(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1578 | } |
| 1579 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1580 | void Browser::UpdateTargetURL(WebContents* source, int32 page_id, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1581 | const GURL& url) { |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1582 | if (!GetStatusBubble()) |
| 1583 | return; |
| 1584 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1585 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1586 | PrefService* prefs = profile_->GetPrefs(); |
[email protected] | 6523305 | 2011-08-22 19:02:48 | [diff] [blame] | 1587 | GetStatusBubble()->SetURL(url, prefs->GetString(prefs::kAcceptLanguages)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1588 | } |
| 1589 | } |
| 1590 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1591 | void Browser::ContentsMouseEvent( |
| 1592 | WebContents* source, const gfx::Point& location, bool motion) { |
| 1593 | if (!GetStatusBubble()) |
| 1594 | return; |
| 1595 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1596 | if (source == chrome::GetActiveWebContents(this)) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1597 | GetStatusBubble()->MouseMoved(location, !motion); |
| 1598 | if (!motion) |
| 1599 | GetStatusBubble()->SetURL(GURL(), std::string()); |
| 1600 | } |
[email protected] | 3a6a3b6 | 2009-05-27 21:36:20 | [diff] [blame] | 1601 | } |
| 1602 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1603 | void Browser::ContentsZoomChange(bool zoom_in) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1604 | chrome::ExecuteCommand(this, zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1605 | } |
| 1606 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1607 | void Browser::WebContentsFocused(WebContents* contents) { |
| 1608 | window_->WebContentsFocused(contents); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1609 | } |
| 1610 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 1611 | bool Browser::TakeFocus(bool reverse) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1612 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1613 | chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1614 | content::Source<Browser>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1615 | content::NotificationService::NoDetails()); |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 1616 | return false; |
| 1617 | } |
| 1618 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1619 | bool Browser::IsApplication() const { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 1620 | return is_app(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1621 | } |
| 1622 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 1623 | gfx::Rect Browser::GetRootWindowResizerRect() const { |
| 1624 | return window_->GetRootWindowResizerRect(); |
| 1625 | } |
| 1626 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1627 | void Browser::BeforeUnloadFired(WebContents* web_contents, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1628 | bool proceed, |
| 1629 | bool* proceed_to_fire_unload) { |
| 1630 | if (!is_attempting_to_close_browser_) { |
| 1631 | *proceed_to_fire_unload = proceed; |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 1632 | if (!proceed) |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1633 | web_contents->SetClosedByUserGesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1634 | return; |
| 1635 | } |
| 1636 | |
| 1637 | if (!proceed) { |
| 1638 | CancelWindowClose(); |
| 1639 | *proceed_to_fire_unload = false; |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1640 | web_contents->SetClosedByUserGesture(false); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1641 | return; |
| 1642 | } |
| 1643 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1644 | if (RemoveFromSet(&tabs_needing_before_unload_fired_, web_contents)) { |
[email protected] | 2d46c84 | 2008-11-14 19:24:31 | [diff] [blame] | 1645 | // Now that beforeunload has fired, put the tab on the queue to fire |
| 1646 | // unload. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1647 | tabs_needing_unload_fired_.insert(web_contents); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1648 | ProcessPendingTabs(); |
[email protected] | adf650f | 2008-12-09 16:10:06 | [diff] [blame] | 1649 | // We want to handle firing the unload event ourselves since we want to |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1650 | // fire all the beforeunload events before attempting to fire the unload |
| 1651 | // events should the user cancel closing the browser. |
| 1652 | *proceed_to_fire_unload = false; |
| 1653 | return; |
| 1654 | } |
| 1655 | |
| 1656 | *proceed_to_fire_unload = true; |
| 1657 | } |
| 1658 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1659 | void Browser::SetFocusToLocationBar(bool select_all) { |
[email protected] | 1a38062 | 2009-02-17 17:33:13 | [diff] [blame] | 1660 | // Two differences between this and FocusLocationBar(): |
| 1661 | // (1) This doesn't get recorded in user metrics, since it's called |
| 1662 | // internally. |
| 1663 | // (2) This checks whether the location bar can be focused, and if not, clears |
| 1664 | // the focus. FocusLocationBar() is only reached when the location bar is |
| 1665 | // focusable, but this may be reached at other times, e.g. while in |
| 1666 | // fullscreen mode, where we need to leave focus in a consistent state. |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 1667 | window_->SetFocusToLocationBar(select_all); |
[email protected] | 4bcefee | 2009-01-29 15:57:57 | [diff] [blame] | 1668 | } |
| 1669 | |
[email protected] | 7d5925a | 2009-03-03 02:59:12 | [diff] [blame] | 1670 | void Browser::RenderWidgetShowing() { |
| 1671 | window_->DisableInactiveFrame(); |
| 1672 | } |
[email protected] | a239c3f | 2009-02-17 22:13:19 | [diff] [blame] | 1673 | |
[email protected] | 0a2aeb8 | 2009-05-15 21:52:48 | [diff] [blame] | 1674 | int Browser::GetExtraRenderViewHeight() const { |
| 1675 | return window_->GetExtraRenderViewHeight(); |
| 1676 | } |
| 1677 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1678 | void Browser::OnStartDownload(WebContents* source, |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 1679 | content::DownloadItem* download) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1680 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 2ae41f9d | 2012-06-11 20:13:38 | [diff] [blame] | 1681 | TabContents* constrained = GetConstrainingTabContents(tab_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1682 | if (constrained != tab_contents) { |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1683 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1684 | WebContents* constrained_tab = constrained->web_contents(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1685 | constrained_tab->GetDelegate()->OnStartDownload(constrained_tab, download); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1686 | return; |
| 1687 | } |
| 1688 | |
| 1689 | if (!window()) |
| 1690 | return; |
| 1691 | |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1692 | // GetDownloadShelf creates the download shelf if it was not yet created. |
| 1693 | DownloadShelf* shelf = window()->GetDownloadShelf(); |
| 1694 | shelf->AddDownload(new DownloadItemModel(download)); |
| 1695 | // Don't show the animation for "Save file" downloads. |
| 1696 | // For non-theme extensions, we don't show the download animation. |
| 1697 | // Show animation in same window as the download shelf. Download shelf |
| 1698 | // may not be in the same window that initiated the download, e.g. |
| 1699 | // Panels. |
| 1700 | // Don't show the animation if the selected tab is not visible (i.e. the |
| 1701 | // window is minimized, we're in a unit test, etc.). |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1702 | WebContents* shelf_tab = chrome::GetActiveWebContents(shelf->browser()); |
[email protected] | 27c14f0 | 2012-06-22 17:29:58 | [diff] [blame] | 1703 | if ((download->GetTotalBytes() > 0) && |
| 1704 | !download_crx_util::IsExtensionDownload(*download) && |
| 1705 | platform_util::IsVisible(shelf_tab->GetNativeView()) && |
| 1706 | ui::Animation::ShouldRenderRichAnimation()) { |
| 1707 | DownloadStartedAnimation::Show(shelf_tab); |
[email protected] | a0e4b07 | 2011-08-17 01:47:07 | [diff] [blame] | 1708 | } |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1709 | |
| 1710 | // If the download occurs in a new tab, close it. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1711 | if (source->GetController().IsInitialNavigation() && tab_count() > 1) |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1712 | CloseContents(source); |
| 1713 | } |
| 1714 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1715 | void Browser::ViewSourceForTab(WebContents* source, const GURL& page_url) { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1716 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1717 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1718 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1719 | chrome::ViewSource(this, tab_contents); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1720 | } |
| 1721 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1722 | void Browser::ViewSourceForFrame(WebContents* source, |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1723 | const GURL& frame_url, |
| 1724 | const std::string& frame_content_state) { |
| 1725 | DCHECK(source); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1726 | TabContents* tab_contents = chrome::GetTabContentsAt(this, |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 1727 | tab_strip_model_->GetIndexOfWebContents(source)); |
[email protected] | 2cd4fde | 2012-06-26 03:10:26 | [diff] [blame] | 1728 | chrome::ViewSource(this, tab_contents, frame_url, frame_content_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1729 | } |
| 1730 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1731 | void Browser::ShowRepostFormWarningDialog(WebContents* source) { |
[email protected] | 67baffc8 | 2011-12-19 18:03:07 | [diff] [blame] | 1732 | browser::ShowTabModalConfirmDialog( |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1733 | new RepostFormWarningController(source), |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1734 | TabContents::FromWebContents(source)); |
[email protected] | 14f3408a | 2009-08-31 20:53:53 | [diff] [blame] | 1735 | } |
| 1736 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 1737 | bool Browser::ShouldAddNavigationToHistory( |
| 1738 | const history::HistoryAddPageArgs& add_page_args, |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 1739 | content::NavigationType navigation_type) { |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 1740 | // Don't update history if running as app. |
| 1741 | return !IsApplication(); |
| 1742 | } |
| 1743 | |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1744 | bool Browser::ShouldCreateWebContents( |
| 1745 | WebContents* web_contents, |
| 1746 | int route_id, |
| 1747 | WindowContainerType window_container_type, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1748 | const string16& frame_name, |
| 1749 | const GURL& target_url) { |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1750 | if (window_container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1751 | // If a BackgroundContents is created, suppress the normal WebContents. |
| 1752 | return !MaybeCreateBackgroundContents( |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 1753 | route_id, web_contents, frame_name, target_url); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | return true; |
| 1757 | } |
| 1758 | |
| 1759 | void Browser::WebContentsCreated(WebContents* source_contents, |
| 1760 | int64 source_frame_id, |
| 1761 | const GURL& target_url, |
| 1762 | WebContents* new_contents) { |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1763 | // Create a TabContents now, so all observers are in place, as the network |
| 1764 | // requests for its initial navigation will start immediately. The WebContents |
| 1765 | // will later be inserted into this browser using Browser::Navigate via |
| 1766 | // AddNewContents. The latter will retrieve the newly created TabContents from |
| 1767 | // WebContents object. |
| 1768 | new TabContents(new_contents); |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 1769 | |
| 1770 | // Notify. |
| 1771 | RetargetingDetails details; |
| 1772 | details.source_web_contents = source_contents; |
| 1773 | details.source_frame_id = source_frame_id; |
| 1774 | details.target_url = target_url; |
| 1775 | details.target_web_contents = new_contents; |
| 1776 | details.not_yet_in_tabstrip = true; |
| 1777 | content::NotificationService::current()->Notify( |
| 1778 | chrome::NOTIFICATION_RETARGETING, |
| 1779 | content::Source<Profile>(profile_), |
| 1780 | content::Details<RetargetingDetails>(&details)); |
[email protected] | 80c7b80 | 2011-10-28 19:59:08 | [diff] [blame] | 1781 | } |
| 1782 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1783 | void Browser::ContentRestrictionsChanged(WebContents* source) { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1784 | command_controller_->ContentRestrictionsChanged(); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 1785 | } |
| 1786 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1787 | void Browser::RendererUnresponsive(WebContents* source) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1788 | // Ignore hangs if print preview is open. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1789 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1790 | if (tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1791 | printing::PrintPreviewTabController* controller = |
| 1792 | printing::PrintPreviewTabController::GetInstance(); |
| 1793 | if (controller) { |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1794 | TabContents* preview_tab = |
| 1795 | controller->GetPrintPreviewForTab(tab_contents); |
| 1796 | if (preview_tab && preview_tab != tab_contents) { |
[email protected] | c19d954 | 2011-11-15 22:26:42 | [diff] [blame] | 1797 | return; |
| 1798 | } |
| 1799 | } |
| 1800 | } |
| 1801 | |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1802 | browser::ShowHungRendererDialog(source); |
| 1803 | } |
| 1804 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1805 | void Browser::RendererResponsive(WebContents* source) { |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1806 | browser::HideHungRendererDialog(source); |
| 1807 | } |
| 1808 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1809 | void Browser::WorkerCrashed(WebContents* source) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1810 | TabContents* tab_contents = TabContents::FromWebContents(source); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1811 | InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 1812 | infobar_helper->AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1813 | infobar_helper, |
| 1814 | NULL, |
| 1815 | l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 1816 | true)); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 1817 | } |
| 1818 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1819 | void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1820 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1821 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1822 | } |
| 1823 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1824 | void Browser::DidNavigateToPendingEntry(WebContents* web_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1825 | if (web_contents == chrome::GetActiveWebContents(this)) |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1826 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1827 | } |
| 1828 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 1829 | content::JavaScriptDialogCreator* Browser::GetJavaScriptDialogCreator() { |
| 1830 | return GetJavaScriptDialogCreatorInstance(); |
| 1831 | } |
| 1832 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1833 | content::ColorChooser* Browser::OpenColorChooser(WebContents* web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1834 | int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1835 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1836 | #if defined(OS_WIN) |
| 1837 | // On Windows, only create a color chooser if one doesn't exist, because we |
| 1838 | // can't close the old color chooser dialog. |
| 1839 | if (!color_chooser_.get()) |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1840 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1841 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1842 | color)); |
| 1843 | #else |
| 1844 | if (color_chooser_.get()) |
| 1845 | color_chooser_->End(); |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1846 | color_chooser_.reset(content::ColorChooser::Create(color_chooser_id, |
| 1847 | web_contents, |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1848 | color)); |
| 1849 | #endif |
| 1850 | return color_chooser_.get(); |
| 1851 | } |
| 1852 | |
| 1853 | void Browser::DidEndColorChooser() { |
| 1854 | color_chooser_.reset(); |
| 1855 | } |
| 1856 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1857 | void Browser::RunFileChooser(WebContents* web_contents, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 1858 | const content::FileChooserParams& params) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1859 | FileSelectHelper::RunFileChooser(web_contents, params); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1860 | } |
| 1861 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1862 | void Browser::EnumerateDirectory(WebContents* web_contents, |
[email protected] | 33f8ad5 | 2012-05-22 18:10:13 | [diff] [blame] | 1863 | int request_id, |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1864 | const FilePath& path) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1865 | FileSelectHelper::EnumerateDirectory(web_contents, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1866 | } |
| 1867 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1868 | void Browser::ToggleFullscreenModeForTab(WebContents* web_contents, |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1869 | bool enter_fullscreen) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1870 | fullscreen_controller_->ToggleFullscreenModeForTab(web_contents, |
| 1871 | enter_fullscreen); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1872 | } |
| 1873 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1874 | bool Browser::IsFullscreenForTabOrPending( |
| 1875 | const WebContents* web_contents) const { |
| 1876 | return fullscreen_controller_->IsFullscreenForTabOrPending(web_contents); |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1877 | } |
| 1878 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1879 | void Browser::JSOutOfMemory(WebContents* web_contents) { |
| 1880 | JSOutOfMemoryHelper(web_contents); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1881 | } |
| 1882 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1883 | void Browser::RegisterProtocolHandler(WebContents* web_contents, |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1884 | const std::string& protocol, |
| 1885 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1886 | const string16& title, |
| 1887 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1888 | RegisterProtocolHandlerHelper( |
[email protected] | 9b4d241c9 | 2012-06-29 19:48:31 | [diff] [blame] | 1889 | web_contents, protocol, url, title, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1890 | } |
| 1891 | |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1892 | void Browser::RegisterIntentHandler( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1893 | WebContents* web_contents, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1894 | const webkit_glue::WebIntentServiceData& data, |
| 1895 | bool user_gesture) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1896 | RegisterIntentHandlerHelper(web_contents, data, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1897 | } |
| 1898 | |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1899 | void Browser::WebIntentDispatch( |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1900 | WebContents* web_contents, |
| 1901 | content::WebIntentsDispatcher* intents_dispatcher) { |
[email protected] | d943615 | 2012-05-24 03:24:46 | [diff] [blame] | 1902 | if (!web_intents::IsWebIntentsEnabledForProfile(profile_)) |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 1903 | return; |
| 1904 | |
[email protected] | 86238d2 | 2012-05-22 20:00:11 | [diff] [blame] | 1905 | UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); |
| 1906 | |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1907 | if (!web_contents) { |
| 1908 | // Intent is system-caused and the picker will show over the currently |
| 1909 | // active web contents. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 1910 | web_contents = chrome::GetActiveWebContents(this); |
[email protected] | bd52a98 | 2012-06-26 23:34:29 | [diff] [blame] | 1911 | } |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1912 | TabContents* tab_contents = TabContents::FromWebContents(web_contents); |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1913 | tab_contents->web_intent_picker_controller()->SetIntentsDispatcher( |
| 1914 | intents_dispatcher); |
| 1915 | tab_contents->web_intent_picker_controller()->ShowDialog( |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1916 | intents_dispatcher->GetIntent().action, |
| 1917 | intents_dispatcher->GetIntent().type); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1918 | } |
| 1919 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 1920 | void Browser::UpdatePreferredSize(WebContents* source, |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1921 | const gfx::Size& pref_size) { |
| 1922 | window_->UpdatePreferredSize(source, pref_size); |
| 1923 | } |
| 1924 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1925 | void Browser::ResizeDueToAutoResize(WebContents* source, |
| 1926 | const gfx::Size& new_size) { |
| 1927 | window_->ResizeDueToAutoResize(source, new_size); |
| 1928 | } |
| 1929 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1930 | void Browser::FindReply(WebContents* web_contents, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1931 | int request_id, |
| 1932 | int number_of_matches, |
| 1933 | const gfx::Rect& selection_rect, |
| 1934 | int active_match_ordinal, |
| 1935 | bool final_update) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1936 | FindReplyHelper(web_contents, request_id, number_of_matches, selection_rect, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1937 | active_match_ordinal, final_update); |
| 1938 | } |
| 1939 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1940 | void Browser::RequestToLockMouse(WebContents* web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1941 | bool user_gesture, |
| 1942 | bool last_unlocked_by_target) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 1943 | fullscreen_controller_->RequestToLockMouse(web_contents, |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1944 | user_gesture, |
| 1945 | last_unlocked_by_target); |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 1946 | } |
| 1947 | |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1948 | void Browser::LostMouseLock() { |
[email protected] | 01a5a76 | 2011-11-21 05:40:55 | [diff] [blame] | 1949 | fullscreen_controller_->LostMouseLock(); |
[email protected] | 5ef8e37 | 2011-10-18 04:25:55 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1952 | void Browser::RequestMediaAccessPermission( |
| 1953 | content::WebContents* web_contents, |
| 1954 | const content::MediaStreamRequest* request, |
| 1955 | const content::MediaResponseCallback& callback) { |
| 1956 | TabContents* tab = TabContents::FromWebContents(web_contents); |
| 1957 | DCHECK(tab); |
| 1958 | |
[email protected] | 4afde5c | 2012-06-25 17:00:53 | [diff] [blame] | 1959 | scoped_ptr<MediaStreamDevicesController> |
| 1960 | controller(new MediaStreamDevicesController(tab->profile(), |
| 1961 | request, |
| 1962 | callback)); |
| 1963 | if (!controller->DismissInfoBarAndTakeActionOnSettings()) { |
| 1964 | InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 1965 | InfoBarDelegate* old_infobar = NULL; |
| 1966 | for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { |
| 1967 | old_infobar = infobar_helper->GetInfoBarDelegateAt(i)-> |
| 1968 | AsMediaStreamInfoBarDelegate(); |
| 1969 | if (old_infobar) |
| 1970 | break; |
| 1971 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1972 | |
[email protected] | 4afde5c | 2012-06-25 17:00:53 | [diff] [blame] | 1973 | InfoBarDelegate* infobar = |
| 1974 | new MediaStreamInfoBarDelegate(infobar_helper, controller.release()); |
| 1975 | if (old_infobar) |
| 1976 | infobar_helper->ReplaceInfoBar(old_infobar, infobar); |
| 1977 | else |
| 1978 | infobar_helper->AddInfoBar(infobar); |
| 1979 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 1980 | } |
| 1981 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 1982 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 1983 | // Browser, CoreTabHelperDelegate implementation: |
[email protected] | a0366a5 | 2011-02-04 20:04:21 | [diff] [blame] | 1984 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 1985 | void Browser::SwapTabContents(TabContents* old_tab_contents, |
| 1986 | TabContents* new_tab_contents) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1987 | int index = tab_strip_model_->GetIndexOfTabContents(old_tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1988 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 1989 | tab_strip_model_->ReplaceTabContentsAt(index, new_tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 1990 | } |
| 1991 | |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1992 | bool Browser::CanReloadContents(TabContents* source) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1993 | return chrome::CanReload(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | bool Browser::CanSaveContents(TabContents* source) const { |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 1997 | return chrome::CanSavePage(this); |
[email protected] | e146195 | 2012-06-14 21:05:35 | [diff] [blame] | 1998 | } |
| 1999 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2000 | /////////////////////////////////////////////////////////////////////////////// |
| 2001 | // Browser, SearchEngineTabHelperDelegate implementation: |
| 2002 | |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 2003 | void Browser::ConfirmAddSearchProvider(TemplateURL* template_url, |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2004 | Profile* profile) { |
| 2005 | window()->ConfirmAddSearchProvider(template_url, profile); |
| 2006 | } |
| 2007 | |
| 2008 | /////////////////////////////////////////////////////////////////////////////// |
| 2009 | // Browser, ConstrainedWindowTabHelperDelegate implementation: |
| 2010 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2011 | void Browser::SetTabContentBlocked(TabContents* tab_contents, bool blocked) { |
| 2012 | int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2013 | if (index == TabStripModel::kNoTab) { |
| 2014 | NOTREACHED(); |
| 2015 | return; |
| 2016 | } |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2017 | tab_strip_model_->SetTabBlocked(index, blocked); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 2018 | command_controller_->PrintingStateChanged(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2019 | if (!blocked && chrome::GetActiveTabContents(this) == tab_contents) |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2020 | tab_contents->web_contents()->Focus(); |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | /////////////////////////////////////////////////////////////////////////////// |
| 2024 | // Browser, BlockedContentTabHelperDelegate implementation: |
| 2025 | |
[email protected] | 2ae41f9d | 2012-06-11 20:13:38 | [diff] [blame] | 2026 | TabContents* Browser::GetConstrainingTabContents(TabContents* source) { |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2027 | return source; |
| 2028 | } |
| 2029 | |
| 2030 | /////////////////////////////////////////////////////////////////////////////// |
| 2031 | // Browser, BookmarkTabHelperDelegate implementation: |
| 2032 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2033 | void Browser::URLStarredChanged(TabContents* source, bool starred) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2034 | if (source == chrome::GetActiveTabContents(this)) |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2035 | window_->SetStarredState(starred); |
| 2036 | } |
| 2037 | |
| 2038 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2039 | // Browser, ZoomObserver implementation: |
| 2040 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2041 | void Browser::OnZoomIconChanged(TabContents* source, |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2042 | ZoomController::ZoomIconState state) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2043 | if (source == chrome::GetActiveTabContents(this)) |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2044 | window_->SetZoomIconState(state); |
| 2045 | } |
| 2046 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2047 | void Browser::OnZoomChanged(TabContents* source, |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2048 | int zoom_percent, |
| 2049 | bool can_show_bubble) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2050 | if (source == chrome::GetActiveTabContents(this)) { |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2051 | window_->SetZoomIconTooltipPercent(zoom_percent); |
| 2052 | |
| 2053 | // Only show the zoom bubble for zoom changes in the active window. |
| 2054 | if (can_show_bubble && window_->IsActive()) |
| 2055 | window_->ShowZoomBubble(zoom_percent); |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2060 | // Browser, ExtensionTabHelperDelegate implementation: |
| 2061 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2062 | void Browser::OnDidGetApplicationInfo(TabContents* source, |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2063 | int32 page_id) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2064 | if (chrome::GetActiveTabContents(this) != source) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2065 | return; |
| 2066 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2067 | NavigationEntry* entry = |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2068 | source->web_contents()->GetController().GetLastCommittedEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2069 | if (!entry || (entry->GetPageID() != page_id)) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2070 | return; |
| 2071 | |
| 2072 | switch (pending_web_app_action_) { |
| 2073 | case CREATE_SHORTCUT: { |
| 2074 | window()->ShowCreateWebAppShortcutsDialog(source); |
| 2075 | break; |
| 2076 | } |
| 2077 | case UPDATE_SHORTCUT: { |
| 2078 | web_app::UpdateShortcutForTabContents(source); |
| 2079 | break; |
| 2080 | } |
| 2081 | default: |
| 2082 | NOTREACHED(); |
| 2083 | break; |
| 2084 | } |
| 2085 | |
| 2086 | pending_web_app_action_ = NONE; |
| 2087 | } |
| 2088 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2089 | void Browser::OnInstallApplication(TabContents* source, |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2090 | const WebApplicationInfo& web_app) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2091 | ExtensionService* extension_service = profile()->GetExtensionService(); |
| 2092 | if (!extension_service) |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2093 | return; |
| 2094 | |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2095 | scoped_refptr<CrxInstaller> installer(CrxInstaller::Create( |
| 2096 | extension_service, |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2097 | extension_service->show_extensions_prompts() ? |
[email protected] | 32fc4ff7 | 2012-06-15 21:50:01 | [diff] [blame] | 2098 | new ExtensionInstallPrompt(this) : NULL)); |
[email protected] | 553602e1 | 2011-04-05 17:01:18 | [diff] [blame] | 2099 | installer->InstallWebApp(web_app); |
| 2100 | } |
| 2101 | |
[email protected] | c90c6ca | 2011-02-16 20:11:38 | [diff] [blame] | 2102 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2103 | // Browser, SelectFileDialog::Listener implementation: |
| 2104 | |
[email protected] | 561abe6 | 2009-04-06 18:08:34 | [diff] [blame] | 2105 | void Browser::FileSelected(const FilePath& path, int index, void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2106 | profile_->set_last_selected_directory(path.DirName()); |
[email protected] | 72cbd32 | 2009-04-07 10:17:12 | [diff] [blame] | 2107 | GURL file_url = net::FilePathToFileURL(path); |
[email protected] | b7813a2 | 2012-04-04 18:41:02 | [diff] [blame] | 2108 | |
| 2109 | #if defined(OS_CHROMEOS) |
| 2110 | gdata::util::ModifyGDataFileResourceUrl(profile_, path, &file_url); |
| 2111 | #endif |
| 2112 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2113 | if (file_url.is_empty()) |
| 2114 | return; |
| 2115 | |
| 2116 | OpenURL(OpenURLParams( |
| 2117 | file_url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 2118 | false)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2122 | // Browser, content::NotificationObserver implementation: |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2123 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2124 | void Browser::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2125 | const content::NotificationSource& source, |
| 2126 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2127 | switch (type) { |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2128 | case content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 2129 | if (is_attempting_to_close_browser_) { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2130 | // Pass in false so that we delay processing. We need to delay the |
| 2131 | // processing as it may close the tab, which is currently on the call |
| 2132 | // stack above us. |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2133 | ClearUnloadState(content::Source<WebContents>(source).ptr(), false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 2134 | } |
| 2135 | break; |
| 2136 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2137 | case content::NOTIFICATION_SSL_VISIBLE_STATE_CHANGED: |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 2138 | // 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] | 2139 | // bar to reflect the new state. Note that it's possible for the selected |
| 2140 | // tab contents to be NULL. This is because we listen for all sources |
| 2141 | // (NavigationControllers) for convenience, so the notification could |
| 2142 | // actually be for a different window while we're doing asynchronous |
| 2143 | // closing of this one. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2144 | if (chrome::GetActiveWebContents(this) && |
| 2145 | &chrome::GetActiveWebContents(this)->GetController() == |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 2146 | content::Source<NavigationController>(source).ptr()) |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2147 | UpdateToolbar(false); |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 2148 | break; |
| 2149 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2150 | case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 2151 | if (window()->GetLocationBar()) |
| 2152 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 57f71b9 | 2009-09-11 19:31:38 | [diff] [blame] | 2153 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 2154 | // Close any tabs from the unloaded extension, unless it's terminated, |
| 2155 | // in which case let the sad tabs remain. |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 2156 | if (content::Details<extensions::UnloadedExtensionInfo>( |
| 2157 | details)->reason != extension_misc::UNLOAD_REASON_TERMINATE) { |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 2158 | const Extension* extension = |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 2159 | content::Details<extensions::UnloadedExtensionInfo>( |
| 2160 | details)->extension; |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2161 | for (int i = tab_strip_model_->count() - 1; i >= 0; --i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2162 | WebContents* tc = chrome::GetTabContentsAt(this, i)->web_contents(); |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 2163 | bool close_tab_contents = |
| 2164 | tc->GetURL().SchemeIs(chrome::kExtensionScheme) && |
| 2165 | tc->GetURL().host() == extension->id(); |
| 2166 | // We want to close all panels originated by the unloaded extension. |
| 2167 | close_tab_contents = close_tab_contents || |
| 2168 | (type_ == TYPE_PANEL && |
| 2169 | (web_app::GetExtensionIdFromApplicationName(app_name_) == |
[email protected] | f9e82d9 | 2011-10-29 00:50:45 | [diff] [blame] | 2170 | extension->id())); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2171 | if (close_tab_contents) |
| 2172 | chrome::CloseWebContents(this, tc); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2173 | } |
| 2174 | } |
| 2175 | break; |
| 2176 | } |
| 2177 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2178 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2179 | Profile* profile = content::Source<Profile>(source).ptr(); |
[email protected] | fe8944f | 2011-08-30 17:47:32 | [diff] [blame] | 2180 | if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 2181 | window()->GetLocationBar()->InvalidatePageActions(); |
[email protected] | 371ed7a | 2009-08-25 15:22:46 | [diff] [blame] | 2182 | break; |
| 2183 | } |
| 2184 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2185 | case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
| 2186 | case chrome::NOTIFICATION_EXTENSION_LOADED: |
[email protected] | 1797f4a | 2011-08-30 18:00:28 | [diff] [blame] | 2187 | // During window creation on Windows we may end up calling into |
| 2188 | // SHAppBarMessage, which internally spawns a nested message loop. This |
| 2189 | // makes it possible for us to end up here before window creation has |
| 2190 | // completed,at which point window_ is NULL. See 94752 for details. |
| 2191 | if (window() && window()->GetLocationBar()) |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 2192 | window()->GetLocationBar()->UpdatePageActions(); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2193 | break; |
[email protected] | ad0c2e1b | 2010-01-30 00:00:10 | [diff] [blame] | 2194 | |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 2195 | #if defined(ENABLE_THEMES) |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2196 | case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 2197 | window()->UserChangedTheme(); |
| 2198 | break; |
[email protected] | 6b40bb58 | 2012-03-15 20:50:38 | [diff] [blame] | 2199 | #endif |
[email protected] | e001d41 | 2009-06-26 20:53:25 | [diff] [blame] | 2200 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2201 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2202 | const std::string& pref_name = |
| 2203 | *content::Details<std::string>(details).ptr(); |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 2204 | if (pref_name == prefs::kInstantEnabled) { |
[email protected] | 3135936 | 2012-06-11 23:27:10 | [diff] [blame] | 2205 | if (browser_shutdown::ShuttingDownWithoutClosingBrowsers() || |
| 2206 | !InstantController::IsEnabled(profile())) { |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 2207 | if (instant()) { |
| 2208 | instant()->DestroyPreviewContents(); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2209 | instant_.reset(); |
| 2210 | instant_unload_handler_.reset(); |
[email protected] | 73de26a | 2010-10-17 03:23:25 | [diff] [blame] | 2211 | } |
| 2212 | } else { |
| 2213 | CreateInstantIfNecessary(); |
| 2214 | } |
[email protected] | 543432ee | 2010-10-22 16:32:13 | [diff] [blame] | 2215 | } else if (pref_name == prefs::kDevToolsDisabled) { |
[email protected] | 97b4638 | 2011-05-02 13:23:04 | [diff] [blame] | 2216 | if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 2217 | content::DevToolsManager::GetInstance()->CloseAllClientHosts(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 2218 | } else if (pref_name == prefs::kShowBookmarkBar) { |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 2219 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2220 | } else if (pref_name == prefs::kHomePage) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2221 | PrefService* pref_service = content::Source<PrefService>(source).ptr(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2222 | MarkHomePageAsChanged(pref_service); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 2223 | } else { |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 2224 | NOTREACHED(); |
[email protected] | 2a7e7c15 | 2010-10-01 20:12:09 | [diff] [blame] | 2225 | } |
[email protected] | b9c505b | 2010-04-30 15:05:10 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 2229 | case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { |
| 2230 | WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2231 | if (web_contents == chrome::GetActiveWebContents(this)) { |
[email protected] | 9a9a9e2 | 2011-05-13 22:20:35 | [diff] [blame] | 2232 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2233 | if (location_bar) |
| 2234 | location_bar->UpdateContentSettingsIcons(); |
| 2235 | } |
| 2236 | break; |
| 2237 | } |
| 2238 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2239 | case content::NOTIFICATION_INTERSTITIAL_ATTACHED: |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2240 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 2241 | break; |
| 2242 | |
| 2243 | case content::NOTIFICATION_INTERSTITIAL_DETACHED: |
| 2244 | UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2245 | break; |
| 2246 | |
[email protected] | e83f168 | 2008-09-07 23:57:40 | [diff] [blame] | 2247 | default: |
| 2248 | NOTREACHED() << "Got a notification we didn't register for."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2249 | } |
| 2250 | } |
| 2251 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 2252 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 37c917b | 2012-06-28 15:53:59 | [diff] [blame] | 2253 | // Browser, InstantControllerDelegate implementation: |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2254 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2255 | void Browser::ShowInstant(TabContents* preview_contents) { |
[email protected] | e3690ed | 2011-03-25 20:25:14 | [diff] [blame] | 2256 | window_->ShowInstant(preview_contents); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 2257 | |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 2258 | // TODO(beng): investigate if we can avoid this and instead rely on the |
| 2259 | // visibility of the WebContentsView |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2260 | chrome::GetActiveWebContents(this)->WasHidden(); |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 2261 | preview_contents->web_contents()->WasRestored(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 2264 | void Browser::HideInstant() { |
[email protected] | 3e48128 | 2011-10-15 15:39:50 | [diff] [blame] | 2265 | window_->HideInstant(); |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2266 | if (chrome::GetActiveWebContents(this)) |
| 2267 | chrome::GetActiveWebContents(this)->WasRestored(); |
[email protected] | 42f027fb | 2011-10-27 16:37:48 | [diff] [blame] | 2268 | if (instant_->GetPreviewContents()) |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 2269 | instant_->GetPreviewContents()->web_contents()->WasHidden(); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2270 | } |
| 2271 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2272 | void Browser::CommitInstant(TabContents* preview_contents) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2273 | TabContents* tab_contents = chrome::GetActiveTabContents(this); |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2274 | int index = tab_strip_model_->GetIndexOfTabContents(tab_contents); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2275 | DCHECK_NE(TabStripModel::kNoTab, index); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2276 | // TabStripModel takes ownership of preview_contents. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2277 | tab_strip_model_->ReplaceTabContentsAt(index, preview_contents); |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2278 | // InstantUnloadHandler takes ownership of tab_contents. |
| 2279 | instant_unload_handler_->RunUnloadListenersOrDestroy(tab_contents, index); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 2280 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2281 | GURL url = preview_contents->web_contents()->GetURL(); |
[email protected] | 6e37fe3 | 2011-03-02 09:06:52 | [diff] [blame] | 2282 | DCHECK(profile_->GetExtensionService()); |
| 2283 | if (profile_->GetExtensionService()->IsInstalledApp(url)) { |
[email protected] | a9acdff | 2012-03-08 04:04:52 | [diff] [blame] | 2284 | AppLauncherHandler::RecordAppLaunchType( |
| 2285 | extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); |
[email protected] | 46fd1ea4 | 2011-02-16 15:59:33 | [diff] [blame] | 2286 | } |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2287 | } |
| 2288 | |
[email protected] | 33b8b8e | 2011-03-15 14:51:55 | [diff] [blame] | 2289 | void Browser::SetSuggestedText(const string16& text, |
| 2290 | InstantCompleteBehavior behavior) { |
[email protected] | ce696a45 | 2011-05-31 17:47:36 | [diff] [blame] | 2291 | if (window()->GetLocationBar()) |
| 2292 | window()->GetLocationBar()->SetSuggestedText(text, behavior); |
[email protected] | 03bb953d | 2010-09-14 21:38:30 | [diff] [blame] | 2293 | } |
| 2294 | |
[email protected] | 6b723f8 | 2010-10-05 20:14:27 | [diff] [blame] | 2295 | gfx::Rect Browser::GetInstantBounds() { |
| 2296 | return window()->GetInstantBounds(); |
[email protected] | 46fe8e9 | 2010-09-22 03:32:47 | [diff] [blame] | 2297 | } |
| 2298 | |
[email protected] | 09c6943 | 2012-03-16 16:23:28 | [diff] [blame] | 2299 | void Browser::InstantPreviewFocused() { |
| 2300 | // NOTE: This is only invoked on aura. |
| 2301 | window_->WebContentsFocused(instant_->GetPreviewContents()->web_contents()); |
| 2302 | } |
| 2303 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2304 | TabContents* Browser::GetInstantHostTabContents() const { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2305 | return chrome::GetActiveTabContents(this); |
[email protected] | 05cf2fa | 2012-05-29 20:36:06 | [diff] [blame] | 2306 | } |
| 2307 | |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2308 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2309 | // Browser, Command and state updating (private): |
| 2310 | |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2311 | void Browser::MarkHomePageAsChanged(PrefService* pref_service) { |
| 2312 | pref_service->SetBoolean(prefs::kHomePageChanged, true); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 2313 | } |
| 2314 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2315 | /////////////////////////////////////////////////////////////////////////////// |
| 2316 | // Browser, UI update coalescing and handling (private): |
| 2317 | |
| 2318 | void Browser::UpdateToolbar(bool should_restore_state) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2319 | window_->UpdateToolbar(chrome::GetActiveTabContents(this), |
| 2320 | should_restore_state); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2321 | } |
| 2322 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2323 | void Browser::UpdateSearchState(TabContents* contents) { |
| 2324 | if (chrome::search::IsInstantExtendedAPIEnabled(profile_)) |
| 2325 | search_delegate_->OnTabActivated(contents); |
| 2326 | } |
| 2327 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2328 | void Browser::ScheduleUIUpdate(const WebContents* source, |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2329 | unsigned changed_flags) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2330 | if (!source) |
| 2331 | return; |
| 2332 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2333 | // Do some synchronous updates. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2334 | if (changed_flags & content::INVALIDATE_TYPE_URL && |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2335 | source == chrome::GetActiveWebContents(this)) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2336 | // Only update the URL for the current tab. Note that we do not update |
| 2337 | // the navigation commands since those would have already been updated |
| 2338 | // synchronously by NavigationStateChanged. |
| 2339 | UpdateToolbar(false); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2340 | changed_flags &= ~content::INVALIDATE_TYPE_URL; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2341 | } |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2342 | if (changed_flags & content::INVALIDATE_TYPE_LOAD) { |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2343 | // Update the loading state synchronously. This is so the throbber will |
| 2344 | // immediately start/stop, which gives a more snappy feel. We want to do |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2345 | // this for any tab so they start & stop quickly. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2346 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2347 | chrome::GetIndexOfTab(this, source), |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2348 | TabStripModelObserver::LOADING_ONLY); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2349 | // The status bubble needs to be updated during INVALIDATE_TYPE_LOAD too, |
| 2350 | // but we do that asynchronously by not stripping INVALIDATE_TYPE_LOAD from |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2351 | // changed_flags. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2352 | } |
| 2353 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2354 | if (changed_flags & content::INVALIDATE_TYPE_TITLE && !source->IsLoading()) { |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2355 | // To correctly calculate whether the title changed while not loading |
| 2356 | // we need to process the update synchronously. This state only matters for |
| 2357 | // the TabStripModel, so we notify the TabStripModel now and notify others |
| 2358 | // asynchronously. |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2359 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2360 | chrome::GetIndexOfTab(this, source), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2361 | TabStripModelObserver::TITLE_NOT_LOADING); |
| 2362 | } |
| 2363 | |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2364 | // If the only updates were synchronously handled above, we're done. |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2365 | if (changed_flags == 0) |
[email protected] | 2b4355c | 2009-04-04 17:55:46 | [diff] [blame] | 2366 | return; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2367 | |
| 2368 | // Save the dirty bits. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2369 | scheduled_updates_[source] |= changed_flags; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2370 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2371 | if (!chrome_updater_factory_.HasWeakPtrs()) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2372 | // No task currently scheduled, start another. |
[email protected] | 0586b0e | 2010-02-12 21:38:37 | [diff] [blame] | 2373 | MessageLoop::current()->PostDelayedTask( |
| 2374 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2375 | base::Bind(&Browser::ProcessPendingUIUpdates, |
| 2376 | chrome_updater_factory_.GetWeakPtr()), |
[email protected] | 11d6ab1a | 2012-01-12 21:37:26 | [diff] [blame] | 2377 | base::TimeDelta::FromMilliseconds(kUIUpdateCoalescingTimeMS)); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | void Browser::ProcessPendingUIUpdates() { |
| 2382 | #ifndef NDEBUG |
| 2383 | // Validate that all tabs we have pending updates for exist. This is scary |
| 2384 | // because the pending list must be kept in sync with any detached or |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2385 | // deleted tabs. |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2386 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2387 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2388 | bool found = false; |
| 2389 | for (int tab = 0; tab < tab_count(); tab++) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2390 | if (chrome::GetWebContentsAt(this, tab) == i->first) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2391 | found = true; |
| 2392 | break; |
| 2393 | } |
| 2394 | } |
| 2395 | DCHECK(found); |
| 2396 | } |
| 2397 | #endif |
| 2398 | |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2399 | chrome_updater_factory_.InvalidateWeakPtrs(); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2400 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2401 | for (UpdateMap::const_iterator i = scheduled_updates_.begin(); |
| 2402 | i != scheduled_updates_.end(); ++i) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2403 | // Do not dereference |contents|, it may be out-of-date! |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 2404 | const WebContents* contents = i->first; |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2405 | unsigned flags = i->second; |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2406 | |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2407 | if (contents == chrome::GetActiveWebContents(this)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2408 | // Updates that only matter when the tab is selected go here. |
[email protected] | f7f3a5f | 2009-05-01 22:02:34 | [diff] [blame] | 2409 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2410 | if (flags & content::INVALIDATE_TYPE_PAGE_ACTIONS) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2411 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2412 | if (location_bar) |
| 2413 | location_bar->UpdatePageActions(); |
| 2414 | } |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2415 | // Updating the URL happens synchronously in ScheduleUIUpdate. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2416 | if (flags & content::INVALIDATE_TYPE_LOAD && GetStatusBubble()) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2417 | GetStatusBubble()->SetStatus(chrome::GetActiveTabContents(this)-> |
| 2418 | core_tab_helper()->GetStatusText()); |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 2419 | } |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2420 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2421 | if (flags & (content::INVALIDATE_TYPE_TAB | |
| 2422 | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2423 | window_->UpdateTitleBar(); |
| 2424 | } |
[email protected] | 4d34e2e | 2009-05-26 22:55:28 | [diff] [blame] | 2425 | } |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2426 | |
[email protected] | a523166 | 2009-09-26 00:56:00 | [diff] [blame] | 2427 | // Updates that don't depend upon the selected state go here. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2428 | if (flags & |
| 2429 | (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2430 | tab_strip_model_->UpdateTabContentsStateAt( |
[email protected] | e52d0a4 | 2012-06-08 22:44:16 | [diff] [blame] | 2431 | tab_strip_model_->GetIndexOfWebContents(contents), |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2432 | TabStripModelObserver::ALL); |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | // We don't need to process INVALIDATE_STATE, since that's not visible. |
| 2436 | } |
| 2437 | |
| 2438 | scheduled_updates_.clear(); |
| 2439 | } |
| 2440 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2441 | void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2442 | if (!contents) |
| 2443 | return; |
| 2444 | |
[email protected] | 8535498 | 2009-09-25 19:58:40 | [diff] [blame] | 2445 | UpdateMap::iterator i = scheduled_updates_.find(contents); |
| 2446 | if (i != scheduled_updates_.end()) |
| 2447 | scheduled_updates_.erase(i); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2448 | } |
| 2449 | |
[email protected] | d938aed9 | 2009-01-22 19:49:33 | [diff] [blame] | 2450 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2451 | /////////////////////////////////////////////////////////////////////////////// |
| 2452 | // Browser, Getters for UI (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2453 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2454 | StatusBubble* Browser::GetStatusBubble() { |
[email protected] | 3493043 | 2009-11-09 00:12:09 | [diff] [blame] | 2455 | // In kiosk mode, we want to always hide the status bubble. |
| 2456 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
| 2457 | return NULL; |
[email protected] | 9b032bf | 2009-07-21 17:34:23 | [diff] [blame] | 2458 | return window_ ? window_->GetStatusBubble() : NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2459 | } |
| 2460 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2461 | /////////////////////////////////////////////////////////////////////////////// |
| 2462 | // Browser, Session restore functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2463 | |
| 2464 | void Browser::SyncHistoryWithTabs(int index) { |
[email protected] | 92371eb | 2011-04-28 11:50:15 | [diff] [blame] | 2465 | SessionService* session_service = |
| 2466 | SessionServiceFactory::GetForProfileIfExisting(profile()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2467 | if (session_service) { |
| 2468 | for (int i = index; i < tab_count(); ++i) { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2469 | TabContents* tab = chrome::GetTabContentsAt(this, i); |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 2470 | if (tab) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2471 | session_service->SetTabIndexInWindow( |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 2472 | session_id(), tab->restore_tab_helper()->session_id(), i); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2473 | session_service->SetPinnedState( |
| 2474 | session_id(), |
[email protected] | 8189899 | 2011-06-14 22:15:00 | [diff] [blame] | 2475 | tab->restore_tab_helper()->session_id(), |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2476 | tab_strip_model_->IsTabPinned(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2482 | /////////////////////////////////////////////////////////////////////////////// |
| 2483 | // Browser, OnBeforeUnload handling (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2484 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2485 | void Browser::ProcessPendingTabs() { |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2486 | if (!is_attempting_to_close_browser_) { |
| 2487 | // Because we might invoke this after a delay it's possible for the value of |
| 2488 | // is_attempting_to_close_browser_ to have changed since we scheduled the |
| 2489 | // task. |
| 2490 | return; |
| 2491 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2492 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2493 | if (HasCompletedUnloadProcessing()) { |
| 2494 | // We've finished all the unload events and can proceed to close the |
| 2495 | // browser. |
| 2496 | OnWindowClosing(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2497 | return; |
| 2498 | } |
| 2499 | |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2500 | // Process beforeunload tabs first. When that queue is empty, process |
| 2501 | // unload tabs. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2502 | if (!tabs_needing_before_unload_fired_.empty()) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2503 | WebContents* web_contents = *(tabs_needing_before_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2504 | // Null check render_view_host here as this gets called on a PostTask and |
| 2505 | // the tab's render_view_host may have been nulled out. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2506 | if (web_contents->GetRenderViewHost()) { |
| 2507 | web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2508 | } else { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2509 | ClearUnloadState(web_contents, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2510 | } |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2511 | } else if (!tabs_needing_unload_fired_.empty()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2512 | // We've finished firing all beforeunload events and can proceed with unload |
| 2513 | // events. |
| 2514 | // TODO(ojan): We should add a call to browser_shutdown::OnShutdownStarting |
| 2515 | // somewhere around here so that we have accurate measurements of shutdown |
| 2516 | // time. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2517 | // TODO(ojan): We can probably fire all the unload events in parallel and |
| 2518 | // get a perf benefit from that in the cases where the tab hangs in it's |
| 2519 | // unload handler or takes a long time to page in. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2520 | WebContents* web_contents = *(tabs_needing_unload_fired_.begin()); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2521 | // Null check render_view_host here as this gets called on a PostTask and |
| 2522 | // the tab's render_view_host may have been nulled out. |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2523 | if (web_contents->GetRenderViewHost()) { |
| 2524 | web_contents->GetRenderViewHost()->ClosePage(); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2525 | } else { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2526 | ClearUnloadState(web_contents, true); |
[email protected] | 2248462 | 2009-06-10 21:17:24 | [diff] [blame] | 2527 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2528 | } else { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2529 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
[email protected] | d043c2cc | 2009-03-25 18:30:45 | [diff] [blame] | 2533 | bool Browser::HasCompletedUnloadProcessing() const { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2534 | return is_attempting_to_close_browser_ && |
| 2535 | tabs_needing_before_unload_fired_.empty() && |
| 2536 | tabs_needing_unload_fired_.empty(); |
| 2537 | } |
| 2538 | |
| 2539 | void Browser::CancelWindowClose() { |
[email protected] | 22bf2c1 | 2012-06-23 08:35:55 | [diff] [blame] | 2540 | // Closing of window can be canceled from a beforeunload handler. |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2541 | DCHECK(is_attempting_to_close_browser_); |
[email protected] | 8f673f3a | 2008-08-05 22:34:28 | [diff] [blame] | 2542 | tabs_needing_before_unload_fired_.clear(); |
| 2543 | tabs_needing_unload_fired_.clear(); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2544 | is_attempting_to_close_browser_ = false; |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 2545 | |
[email protected] | 9cc82165 | 2012-04-18 18:18:10 | [diff] [blame] | 2546 | content::NotificationService::current()->Notify( |
| 2547 | chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED, |
| 2548 | content::Source<Browser>(this), |
| 2549 | content::NotificationService::NoDetails()); |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2550 | } |
| 2551 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2552 | bool Browser::RemoveFromSet(UnloadListenerSet* set, WebContents* web_contents) { |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2553 | DCHECK(is_attempting_to_close_browser_); |
| 2554 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2555 | UnloadListenerSet::iterator iter = |
| 2556 | std::find(set->begin(), set->end(), web_contents); |
[email protected] | 06b42f03 | 2008-12-03 18:43:05 | [diff] [blame] | 2557 | if (iter != set->end()) { |
| 2558 | set->erase(iter); |
| 2559 | return true; |
[email protected] | 04b4a6c | 2008-08-02 00:44:47 | [diff] [blame] | 2560 | } |
| 2561 | return false; |
| 2562 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2563 | |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2564 | void Browser::ClearUnloadState(WebContents* web_contents, bool process_now) { |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 2565 | if (is_attempting_to_close_browser_) { |
[email protected] | 1d3e917 | 2012-06-12 02:59:13 | [diff] [blame] | 2566 | RemoveFromSet(&tabs_needing_before_unload_fired_, web_contents); |
| 2567 | RemoveFromSet(&tabs_needing_unload_fired_, web_contents); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2568 | if (process_now) { |
| 2569 | ProcessPendingTabs(); |
| 2570 | } else { |
| 2571 | MessageLoop::current()->PostTask( |
| 2572 | FROM_HERE, |
[email protected] | 24f147753 | 2011-11-22 22:55:36 | [diff] [blame] | 2573 | base::Bind(&Browser::ProcessPendingTabs, weak_factory_.GetWeakPtr())); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2574 | } |
[email protected] | 0b4d338 | 2010-07-14 16:13:04 | [diff] [blame] | 2575 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2576 | } |
| 2577 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2578 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2579 | // Browser, In-progress download termination handling (private): |
| 2580 | |
[email protected] | b6a4ac2b | 2011-10-17 20:05:48 | [diff] [blame] | 2581 | bool Browser::CanCloseWithInProgressDownloads() { |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2582 | // If we've prompted, we need to hear from the user before we |
| 2583 | // can close. |
| 2584 | if (cancel_download_confirmation_state_ != NOT_PROMPTED) |
| 2585 | return cancel_download_confirmation_state_ != WAITING_FOR_RESPONSE; |
| 2586 | |
| 2587 | int num_downloads_blocking; |
| 2588 | if (DOWNLOAD_CLOSE_OK == |
| 2589 | OkToCloseWithInProgressDownloads(&num_downloads_blocking)) |
[email protected] | 446295a | 2010-04-19 23:43:00 | [diff] [blame] | 2590 | return true; |
| 2591 | |
[email protected] | 5a17d49 | 2011-10-24 19:37:03 | [diff] [blame] | 2592 | // Closing this window will kill some downloads; prompt to make sure |
| 2593 | // that's ok. |
[email protected] | 69444cc | 2009-04-09 20:40:06 | [diff] [blame] | 2594 | cancel_download_confirmation_state_ = WAITING_FOR_RESPONSE; |
| 2595 | window_->ConfirmBrowserCloseWithPendingDownloads(); |
| 2596 | |
| 2597 | // Return false so the browser does not close. We'll close if the user |
| 2598 | // confirms in the dialog. |
| 2599 | return false; |
| 2600 | } |
| 2601 | |
| 2602 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2603 | // Browser, Assorted utility functions (private): |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2604 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2605 | void Browser::SetAsDelegate(TabContents* tab, Browser* delegate) { |
[email protected] | 075969d | 2012-04-17 20:05:55 | [diff] [blame] | 2606 | // WebContents... |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2607 | tab->web_contents()->SetDelegate(delegate); |
[email protected] | e7cfdbd | 2011-04-22 14:41:37 | [diff] [blame] | 2608 | |
| 2609 | // ...and all the helpers. |
| 2610 | tab->blocked_content_tab_helper()->set_delegate(delegate); |
[email protected] | 35699d57 | 2011-05-11 19:46:14 | [diff] [blame] | 2611 | tab->bookmark_tab_helper()->set_delegate(delegate); |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 2612 | tab->zoom_controller()->set_observer(delegate); |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 2613 | tab->constrained_window_tab_helper()->set_delegate(delegate); |
[email protected] | 51d83bdf | 2011-12-09 16:09:29 | [diff] [blame] | 2614 | tab->core_tab_helper()->set_delegate(delegate); |
[email protected] | 1739e57d | 2011-11-30 21:18:25 | [diff] [blame] | 2615 | tab->extension_tab_helper()->set_delegate(delegate); |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 2616 | tab->search_engine_tab_helper()->set_delegate(delegate); |
| 2617 | } |
| 2618 | |
[email protected] | 36b6dcb | 2008-11-12 01:19:57 | [diff] [blame] | 2619 | void Browser::CloseFrame() { |
| 2620 | window_->Close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2621 | } |
| 2622 | |
[email protected] | 3d61dd0 | 2012-06-07 00:05:53 | [diff] [blame] | 2623 | void Browser::TabDetachedAtImpl(TabContents* contents, int index, |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2624 | DetachType type) { |
| 2625 | if (type == DETACH_TYPE_DETACH) { |
[email protected] | 5658085 | 2010-11-17 16:09:15 | [diff] [blame] | 2626 | // Save the current location bar state, but only if the tab being detached |
| 2627 | // is the selected tab. Because saving state can conditionally revert the |
| 2628 | // location bar, saving the current tab's location bar state to a |
| 2629 | // non-selected tab can corrupt both tabs. |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2630 | if (contents == chrome::GetActiveTabContents(this)) { |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2631 | LocationBar* location_bar = window()->GetLocationBar(); |
| 2632 | if (location_bar) |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 2633 | location_bar->SaveStateToContents(contents->web_contents()); |
[email protected] | 9800de5e | 2011-03-11 18:19:49 | [diff] [blame] | 2634 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2635 | |
[email protected] | 2fc15ae | 2012-05-06 00:01:37 | [diff] [blame] | 2636 | if (!tab_strip_model_->closing_all()) |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2637 | SyncHistoryWithTabs(0); |
| 2638 | } |
| 2639 | |
[email protected] | 9219d26 | 2011-02-15 21:05:12 | [diff] [blame] | 2640 | SetAsDelegate(contents, NULL); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2641 | RemoveScheduledUpdatesFor(contents->web_contents()); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2642 | |
[email protected] | 41f022e | 2012-01-31 05:56:40 | [diff] [blame] | 2643 | if (find_bar_controller_.get() && index == active_index()) { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2644 | find_bar_controller_->ChangeTabContents(NULL); |
[email protected] | ecc523f6 | 2010-09-28 22:45:40 | [diff] [blame] | 2645 | } |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2646 | |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2647 | if (is_attempting_to_close_browser_) { |
| 2648 | // If this is the last tab with unload handlers, then ProcessPendingTabs |
| 2649 | // would call back into the TabStripModel (which is invoking this method on |
| 2650 | // us). Avoid that by passing in false so that the call to |
| 2651 | // ProcessPendingTabs is delayed. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2652 | ClearUnloadState(contents->web_contents(), false); |
[email protected] | 08f0d61 | 2011-01-13 23:58:21 | [diff] [blame] | 2653 | } |
| 2654 | |
[email protected] | e3a5d5b | 2012-06-22 17:56:46 | [diff] [blame] | 2655 | // Stop observing search model changes for this tab. |
| 2656 | search_delegate_->OnTabDetached(contents); |
| 2657 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2658 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2659 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | e397a447 | 2011-12-21 21:47:50 | [diff] [blame] | 2660 | registrar_.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED, |
[email protected] | 4b19ea5 | 2012-01-02 20:15:25 | [diff] [blame] | 2661 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2662 | registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 2663 | content::Source<WebContents>(contents->web_contents())); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 2664 | } |
| 2665 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2666 | bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, |
| 2667 | bool check_fullscreen) const { |
| 2668 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). On |
| 2669 | // other platforms, we hide some controls when in fullscreen mode. |
| 2670 | bool hide_ui_for_fullscreen = false; |
| 2671 | #if !defined(OS_MACOSX) |
| 2672 | hide_ui_for_fullscreen = check_fullscreen && window_ && |
| 2673 | window_->IsFullscreen(); |
| 2674 | #endif |
| 2675 | |
| 2676 | unsigned int features = FEATURE_INFOBAR | FEATURE_DOWNLOADSHELF; |
| 2677 | |
| 2678 | if (is_type_tabbed()) |
| 2679 | features |= FEATURE_BOOKMARKBAR; |
| 2680 | |
| 2681 | if (!hide_ui_for_fullscreen) { |
| 2682 | if (!is_type_tabbed()) |
| 2683 | features |= FEATURE_TITLEBAR; |
| 2684 | |
| 2685 | if (is_type_tabbed()) |
| 2686 | features |= FEATURE_TABSTRIP; |
| 2687 | |
| 2688 | if (is_type_tabbed()) |
| 2689 | features |= FEATURE_TOOLBAR; |
| 2690 | |
| 2691 | if (!is_app()) |
| 2692 | features |= FEATURE_LOCATIONBAR; |
| 2693 | } |
| 2694 | return !!(features & feature); |
| 2695 | } |
| 2696 | |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 2697 | void Browser::CreateInstantIfNecessary() { |
[email protected] | b35b26b3 | 2011-05-05 20:35:14 | [diff] [blame] | 2698 | if (is_type_tabbed() && InstantController::IsEnabled(profile()) && |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 2699 | !profile()->IsOffTheRecord()) { |
[email protected] | 05cf2fa | 2012-05-29 20:36:06 | [diff] [blame] | 2700 | instant_.reset(new InstantController(this, InstantController::INSTANT)); |
[email protected] | 5aab5e2 | 2010-12-08 22:13:29 | [diff] [blame] | 2701 | instant_unload_handler_.reset(new InstantUnloadHandler(this)); |
[email protected] | 2031cf9d | 2010-10-12 05:05:37 | [diff] [blame] | 2702 | } |
| 2703 | } |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 2704 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2705 | void Browser::UpdateBookmarkBarState(BookmarkBarStateChangeReason reason) { |
| 2706 | BookmarkBar::State state; |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2707 | // 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] | 2708 | if (browser_defaults::bookmarks_enabled && |
| 2709 | profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar) && |
[email protected] | 227393e | 2011-06-29 21:28:39 | [diff] [blame] | 2710 | (!window_ || !window_->IsFullscreen())) { |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2711 | state = BookmarkBar::SHOW; |
| 2712 | } else { |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 2713 | TabContents* tab = chrome::GetActiveTabContents(this); |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2714 | if (tab && tab->bookmark_tab_helper()->ShouldShowBookmarkBar()) |
| 2715 | state = BookmarkBar::DETACHED; |
| 2716 | else |
| 2717 | state = BookmarkBar::HIDDEN; |
| 2718 | } |
[email protected] | 2d4e43a0 | 2012-06-26 00:11:55 | [diff] [blame] | 2719 | |
| 2720 | // Only allow the bookmark bar to be shown in default mode. |
| 2721 | if (!search_model_->mode().is_default()) |
| 2722 | state = BookmarkBar::HIDDEN; |
| 2723 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 2724 | if (state == bookmark_bar_state_) |
| 2725 | return; |
| 2726 | |
| 2727 | bookmark_bar_state_ = state; |
| 2728 | |
| 2729 | if (!window_) |
| 2730 | return; // This is called from the constructor when window_ is NULL. |
| 2731 | |
| 2732 | if (reason == BOOKMARK_BAR_STATE_CHANGE_TAB_SWITCH) { |
| 2733 | // Don't notify BrowserWindow on a tab switch as at the time this is invoked |
| 2734 | // BrowserWindow hasn't yet switched tabs. The BrowserWindow implementations |
| 2735 | // end up querying state once they process the tab switch. |
| 2736 | return; |
| 2737 | } |
| 2738 | |
| 2739 | BookmarkBar::AnimateChangeType animate_type = |
| 2740 | (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? |
| 2741 | BookmarkBar::ANIMATE_STATE_CHANGE : |
| 2742 | BookmarkBar::DONT_ANIMATE_STATE_CHANGE; |
| 2743 | window_->BookmarkBarStateChanged(animate_type); |
| 2744 | } |
[email protected] | 2e2cacc | 2011-07-12 21:54:26 | [diff] [blame] | 2745 | |
[email protected] | 9265536 | 2012-04-20 21:33:17 | [diff] [blame] | 2746 | bool Browser::MaybeCreateBackgroundContents(int route_id, |
| 2747 | WebContents* opener_web_contents, |
| 2748 | const string16& frame_name, |
| 2749 | const GURL& target_url) { |
| 2750 | GURL opener_url = opener_web_contents->GetURL(); |
| 2751 | ExtensionService* extensions_service = profile_->GetExtensionService(); |
| 2752 | |
| 2753 | if (!opener_url.is_valid() || |
| 2754 | frame_name.empty() || |
| 2755 | !extensions_service || |
| 2756 | !extensions_service->is_ready()) |
| 2757 | return false; |
| 2758 | |
| 2759 | // Only hosted apps have web extents, so this ensures that only hosted apps |
| 2760 | // can create BackgroundContents. We don't have to check for background |
| 2761 | // permission as that is checked in RenderMessageFilter when the CreateWindow |
| 2762 | // message is processed. |
| 2763 | const Extension* extension = |
| 2764 | extensions_service->extensions()->GetHostedAppByURL( |
| 2765 | ExtensionURLInfo(opener_url)); |
| 2766 | if (!extension) |
| 2767 | return false; |
| 2768 | |
| 2769 | // No BackgroundContents allowed if BackgroundContentsService doesn't exist. |
| 2770 | BackgroundContentsService* service = |
| 2771 | BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 2772 | if (!service) |
| 2773 | return false; |
| 2774 | |
| 2775 | // Ensure that we're trying to open this from the extension's process. |
| 2776 | SiteInstance* opener_site_instance = opener_web_contents->GetSiteInstance(); |
| 2777 | extensions::ProcessMap* process_map = extensions_service->process_map(); |
| 2778 | if (!opener_site_instance->GetProcess() || |
| 2779 | !process_map->Contains( |
| 2780 | extension->id(), opener_site_instance->GetProcess()->GetID())) { |
| 2781 | return false; |
| 2782 | } |
| 2783 | |
| 2784 | // Only allow a single background contents per app. |
| 2785 | bool allow_js_access = extension->allow_background_js_access(); |
| 2786 | BackgroundContents* existing = |
| 2787 | service->GetAppBackgroundContents(ASCIIToUTF16(extension->id())); |
| 2788 | if (existing) { |
| 2789 | // For non-scriptable background contents, ignore the request altogether, |
| 2790 | // (returning true, so that a regular WebContents isn't created either). |
| 2791 | if (!allow_js_access) |
| 2792 | return true; |
| 2793 | // For scriptable background pages, if one already exists, close it (even |
| 2794 | // if it was specified in the manifest). |
| 2795 | DLOG(INFO) << "Closing existing BackgroundContents for " << opener_url; |
| 2796 | delete existing; |
| 2797 | } |
| 2798 | |
| 2799 | // If script access is not allowed, create the the background contents in a |
| 2800 | // new SiteInstance, so that a separate process is used. |
| 2801 | scoped_refptr<content::SiteInstance> site_instance = |
| 2802 | allow_js_access ? |
| 2803 | opener_site_instance : |
| 2804 | content::SiteInstance::Create(opener_web_contents->GetBrowserContext()); |
| 2805 | |
| 2806 | // Passed all the checks, so this should be created as a BackgroundContents. |
| 2807 | BackgroundContents* contents = service->CreateBackgroundContents( |
| 2808 | site_instance, |
| 2809 | route_id, |
| 2810 | profile_, |
| 2811 | frame_name, |
| 2812 | ASCIIToUTF16(extension->id())); |
| 2813 | |
| 2814 | // When a separate process is used, the original renderer cannot access the |
| 2815 | // new window later, thus we need to navigate the window now. |
| 2816 | if (contents && !allow_js_access) { |
| 2817 | contents->web_contents()->GetController().LoadURL( |
| 2818 | target_url, |
| 2819 | content::Referrer(), |
| 2820 | content::PAGE_TRANSITION_LINK, |
| 2821 | std::string()); // No extra headers. |
| 2822 | } |
| 2823 | |
| 2824 | return contents != NULL; |
[email protected] | afcb4356 | 2011-09-02 23:33:38 | [diff] [blame] | 2825 | } |