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